Wait 11 minutes before deciding a machine is down (same as ruptime).
[unix-history] / usr / src / usr.bin / expand / expand.c
CommitLineData
32a94702 1static char *sccsid = "@(#)expand.c 4.3 (Berkeley) %G%";
fb2da2bb
BJ
2#include <stdio.h>
3/*
4 * expand - expand tabs to equivalent spaces
5 */
fb2da2bb
BJ
6int nstops;
7int tabstops[100];
8
9main(argc, argv)
10 int argc;
11 char *argv[];
12{
13 register int c, column;
14 register int n;
15
fb2da2bb
BJ
16 argc--, argv++;
17 do {
18 while (argc > 0 && argv[0][0] == '-') {
19 getstops(argv[0]);
20 argc--, argv++;
21 }
22 if (argc > 0) {
23 if (freopen(argv[0], "r", stdin) == NULL) {
24 perror(argv[0]);
25 exit(1);
26 }
27 argc--, argv++;
28 }
29 column = 0;
30 for (;;) {
31 c = getc(stdin);
32 if (c == -1)
33 break;
34 switch (c) {
35
36 case '\t':
37 if (nstops == 0) {
38 do {
39 putchar(' ');
40 column++;
41 } while (column & 07);
42 continue;
43 }
44 if (nstops == 1) {
45 do {
46 putchar(' ');
47 column++;
48 } while (((column - 1) % tabstops[0]) != (tabstops[0] - 1));
49 continue;
50 }
51 for (n = 0; n < nstops; n++)
52 if (tabstops[n] > column)
53 break;
54 if (n == nstops) {
55 putchar(' ');
56 column++;
57 continue;
58 }
59 while (column < tabstops[n]) {
60 putchar(' ');
61 column++;
62 }
63 continue;
64
65 case '\b':
66 if (column)
67 column--;
68 putchar('\b');
69 continue;
70
71 default:
72 putchar(c);
73 column++;
74 continue;
75
76 case '\n':
77 putchar(c);
78 column = 0;
79 continue;
80 }
81 }
82 } while (argc > 0);
83 exit(0);
84}
85
86getstops(cp)
87 register char *cp;
88{
89 register int i;
90
91 nstops = 0;
92 cp++;
93 for (;;) {
94 i = 0;
95 while (*cp >= '0' && *cp <= '9')
96 i = i * 10 + *cp++ - '0';
97 if (i <= 0 || i > 256) {
98bad:
99 fprintf(stderr, "Bad tab stop spec\n");
100 exit(1);
101 }
73c2cdfe 102 if (nstops > 0 && i <= tabstops[nstops-1])
fb2da2bb
BJ
103 goto bad;
104 tabstops[nstops++] = i;
105 if (*cp == 0)
106 break;
107 if (*cp++ != ',')
108 goto bad;
109 }
110}