Annotation of 42BSD/ucb/colrm.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.