1 |
#ifndef lint |
2 |
static const char RCSid[] = "$Id$"; |
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 |
|
12 |
#ifdef MSDOS |
13 |
#include <fcntl.h> |
14 |
extern int _fmode; |
15 |
#endif |
16 |
|
17 |
extern int fputs(); |
18 |
|
19 |
|
20 |
int |
21 |
tabstr(s) /* put out line followed by tab */ |
22 |
register char *s; |
23 |
{ |
24 |
while (*s) { |
25 |
putchar(*s); |
26 |
s++; |
27 |
} |
28 |
if (*--s == '\n') |
29 |
putchar('\t'); |
30 |
return(0); |
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 |
#ifdef MSDOS |
46 |
setmode(fileno(stdin), _fmode = O_BINARY); |
47 |
#endif |
48 |
} else if (argc == 2 && !strcmp(argv[1], "-")) { |
49 |
#ifdef MSDOS |
50 |
setmode(fileno(stdin), O_BINARY); |
51 |
setmode(fileno(stdout), O_BINARY); |
52 |
#endif |
53 |
getheader(stdin, NULL, NULL); |
54 |
copycat(); |
55 |
exit(0); |
56 |
} |
57 |
for (i = 1; i < argc; i++) { |
58 |
fputs(argv[i], stdout); |
59 |
if ((fp = fopen(argv[i], "r")) == NULL) |
60 |
fputs(": cannot open\n", stdout); |
61 |
else { |
62 |
if (dim) { |
63 |
fputs(": ", stdout); |
64 |
getdim(fp); |
65 |
} else { |
66 |
tabstr(":\n"); |
67 |
getheader(fp, tabstr, NULL); |
68 |
putchar('\n'); |
69 |
} |
70 |
fclose(fp); |
71 |
} |
72 |
} |
73 |
if (argc == 1) |
74 |
if (dim) { |
75 |
getdim(stdin); |
76 |
} else { |
77 |
getheader(stdin, fputs, stdout); |
78 |
putchar('\n'); |
79 |
} |
80 |
exit(0); |
81 |
} |
82 |
|
83 |
|
84 |
getdim(fp) /* get dimensions from file */ |
85 |
register FILE *fp; |
86 |
{ |
87 |
int j; |
88 |
register int c; |
89 |
|
90 |
getheader(fp, NULL, NULL); /* skip header */ |
91 |
|
92 |
switch (c = getc(fp)) { |
93 |
case '+': /* picture */ |
94 |
case '-': |
95 |
do |
96 |
putchar(c); |
97 |
while (c != '\n' && (c = getc(fp)) != EOF); |
98 |
break; |
99 |
case 1: /* octree */ |
100 |
getc(fp); |
101 |
j = 0; |
102 |
while ((c = getc(fp)) != EOF) |
103 |
if (c == 0) |
104 |
if (++j >= 4) |
105 |
break; |
106 |
else |
107 |
putchar(' '); |
108 |
else |
109 |
putchar(c); |
110 |
putchar('\n'); |
111 |
break; |
112 |
default: /* ??? */ |
113 |
fputs("unknown file type\n", stdout); |
114 |
break; |
115 |
} |
116 |
} |
117 |
|
118 |
|
119 |
copycat() /* copy input to output */ |
120 |
{ |
121 |
register int c; |
122 |
|
123 |
while ((c = getchar()) != EOF) |
124 |
putchar(c); |
125 |
} |