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