prettyness police
authorJan-Simon Pendry <pendry@ucbvax.Berkeley.EDU>
Fri, 1 Apr 1994 22:56:27 +0000 (14:56 -0800)
committerJan-Simon Pendry <pendry@ucbvax.Berkeley.EDU>
Fri, 1 Apr 1994 22:56:27 +0000 (14:56 -0800)
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

usr/src/usr.bin/cmp/cmp.c
usr/src/usr.bin/cmp/extern.h
usr/src/usr.bin/cmp/misc.c
usr/src/usr.bin/cmp/regular.c
usr/src/usr.bin/col/col.c

index d3320a3..5f18f11 100644 (file)
@@ -12,23 +12,26 @@ static char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #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 <sys/types.h>
 #include <sys/stat.h>
 #endif /* not lint */
 
 #include <sys/types.h>
 #include <sys/stat.h>
+
+#include <err.h>
 #include <fcntl.h>
 #include <fcntl.h>
-#include <errno.h>
-#include <unistd.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
+
 #include "extern.h"
 
 int    lflag, sflag;
 
 static void usage __P((void));
 
 #include "extern.h"
 
 int    lflag, sflag;
 
 static void usage __P((void));
 
+int
 main(argc, argv)
        int argc;
        char *argv[];
 main(argc, argv)
        int argc;
        char *argv[];
@@ -58,7 +61,7 @@ endargs:
        argc -= optind;
 
        if (lflag && sflag)
        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();
 
        if (argc < 2 || argc > 4)
                usage();
@@ -71,28 +74,29 @@ endargs:
                file1 = "stdin";
        }
        else if ((fd1 = open(file1, O_RDONLY, 0)) < 0)
                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)
        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)
                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))
 
        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))
                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;
                }
                        if (!S_ISREG(sb2.st_mode))
                                special = 1;
                }
@@ -109,7 +113,8 @@ endargs:
 static void
 usage()
 {
 static void
 usage()
 {
+
        (void)fprintf(stderr,
            "usage: cmp [-l | s] file1 file2 [skip1 [skip2]]\n");
        (void)fprintf(stderr,
            "usage: cmp [-l | s] file1 file2 [skip1 [skip2]]\n");
-       exit(2);
+       exit(ERR_EXIT);
 }
 }
index 2fa856f..169c100 100644 (file)
@@ -4,13 +4,16 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %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   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;
 
 extern int lflag, sflag;
index 8f7745d..3bb2f8a 100644 (file)
@@ -6,12 +6,15 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)misc.c     8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)misc.c     8.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
+
+#include <err.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdlib.h>
+
 #include "extern.h"
 
 void
 #include "extern.h"
 
 void
@@ -19,8 +22,8 @@ eofmsg(file)
        char *file;
 {
        if (!sflag)
        char *file;
 {
        if (!sflag)
-               (void)fprintf(stderr, "cmp: EOF on %s\n", file);
-       exit(1);
+               warnx("EOF on %s", file);
+       exit(DIFF_EXIT);
 }
 
 void
 }
 
 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);
        if (!sflag)
                (void)printf("%s %s differ: char %qd, line %qd\n",
                    file1, file2, byte, line);
-       exit(1);
-}
-
-#if __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#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);
 }
 }
index d06628a..ff93e2c 100644 (file)
@@ -6,18 +6,19 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)regular.c  8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)regular.c  8.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #include <sys/mman.h>
 #include <sys/stat.h>
 
 #endif /* not lint */
 
 #include <sys/param.h>
 #include <sys/mman.h>
 #include <sys/stat.h>
 
+#include <err.h>
 #include <limits.h>
 #include <limits.h>
-#include <errno.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+
 #include "extern.h"
 
 void
 #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;
 {
        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)
        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)
 
        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)
        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) {
 
        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)
        if (len1 != len2)
                eofmsg (len1 > len2 ? file2 : file1);
        if (dfound)
-               exit(1);
+               exit(DIFF_EXIT);
 }
 }
index cb19be3..4bbe87b 100644 (file)
@@ -15,13 +15,14 @@ static char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #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 */
 
 #endif /* not lint */
 
-#include <errno.h>
 #include <ctype.h>
 #include <ctype.h>
+#include <err.h>
 #include <string.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdio.h>
+#include <stdlib.h>
 
 #define        BS      '\b'            /* backspace */
 #define        TAB     '\t'            /* tab */
 
 #define        BS      '\b'            /* backspace */
 #define        TAB     '\t'            /* tab */
@@ -60,28 +61,34 @@ struct line_str {
        int     l_max_col;              /* max column in the line */
 };
 
        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();
 
 
 #define        PUTC(ch) \
        if (putchar(ch) == EOF) \
                wrerr();
 
+int
 main(argc, argv)
        int argc;
        char **argv;
 {
 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 */
        CHAR *c;
        CSET cur_set;                   /* current character set */
        LINE *l;                        /* current line */
@@ -216,7 +223,7 @@ main(argc, argv)
                                                }
                                        } else {
                                                if (!warned++)
                                                }
                                        } else {
                                                if (!warned++)
-                                                       warn(cur_line);
+                                                       dowarn(cur_line);
                                                cur_line -= nmove;
                                        }
                                }
                                                cur_line -= nmove;
                                        }
                                }
@@ -281,6 +288,7 @@ main(argc, argv)
        exit(0);
 }
 
        exit(0);
 }
 
+void
 flush_lines(nflush)
        int nflush;
 {
 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.
  */
  * is the number of half line feeds, otherwise it is the number of whole line
  * feeds.
  */
+void
 flush_blanks()
 {
        int half, i, nb;
 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.
  */
  * Write a line to stdout taking care of space to tab conversion (-h flag)
  * and character set shifts.
  */
+void
 flush_line(l)
        LINE *l;
 {
 flush_line(l)
        LINE *l;
 {
@@ -362,7 +372,7 @@ flush_line(l)
                        count = (int *)xmalloc((void *)count,
                            (unsigned)sizeof(int) * count_size);
                }
                        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]++;
 
                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;
 
        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;
 {
 free_line(l)
        LINE *l;
 {
+
        l->l_next = line_freelist;
        line_freelist = l;
 }
        l->l_next = line_freelist;
        line_freelist = l;
 }
@@ -464,29 +476,33 @@ xmalloc(p, size)
        void *p;
        size_t 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()
 {
 usage()
 {
+
        (void)fprintf(stderr, "usage: col [-bfx] [-l nline]\n");
        exit(1);
 }
 
        (void)fprintf(stderr, "usage: col [-bfx] [-l nline]\n");
        exit(1);
 }
 
+void
 wrerr()
 {
 wrerr()
 {
+
        (void)fprintf(stderr, "col: write error.\n");
        exit(1);
 }
 
        (void)fprintf(stderr, "col: write error.\n");
        exit(1);
 }
 
-warn(line)
+void
+dowarn(line)
        int 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");
 }
 }