ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/getinfo.c
Revision: 2.11
Committed: Mon Jul 28 20:12:20 2014 UTC (9 years, 8 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad4R2
Changes since 2.10: +3 -2 lines
Log Message:
Fixes for Windows

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: getinfo.c,v 2.10 2014/07/28 17:25:03 greg Exp $";
3 #endif
4 /*
5 * getinfo.c - program to read info. header from file.
6 *
7 * 1/3/86
8 */
9
10 #include <stdio.h>
11 #include <string.h>
12
13 #include "platform.h"
14 #include "resolu.h"
15
16 #ifdef getc_unlocked /* avoid nasty file-locking overhead */
17 #undef getchar
18 #undef putchar
19 #define getchar getchar_unlocked
20 #define putchar putchar_unlocked
21 #endif
22
23 #ifdef _WIN32
24 #include <process.h>
25 #define execvp _execvp
26 #endif
27
28 static gethfunc tabstr;
29 static void getdim(FILE *fp);
30 static void copycat(void);
31
32
33 static int
34 tabstr( /* put out line followed by tab */
35 char *s,
36 void *p
37 )
38 {
39 while (*s) {
40 putchar(*s);
41 s++;
42 }
43 if (*--s == '\n')
44 putchar('\t');
45 return(0);
46 }
47
48
49 int
50 main(
51 int argc,
52 char **argv
53 )
54 {
55 int dim = 0;
56 FILE *fp;
57 int i;
58
59 if (argc > 1 && !strcmp(argv[1], "-d")) {
60 argc--; argv++;
61 dim = 1;
62 SET_FILE_BINARY(stdin);
63 } else if (argc > 2 && !strcmp(argv[1], "-c")) {
64 SET_FILE_BINARY(stdin);
65 SET_FILE_BINARY(stdout);
66 getheader(stdin, (gethfunc *)fputs, stdout);
67 printargs(argc-2, argv+2, stdout);
68 fputc('\n', stdout);
69 fflush(stdout);
70 execvp(argv[2], argv+2);
71 perror(argv[2]);
72 return 1;
73 } else if (argc == 2 && !strcmp(argv[1], "-")) {
74 SET_FILE_BINARY(stdin);
75 SET_FILE_BINARY(stdout);
76 getheader(stdin, NULL, NULL);
77 copycat();
78 return 0;
79 }
80 for (i = 1; i < argc; i++) {
81 fputs(argv[i], stdout);
82 if ((fp = fopen(argv[i], "r")) == NULL)
83 fputs(": cannot open\n", stdout);
84 else {
85 if (dim) {
86 fputs(": ", stdout);
87 getdim(fp);
88 } else {
89 tabstr(":\n", NULL);
90 getheader(fp, tabstr, NULL);
91 fputc('\n', stdout);
92 }
93 fclose(fp);
94 }
95 }
96 if (argc == 1) {
97 if (dim) {
98 getdim(stdin);
99 } else {
100 getheader(stdin, (gethfunc *)fputs, stdout);
101 fputc('\n', stdout);
102 }
103 }
104 return 0;
105 }
106
107
108 static void
109 getdim( /* get dimensions from file */
110 FILE *fp
111 )
112 {
113 int j;
114 int c;
115
116 getheader(fp, NULL, NULL); /* skip header */
117
118 switch (c = getc(fp)) {
119 case '+': /* picture */
120 case '-':
121 do
122 putchar(c);
123 while (c != '\n' && (c = getc(fp)) != EOF);
124 break;
125 case 1: /* octree */
126 getc(fp);
127 j = 0;
128 while ((c = getc(fp)) != EOF)
129 if (c == 0) {
130 if (++j >= 4)
131 break;
132 putchar(' ');
133 } else {
134 putchar(c);
135 }
136 putchar('\n');
137 break;
138 default: /* ??? */
139 fputs("unknown file type\n", stdout);
140 break;
141 }
142 }
143
144
145 static void
146 copycat(void) /* copy input to output */
147 {
148 char buf[8192];
149 int n;
150
151 fflush(stdout);
152 while ((n = fread(buf, 1, sizeof(buf), stdin)) > 0)
153 if (write(fileno(stdout), buf, n) != n)
154 break;
155 }