summaryrefslogtreecommitdiffstats
path: root/usr.bin/unexpand
diff options
context:
space:
mode:
authortjr <tjr@FreeBSD.org>2002-04-25 23:04:52 +0000
committertjr <tjr@FreeBSD.org>2002-04-25 23:04:52 +0000
commitdd646660bacb400f8caa5714bb3fa9490dcefc26 (patch)
treedd4e2a89f8e06e25b333fd21a63de209e7585aaa /usr.bin/unexpand
parentb3648bf70664d6603e06feb3687da4b7c8c9ea63 (diff)
downloadFreeBSD-src-dd646660bacb400f8caa5714bb3fa9490dcefc26.zip
FreeBSD-src-dd646660bacb400f8caa5714bb3fa9490dcefc26.tar.gz
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
Diffstat (limited to 'usr.bin/unexpand')
-rw-r--r--usr.bin/unexpand/unexpand.c43
1 files changed, 25 insertions, 18 deletions
diff --git a/usr.bin/unexpand/unexpand.c b/usr.bin/unexpand/unexpand.c
index 1df6c46..37ba49c 100644
--- a/usr.bin/unexpand/unexpand.c
+++ b/usr.bin/unexpand/unexpand.c
@@ -68,7 +68,8 @@ main(argc, argv)
int argc;
char *argv[];
{
- int ch;
+ int ch, failed;
+ char *filename;
nstops = 1;
tabstops[0] = 8;
@@ -89,15 +90,19 @@ main(argc, argv)
argc -= optind;
argv += optind;
- do {
- if (argc > 0) {
- if (freopen(argv[0], "r", stdin) == NULL)
- err(1, "%s", argv[0]);
- argc--, argv++;
- }
+ failed = 0;
+ if (argc == 0)
tabify();
- } while (argc > 0);
- exit(0);
+ else {
+ while ((filename = *argv++) != NULL) {
+ if (freopen(filename, "r", stdin) == NULL) {
+ warn("%s", filename);
+ failed++;
+ } else
+ tabify();
+ }
+ }
+ exit(failed != 0);
}
static void
@@ -116,16 +121,10 @@ tabify()
doneline = ocol = dcol = 0;
while ((ch = getchar()) != EOF) {
- if (ch == '\n') {
- putchar('\n');
- doneline = ocol = dcol = 0;
- continue;
- } else if (ch == ' ' && !doneline) {
+ if (ch == ' ' && !doneline) {
if (++dcol >= limit)
doneline = 1;
continue;
- } else if (ch == '\b' && dcol > 0) {
- dcol--;
} else if (ch == '\t') {
if (nstops == 1) {
dcol = (1 + dcol / tabstops[0]) *
@@ -168,7 +167,14 @@ tabify()
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);
ocol++, dcol++;
}
@@ -181,7 +187,8 @@ tabify()
while ((ch = getchar()) != '\n' && ch != EOF)
putchar(ch);
if (ch == '\n')
- ungetc(ch, stdin);
+ putchar('\n');
+ doneline = ocol = dcol = 0;
}
}
}
OpenPOWER on IntegriCloud