prettyness police
authorJan-Simon Pendry <pendry@ucbvax.Berkeley.EDU>
Fri, 1 Apr 1994 23:28:20 +0000 (15:28 -0800)
committerJan-Simon Pendry <pendry@ucbvax.Berkeley.EDU>
Fri, 1 Apr 1994 23:28:20 +0000 (15:28 -0800)
SCCS-vsn: usr.bin/column/column.c 8.2
SCCS-vsn: usr.bin/comm/comm.c 8.2

usr/src/usr.bin/column/column.c
usr/src/usr.bin/comm/comm.c

index 92642c3..e3081f8 100644 (file)
@@ -12,22 +12,23 @@ static char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)column.c   8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)column.c   8.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #include <sys/ioctl.h>
 #endif /* not lint */
 
 #include <sys/types.h>
 #include <sys/ioctl.h>
-#include <errno.h>
+
+#include <ctype.h>
+#include <err.h>
+#include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <ctype.h>
 
 void  c_columnate __P((void));
 void *emalloc __P((int));
 void  input __P((FILE *));
 void  maketbl __P((void));
 
 void  c_columnate __P((void));
 void *emalloc __P((int));
 void  input __P((FILE *));
 void  maketbl __P((void));
-void  nomem __P((void));
 void  print __P((void));
 void  r_columnate __P((void));
 void  usage __P((void));
 void  print __P((void));
 void  r_columnate __P((void));
 void  usage __P((void));
@@ -85,8 +86,7 @@ main(argc, argv)
                        input(fp);
                        (void)fclose(fp);
                } else {
                        input(fp);
                        (void)fclose(fp);
                } else {
-                       (void)fprintf(stderr, "column: %s: %s\n", *argv,
-                           strerror(errno));
+                       warn("%s", *argv);
                        eval = 1;
                }
 
                        eval = 1;
                }
 
@@ -108,8 +108,7 @@ main(argc, argv)
 void
 c_columnate()
 {
 void
 c_columnate()
 {
-       register int chcnt, col, cnt, numcols;
-       int endcol;
+       int chcnt, col, cnt, endcol, numcols;
        char **lp;
 
        maxlength = (maxlength + TAB) & ~(TAB - 1);
        char **lp;
 
        maxlength = (maxlength + TAB) & ~(TAB - 1);
@@ -138,8 +137,7 @@ c_columnate()
 void
 r_columnate()
 {
 void
 r_columnate()
 {
-       register int base, chcnt, cnt, col;
-       int endcol, numcols, numrows, row;
+       int base, chcnt, cnt, col, endcol, numcols, numrows, row;
 
        maxlength = (maxlength + TAB) & ~(TAB - 1);
        numcols = termwidth / maxlength;
 
        maxlength = (maxlength + TAB) & ~(TAB - 1);
        numcols = termwidth / maxlength;
@@ -166,8 +164,8 @@ r_columnate()
 void
 print()
 {
 void
 print()
 {
-       register int cnt;
-       register char **lp;
+       int cnt;
+       char **lp;
 
        for (cnt = entries, lp = list; cnt--; ++lp)
                (void)printf("%s\n", *lp);
 
        for (cnt = entries, lp = list; cnt--; ++lp)
                (void)printf("%s\n", *lp);
@@ -182,9 +180,9 @@ typedef struct _tbl {
 void
 maketbl()
 {
 void
 maketbl()
 {
-       register TBL *t;
-       register int coloff, cnt;
-       register char *p, **lp;
+       TBL *t;
+       int coloff, cnt;
+       char *p, **lp;
        int *lens, maxcols;
        TBL *tbl;
        char **cols;
        int *lens, maxcols;
        TBL *tbl;
        char **cols;
@@ -200,9 +198,9 @@ maketbl()
                                    DEFCOLS * sizeof(char *))) ||
                                    !(lens = realloc(lens,
                                    (u_int)maxcols + DEFCOLS * sizeof(int))))
                                    DEFCOLS * sizeof(char *))) ||
                                    !(lens = realloc(lens,
                                    (u_int)maxcols + DEFCOLS * sizeof(int))))
-                                       nomem();
-                               bzero((char *)lens + maxcols * sizeof(int),
-                                   DEFCOLS * sizeof(int));
+                                       err(1, NULL);
+                               memset((char *)lens + maxcols * sizeof(int),
+                                   0, DEFCOLS * sizeof(int));
                                maxcols += DEFCOLS;
                        }
                t->list = emalloc(coloff * sizeof(char *));
                                maxcols += DEFCOLS;
                        }
                t->list = emalloc(coloff * sizeof(char *));
@@ -223,16 +221,15 @@ maketbl()
 }
 
 #define        DEFNUM          1000
 }
 
 #define        DEFNUM          1000
-#define        MAXLINELEN      (2048 + 1)
+#define        MAXLINELEN      (LINE_MAX + 1)
 
 void
 input(fp)
 
 void
 input(fp)
