Some minor nits exposed by the Open Group's VSC Lite verification suite:

- When an error occurs processing one file, we must continue to process
  the remaining files.
- Convert trailing whitespace to tabs as appropriate.
- Align backspace handling with what the verification suite expects.

Reviewed by:	mike
This commit is contained in:
Tim J. Robbins 2002-04-25 23:04:52 +00:00
parent 521eb014c8
commit 4596ce3d47
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=95474

View File

@ -68,7 +68,8 @@ main(argc, argv)
int argc; int argc;
char *argv[]; char *argv[];
{ {
int ch; int ch, failed;
char *filename;
nstops = 1; nstops = 1;
tabstops[0] = 8; tabstops[0] = 8;
@ -89,15 +90,19 @@ main(argc, argv)
argc -= optind; argc -= optind;
argv += optind; argv += optind;
do { failed = 0;
if (argc > 0) { if (argc == 0)
if (freopen(argv[0], "r", stdin) == NULL)
err(1, "%s", argv[0]);
argc--, argv++;
}
tabify(); tabify();
} while (argc > 0); else {
exit(0); while ((filename = *argv++) != NULL) {
if (freopen(filename, "r", stdin) == NULL) {
warn("%s", filename);
failed++;
} else
tabify();
}
}
exit(failed != 0);
} }
static void static void
@ -116,16 +121,10 @@ tabify()
doneline = ocol = dcol = 0; doneline = ocol = dcol = 0;
while ((ch = getchar()) != EOF) { while ((ch = getchar()) != EOF) {
if (ch == '\n') { if (ch == ' ' && !doneline) {
putchar('\n');
doneline = ocol = dcol = 0;
continue;
} else if (ch == ' ' && !doneline) {
if (++dcol >= limit) if (++dcol >= limit)
doneline = 1; doneline = 1;
continue; continue;
} else if (ch == '\b' && dcol > 0) {
dcol--;
} else if (ch == '\t') { } else if (ch == '\t') {
if (nstops == 1) { if (nstops == 1) {
dcol = (1 + dcol / tabstops[0]) * dcol = (1 + dcol / tabstops[0]) *
@ -168,7 +167,14 @@ tabify()
ocol++; ocol++;
} }
if (ch != ' ' || dcol > limit) { if (ch == '\b') {
putchar('\b');
if (ocol > 0)
ocol--, dcol--;
} else if (ch == '\n') {
putchar('\n');
doneline = ocol = dcol = 0;
} else if (ch != ' ' || dcol > limit) {
putchar(ch); putchar(ch);
ocol++, dcol++; ocol++, dcol++;
} }
@ -181,7 +187,8 @@ tabify()
while ((ch = getchar()) != '\n' && ch != EOF) while ((ch = getchar()) != '\n' && ch != EOF)
putchar(ch); putchar(ch);
if (ch == '\n') if (ch == '\n')
ungetc(ch, stdin); putchar('\n');
doneline = ocol = dcol = 0;
} }
} }
} }