Annotation of 43BSDTahoe/ucb/colrm.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1980 Regents of the University of California.
        !             3:  * All rights reserved.
        !             4:  *
        !             5:  * Redistribution and use in source and binary forms are permitted
        !             6:  * provided that the above copyright notice and this paragraph are
        !             7:  * duplicated in all such forms and that any documentation,
        !             8:  * advertising materials, and other materials related to such
        !             9:  * distribution and use acknowledge that the software was developed
        !            10:  * by the University of California, Berkeley.  The name of the
        !            11:  * University may not be used to endorse or promote products derived
        !            12:  * from this software without specific prior written permission.
        !            13:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
        !            14:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
        !            15:  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
        !            16:  */
        !            17: 
        !            18: #ifndef lint
        !            19: char copyright[] =
        !            20: "@(#) Copyright (c) 1980 Regents of the University of California.\n\
        !            21:  All rights reserved.\n";
        !            22: #endif /* not lint */
        !            23: 
        !            24: #ifndef lint
        !            25: static char sccsid[] = "@(#)colrm.c    5.3 (Berkeley) 6/29/88";
        !            26: #endif /* not lint */
        !            27: 
        !            28: #include <stdio.h>
        !            29: /*
        !            30: COLRM removes unwanted columns from a file
        !            31:        Jeff Schriebman  UC Berkeley 11-74
        !            32: */
        !            33: 
        !            34: 
        !            35: main(argc,argv)
        !            36: char **argv;
        !            37: {
        !            38:        register c, ct, first, last;
        !            39: 
        !            40:        first = 0;
        !            41:        last = 0;
        !            42:        if (argc > 1)
        !            43:                first = getn(*++argv);
        !            44:        if (argc > 2)
        !            45:                last = getn(*++argv);
        !            46: 
        !            47: start:
        !            48:        ct = 0;
        !            49: loop1:
        !            50:        c = getc(stdin);
        !            51:        if (feof(stdin))
        !            52:                goto fin;
        !            53:        if (c == '\t')
        !            54:                ct = (ct + 8) & ~7;
        !            55:        else if (c == '\b')
        !            56:                ct = ct ? ct - 1 : 0;
        !            57:        else
        !            58:                ct++;
        !            59:        if (c == '\n') {
        !            60:                putc(c, stdout);
        !            61:                goto start;
        !            62:        }
        !            63:        if (!first || ct < first) {
        !            64:                putc(c, stdout);
        !            65:                goto loop1;
        !            66:        }
        !            67: 
        !            68: /* Loop getting rid of characters */
        !            69:        while (!last || ct < last) {
        !            70:                c = getc(stdin);
        !            71:                if (feof(stdin))
        !            72:                        goto fin;
        !            73:                if (c == '\n') {
        !            74:                        putc(c, stdout);
        !            75:                        goto start;
        !            76:                }
        !            77:                if (c == '\t')
        !            78:                        ct = (ct + 8) & ~7;
        !            79:                else if (c == '\b')
        !            80:                        ct = ct ? ct - 1 : 0;
        !            81:                else
        !            82:                        ct++;
        !            83:        }
        !            84: 
        !            85: /* Output last of the line */
        !            86:        for (;;) {
        !            87:                c = getc(stdin);
        !            88:                if (feof(stdin))
        !            89:                        break;
        !            90:                putc(c, stdout);
        !            91:                if (c == '\n')
        !            92:                        goto start;
        !            93:        }
        !            94: fin:
        !            95:        fflush(stdout);
        !            96:        exit(0);
        !            97: }
        !            98: 
        !            99: getn(ap)
        !           100: char *ap;
        !           101: {
        !           102:        register int n,c;
        !           103:        register char *p;
        !           104: 
        !           105:        p = ap;
        !           106:        n = 0;
        !           107:        while ((c = *p++) >= '0' && c <= '9')
        !           108:                n = n*10 + c - '0';
        !           109:        return(n);
        !           110: }

unix.superglobalmegacorp.com

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