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 (8 years, 4 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

# User Rev Content
1 greg 1.1 #ifndef lint
2 greg 2.11 static const char RCSid[] = "$Id: getinfo.c,v 2.10 2014/07/28 17:25:03 greg Exp $";
3 greg 1.1 #endif
4     /*
5     * getinfo.c - program to read info. header from file.
6     *
7     * 1/3/86
8     */
9    
10     #include <stdio.h>
11 schorsch 2.8 #include <string.h>
12 greg 1.1
13 schorsch 2.6 #include "platform.h"
14 schorsch 2.8 #include "resolu.h"
15 greg 2.2
16 greg 2.9 #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 greg 2.10 #ifdef _WIN32
24 greg 2.11 #include <process.h>
25 greg 2.10 #define execvp _execvp
26     #endif
27 greg 2.9
28 schorsch 2.8 static gethfunc tabstr;
29 greg 2.10 static void getdim(FILE *fp);
30 schorsch 2.8 static void copycat(void);
31 greg 1.1
32 greg 1.3
33 schorsch 2.8 static int
34     tabstr( /* put out line followed by tab */
35 greg 2.10 char *s,
36 schorsch 2.8 void *p
37     )
38 greg 1.1 {
39     while (*s) {
40     putchar(*s);
41     s++;
42     }
43     if (*--s == '\n')
44     putchar('\t');
45 gwlarson 2.4 return(0);
46 greg 1.1 }
47    
48    
49 schorsch 2.8 int
50     main(
51     int argc,
52     char **argv
53     )
54 greg 1.1 {
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 schorsch 2.6 SET_FILE_BINARY(stdin);
63 greg 2.10 } 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 greg 1.2 } else if (argc == 2 && !strcmp(argv[1], "-")) {
74 schorsch 2.6 SET_FILE_BINARY(stdin);
75     SET_FILE_BINARY(stdout);
76 greg 2.3 getheader(stdin, NULL, NULL);
77 greg 1.2 copycat();
78 schorsch 2.8 return 0;
79 greg 1.1 }
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 schorsch 2.8 tabstr(":\n", NULL);
90 greg 1.3 getheader(fp, tabstr, NULL);
91 greg 2.10 fputc('\n', stdout);
92 greg 1.1 }
93     fclose(fp);
94     }
95     }
96 schorsch 2.7 if (argc == 1) {
97 greg 1.1 if (dim) {
98     getdim(stdin);
99     } else {
100 greg 2.10 getheader(stdin, (gethfunc *)fputs, stdout);
101     fputc('\n', stdout);
102 greg 1.1 }
103 schorsch 2.7 }
104 schorsch 2.8 return 0;
105 greg 1.1 }
106    
107    
108 schorsch 2.8 static void
109     getdim( /* get dimensions from file */
110 greg 2.10 FILE *fp
111 schorsch 2.8 )
112 greg 1.1 {
113     int j;
114 greg 2.10 int c;
115 greg 1.1
116 greg 2.3 getheader(fp, NULL, NULL); /* skip header */
117 greg 1.1
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 greg 2.10 if (c == 0) {
130 greg 1.1 if (++j >= 4)
131     break;
132 greg 2.10 putchar(' ');
133     } else {
134 greg 1.1 putchar(c);
135 greg 2.10 }
136 greg 1.1 putchar('\n');
137     break;
138     default: /* ??? */
139     fputs("unknown file type\n", stdout);
140     break;
141     }
142 greg 1.2 }
143    
144    
145 schorsch 2.8 static void
146     copycat(void) /* copy input to output */
147 greg 1.2 {
148 greg 2.10 char buf[8192];
149 greg 2.11 int n;
150 greg 2.3
151 greg 2.10 fflush(stdout);
152     while ((n = fread(buf, 1, sizeof(buf), stdin)) > 0)
153     if (write(fileno(stdout), buf, n) != n)
154     break;
155 greg 1.1 }