| 1 | /* |
| 2 | * Copyright (c) 1980 Regents of the University of California. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * %sccs.include.redist.c% |
| 6 | */ |
| 7 | |
| 8 | #ifndef lint |
| 9 | char copyright[] = |
| 10 | "@(#) Copyright (c) 1980 Regents of the University of California.\n\ |
| 11 | All rights reserved.\n"; |
| 12 | #endif /* not lint */ |
| 13 | |
| 14 | #ifndef lint |
| 15 | static char sccsid[] = "@(#)colrm.c 5.4 (Berkeley) %G%"; |
| 16 | #endif /* not lint */ |
| 17 | |
| 18 | #include <stdio.h> |
| 19 | /* |
| 20 | COLRM removes unwanted columns from a file |
| 21 | Jeff Schriebman UC Berkeley 11-74 |
| 22 | */ |
| 23 | |
| 24 | |
| 25 | main(argc,argv) |
| 26 | char **argv; |
| 27 | { |
| 28 | register c, ct, first, last; |
| 29 | |
| 30 | first = 0; |
| 31 | last = 0; |
| 32 | if (argc > 1) |
| 33 | first = getn(*++argv); |
| 34 | if (argc > 2) |
| 35 | last = getn(*++argv); |
| 36 | |
| 37 | start: |
| 38 | ct = 0; |
| 39 | loop1: |
| 40 | c = getc(stdin); |
| 41 | if (feof(stdin)) |
| 42 | goto fin; |
| 43 | if (c == '\t') |
| 44 | ct = (ct + 8) & ~7; |
| 45 | else if (c == '\b') |
| 46 | ct = ct ? ct - 1 : 0; |
| 47 | else |
| 48 | ct++; |
| 49 | if (c == '\n') { |
| 50 | putc(c, stdout); |
| 51 | goto start; |
| 52 | } |
| 53 | if (!first || ct < first) { |
| 54 | putc(c, stdout); |
| 55 | goto loop1; |
| 56 | } |
| 57 | |
| 58 | /* Loop getting rid of characters */ |
| 59 | while (!last || ct < last) { |
| 60 | c = getc(stdin); |
| 61 | if (feof(stdin)) |
| 62 | goto fin; |
| 63 | if (c == '\n') { |
| 64 | putc(c, stdout); |
| 65 | goto start; |
| 66 | } |
| 67 | if (c == '\t') |
| 68 | ct = (ct + 8) & ~7; |
| 69 | else if (c == '\b') |
| 70 | ct = ct ? ct - 1 : 0; |
| 71 | else |
| 72 | ct++; |
| 73 | } |
| 74 | |
| 75 | /* Output last of the line */ |
| 76 | for (;;) { |
| 77 | c = getc(stdin); |
| 78 | if (feof(stdin)) |
| 79 | break; |
| 80 | putc(c, stdout); |
| 81 | if (c == '\n') |
| 82 | goto start; |
| 83 | } |
| 84 | fin: |
| 85 | fflush(stdout); |
| 86 | exit(0); |
| 87 | } |
| 88 | |
| 89 | getn(ap) |
| 90 | char *ap; |
| 91 | { |
| 92 | register int n,c; |
| 93 | register char *p; |
| 94 | |
| 95 | p = ap; |
| 96 | n = 0; |
| 97 | while ((c = *p++) >= '0' && c <= '9') |
| 98 | n = n*10 + c - '0'; |
| 99 | return(n); |
| 100 | } |