home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Distributions / ucb / spencer_2bsd.tar.gz / 2bsd.tar / src / num.c < prev    next >
C/C++ Source or Header  |  1980-02-17  |  632b  |  40 lines

  1. /* Copyright (c) 1979 Regents of the University of California */
  2. #include "stdio.h"
  3. /*
  4.  * number - a cat like program which prints lines like the editor '#'' command
  5.  *
  6.  * Bill Joy UCB June 28, 1977
  7.  */
  8.  
  9. int    lino;
  10.  
  11. main(argc, argv)
  12.     int argc;
  13.     char *argv[];
  14. {
  15.     register c;
  16.     register lastc;
  17.  
  18.     argc--, argv++;
  19.     do {
  20.         if (argc > 0) {
  21.             if (freopen(argv[0], "r", stdin) == NULL) {
  22.                 perror(argv[0]);
  23.                 exit(1);
  24.             }
  25.             argc--, argv++;
  26.         }
  27.         lastc = '\n';
  28.         for (;;) {
  29.             c = getchar();
  30.             if (c == -1)
  31.                 break;
  32.             if (lastc == '\n')
  33.                 printf("%6d  ", ++lino);
  34.             lastc = c;
  35.             putchar(c);
  36.         }
  37.     } while (argc > 0);
  38.     exit(0);
  39. }
  40.