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

# User Rev Content
1 greg 2.2 /* Copyright (c) 1992 Regents of the University of California */
2 greg 1.1
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 2.2 #ifdef MSDOS
16     #include <fcntl.h>
17 greg 2.3 extern int _fmode;
18 greg 2.2 #endif
19    
20 greg 1.3 extern int fputs();
21 greg 1.1
22 greg 1.3
23 greg 1.1 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 greg 2.3 char **argv;
38 greg 1.1 {
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 greg 2.3 #ifdef MSDOS
47     setmode(fileno(stdin), _fmode = O_BINARY);
48     #endif
49 greg 1.2 } else if (argc == 2 && !strcmp(argv[1], "-")) {
50 greg 2.2 #ifdef MSDOS
51     setmode(fileno(stdin), O_BINARY);
52     setmode(fileno(stdout), O_BINARY);
53     #endif
54 greg 2.3 getheader(stdin, NULL, NULL);
55 greg 1.2 copycat();
56     exit(0);
57 greg 1.1 }
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 greg 1.3 getheader(fp, tabstr, NULL);
69 greg 1.1 putchar('\n');
70     }
71     fclose(fp);
72     }
73     }
74     if (argc == 1)
75     if (dim) {
76     getdim(stdin);
77     } else {
78 greg 1.3 getheader(stdin, fputs, stdout);
79 greg 1.1 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 greg 2.3 getheader(fp, NULL, NULL); /* skip header */
92 greg 1.1
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 greg 1.2 }
118    
119    
120     copycat() /* copy input to output */
121     {
122     register int c;
123 greg 2.3
124 greg 1.2 while ((c = getchar()) != EOF)
125     putchar(c);
126 greg 1.1 }