1: #ifndef lint
2: static char *sccsid = "@(#)unexpand.c 4.1 (Berkeley) 10/1/80";
3: #endif
4: /*
5: * unexpand - put tabs into a file replacing blanks
6: */
7: #include <stdio.h>
8:
9: char genbuf[BUFSIZ];
10: char linebuf[BUFSIZ];
11: int all;
12:
13: main(argc, argv)
14: int argc;
15: char *argv[];
16: {
17: register char *cp;
18:
19: argc--, argv++;
20: if (argv[0][0] == '-') {
21: if (strcmp(argv[0], "-a") != 0) {
22: fprintf(stderr, "usage: unexpand [ -a ] file ...\n");
23: exit(1);
24: }
25: all++;
26: argc--, argv++;
27: }
28: do {
29: if (argc > 0) {
30: if (freopen(argv[0], "r", stdin) == NULL) {
31: perror(argv[0]);
32: exit(1);
33: }
34: argc--, argv++;
35: }
36: while (fgets(genbuf, BUFSIZ, stdin) != NULL) {
37: for (cp = linebuf; *cp; cp++)
38: continue;
39: if (cp > linebuf)
40: cp[-1] = 0;
41: tabify(all);
42: printf("%s", linebuf);
43: }
44: } while (argc > 0);
45: exit(0);
46: }
47:
48: tabify(c)
49: char c;
50: {
51: register char *cp, *dp;
52: register int dcol;
53: int ocol;
54:
55: ocol = 0;
56: dcol = 0;
57: cp = genbuf, dp = linebuf;
58: for (;;) {
59: switch (*cp) {
60:
61: case ' ':
62: dcol++;
63: break;
64:
65: case '\t':
66: dcol += 8;
67: dcol &= ~07;
68: break;
69:
70: default:
71: while (((ocol + 8) &~ 07) <= dcol) {
72: if (ocol + 1 == dcol)
73: break;
74: *dp++ = '\t';
75: ocol += 8;
76: ocol &= ~07;
77: }
78: while (ocol < dcol) {
79: *dp++ = ' ';
80: ocol++;
81: }
82: if (*cp == 0 || c == 0) {
83: strcpy(dp, cp);
84: return;
85: }
86: *dp++ = *cp;
87: ocol++, dcol++;
88: }
89: cp++;
90: }
91: }
Defined functions
main
defined in line
13;
never used
Defined variables
all
defined in line
11; used 2 times
genbuf
defined in line
9; used 2 times
sccsid
defined in line
2;
never used