Back to index

radiance  4R0+20100331
getinfo.c
Go to the documentation of this file.
00001 #ifndef lint
00002 static const char    RCSid[] = "$Id: getinfo.c,v 2.8 2004/01/02 11:44:24 schorsch Exp $";
00003 #endif
00004 /*
00005  *  getinfo.c - program to read info. header from file.
00006  *
00007  *     1/3/86
00008  */
00009 
00010 #include  <stdio.h>
00011 #include  <string.h>
00012 
00013 #include  "platform.h"
00014 #include  "resolu.h"
00015 
00016 static gethfunc tabstr;
00017 static void getdim(register FILE *fp);
00018 static void copycat(void);
00019 
00020 
00021 static int
00022 tabstr(                            /* put out line followed by tab */
00023        register char  *s,
00024        void *p
00025 )
00026 {
00027        while (*s) {
00028               putchar(*s);
00029               s++;
00030        }
00031        if (*--s == '\n')
00032               putchar('\t');
00033        return(0);
00034 }
00035 
00036 
00037 int
00038 main(
00039        int  argc,
00040        char  **argv
00041 )
00042 {
00043        int  dim = 0;
00044        FILE  *fp;
00045        int  i;
00046 
00047        if (argc > 1 && !strcmp(argv[1], "-d")) {
00048               argc--; argv++;
00049               dim = 1;
00050               SET_DEFAULT_BINARY(); /* for output file */
00051               SET_FILE_BINARY(stdin);
00052        } else if (argc == 2 && !strcmp(argv[1], "-")) {
00053               SET_FILE_BINARY(stdin);
00054               SET_FILE_BINARY(stdout);
00055               getheader(stdin, NULL, NULL);
00056               copycat();
00057               return 0;
00058        }
00059        for (i = 1; i < argc; i++) {
00060               fputs(argv[i], stdout);
00061               if ((fp = fopen(argv[i], "r")) == NULL)
00062                      fputs(": cannot open\n", stdout);
00063               else {
00064                      if (dim) {
00065                             fputs(": ", stdout);
00066                             getdim(fp);
00067                      } else {
00068                             tabstr(":\n", NULL);
00069                             getheader(fp, tabstr, NULL);
00070                             putchar('\n');
00071                      }
00072                      fclose(fp);
00073               }
00074        }
00075        if (argc == 1) {
00076               if (dim) {
00077                      getdim(stdin);
00078               } else {
00079                      getheader(stdin, (gethfunc*)fputs, stdout);
00080                      putchar('\n');
00081               }
00082        }
00083        return 0;
00084 }
00085 
00086 
00087 static void
00088 getdim(                            /* get dimensions from file */
00089        register FILE  *fp
00090 )
00091 {
00092        int  j;
00093        register int  c;
00094 
00095        getheader(fp, NULL, NULL);  /* skip header */
00096 
00097        switch (c = getc(fp)) {
00098        case '+':            /* picture */
00099        case '-':
00100               do
00101                      putchar(c);
00102               while (c != '\n' && (c = getc(fp)) != EOF);
00103               break;
00104        case 1:                     /* octree */
00105               getc(fp);
00106               j = 0;
00107               while ((c = getc(fp)) != EOF)
00108                      if (c == 0)
00109                             if (++j >= 4)
00110                                    break;
00111                             else
00112                                    putchar(' ');
00113                      else
00114                             putchar(c);
00115               putchar('\n');
00116               break;
00117        default:             /* ??? */
00118               fputs("unknown file type\n", stdout);
00119               break;
00120        }
00121 }
00122 
00123 
00124 static void
00125 copycat(void)               /* copy input to output */
00126 {
00127        register int  c;
00128 
00129        while ((c = getchar()) != EOF)
00130               putchar(c);
00131 }