| 1 |
#ifndef lint |
| 2 |
static const char RCSid[] = "$Id: dgraph.c,v 1.2 2003/08/01 14:14:24 schorsch Exp $"; |
| 3 |
#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 |
#include <stdlib.h> |
| 13 |
#include <stdio.h> |
| 14 |
|
| 15 |
#include "rterror.h" |
| 16 |
#include "mgvars.h" |
| 17 |
#include "meta.h" |
| 18 |
|
| 19 |
#define isopt(s) (s[0] == '+' || s[0] == '-') |
| 20 |
|
| 21 |
char *progname; |
| 22 |
|
| 23 |
char *libpath[4]; |
| 24 |
|
| 25 |
static void dofile(int optc, char *optv[], char *file); |
| 26 |
|
| 27 |
|
| 28 |
int |
| 29 |
main( |
| 30 |
int argc, |
| 31 |
char *argv[] |
| 32 |
) |
| 33 |
{ |
| 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 |
return 0; /* pro forma return */ |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
void |
| 60 |
dofile( /* plot a file */ |
| 61 |
int optc, |
| 62 |
char *optv[], |
| 63 |
char *file |
| 64 |
) |
| 65 |
{ |
| 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 |
void |
| 99 |
eputs( /* print error message */ |
| 100 |
char *msg |
| 101 |
) |
| 102 |
{ |
| 103 |
fputs(msg, stderr); |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
void |
| 108 |
quit( /* quit program */ |
| 109 |
int code |
| 110 |
) |
| 111 |
{ |
| 112 |
exit(code); |
| 113 |
} |