Back to index

radiance  4R0+20100331
bgraph.c
Go to the documentation of this file.
00001 #ifndef lint
00002 static const char    RCSid[] = "$Id: bgraph.c,v 1.4 2003/11/15 02:13:36 schorsch Exp $";
00003 #endif
00004 /*
00005  *  bgraph.c - program to send plots to metafile graphics programs.
00006  *
00007  *     6/25/86
00008  *
00009  *     Greg Ward Larson
00010  */
00011 
00012 #include  <stdio.h>
00013 
00014 #include  "meta.h"
00015 #include  "mgvars.h"
00016 #include  "mgraph.h"
00017 
00018 #define  istyp(s)    (s[0] == '-')
00019 
00020 #define  isvar(s)    (s[0] == '+')
00021 
00022 char  *progname;
00023 
00024 char  *libpath[4];
00025 
00026 static void dofile(int  optc, char  *optv[], char  *file);
00027 
00028 
00029 int
00030 main(
00031        int  argc,
00032        char  *argv[]
00033 )
00034 {
00035        char  *getenv();
00036        int  i, file0;
00037        progname = argv[0];
00038        libpath[0] = "";
00039        if ((libpath[i=1] = getenv("MDIR")) != NULL)
00040               i++;
00041        libpath[i++] = MDIR;
00042        libpath[i] = NULL;
00043 
00044        for (file0 = 1; file0 < argc; )
00045               if (istyp(argv[file0]))
00046                      file0++;
00047               else if (isvar(argv[file0]) && file0 < argc-1)
00048                      file0 += 2;
00049               else
00050                      break;
00051 
00052        if (file0 >= argc)
00053               dofile(argc-1, argv+1, NULL);
00054        else
00055               for (i = file0; i < argc; i++)
00056                      dofile(file0-1, argv+1, argv[i]);
00057 
00058        quit(0);
00059        return 0; /* pro forma return */
00060 }
00061 
00062 
00063 static void
00064 dofile(              /* plot a file */
00065        int  optc,
00066        char  *optv[],
00067        char  *file
00068 )
00069 {
00070        char  stmp[256];
00071        int  i;
00072                                           /* start fresh */
00073        mgclearall();
00074                                           /* type options first */
00075        for (i = 0; i < optc; i++)
00076               if (istyp(optv[i])) {
00077                      sprintf(stmp, "include=%s.plt", optv[i]+1);
00078                      setmgvar(progname, stdin, stmp);
00079               } else
00080                      i++;
00081                                           /* file next */
00082        mgload(file);
00083                                           /* variable options last */
00084        for (i = 0; i < optc; i++)
00085               if (isvar(optv[i])) {
00086                      sprintf(stmp, "%s=%s", optv[i]+1, optv[i+1]);
00087                      setmgvar(progname, stdin, stmp);
00088                      i++;
00089               }
00090                                           /* graph it */
00091        mgraph();
00092 }
00093 
00094 
00095 void
00096 quit(code)                         /* quit program */
00097 int  code;
00098 {
00099        mdone();
00100        exit(code);
00101 }