changed INDEX operator to handle multiple subscript arrays correctly
[unix-history] / usr / src / usr.bin / wc / wc.c
index 30d6b81..f6f9dfb 100644 (file)
@@ -1,4 +1,4 @@
-static char *sccsid = "@(#)wc.c        4.1 (Berkeley) %G%";
+static char *sccsid = "@(#)wc.c        4.4 (Berkeley) %G%";
 /* wc line and word count */
 
 #include <stdio.h>
 /* wc line and word count */
 
 #include <stdio.h>
@@ -26,6 +26,8 @@ char **argv;
                        break;
                case 's':
                        lpp = atoi(argv[1]+2);
                        break;
                case 's':
                        lpp = atoi(argv[1]+2);
+                       if (lpp <= 0)
+                               goto usage;
                        break;
                case 'v':
                        verbose++;
                        break;
                case 'v':
                        verbose++;
@@ -40,7 +42,13 @@ char **argv;
                                cps = 10;
                        else
                                cps = baud / 10;
                                cps = 10;
                        else
                                cps = baud / 10;
+                       if (cps <= 0)
+                               goto usage;
                        break;
                        break;
+               default:
+               usage:
+                       fprintf(stderr, "Usage: wc [-lwcpt] [-v] [-u] [-spagesize] [-bbaudrate]\n");
+                       exit(1);
                }
                argc--;
                argv++;
                }
                argc--;
                argv++;
@@ -156,7 +164,7 @@ long num;
        if (verbose)
                printf("%ld\t", num);
        else
        if (verbose)
                printf("%ld\t", num);
        else
-               printf("%7ld", num);
+               printf(" %7ld", num);
 }
 
 prttime(secs)
 }
 
 prttime(secs)
@@ -183,5 +191,8 @@ long secs;
        } else {
                units = "se";
        }
        } else {
                units = "se";
        }
-       printf("%4.1f %2s\t", t, units);
+       if (verbose)
+               printf("%4.1f %2s\t", t, units);
+       else
+               printf(" %4.1f %2s", t, units);
 }
 }