Back to index

radiance  4R0+20100331
dgraph.c
Go to the documentation of this file.
00001 #ifndef lint
00002 static const char    RCSid[] = "$Id: dgraph.c,v 1.3 2003/11/15 02:13:36 schorsch Exp $";
00003 #endif
00004 /*
00005  *  dgraph.c - program to send plots to dumb terminal.
00006  *
00007  *     7/7/86
00008  *
00009  *     Greg Ward Larson
00010  */
00011 
00012 #include  <stdlib.h>
00013 #include  <stdio.h>
00014 
00015 #include  "rterror.h"
00016 #include  "mgvars.h"
00017 #include  "meta.h"
00018 
00019 #define  isopt(s)    (s[0] == '+' || s[0] == '-')
00020 
00021 char  *progname;
00022 
00023 char  *libpath[4];
00024 
00025 static void dofile(int  optc, char  *optv[], char  *file);
00026 
00027 
00028 int
00029 main(
00030        int  argc,
00031        char  *argv[]
00032 )
00033 {
00034        char  *getenv();
00035        int  i, file0;
00036 
00037        progname = argv[0];
00038        libpath[0] = "./";
00039        if ((libpath[i=1] = getenv("MDIR")) != NULL)
00040               i++;
00041        libpath[i++] = "/usr/local/lib/meta/";
00042        libpath[i] = NULL;
00043 
00044        for (file0 = 1; file0 < argc-1; file0 += 2)
00045               if (!isopt(argv[file0]))
00046                      break;
00047 
00048        if (file0 >= argc)
00049               dofile(argc-1, argv+1, NULL);
00050        else
00051               for (i = file0; i < argc; i++)
00052                      dofile(file0-1, argv+1, argv[i]);
00053 
00054        quit(0);
00055        return 0; /* pro forma return */
00056 }
00057 
00058 
00059 void
00060 dofile(              /* plot a file */
00061        int  optc,
00062        char  *optv[],
00063        char  *file
00064 )
00065 {
00066        int  width = 79;
00067        int  length = 21;
00068        char  stmp[256];
00069        int  i;
00070                                           /* start fresh */
00071        mgclearall();
00072                                           /* load file */
00073        mgload(file);
00074                                           /* do options */
00075        for (i = 0; i < optc; i += 2)
00076               if (optv[i][0] == '+') {
00077                      sprintf(stmp, "%s=%s", optv[i]+1, optv[i+1]);
00078                      setmgvar("command line", stdin, stmp);
00079               } else
00080                      switch (optv[i][1]) {
00081                      case 'w':
00082                             width = atoi(optv[i+1]);
00083                             break;
00084                      case 'l':
00085                             length = atoi(optv[i+1]);
00086                             break;
00087                      default:
00088                             fprintf(stderr, "%s: unknown option: %s\n",
00089                                           progname, optv[i]);
00090                             quit(1);
00091                      }
00092 
00093                                           /* graph it */
00094        cgraph(width, length);
00095 }
00096 
00097 
00098 void
00099 eputs(                      /* print error message */
00100        char  *msg
00101 )
00102 {
00103        fputs(msg, stderr);
00104 }
00105 
00106 
00107 void
00108 quit(                       /* quit program */
00109        int  code
00110 )
00111 {
00112        exit(code);
00113 }