| 1 | 
greg | 
1.1 | 
#ifndef lint | 
| 2 | 
greg | 
1.2 | 
static const char       RCSid[] = "$Id: bgraph.c,v 1.1 2003/02/22 02:07:26 greg Exp $"; | 
| 3 | 
greg | 
1.1 | 
#endif | 
| 4 | 
  | 
  | 
/* | 
| 5 | 
  | 
  | 
 *  bgraph.c - program to send plots to metafile graphics programs. | 
| 6 | 
  | 
  | 
 * | 
| 7 | 
  | 
  | 
 *     6/25/86 | 
| 8 | 
  | 
  | 
 * | 
| 9 | 
  | 
  | 
 *     Greg Ward Larson | 
| 10 | 
  | 
  | 
 */ | 
| 11 | 
  | 
  | 
 | 
| 12 | 
  | 
  | 
#include  <stdio.h> | 
| 13 | 
  | 
  | 
 | 
| 14 | 
  | 
  | 
#include  "meta.h" | 
| 15 | 
  | 
  | 
 | 
| 16 | 
  | 
  | 
#define  istyp(s)       (s[0] == '-') | 
| 17 | 
  | 
  | 
 | 
| 18 | 
  | 
  | 
#define  isvar(s)       (s[0] == '+') | 
| 19 | 
  | 
  | 
 | 
| 20 | 
  | 
  | 
char  *progname; | 
| 21 | 
  | 
  | 
 | 
| 22 | 
  | 
  | 
char  *libpath[4]; | 
| 23 | 
  | 
  | 
 | 
| 24 | 
  | 
  | 
 | 
| 25 | 
  | 
  | 
main(argc, argv) | 
| 26 | 
  | 
  | 
int  argc; | 
| 27 | 
  | 
  | 
char  *argv[]; | 
| 28 | 
  | 
  | 
{ | 
| 29 | 
  | 
  | 
#if  UNIX || MAC | 
| 30 | 
  | 
  | 
        char  *getenv(); | 
| 31 | 
  | 
  | 
#endif | 
| 32 | 
  | 
  | 
        int  i, file0; | 
| 33 | 
  | 
  | 
#ifdef  CPM | 
| 34 | 
  | 
  | 
#define getenv(s) NULL | 
| 35 | 
  | 
  | 
        fixargs("bgraph", &argc, &argv); | 
| 36 | 
  | 
  | 
#endif | 
| 37 | 
  | 
  | 
        progname = argv[0]; | 
| 38 | 
  | 
  | 
        libpath[0] = ""; | 
| 39 | 
  | 
  | 
        if ((libpath[i=1] = getenv("MDIR")) != NULL) | 
| 40 | 
  | 
  | 
                i++; | 
| 41 | 
  | 
  | 
        libpath[i++] = MDIR; | 
| 42 | 
  | 
  | 
        libpath[i] = NULL; | 
| 43 | 
  | 
  | 
 | 
| 44 | 
  | 
  | 
        for (file0 = 1; file0 < argc; ) | 
| 45 | 
  | 
  | 
                if (istyp(argv[file0])) | 
| 46 | 
  | 
  | 
                        file0++; | 
| 47 | 
  | 
  | 
                else if (isvar(argv[file0]) && file0 < argc-1) | 
| 48 | 
  | 
  | 
                        file0 += 2; | 
| 49 | 
  | 
  | 
                else | 
| 50 | 
  | 
  | 
                        break; | 
| 51 | 
  | 
  | 
 | 
| 52 | 
  | 
  | 
        if (file0 >= argc) | 
| 53 | 
  | 
  | 
                dofile(argc-1, argv+1, NULL); | 
| 54 | 
  | 
  | 
        else | 
| 55 | 
  | 
  | 
                for (i = file0; i < argc; i++) | 
| 56 | 
  | 
  | 
                        dofile(file0-1, argv+1, argv[i]); | 
| 57 | 
  | 
  | 
 | 
| 58 | 
  | 
  | 
        quit(0); | 
| 59 | 
  | 
  | 
} | 
| 60 | 
  | 
  | 
 | 
| 61 | 
  | 
  | 
 | 
| 62 | 
  | 
  | 
dofile(optc, optv, file)                /* plot a file */ | 
| 63 | 
  | 
  | 
int  optc; | 
| 64 | 
  | 
  | 
char  *optv[]; | 
| 65 | 
  | 
  | 
char  *file; | 
| 66 | 
  | 
  | 
{ | 
| 67 | 
  | 
  | 
        char  stmp[256]; | 
| 68 | 
  | 
  | 
        int  i; | 
| 69 | 
  | 
  | 
                                                /* start fresh */ | 
| 70 | 
  | 
  | 
        mgclearall(); | 
| 71 | 
  | 
  | 
                                                /* type options first */ | 
| 72 | 
  | 
  | 
        for (i = 0; i < optc; i++) | 
| 73 | 
  | 
  | 
                if (istyp(optv[i])) { | 
| 74 | 
  | 
  | 
                        sprintf(stmp, "include=%s.plt", optv[i]+1); | 
| 75 | 
  | 
  | 
                        setmgvar(progname, stdin, stmp); | 
| 76 | 
  | 
  | 
                } else | 
| 77 | 
  | 
  | 
                        i++; | 
| 78 | 
  | 
  | 
                                                /* file next */ | 
| 79 | 
  | 
  | 
        mgload(file); | 
| 80 | 
  | 
  | 
                                                /* variable options last */ | 
| 81 | 
  | 
  | 
        for (i = 0; i < optc; i++) | 
| 82 | 
  | 
  | 
                if (isvar(optv[i])) { | 
| 83 | 
  | 
  | 
                        sprintf(stmp, "%s=%s", optv[i]+1, optv[i+1]); | 
| 84 | 
  | 
  | 
                        setmgvar(progname, stdin, stmp); | 
| 85 | 
  | 
  | 
                        i++; | 
| 86 | 
  | 
  | 
                } | 
| 87 | 
  | 
  | 
                                                /* graph it */ | 
| 88 | 
  | 
  | 
        mgraph(); | 
| 89 | 
  | 
  | 
} | 
| 90 | 
  | 
  | 
 | 
| 91 | 
  | 
  | 
 | 
| 92 | 
greg | 
1.2 | 
void | 
| 93 | 
greg | 
1.1 | 
quit(code)                              /* quit program */ | 
| 94 | 
  | 
  | 
int  code; | 
| 95 | 
  | 
  | 
{ | 
| 96 | 
  | 
  | 
        mdone(); | 
| 97 | 
  | 
  | 
        exit(code); | 
| 98 | 
  | 
  | 
} |