From 62b47b1e633a781b6f0b1e4ca26770684f349121 Mon Sep 17 00:00:00 2001 From: eivind Date: Tue, 2 Feb 1999 15:48:04 +0000 Subject: Merge from NetBSD: cut.1 rev 1.6 to 1.8 cut.c rev 1.9 to 1.13 * Man page internal cleanups * 8-bit characters cast to unsigned for is*() * Misc cleanups for egcs -Wall compatibility --- usr.bin/cut/cut.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) (limited to 'usr.bin/cut/cut.c') diff --git a/usr.bin/cut/cut.c b/usr.bin/cut/cut.c index 11e9513..1dfd3b0 100644 --- a/usr.bin/cut/cut.c +++ b/usr.bin/cut/cut.c @@ -63,7 +63,8 @@ int sflag; void c_cut __P((FILE *, char *)); void f_cut __P((FILE *, char *)); void get_list __P((char *)); -static void usage __P((void)); +int main __P((int, char **)); +static void usage __P((void)); int main(argc, argv) @@ -74,6 +75,7 @@ main(argc, argv) void (*fcn) __P((FILE *, char *)) = NULL; int ch; + fcn = NULL; setlocale (LC_ALL, ""); dchar = '\t'; /* default delimiter is \t */ @@ -135,8 +137,8 @@ void get_list(list) char *list; { - register int setautostart, start, stop; - register char *pos; + int setautostart, start, stop; + char *pos; char *p; /* @@ -147,19 +149,19 @@ get_list(list) * overlapping lists. We also handle "-3-5" although there's no * real reason too. */ - for (; (p = strsep(&list, ", \t"));) { + for (; (p = strsep(&list, ", \t")) != NULL;) { setautostart = start = stop = 0; if (*p == '-') { ++p; setautostart = 1; } - if (isdigit(*p)) { + if (isdigit((unsigned char)*p)) { start = stop = strtol(p, &p, 10); if (setautostart && start > autostart) autostart = start; } if (*p == '-') { - if (isdigit(p[1])) + if (isdigit((unsigned char)p[1])) stop = strtol(p + 1, &p, 10); if (*p == '-') { ++p; @@ -194,9 +196,10 @@ c_cut(fp, fname) FILE *fp; char *fname; { - register int ch = 0, col; - register char *pos; + int ch, col; + char *pos; + ch = 0; for (;;) { pos = positions + 1; for (col = maxval; col; --col) { @@ -207,12 +210,13 @@ c_cut(fp, fname) if (*pos++) (void)putchar(ch); } - if (ch != '\n') + if (ch != '\n') { if (autostop) while ((ch = getc(fp)) != EOF && ch != '\n') (void)putchar(ch); else while ((ch = getc(fp)) != EOF && ch != '\n'); + } (void)putchar('\n'); } } @@ -222,8 +226,8 @@ f_cut(fp, fname) FILE *fp; char *fname; { - register int ch, field, isdelim; - register char *pos, *p, sep; + int ch, field, isdelim; + char *pos, *p, sep; int output; char lbuf[_POSIX2_LINE_MAX + 1]; @@ -251,12 +255,14 @@ f_cut(fp, fname) (void)putchar(sep); while ((ch = *p++) != '\n' && ch != sep) (void)putchar(ch); - } else - while ((ch = *p++) != '\n' && ch != sep); + } else { + while ((ch = *p++) != '\n' && ch != sep) + continue; + } if (ch == '\n') break; } - if (ch != '\n') + if (ch != '\n') { if (autostop) { if (output) (void)putchar(sep); @@ -264,6 +270,7 @@ f_cut(fp, fname) (void)putchar(ch); } else for (; (ch = *p) != '\n'; ++p); + } (void)putchar('\n'); } } -- cgit v1.1