ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/getinfo.c
Revision: 2.2
Committed: Mon Sep 21 12:13:25 1992 UTC (30 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.1: +10 -2 lines
Log Message:
Changes for 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     #endif
18    
19 greg 1.3 extern int fputs();
20 greg 1.1
21 greg 1.3
22 greg 1.1 tabstr(s) /* put out line followed by tab */
23     register char *s;
24     {
25     while (*s) {
26     putchar(*s);
27     s++;
28     }
29     if (*--s == '\n')
30     putchar('\t');
31     }
32    
33    
34     main(argc, argv)
35     int argc;
36     char *argv[];
37     {
38     int dim = 0;
39     FILE *fp;
40     int i;
41    
42     if (argc > 1 && !strcmp(argv[1], "-d")) {
43     argc--; argv++;
44     dim = 1;
45 greg 1.2 } else if (argc == 2 && !strcmp(argv[1], "-")) {
46 greg 2.2 #ifdef MSDOS
47     setmode(fileno(stdin), O_BINARY);
48     setmode(fileno(stdout), O_BINARY);
49     #endif
50 greg 1.2 getheader(stdin, NULL);
51     copycat();
52     exit(0);
53 greg 1.1 }
54     for (i = 1; i < argc; i++) {
55     fputs(argv[i], stdout);
56     if ((fp = fopen(argv[i], "r")) == NULL)
57     fputs(": cannot open\n", stdout);
58     else {
59     if (dim) {
60     fputs(": ", stdout);
61     getdim(fp);
62     } else {
63     tabstr(":\n");
64 greg 1.3 getheader(fp, tabstr, NULL);
65 greg 1.1 putchar('\n');
66     }
67     fclose(fp);
68     }
69     }
70     if (argc == 1)
71     if (dim) {
72     getdim(stdin);
73     } else {
74 greg 1.3 getheader(stdin, fputs, stdout);
75 greg 1.1 putchar('\n');
76     }
77     exit(0);
78     }
79    
80    
81     getdim(fp) /* get dimensions from file */
82     register FILE *fp;
83     {
84     int j;
85     register int c;
86    
87     getheader(fp, NULL); /* skip header */
88    
89     switch (c = getc(fp)) {
90     case '+': /* picture */
91     case '-':
92     do
93     putchar(c);
94     while (c != '\n' && (c = getc(fp)) != EOF);
95     break;
96     case 1: /* octree */
97     getc(fp);
98     j = 0;
99     while ((c = getc(fp)) != EOF)
100     if (c == 0)
101     if (++j >= 4)
102     break;
103     else
104     putchar(' ');
105     else
106     putchar(c);
107     putchar('\n');
108     break;
109     default: /* ??? */
110     fputs("unknown file type\n", stdout);
111     break;
112     }
113 greg 1.2 }
114    
115    
116     copycat() /* copy input to output */
117     {
118     register int c;
119 greg 2.2
120 greg 1.2 while ((c = getchar()) != EOF)
121     putchar(c);
122 greg 1.1 }