update to source on arpa
authorKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Fri, 22 Oct 1982 15:47:13 +0000 (07:47 -0800)
committerKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Fri, 22 Oct 1982 15:47:13 +0000 (07:47 -0800)
SCCS-vsn: old/pr/pr.c 4.2

usr/src/old/pr/pr.c

index e9b3638..e9436f2 100644 (file)
@@ -1,4 +1,5 @@
-static char *sccsid = "@(#)pr.c        4.1 (Berkeley) %G%";
+static char *sccsid = "@(#)pr.c        4.2 (Berkeley) %G%";
+
 /*
  *   print file with headings
  *  2+head+2+page[56]+5
 /*
  *   print file with headings
  *  2+head+2+page[56]+5
@@ -61,46 +62,54 @@ char **argv;
                argv++;
                if (**argv == '-') {
                        switch (*++*argv) {
                argv++;
                if (**argv == '-') {
                        switch (*++*argv) {
-                       case 'h':
+                       case 'h':               /* define page header */
                                if (argc>=2) {
                                        header = *++argv;
                                        argc--;
                                }
                                continue;
 
                                if (argc>=2) {
                                        header = *++argv;
                                        argc--;
                                }
                                continue;
 
-                       case 't':
+                       case 't':               /* don't print page headers */
                                ntflg++;
                                continue;
 
                                ntflg++;
                                continue;
 
-                       case 'f':
+                       case 'f':               /* use form feeds */
                                fflg++;
                                plength = 60;
                                continue;
 
                                fflg++;
                                plength = 60;
                                continue;
 
-                       case 'l':
+                       case 'l':               /* length of page */
                                length = atoi(++*argv);
                                continue;
 
                                length = atoi(++*argv);
                                continue;
 
-                       case 'w':
+                       case 'w':               /* width of page */
                                width = atoi(++*argv);
                                continue;
 
                                width = atoi(++*argv);
                                continue;
 
-                       case 's':
+                       case 's':               /* col separator */
                                if (*++*argv)
                                        tabc = **argv;
                                else
                                        tabc = '\t';
                                continue;
 
                                if (*++*argv)
                                        tabc = **argv;
                                else
                                        tabc = '\t';
                                continue;
 
-                       case 'm':
+                       case 'm':               /* all files at once */
                                mflg++;
                                continue;
 
                        default:
                                mflg++;
                                continue;
 
                        default:
-                               ncol = atoi(*argv);
+                               if (numeric(*argv)) {   /* # of cols */
+                                       if ((ncol = atoi(*argv)) == 0) {
+                                               fprintf(stderr, "can't print 0 cols, using 1 instead.\n");
+                                               ncol = 1;
+                                       }
+                               } else {
+                                       fprintf(stderr, "pr: bad key %s\n", *argv);
+                                       exit(1);
+                               }
                                continue;
                        }
                                continue;
                        }
-               } else if (**argv == '+') {
+               } else if (**argv == '+') {     /* start at page ++*argv */
                        fpage = atoi(++*argv);
                } else {
                        print(*argv, argv);
                        fpage = atoi(++*argv);
                } else {
                        print(*argv, argv);
@@ -122,6 +131,18 @@ done()
        exit(0);
 }
 
        exit(0);
 }
 
+/* numeric -- returns 1 if str is numeric, elsewise 0 */
+numeric(str)
+       char    *str;
+{
+       for (; *str ; str++) {
+               if (*str > '9' || *str < '0') {
+                       return(0);
+               }
+       }
+       return(1);
+}
+
 onintr()
 {
 
 onintr()
 {
 
@@ -142,6 +163,7 @@ fixtty()
        chmod(tty, 0600);
 }
 
        chmod(tty, 0600);
 }
 
+/* print -- print file */
 print(fp, argp)
 char *fp;
 char **argp;
 print(fp, argp)
 char *fp;
 char **argp;