ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/getinfo.c
Revision: 2.7
Committed: Mon Jul 21 22:30:19 2003 UTC (20 years, 8 months ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 2.6: +3 -2 lines
Log Message:
Eliminated copystruct() macro, which is unnecessary in ANSI.
Reduced ambiguity warnings for nested if/if/else clauses.

File Contents

# User Rev Content
1 greg 1.1 #ifndef lint
2 schorsch 2.7 static const char RCSid[] = "$Id: getinfo.c,v 2.6 2003/06/05 19:29:35 schorsch Exp $";
3 greg 1.1 #endif
4     /*
5     * getinfo.c - program to read info. header from file.
6     *
7     * 1/3/86
8     */
9    
10     #include <stdio.h>
11    
12 schorsch 2.6 #include "platform.h"
13 greg 2.2
14 greg 1.1
15 greg 1.3
16 gwlarson 2.4 int
17 greg 1.1 tabstr(s) /* put out line followed by tab */
18     register char *s;
19     {
20     while (*s) {
21     putchar(*s);
22     s++;
23     }
24     if (*--s == '\n')
25     putchar('\t');
26 gwlarson 2.4 return(0);
27 greg 1.1 }
28    
29    
30     main(argc, argv)
31     int argc;
32 greg 2.3 char **argv;
33 greg 1.1 {
34     int dim = 0;
35     FILE *fp;
36     int i;
37    
38     if (argc > 1 && !strcmp(argv[1], "-d")) {
39     argc--; argv++;
40     dim = 1;
41 schorsch 2.6 SET_DEFAULT_BINARY(); /* for output file */
42     SET_FILE_BINARY(stdin);
43 greg 1.2 } else if (argc == 2 && !strcmp(argv[1], "-")) {
44 schorsch 2.6 SET_FILE_BINARY(stdin);
45     SET_FILE_BINARY(stdout);
46 greg 2.3 getheader(stdin, NULL, NULL);
47 greg 1.2 copycat();
48     exit(0);
49 greg 1.1 }
50     for (i = 1; i < argc; i++) {
51     fputs(argv[i], stdout);
52     if ((fp = fopen(argv[i], "r")) == NULL)
53     fputs(": cannot open\n", stdout);
54     else {
55     if (dim) {
56     fputs(": ", stdout);
57     getdim(fp);
58     } else {
59     tabstr(":\n");
60 greg 1.3 getheader(fp, tabstr, NULL);
61 greg 1.1 putchar('\n');
62     }
63     fclose(fp);
64     }
65     }
66 schorsch 2.7 if (argc == 1) {
67 greg 1.1 if (dim) {
68     getdim(stdin);
69     } else {
70 greg 1.3 getheader(stdin, fputs, stdout);
71 greg 1.1 putchar('\n');
72     }
73 schorsch 2.7 }
74 greg 1.1 exit(0);
75     }
76    
77    
78     getdim(fp) /* get dimensions from file */
79     register FILE *fp;
80     {
81     int j;
82     register int c;
83    
84 greg 2.3 getheader(fp, NULL, NULL); /* skip header */
85 greg 1.1
86     switch (c = getc(fp)) {
87     case '+': /* picture */
88     case '-':
89     do
90     putchar(c);
91     while (c != '\n' && (c = getc(fp)) != EOF);
92     break;
93     case 1: /* octree */
94     getc(fp);
95     j = 0;
96     while ((c = getc(fp)) != EOF)
97     if (c == 0)
98     if (++j >= 4)
99     break;
100     else
101     putchar(' ');
102     else
103     putchar(c);
104     putchar('\n');
105     break;
106     default: /* ??? */
107     fputs("unknown file type\n", stdout);
108     break;
109     }
110 greg 1.2 }
111    
112    
113     copycat() /* copy input to output */
114     {
115     register int c;
116 greg 2.3
117 greg 1.2 while ((c = getchar()) != EOF)
118     putchar(c);
119 greg 1.1 }