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