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