ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cal/neat.c
Revision: 1.4
Committed: Fri Nov 14 17:31:24 2003 UTC (20 years, 11 months ago) by schorsch
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R4, rad5R2, rad4R2P2, rad5R0, rad5R1, rad3R7P2, rad3R7P1, rad4R2, rad4R1, rad4R0, rad3R6, rad3R6P1, rad3R8, rad3R9, rad4R2P1, rad5R3, HEAD
Changes since 1.3: +2 -1 lines
Log Message:
Reduced compile warnings.

File Contents

# User Rev Content
1 greg 1.1 #ifndef lint
2 schorsch 1.4 static const char RCSid[] = "$Id: neat.c,v 1.3 2003/07/27 22:12:01 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 schorsch 1.4 int
20 greg 1.1 main(argc, argv)
21     int argc;
22     char *argv[];
23     {
24     int left, anchor, right;
25     char buf[512];
26     register char *cp, *word;
27     register int i;
28    
29     if (argc == 2)
30     format = argv[1];
31     else if (argc > 2)
32     goto userror;
33     left = 0;
34     for (cp = format; isdigit(*cp); cp++)
35     left = left*10 + *cp - '0';
36     right = 0;
37 schorsch 1.3 if ( (anchor = *cp) )
38 greg 1.1 for (cp++; isdigit(*cp); cp++)
39     right = right*10 + *cp - '0';
40     if (*cp)
41     goto userror;
42    
43     while ((cp = fgets(buf, sizeof(buf), stdin)) != NULL)
44     for ( ; ; ) {
45     while (isspace(*cp))
46     cp++;
47     if (!*cp) {
48     putchar('\n');
49     break;
50     }
51     word = cp;
52     while (*cp && *cp != anchor && !isspace(*cp))
53     cp++;
54     i = left-(cp-word);
55     while (i-- > 0)
56     putchar(' ');
57     while (word < cp)
58     putchar(*word++);
59     i = right+1;
60     if (*cp == anchor)
61     do {
62     putchar(*cp++);
63     i--;
64     } while (*cp && !isspace(*cp));
65     while (i-- > 0)
66     putchar(' ');
67     }
68     exit(0);
69     userror:
70     fputs("Usage: ", stderr);
71     fputs(argv[0], stderr);
72     fputs(" [format]\n", stderr);
73     exit(1);
74     }