ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/getinfo.c
Revision: 1.3
Committed: Thu Apr 18 14:35:06 1991 UTC (32 years, 11 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.2: +4 -2 lines
Log Message:
added format information to headers

File Contents

# Content
1 /* Copyright (c) 1986 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 extern int fputs();
16
17
18 tabstr(s) /* put out line followed by tab */
19 register char *s;
20 {
21 while (*s) {
22 putchar(*s);
23 s++;
24 }
25 if (*--s == '\n')
26 putchar('\t');
27 }
28
29
30 main(argc, argv)
31 int argc;
32 char *argv[];
33 {
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 } else if (argc == 2 && !strcmp(argv[1], "-")) {
42 getheader(stdin, NULL);
43 copycat();
44 exit(0);
45 }
46 for (i = 1; i < argc; i++) {
47 fputs(argv[i], stdout);
48 if ((fp = fopen(argv[i], "r")) == NULL)
49 fputs(": cannot open\n", stdout);
50 else {
51 if (dim) {
52 fputs(": ", stdout);
53 getdim(fp);
54 } else {
55 tabstr(":\n");
56 getheader(fp, tabstr, NULL);
57 putchar('\n');
58 }
59 fclose(fp);
60 }
61 }
62 if (argc == 1)
63 if (dim) {
64 getdim(stdin);
65 } else {
66 getheader(stdin, fputs, stdout);
67 putchar('\n');
68 }
69 exit(0);
70 }
71
72
73 getdim(fp) /* get dimensions from file */
74 register FILE *fp;
75 {
76 int j;
77 register int c;
78
79 getheader(fp, NULL); /* skip header */
80
81 switch (c = getc(fp)) {
82 case '+': /* picture */
83 case '-':
84 do
85 putchar(c);
86 while (c != '\n' && (c = getc(fp)) != EOF);
87 break;
88 case 1: /* octree */
89 getc(fp);
90 j = 0;
91 while ((c = getc(fp)) != EOF)
92 if (c == 0)
93 if (++j >= 4)
94 break;
95 else
96 putchar(' ');
97 else
98 putchar(c);
99 putchar('\n');
100 break;
101 default: /* ??? */
102 fputs("unknown file type\n", stdout);
103 break;
104 }
105 }
106
107
108 copycat() /* copy input to output */
109 {
110 register int c;
111
112 while ((c = getchar()) != EOF)
113 putchar(c);
114 }