ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/getinfo.c
Revision: 2.4
Committed: Tue Oct 27 08:47:17 1998 UTC (24 years, 1 month ago) by gwlarson
Content type: text/plain
Branch: MAIN
Changes since 2.3: +2 -0 lines
Log Message:
changed getheader() to listen to return value of passed function

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