diff options
-rw-r--r-- | bin/cat/cat.c | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/bin/cat/cat.c b/bin/cat/cat.c index 227d11b6c5b..44e33756b1d 100644 --- a/bin/cat/cat.c +++ b/bin/cat/cat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cat.c,v 1.12 2002/02/16 21:27:05 millert Exp $ */ +/* $OpenBSD: cat.c,v 1.13 2002/03/14 21:17:50 millert Exp $ */ /* $NetBSD: cat.c,v 1.11 1995/09/07 06:12:54 jtc Exp $ */ /* @@ -47,18 +47,18 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)cat.c 8.2 (Berkeley) 4/27/95"; #else -static char rcsid[] = "$OpenBSD: cat.c,v 1.12 2002/02/16 21:27:05 millert Exp $"; +static char rcsid[] = "$OpenBSD: cat.c,v 1.13 2002/03/14 21:17:50 millert Exp $"; #endif #endif /* not lint */ #include <sys/param.h> #include <sys/stat.h> -#include <locale.h> #include <ctype.h> #include <err.h> #include <errno.h> #include <fcntl.h> +#include <locale.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -111,6 +111,7 @@ main(argc, argv) (void)fprintf(stderr, "usage: %s [-benstuv] [-] [file ...]\n", __progname); exit(1); + /* NOTREACHED */ } argv += optind; @@ -158,29 +159,23 @@ cook_buf(fp) line = gobble = 0; for (prev = '\n'; (ch = getc(fp)) != EOF; prev = ch) { if (prev == '\n') { - if (ch == '\n') { - if (sflag) { - if (!gobble && putchar(ch) == EOF) - break; + if (sflag) { + if (ch == '\n') { + if (gobble) + continue; gobble = 1; - continue; - } - if (nflag && !bflag) { - (void)fprintf(stdout, "%6d\t", ++line); - if (ferror(stdout)) - break; - } - } else if (nflag) { + } else + gobble = 0; + } + if (nflag && (!bflag || ch != '\n')) { (void)fprintf(stdout, "%6d\t", ++line); if (ferror(stdout)) break; } } - gobble = 0; if (ch == '\n') { - if (eflag) - if (putchar('$') == EOF) - break; + if (eflag && putchar('$') == EOF) + break; } else if (ch == '\t') { if (tflag) { if (putchar('^') == EOF || putchar('I') == EOF) |