ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cal/neat.c
Revision: 1.2
Committed: Sun Jun 8 12:03:09 2003 UTC (21 years, 1 month ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 1.1: +2 -1 lines
Log Message:
Reduced compile warnings/errors on Windows.

File Contents

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