|
|
1.1 ! root 1: #include "stdio.h" ! 2: #define formfeed 0xc ! 3: ! 4: /* ! 5: * number - a cat like program which prints a file with line ! 6: * numbers. Printing of numbers is suppressed on blank ! 7: * lines. ! 8: * ! 9: * Original Version by William Joy, June 1977 ! 10: * Updated October 1979 by M. Kirk McKusick ! 11: */ ! 12: main(ac, av) ! 13: int ac; ! 14: char *av[]; ! 15: { ! 16: register int argc = ac; ! 17: register char **argv = av; ! 18: register int lino; ! 19: register char *lineptr; ! 20: register FILE *STDOUT = stdout; ! 21: register FILE *STDIN = stdin; ! 22: char line[512]; ! 23: extern char _sibuf[], _sobuf[]; ! 24: ! 25: argv++; ! 26: argc--; ! 27: lino = 1; ! 28: setbuf(STDIN,_sibuf); ! 29: setbuf(STDOUT,_sobuf); ! 30: do ! 31: { ! 32: if (argc) ! 33: if (freopen(*argv++, "r", STDIN) == NULL) ! 34: { ! 35: perror(*--argv); ! 36: exit(1); ! 37: } ! 38: for(;;) ! 39: { ! 40: lineptr = line; ! 41: *lineptr = 0; ! 42: fscanf(STDIN,"%[^\n]",lineptr); ! 43: if (feof(STDIN)) ! 44: break; ! 45: if (*lineptr == formfeed) ! 46: putc(*lineptr++,STDOUT); ! 47: if (!*lineptr) ! 48: putc('\n',STDOUT); ! 49: else ! 50: fprintf(STDOUT,"%6d %s\n",lino,lineptr); ! 51: lino++; ! 52: getc(STDIN); ! 53: } ! 54: } ! 55: while (--argc > 0); ! 56: exit(); ! 57: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.