1 |
#ifndef lint |
2 |
static const char RCSid[] = "$Id$"; |
3 |
#endif |
4 |
/* |
5 |
* neat.c - program to tidy up columns. |
6 |
* |
7 |
* 10/24/86 |
8 |
*/ |
9 |
|
10 |
#include <stdio.h> |
11 |
|
12 |
#include <ctype.h> |
13 |
|
14 |
|
15 |
char *format = "8.8"; /* default format */ |
16 |
|
17 |
|
18 |
main(argc, argv) |
19 |
int argc; |
20 |
char *argv[]; |
21 |
{ |
22 |
int left, anchor, right; |
23 |
char buf[512]; |
24 |
register char *cp, *word; |
25 |
register int i; |
26 |
|
27 |
if (argc == 2) |
28 |
format = argv[1]; |
29 |
else if (argc > 2) |
30 |
goto userror; |
31 |
left = 0; |
32 |
for (cp = format; isdigit(*cp); cp++) |
33 |
left = left*10 + *cp - '0'; |
34 |
right = 0; |
35 |
if (anchor = *cp) |
36 |
for (cp++; isdigit(*cp); cp++) |
37 |
right = right*10 + *cp - '0'; |
38 |
if (*cp) |
39 |
goto userror; |
40 |
|
41 |
while ((cp = fgets(buf, sizeof(buf), stdin)) != NULL) |
42 |
for ( ; ; ) { |
43 |
while (isspace(*cp)) |
44 |
cp++; |
45 |
if (!*cp) { |
46 |
putchar('\n'); |
47 |
break; |
48 |
} |
49 |
word = cp; |
50 |
while (*cp && *cp != anchor && !isspace(*cp)) |
51 |
cp++; |
52 |
i = left-(cp-word); |
53 |
while (i-- > 0) |
54 |
putchar(' '); |
55 |
while (word < cp) |
56 |
putchar(*word++); |
57 |
i = right+1; |
58 |
if (*cp == anchor) |
59 |
do { |
60 |
putchar(*cp++); |
61 |
i--; |
62 |
} while (*cp && !isspace(*cp)); |
63 |
while (i-- > 0) |
64 |
putchar(' '); |
65 |
} |
66 |
exit(0); |
67 |
userror: |
68 |
fputs("Usage: ", stderr); |
69 |
fputs(argv[0], stderr); |
70 |
fputs(" [format]\n", stderr); |
71 |
exit(1); |
72 |
} |