-       register FILE *fp;
+       FILE *fp;
 {
        static int maxentry;
 {
        static int maxentry;
-       register int len;
-       register char *p;
-       char buf[MAXLINELEN];
+       int len;
+       char *p, buf[MAXLINELEN];
 
        if (!list)
                list = emalloc((maxentry = DEFNUM) * sizeof(char *));
 
        if (!list)
                list = emalloc((maxentry = DEFNUM) * sizeof(char *));
@@ -240,8 +237,8 @@ input(fp)
                for (p = buf; *p && isspace(*p); ++p);
                if (!*p)
                        continue;
                for (p = buf; *p && isspace(*p); ++p);
                if (!*p)
                        continue;
-               if (!(p = index(p, '\n'))) {
-                       (void)fprintf(stderr, "column: line too long.\n");
+               if (!(p = strchr(p, '\n'))) {
+                       warnx("line too long");
                        eval = 1;
                        continue;
                }
                        eval = 1;
                        continue;
                }
@@ -253,7 +250,7 @@ input(fp)
                        maxentry += DEFNUM;
                        if (!(list = realloc(list,
                            (u_int)maxentry * sizeof(char *))))
                        maxentry += DEFNUM;
                        if (!(list = realloc(list,
                            (u_int)maxentry * sizeof(char *))))
-                               nomem();
+                               err(1, NULL);
                }
                list[entries++] = strdup(buf);
        }
                }
                list[entries++] = strdup(buf);
        }
@@ -266,21 +263,15 @@ emalloc(size)
        char *p;
 
        if (!(p = malloc(size)))
        char *p;
 
        if (!(p = malloc(size)))
-               nomem();
-       bzero(p, size);
-       return(p);
-}
-
-void
-nomem()
-{
-       (void)fprintf(stderr, "column: out of memory.\n");
-       exit(1);
+               err(1, NULL);
+       memset(p, 0, size);
+       return (p);
 }
 
 void
 usage()
 {
 }
 
 void
 usage()
 {
+
        (void)fprintf(stderr,
            "usage: column [-tx] [-c columns] [file ...]\n");
        exit(1);
        (void)fprintf(stderr,
            "usage: column [-tx] [-c columns] [file ...]\n");
        exit(1);
index 6a08fb8..37e17be 100644 (file)
@@ -15,7 +15,7 @@ static char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)comm.c     8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)comm.c     8.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <fcntl.h>
 #endif /* not lint */
 
 #include <fcntl.h>
@@ -25,20 +25,24 @@ static char sccsid[] = "@(#)comm.c  8.1 (Berkeley) %G%";
 #include <stdlib.h>
 #include <string.h>
 
 #include <stdlib.h>
 #include <string.h>
 
-#define        MAXLINELEN      (_POSIX2_LINE_MAX + 1)
+#define        MAXLINELEN      (LINE_MAX + 1)
 
 char *tabs[] = { "", "\t", "\t\t" };
 
 
 char *tabs[] = { "", "\t", "\t\t" };
 
-main(argc,argv)
+FILE   *file __P((char *));
+void   show __P((FILE *, char *, char *));
+void   usage __P((void));
+
+int
+main(argc, argv)
        int argc;
        char *argv[];
 {
        int argc;
        char *argv[];
 {
-       register int comp, file1done, file2done, read1, read2;
-       register char *col1, *col2, *col3;
+       int comp, file1done, file2done, read1, read2;
        int ch, flag1, flag2, flag3;
        int ch, flag1, flag2, flag3;
-       FILE *fp1, *fp2, *file();
+       FILE *fp1, *fp2;
+       char *col1, *col2, *col3;
        char **p, line1[MAXLINELEN], line2[MAXLINELEN];
        char **p, line1[MAXLINELEN], line2[MAXLINELEN];
-       extern int optind;
 
        flag1 = flag2 = flag3 = 1;
        while ((ch = getopt(argc, argv, "-123")) != EOF)
 
        flag1 = flag2 = flag3 = 1;
        while ((ch = getopt(argc, argv, "-123")) != EOF)
@@ -121,10 +125,12 @@ done:     argc -= optind;
        exit(0);
 }
 
        exit(0);
 }
 
+void
 show(fp, offset, buf)
        FILE *fp;
        char *offset, *buf;
 {
 show(fp, offset, buf)
        FILE *fp;
        char *offset, *buf;
 {
+
        do {
                (void)printf("%s%s", offset, buf);
        } while (fgets(buf, MAXLINELEN, fp));
        do {
                (void)printf("%s%s", offset, buf);
        } while (fgets(buf, MAXLINELEN, fp));
@@ -137,16 +143,18 @@ file(name)
        FILE *fp;
 
        if (!strcmp(name, "-"))
        FILE *fp;
 
        if (!strcmp(name, "-"))
-               return(stdin);
+               return (stdin);
        if ((fp = fopen(name, "r")) == NULL) {
                (void)fprintf(stderr, "comm: %s: %s\n", name, strerror(errno));
                exit(1);
        }
        if ((fp = fopen(name, "r")) == NULL) {
                (void)fprintf(stderr, "comm: %s: %s\n", name, strerror(errno));
                exit(1);
        }
-       return(fp);
+       return (fp);
 }
 
 }
 
+void
 usage()
 {
 usage()
 {
+
        (void)fprintf(stderr, "usage: comm [-123] file1 file2\n");
        exit(1);
 }
        (void)fprintf(stderr, "usage: comm [-123] file1 file2\n");
        exit(1);
 }