From: Jan-Simon Pendry Date: Fri, 1 Apr 1994 22:56:27 +0000 (-0800) Subject: prettyness police X-Git-Tag: BSD-4_4_Lite1-Snapshot-Development~11 X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/commitdiff_plain/c3afbeb578ca8977721eacb60b8cd2714beb7ffd prettyness police SCCS-vsn: usr.bin/cmp/cmp.c 8.2 SCCS-vsn: usr.bin/cmp/misc.c 8.2 SCCS-vsn: usr.bin/cmp/extern.h 8.2 SCCS-vsn: usr.bin/cmp/regular.c 8.2 SCCS-vsn: usr.bin/col/col.c 8.2 --- diff --git a/usr/src/usr.bin/cmp/cmp.c b/usr/src/usr.bin/cmp/cmp.c index d3320a3d7b..5f18f11ad8 100644 --- a/usr/src/usr.bin/cmp/cmp.c +++ b/usr/src/usr.bin/cmp/cmp.c @@ -12,23 +12,26 @@ static char copyright[] = #endif /* not lint */ #ifndef lint -static char sccsid[] = "@(#)cmp.c 8.1 (Berkeley) %G%"; +static char sccsid[] = "@(#)cmp.c 8.2 (Berkeley) %G%"; #endif /* not lint */ #include #include + +#include #include -#include -#include #include #include #include +#include + #include "extern.h" int lflag, sflag; static void usage __P((void)); +int main(argc, argv) int argc; char *argv[]; @@ -58,7 +61,7 @@ endargs: argc -= optind; if (lflag && sflag) - err("only one of -l and -s may be specified"); + errx(ERR_EXIT, "only one of -l and -s may be specified"); if (argc < 2 || argc > 4) usage(); @@ -71,28 +74,29 @@ endargs: file1 = "stdin"; } else if ((fd1 = open(file1, O_RDONLY, 0)) < 0) - err("%s: %s", file1, strerror(errno)); + err(ERR_EXIT, "%s", file1); if (strcmp(file2 = argv[1], "-") == 0) { if (special) - err("standard input may only be specified once"); + errx(ERR_EXIT, + "standard input may only be specified once"); special = 1; fd2 = 0; file2 = "stdin"; } else if ((fd2 = open(file2, O_RDONLY, 0)) < 0) - err("%s: %s", file2, strerror(errno)); + err(ERR_EXIT, "%s", file2); skip1 = argc > 2 ? strtol(argv[2], NULL, 10) : 0; skip2 = argc == 4 ? strtol(argv[3], NULL, 10) : 0; if (!special) { if (fstat(fd1, &sb1)) - err("%s: %s", file1, strerror(errno)); + err(ERR_EXIT, "%s", file1); if (!S_ISREG(sb1.st_mode)) special = 1; else { if (fstat(fd2, &sb2)) - err("%s: %s", file2, strerror(errno)); + err(ERR_EXIT, "%s", file2); if (!S_ISREG(sb2.st_mode)) special = 1; } @@ -109,7 +113,8 @@ endargs: static void usage() { + (void)fprintf(stderr, "usage: cmp [-l | s] file1 file2 [skip1 [skip2]]\n"); - exit(2); + exit(ERR_EXIT); } diff --git a/usr/src/usr.bin/cmp/extern.h b/usr/src/usr.bin/cmp/extern.h index 2fa856f7ac..169c100857 100644 --- a/usr/src/usr.bin/cmp/extern.h +++ b/usr/src/usr.bin/cmp/extern.h @@ -4,13 +4,16 @@ * * %sccs.include.redist.c% * - * @(#)extern.h 8.1 (Berkeley) %G% + * @(#)extern.h 8.2 (Berkeley) %G% */ +#define OK_EXIT 0 +#define DIFF_EXIT 1 +#define ERR_EXIT 2 /* error exit code */ + void c_regular __P((int, char *, off_t, off_t, int, char *, off_t, off_t)); void c_special __P((int, char *, off_t, int, char *, off_t)); void diffmsg __P((char *, char *, off_t, off_t)); void eofmsg __P((char *)); -void err __P((const char *fmt, ...)); extern int lflag, sflag; diff --git a/usr/src/usr.bin/cmp/misc.c b/usr/src/usr.bin/cmp/misc.c index 8f7745d37f..3bb2f8a740 100644 --- a/usr/src/usr.bin/cmp/misc.c +++ b/usr/src/usr.bin/cmp/misc.c @@ -6,12 +6,15 @@ */ #ifndef lint -static char sccsid[] = "@(#)misc.c 8.1 (Berkeley) %G%"; +static char sccsid[] = "@(#)misc.c 8.2 (Berkeley) %G%"; #endif /* not lint */ #include + +#include #include #include + #include "extern.h" void @@ -19,8 +22,8 @@ eofmsg(file) char *file; { if (!sflag) - (void)fprintf(stderr, "cmp: EOF on %s\n", file); - exit(1); + warnx("EOF on %s", file); + exit(DIFF_EXIT); } void @@ -31,34 +34,5 @@ diffmsg(file1, file2, byte, line) if (!sflag) (void)printf("%s %s differ: char %qd, line %qd\n", file1, file2, byte, line); - exit(1); -} - -#if __STDC__ -#include -#else -#include -#endif - -void -#if __STDC__ -err(const char *fmt, ...) -#else -err(fmt, va_alist) - char *fmt; - va_dcl -#endif -{ - va_list ap; -#if __STDC__ - va_start(ap, fmt); -#else - va_start(ap); -#endif - (void)fprintf(stderr, "cmp: "); - (void)vfprintf(stderr, fmt, ap); - va_end(ap); - (void)fprintf(stderr, "\n"); - exit(2); - /* NOTREACHED */ + exit(DIFF_EXIT); } diff --git a/usr/src/usr.bin/cmp/regular.c b/usr/src/usr.bin/cmp/regular.c index d06628ae86..ff93e2cb54 100644 --- a/usr/src/usr.bin/cmp/regular.c +++ b/usr/src/usr.bin/cmp/regular.c @@ -6,18 +6,19 @@ */ #ifndef lint -static char sccsid[] = "@(#)regular.c 8.1 (Berkeley) %G%"; +static char sccsid[] = "@(#)regular.c 8.2 (Berkeley) %G%"; #endif /* not lint */ #include #include #include +#include #include -#include #include #include #include + #include "extern.h" void @@ -26,8 +27,8 @@ c_regular(fd1, file1, skip1, len1, fd2, file2, skip2, len2) char *file1, *file2; off_t skip1, len1, skip2, len2; { - register u_char ch, *p1, *p2; - register off_t byte, length, line; + u_char ch, *p1, *p2; + off_t byte, length, line; int dfound; if (sflag && len1 != len2) @@ -46,10 +47,10 @@ c_regular(fd1, file1, skip1, len1, fd2, file2, skip2, len2) if ((p1 = (u_char *)mmap(NULL, (size_t)length, PROT_READ, 0, fd1, skip1)) == (u_char *)-1) - err("%s: %s", file1, strerror(errno)); + err(ERR_EXIT, "%s", file1); if ((p2 = (u_char *)mmap(NULL, (size_t)length, PROT_READ, 0, fd2, skip2)) == (u_char *)-1) - err("%s: %s", file2, strerror(errno)); + err(ERR_EXIT, "%s", file2); dfound = 0; for (byte = line = 1; length--; ++p1, ++p2, ++byte) { @@ -67,5 +68,5 @@ c_regular(fd1, file1, skip1, len1, fd2, file2, skip2, len2) if (len1 != len2) eofmsg (len1 > len2 ? file2 : file1); if (dfound) - exit(1); + exit(DIFF_EXIT); } diff --git a/usr/src/usr.bin/col/col.c b/usr/src/usr.bin/col/col.c index cb19be3162..4bbe87b854 100644 --- a/usr/src/usr.bin/col/col.c +++ b/usr/src/usr.bin/col/col.c @@ -15,13 +15,14 @@ static char copyright[] = #endif /* not lint */ #ifndef lint -static char sccsid[] = "@(#)col.c 8.1 (Berkeley) %G%"; +static char sccsid[] = "@(#)col.c 8.2 (Berkeley) %G%"; #endif /* not lint */ -#include #include +#include #include #include +#include #define BS '\b' /* backspace */ #define TAB '\t' /* tab */ @@ -60,28 +61,34 @@ struct line_str { int l_max_col; /* max column in the line */ }; -LINE *alloc_line(); -void *xmalloc(); - -CSET last_set; /* char_set of last char printed */ -LINE *lines; -int compress_spaces; /* if doing space -> tab conversion */ -int fine; /* if `fine' resolution (half lines) */ -int max_bufd_lines; /* max # lines to keep in memory */ -int nblank_lines; /* # blanks after last flushed line */ -int no_backspaces; /* if not to output any backspaces */ +LINE *alloc_line __P((void)); +void dowarn __P((int)); +void flush_line __P((LINE *)); +void flush_lines __P((int)); +void flush_blanks __P((void)); +void free_line __P((LINE *)); +void usage __P((void)); +void wrerr __P((void)); +void *xmalloc __P((void *, size_t)); + +CSET last_set; /* char_set of last char printed */ +LINE *lines; +int compress_spaces; /* if doing space -> tab conversion */ +int fine; /* if `fine' resolution (half lines) */ +int max_bufd_lines; /* max # lines to keep in memory */ +int nblank_lines; /* # blanks after last flushed line */ +int no_backspaces; /* if not to output any backspaces */ #define PUTC(ch) \ if (putchar(ch) == EOF) \ wrerr(); +int main(argc, argv) int argc; char **argv; { - extern int optind; - extern char *optarg; - register int ch; + int ch; CHAR *c; CSET cur_set; /* current character set */ LINE *l; /* current line */ @@ -216,7 +223,7 @@ main(argc, argv) } } else { if (!warned++) - warn(cur_line); + dowarn(cur_line); cur_line -= nmove; } } @@ -281,6 +288,7 @@ main(argc, argv) exit(0); } +void flush_lines(nflush) int nflush; { @@ -307,6 +315,7 @@ flush_lines(nflush) * is the number of half line feeds, otherwise it is the number of whole line * feeds. */ +void flush_blanks() { int half, i, nb; @@ -335,6 +344,7 @@ flush_blanks() * Write a line to stdout taking care of space to tab conversion (-h flag) * and character set shifts. */ +void flush_line(l) LINE *l; { @@ -362,7 +372,7 @@ flush_line(l) count = (int *)xmalloc((void *)count, (unsigned)sizeof(int) * count_size); } - bzero((char *)count, sizeof(int) * l->l_max_col + 1); + memset((char *)count, 0, sizeof(int) * l->l_max_col + 1); for (i = nchars, c = l->l_line; --i >= 0; c++) count[c->c_column]++; @@ -448,13 +458,15 @@ alloc_line() l = line_freelist; line_freelist = l->l_next; - bzero(l, sizeof(LINE)); - return(l); + memset(l, 0, sizeof(LINE)); + return (l); } +void free_line(l) LINE *l; { + l->l_next = line_freelist; line_freelist = l; } @@ -464,29 +476,33 @@ xmalloc(p, size) void *p; size_t size; { - if (!(p = (void *)realloc(p, size))) { - (void)fprintf(stderr, "col: %s.\n", strerror(ENOMEM)); - exit(1); - } - return(p); + + if (!(p = (void *)realloc(p, size))) + err(1, NULL); + return (p); } +void usage() { + (void)fprintf(stderr, "usage: col [-bfx] [-l nline]\n"); exit(1); } +void wrerr() { + (void)fprintf(stderr, "col: write error.\n"); exit(1); } -warn(line) +void +dowarn(line) int line; { - (void)fprintf(stderr, - "col: warning: can't back up %s.\n", line < 0 ? - "past first line" : "-- line already flushed"); + + warnx("warning: can't back up %s", + line < 0 ? "past first line" : "-- line already flushed"); }