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