ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/getinfo.c
Revision: 2.3
Committed: Thu Nov 12 10:06:11 1992 UTC (30 years ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.2: +8 -4 lines
Log Message:
Changes for 32-bit PC port

File Contents

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