1 static char *Sccsid = "@(#)colrm.c 4.2 (Berkeley) 10/10/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 if (c == '\t') 33 ct = (ct + 8) &~ 7; 34 else if (c == '\b') 35 ct = ct ? ct - 1 : 0; 36 else 37 ct++; 38 if (c=='\n') { 39 putc(c,stdout); 40 goto start; 41 } 42 if (ct<first) { 43 putc(c,stdout); 44 goto loop1; 45 } 46 47 /* Loop getting rid of characters */ 48 for (;ct<last;ct++) { 49 if ((c=getc(stdin))<0) 50 goto fin; 51 if (c=='\n') { 52 putc(c,stdout); 53 goto start; 54 } 55 } 56 57 /* Output last of the line */ 58 while ((c=getc(stdin))>0) { 59 putc(c,stdout); 60 if (c=='\n') 61 goto start; 62 } 63 fin: 64 fflush(stdout); 65 } 66 67 getn(ap) 68 char *ap; 69 { 70 register int n,c; 71 register char *p; 72 73 p = ap; 74 n = 0; 75 while ((c = *p++) >= '0' && c <= '9') 76 n = n*10 + c - '0'; 77 return(n); 78 } 79