Commit | Line | Data |
---|---|---|
fcd2465c DF |
1 | /* |
2 | * Copyright (c) 1980 Regents of the University of California. | |
0aeae7c2 KB |
3 | * All rights reserved. |
4 | * | |
f15db449 | 5 | * %sccs.include.redist.c% |
fcd2465c DF |
6 | */ |
7 | ||
8 | #ifndef lint | |
9 | char copyright[] = | |
10 | "@(#) Copyright (c) 1980 Regents of the University of California.\n\ | |
11 | All rights reserved.\n"; | |
0aeae7c2 | 12 | #endif /* not lint */ |
fcd2465c DF |
13 | |
14 | #ifndef lint | |
f15db449 | 15 | static char sccsid[] = "@(#)colrm.c 5.4 (Berkeley) %G%"; |
0aeae7c2 | 16 | #endif /* not lint */ |
fcd2465c | 17 | |
b60303bc BJ |
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 | { | |
086d5c60 | 28 | register c, ct, first, last; |
b60303bc | 29 | |
086d5c60 RC |
30 | first = 0; |
31 | last = 0; | |
32 | if (argc > 1) | |
b60303bc | 33 | first = getn(*++argv); |
086d5c60 | 34 | if (argc > 2) |
b60303bc BJ |
35 | last = getn(*++argv); |
36 | ||
37 | start: | |
38 | ct = 0; | |
39 | loop1: | |
dbd0bde5 BJ |
40 | c = getc(stdin); |
41 | if (feof(stdin)) | |
b60303bc | 42 | goto fin; |
83ded028 | 43 | if (c == '\t') |
086d5c60 | 44 | ct = (ct + 8) & ~7; |
83ded028 BJ |
45 | else if (c == '\b') |
46 | ct = ct ? ct - 1 : 0; | |
47 | else | |
48 | ct++; | |
086d5c60 RC |
49 | if (c == '\n') { |
50 | putc(c, stdout); | |
b60303bc BJ |
51 | goto start; |
52 | } | |
086d5c60 RC |
53 | if (!first || ct < first) { |
54 | putc(c, stdout); | |
b60303bc BJ |
55 | goto loop1; |
56 | } | |
57 | ||
58 | /* Loop getting rid of characters */ | |
086d5c60 | 59 | while (!last || ct < last) { |
dbd0bde5 BJ |
60 | c = getc(stdin); |
61 | if (feof(stdin)) | |
b60303bc | 62 | goto fin; |
086d5c60 RC |
63 | if (c == '\n') { |
64 | putc(c, stdout); | |
b60303bc BJ |
65 | goto start; |
66 | } | |
086d5c60 RC |
67 | if (c == '\t') |
68 | ct = (ct + 8) & ~7; | |
69 | else if (c == '\b') | |
70 | ct = ct ? ct - 1 : 0; | |
71 | else | |
72 | ct++; | |
b60303bc BJ |
73 | } |
74 | ||
75 | /* Output last of the line */ | |
dbd0bde5 BJ |
76 | for (;;) { |
77 | c = getc(stdin); | |
78 | if (feof(stdin)) | |
79 | break; | |
086d5c60 RC |
80 | putc(c, stdout); |
81 | if (c == '\n') | |
b60303bc BJ |
82 | goto start; |
83 | } | |
84 | fin: | |
85 | fflush(stdout); | |
0aeae7c2 | 86 | exit(0); |
b60303bc BJ |
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 | } |