ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/getinfo.c
Revision: 2.1
Committed: Tue Nov 12 16:05:05 1991 UTC (31 years ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.3: +0 -0 lines
Log Message:
updated revision number for release 2.0

File Contents

# User Rev Content
1 greg 1.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 greg 1.3 extern int fputs();
16 greg 1.1
17 greg 1.3
18 greg 1.1 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 greg 1.2 } else if (argc == 2 && !strcmp(argv[1], "-")) {
42     getheader(stdin, NULL);
43     copycat();
44     exit(0);
45 greg 1.1 }
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 greg 1.3 getheader(fp, tabstr, NULL);
57 greg 1.1 putchar('\n');
58     }
59     fclose(fp);
60     }
61     }
62     if (argc == 1)
63     if (dim) {
64     getdim(stdin);
65     } else {
66 greg 1.3 getheader(stdin, fputs, stdout);
67 greg 1.1 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 greg 1.2 }
106    
107    
108     copycat() /* copy input to output */
109     {
110     register int c;
111    
112     while ((c = getchar()) != EOF)
113     putchar(c);
114 greg 1.1 }