Back to index

radiance  4R0+20100331
cv.c
Go to the documentation of this file.
00001 #ifndef lint
00002 static const char    RCSid[] = "$Id: cv.c,v 1.4 2007/11/21 18:51:05 greg Exp $";
00003 #endif
00004 /*
00005  *    Human-readable file I/O conversion program
00006  *
00007  *    cc -o ../cv cv.c mfio.o cvhfio.o syscalls.o misc.o
00008  */
00009 
00010 
00011 #include  "meta.h"
00012 
00013 extern int scanp(PRIMITIVE  *p, FILE  *fp);
00014 extern void printp(PRIMITIVE  *p, FILE  *fp);
00015 extern void printeof(FILE  *fp); 
00016 
00017 char  *progname;
00018 
00019 
00020 int
00021 main(
00022        int  argc,
00023        char  **argv
00024 )
00025 
00026 {
00027  FILE  *fp;
00028  PRIMITIVE  curp;
00029  short  htom = TRUE;
00030 
00031  progname = *argv++;
00032  argc--;
00033 
00034  if (argc && **argv == '-') {
00035     htom = FALSE;
00036     argv++;
00037     argc--;
00038     }
00039 
00040  if (argc)
00041     for (; argc; argc--, argv++) {
00042        fp = efopen(*argv, "r");
00043        if (htom)
00044           while (scanp(&curp, fp)) {
00045              writep(&curp, stdout);
00046             fargs(&curp);
00047              }
00048        else
00049           while (readp(&curp, fp)) {
00050              printp(&curp, stdout);
00051             fargs(&curp);
00052              }
00053        fclose(fp);
00054        }
00055  else
00056     if (htom)
00057        while (scanp(&curp, stdin)) {
00058           writep(&curp, stdout);
00059          fargs(&curp);
00060           }
00061     else
00062        while (readp(&curp, stdin)) {
00063           printp(&curp, stdout);
00064          fargs(&curp);
00065           }
00066 
00067  if (htom)
00068     writeof(stdout);
00069     
00070  return(0);
00071  }