ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/getinfo.c
Revision: 2.8
Committed: Fri Jan 2 11:44:24 2004 UTC (18 years, 11 months ago) by schorsch
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R7P2, rad3R7P1, rad4R1, rad4R0, rad3R6, rad3R6P1, rad3R8, rad3R9
Changes since 2.7: +26 -14 lines
Log Message:
Ansification and fixed typing/prototype of getheader() and its callback.

File Contents

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