1 static char *sccsid = "@(#)colrm.c 4.1 (Berkeley) 10/01/80"; 2 #include <stdio.h> 3 /* 4 COLRM removes unwanted columns from a file 5 Jeff Schriebman UC Berkeley 11-74 6 */ 7 8 9 main(argc,argv) 10 char **argv; 11 { 12 int first; 13 register ct,last; 14 register char c; 15 char buffer[BUFSIZ]; 16 17 setbuf(stdout, buffer); 18 first = 20000; 19 last = -1; 20 if (argc>1) { 21 first = getn(*++argv); 22 last = 20000; 23 } 24 if (argc>2) 25 last = getn(*++argv); 26 27 start: 28 ct = 0; 29 loop1: 30 if ((c=getc(stdin))<0) 31 goto fin; 32 ct++; 33 if (c=='\n') { 34 putc(c,stdout); 35 goto start; 36 } 37 if (ct<first) { 38 putc(c,stdout); 39 goto loop1; 40 } 41 42 /* Loop getting rid of characters */ 43 for (;ct<last;ct++) { 44 if ((c=getc(stdin))<0) 45 goto fin; 46 if (c=='\n') { 47 putc(c,stdout); 48 goto start; 49 } 50 } 51 52 /* Output last of the line */ 53 while ((c=getc(stdin))>0) { 54 putc(c,stdout); 55 if (c=='\n') 56 goto start; 57 } 58 fin: 59 fflush(stdout); 60 } 61 62 getn(ap) 63 char *ap; 64 { 65 register int n,c; 66 register char *p; 67 68 p = ap; 69 n = 0; 70 while ((c = *p++) >= '0' && c <= '9') 71 n = n*10 + c - '0'; 72 return(n); 73 } 74