| Revision: | 1.1 |
| Committed: | Sat Feb 22 02:07:20 2003 UTC (22 years, 8 months ago) by greg |
| Content type: | text/plain |
| Branch: | MAIN |
| CVS Tags: | rad3R5 |
| Log Message: | Changes and check-in for 3.5 release Includes new source files and modifications not recorded for many years See ray/doc/notes/ReleaseNotes for notes between 3.1 and 3.5 release |
| # | User | Rev | Content |
|---|---|---|---|
| 1 | greg | 1.1 | #ifndef lint |
| 2 | static const char RCSid[] = "$Id$"; | ||
| 3 | #endif | ||
| 4 | /* | ||
| 5 | * cnt.c - simple counting program. | ||
| 6 | * | ||
| 7 | * 2/1/88 | ||
| 8 | */ | ||
| 9 | |||
| 10 | #include <stdio.h> | ||
| 11 | |||
| 12 | |||
| 13 | int n[50]; | ||
| 14 | char buf[256]; | ||
| 15 | |||
| 16 | |||
| 17 | main(argc, argv) | ||
| 18 | int argc; | ||
| 19 | char *argv[]; | ||
| 20 | { | ||
| 21 | int a; | ||
| 22 | |||
| 23 | argv++; argc--; | ||
| 24 | for (a = 0; a < argc; a++) | ||
| 25 | n[a] = atoi(argv[a]); | ||
| 26 | n[a] = 0; | ||
| 27 | loop(n, buf); | ||
| 28 | |||
| 29 | exit(0); | ||
| 30 | } | ||
| 31 | |||
| 32 | |||
| 33 | char * | ||
| 34 | tack(b, i) | ||
| 35 | register char *b; | ||
| 36 | register int i; | ||
| 37 | { | ||
| 38 | register char *cp; | ||
| 39 | char *res; | ||
| 40 | |||
| 41 | *b++ = '\t'; | ||
| 42 | cp = b; | ||
| 43 | if (i == 0) | ||
| 44 | *cp++ = '0'; | ||
| 45 | else | ||
| 46 | do { | ||
| 47 | *cp++ = i%10 + '0'; | ||
| 48 | i /= 10; | ||
| 49 | } while (i); | ||
| 50 | res = cp--; | ||
| 51 | #define c i | ||
| 52 | while (cp > b) { /* reverse string */ | ||
| 53 | c = *cp; | ||
| 54 | *cp-- = *b; | ||
| 55 | *b++ = c; | ||
| 56 | } | ||
| 57 | #undef c | ||
| 58 | return(res); | ||
| 59 | } | ||
| 60 | |||
| 61 | |||
| 62 | loop(n, b) | ||
| 63 | int *n; | ||
| 64 | char *b; | ||
| 65 | { | ||
| 66 | int i; | ||
| 67 | |||
| 68 | if (n[0] == 0) { | ||
| 69 | *b = '\0'; | ||
| 70 | puts(buf); | ||
| 71 | return; | ||
| 72 | } | ||
| 73 | for (i = 0; i < n[0]; i++) | ||
| 74 | loop(n+1, tack(b, i)); | ||
| 75 | } |