ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cal/neat.c
Revision: 1.3
Committed: Sun Jul 27 22:12:01 2003 UTC (20 years, 8 months ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 1.2: +2 -2 lines
Log Message:
Added grouping parens to reduce ambiguity warnings.

File Contents

# User Rev Content
1 greg 1.1 #ifndef lint
2 schorsch 1.3 static const char RCSid[] = "$Id: neat.c,v 1.2 2003/06/08 12:03:09 schorsch Exp $";
3 greg 1.1 #endif
4     /*
5     * neat.c - program to tidy up columns.
6     *
7     * 10/24/86
8     */
9    
10 schorsch 1.2 #include <stdlib.h>
11 greg 1.1 #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 schorsch 1.3 if ( (anchor = *cp) )
37 greg 1.1 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     }