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