ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/getinfo.c
Revision: 2.5
Committed: Sat Feb 22 02:07:30 2003 UTC (21 years, 1 month ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5
Changes since 2.4: +1 -4 lines
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

File Contents

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