ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cal/cnt.c
Revision: 1.2
Committed: Sun Jun 8 12:03:09 2003 UTC (21 years, 4 months ago) by schorsch
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R2, rad4R2P2, rad5R0, rad5R1, rad3R7P2, rad3R7P1, rad4R2, rad4R1, rad4R0, rad3R6, rad3R6P1, rad3R8, rad3R9, rad4R2P1, rad5R3
Changes since 1.1: +17 -10 lines
Log Message:
Reduced compile warnings/errors on Windows.

File Contents

# User Rev Content
1 greg 1.1 #ifndef lint
2 schorsch 1.2 static const char RCSid[] = "$Id: cnt.c,v 1.1 2003/02/22 02:07:20 greg Exp $";
3 greg 1.1 #endif
4     /*
5     * cnt.c - simple counting program.
6     *
7     * 2/1/88
8     */
9    
10 schorsch 1.2 #include <stdlib.h>
11 greg 1.1 #include <stdio.h>
12    
13    
14     int n[50];
15     char buf[256];
16    
17 schorsch 1.2 static void loop(int *n, char *b);
18 greg 1.1
19 schorsch 1.2 int
20     main(
21     int argc,
22     char *argv[]
23     )
24 greg 1.1 {
25     int a;
26    
27     argv++; argc--;
28     for (a = 0; a < argc; a++)
29     n[a] = atoi(argv[a]);
30     n[a] = 0;
31     loop(n, buf);
32    
33     exit(0);
34     }
35    
36    
37     char *
38 schorsch 1.2 tack(
39     register char *b,
40     register int i
41     )
42 greg 1.1 {
43     register char *cp;
44     char *res;
45    
46     *b++ = '\t';
47     cp = b;
48     if (i == 0)
49     *cp++ = '0';
50     else
51     do {
52     *cp++ = i%10 + '0';
53     i /= 10;
54     } while (i);
55     res = cp--;
56     #define c i
57     while (cp > b) { /* reverse string */
58     c = *cp;
59     *cp-- = *b;
60     *b++ = c;
61     }
62     #undef c
63     return(res);
64     }
65    
66    
67 schorsch 1.2 static void
68     loop(
69     int *n,
70     char *b
71     )
72 greg 1.1 {
73     int i;
74    
75     if (n[0] == 0) {
76     *b = '\0';
77     puts(buf);
78     return;
79     }
80     for (i = 0; i < n[0]; i++)
81     loop(n+1, tack(b, i));
82     }