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