ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/getinfo.c
Revision: 1.2
Committed: Thu Jun 28 16:39:32 1990 UTC (32 years, 5 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.1: +13 -0 lines
Log Message:
added - option to elide header

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