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