| 1 | greg | 1.1 | #ifndef lint | 
| 2 | greg | 1.4 | static const char       RCSid[] = "$Id: dgraph.c,v 1.3 2003/11/15 02:13:36 schorsch Exp $"; | 
| 3 | greg | 1.1 | #endif | 
| 4 |  |  | /* | 
| 5 |  |  | *  dgraph.c - program to send plots to dumb terminal. | 
| 6 |  |  | * | 
| 7 |  |  | *     7/7/86 | 
| 8 |  |  | * | 
| 9 |  |  | *     Greg Ward Larson | 
| 10 |  |  | */ | 
| 11 |  |  |  | 
| 12 | schorsch | 1.3 | #include  <stdlib.h> | 
| 13 | greg | 1.1 | #include  <stdio.h> | 
| 14 |  |  |  | 
| 15 | schorsch | 1.3 | #include  "rterror.h" | 
| 16 |  |  | #include  "mgvars.h" | 
| 17 |  |  | #include  "meta.h" | 
| 18 | greg | 1.1 |  | 
| 19 |  |  | #define  isopt(s)       (s[0] == '+' || s[0] == '-') | 
| 20 |  |  |  | 
| 21 |  |  | char  *progname; | 
| 22 |  |  |  | 
| 23 |  |  | char  *libpath[4]; | 
| 24 |  |  |  | 
| 25 | schorsch | 1.3 | static void dofile(int  optc, char  *optv[], char  *file); | 
| 26 | greg | 1.1 |  | 
| 27 | schorsch | 1.3 |  | 
| 28 |  |  | int | 
| 29 |  |  | main( | 
| 30 |  |  | int  argc, | 
| 31 |  |  | char  *argv[] | 
| 32 |  |  | ) | 
| 33 | greg | 1.1 | { | 
| 34 |  |  | char  *getenv(); | 
| 35 |  |  | int  i, file0; | 
| 36 |  |  |  | 
| 37 |  |  | progname = argv[0]; | 
| 38 |  |  | libpath[0] = "./"; | 
| 39 |  |  | if ((libpath[i=1] = getenv("MDIR")) != NULL) | 
| 40 |  |  | i++; | 
| 41 |  |  | libpath[i++] = "/usr/local/lib/meta/"; | 
| 42 |  |  | libpath[i] = NULL; | 
| 43 |  |  |  | 
| 44 |  |  | for (file0 = 1; file0 < argc-1; file0 += 2) | 
| 45 |  |  | if (!isopt(argv[file0])) | 
| 46 |  |  | break; | 
| 47 |  |  |  | 
| 48 |  |  | if (file0 >= argc) | 
| 49 |  |  | dofile(argc-1, argv+1, NULL); | 
| 50 |  |  | else | 
| 51 |  |  | for (i = file0; i < argc; i++) | 
| 52 |  |  | dofile(file0-1, argv+1, argv[i]); | 
| 53 |  |  |  | 
| 54 |  |  | quit(0); | 
| 55 | schorsch | 1.3 | return 0; /* pro forma return */ | 
| 56 | greg | 1.1 | } | 
| 57 |  |  |  | 
| 58 |  |  |  | 
| 59 | schorsch | 1.3 | void | 
| 60 |  |  | dofile(         /* plot a file */ | 
| 61 |  |  | int  optc, | 
| 62 |  |  | char  *optv[], | 
| 63 |  |  | char  *file | 
| 64 |  |  | ) | 
| 65 | greg | 1.1 | { | 
| 66 |  |  | int  width = 79; | 
| 67 |  |  | int  length = 21; | 
| 68 |  |  | char  stmp[256]; | 
| 69 |  |  | int  i; | 
| 70 |  |  | /* start fresh */ | 
| 71 |  |  | mgclearall(); | 
| 72 |  |  | /* load file */ | 
| 73 |  |  | mgload(file); | 
| 74 |  |  | /* do options */ | 
| 75 |  |  | for (i = 0; i < optc; i += 2) | 
| 76 |  |  | if (optv[i][0] == '+') { | 
| 77 |  |  | sprintf(stmp, "%s=%s", optv[i]+1, optv[i+1]); | 
| 78 |  |  | setmgvar("command line", stdin, stmp); | 
| 79 |  |  | } else | 
| 80 |  |  | switch (optv[i][1]) { | 
| 81 |  |  | case 'w': | 
| 82 |  |  | width = atoi(optv[i+1]); | 
| 83 |  |  | break; | 
| 84 |  |  | case 'l': | 
| 85 |  |  | length = atoi(optv[i+1]); | 
| 86 |  |  | break; | 
| 87 |  |  | default: | 
| 88 |  |  | fprintf(stderr, "%s: unknown option: %s\n", | 
| 89 |  |  | progname, optv[i]); | 
| 90 |  |  | quit(1); | 
| 91 |  |  | } | 
| 92 |  |  |  | 
| 93 |  |  | /* graph it */ | 
| 94 |  |  | cgraph(width, length); | 
| 95 |  |  | } | 
| 96 |  |  |  | 
| 97 |  |  |  | 
| 98 | schorsch | 1.3 | void | 
| 99 |  |  | eputs(                          /* print error message */ | 
| 100 | greg | 1.4 | const char  *msg | 
| 101 | schorsch | 1.3 | ) | 
| 102 | greg | 1.1 | { | 
| 103 |  |  | fputs(msg, stderr); | 
| 104 |  |  | } | 
| 105 |  |  |  | 
| 106 |  |  |  | 
| 107 | schorsch | 1.3 | void | 
| 108 |  |  | quit(                           /* quit program */ | 
| 109 |  |  | int  code | 
| 110 |  |  | ) | 
| 111 | greg | 1.1 | { | 
| 112 |  |  | exit(code); | 
| 113 |  |  | } |