1*5791Sroot static char *Sccsid = "@(#)colrm.c 4.3 (Berkeley) 02/13/82"; 2986Sbill #include <stdio.h> 3986Sbill /* 4986Sbill COLRM removes unwanted columns from a file 5986Sbill Jeff Schriebman UC Berkeley 11-74 6986Sbill */ 7986Sbill 8986Sbill 9986Sbill main(argc,argv) 10986Sbill char **argv; 11986Sbill { 12986Sbill int first; 13986Sbill register ct,last; 14986Sbill register char c; 15986Sbill char buffer[BUFSIZ]; 16986Sbill 17986Sbill setbuf(stdout, buffer); 18986Sbill first = 20000; 19986Sbill last = -1; 20986Sbill if (argc>1) { 21986Sbill first = getn(*++argv); 22986Sbill last = 20000; 23986Sbill } 24986Sbill if (argc>2) 25986Sbill last = getn(*++argv); 26986Sbill 27986Sbill start: 28986Sbill ct = 0; 29986Sbill loop1: 30*5791Sroot c = getc(stdin); 31*5791Sroot if (feof(stdin)) 32986Sbill goto fin; 331358Sbill if (c == '\t') 341358Sbill ct = (ct + 8) &~ 7; 351358Sbill else if (c == '\b') 361358Sbill ct = ct ? ct - 1 : 0; 371358Sbill else 381358Sbill ct++; 39986Sbill if (c=='\n') { 40986Sbill putc(c,stdout); 41986Sbill goto start; 42986Sbill } 43986Sbill if (ct<first) { 44986Sbill putc(c,stdout); 45986Sbill goto loop1; 46986Sbill } 47986Sbill 48986Sbill /* Loop getting rid of characters */ 49986Sbill for (;ct<last;ct++) { 50*5791Sroot c = getc(stdin); 51*5791Sroot if (feof(stdin)) 52986Sbill goto fin; 53986Sbill if (c=='\n') { 54986Sbill putc(c,stdout); 55986Sbill goto start; 56986Sbill } 57986Sbill } 58986Sbill 59986Sbill /* Output last of the line */ 60*5791Sroot for (;;) { 61*5791Sroot c = getc(stdin); 62*5791Sroot if (feof(stdin)) 63*5791Sroot break; 64986Sbill putc(c,stdout); 65986Sbill if (c=='\n') 66986Sbill goto start; 67986Sbill } 68986Sbill fin: 69986Sbill fflush(stdout); 70986Sbill } 71986Sbill 72986Sbill getn(ap) 73986Sbill char *ap; 74986Sbill { 75986Sbill register int n,c; 76986Sbill register char *p; 77986Sbill 78986Sbill p = ap; 79986Sbill n = 0; 80986Sbill while ((c = *p++) >= '0' && c <= '9') 81986Sbill n = n*10 + c - '0'; 82986Sbill return(n); 83986Sbill } 84