| 1 |
#ifndef lint
|
| 2 |
static const char RCSid[] = "$Id: gcomp.c,v 1.3 2003/11/15 02:13:37 schorsch Exp $";
|
| 3 |
#endif
|
| 4 |
/*
|
| 5 |
* gcomp.c - program to calculate things from graph files.
|
| 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 "meta.h"
|
| 17 |
#include "mgvars.h"
|
| 18 |
|
| 19 |
#define istyp(s) (s[0] == '-')
|
| 20 |
|
| 21 |
#define isvar(s) (s[0] == '+')
|
| 22 |
|
| 23 |
char *progname;
|
| 24 |
|
| 25 |
char *libpath[4];
|
| 26 |
|
| 27 |
static void dofile(int optc, char *optv[], char *file);
|
| 28 |
|
| 29 |
int
|
| 30 |
main(
|
| 31 |
int argc,
|
| 32 |
char *argv[]
|
| 33 |
)
|
| 34 |
{
|
| 35 |
char *getenv();
|
| 36 |
int i, file0;
|
| 37 |
|
| 38 |
progname = argv[0];
|
| 39 |
libpath[0] = "./";
|
| 40 |
if ((libpath[i=1] = getenv("MDIR")) != NULL)
|
| 41 |
i++;
|
| 42 |
libpath[i++] = MDIR;
|
| 43 |
libpath[i] = NULL;
|
| 44 |
|
| 45 |
for (file0 = 1; file0 < argc; )
|
| 46 |
if (istyp(argv[file0]))
|
| 47 |
file0++;
|
| 48 |
else if (isvar(argv[file0]) && file0 < argc-1)
|
| 49 |
file0 += 2;
|
| 50 |
else
|
| 51 |
break;
|
| 52 |
|
| 53 |
if (file0 >= argc)
|
| 54 |
dofile(argc-1, argv+1, NULL);
|
| 55 |
else
|
| 56 |
for (i = file0; i < argc; i++)
|
| 57 |
dofile(file0-1, argv+1, argv[i]);
|
| 58 |
|
| 59 |
quit(0);
|
| 60 |
return 0; /* pro forma return */
|
| 61 |
}
|
| 62 |
|
| 63 |
|
| 64 |
void
|
| 65 |
dofile( /* plot a file */
|
| 66 |
int optc,
|
| 67 |
char *optv[],
|
| 68 |
char *file
|
| 69 |
)
|
| 70 |
{
|
| 71 |
char types[16], stmp[256], *strcat();
|
| 72 |
int i;
|
| 73 |
|
| 74 |
mgclearall();
|
| 75 |
|
| 76 |
mgload(file);
|
| 77 |
|
| 78 |
types[0] = '\0';
|
| 79 |
for (i = 0; i < optc; i++)
|
| 80 |
if (istyp(optv[i]))
|
| 81 |
strcat(types, optv[i]+1);
|
| 82 |
else {
|
| 83 |
sprintf(stmp, "%s=%s", optv[i]+1, optv[i+1]);
|
| 84 |
setmgvar("command line", stdin, stmp);
|
| 85 |
i++;
|
| 86 |
}
|
| 87 |
|
| 88 |
gcalc(types);
|
| 89 |
}
|
| 90 |
|
| 91 |
|
| 92 |
void
|
| 93 |
eputs( /* print error message */
|
| 94 |
const char *msg
|
| 95 |
)
|
| 96 |
{
|
| 97 |
fputs(msg, stderr);
|
| 98 |
}
|
| 99 |
|
| 100 |
|
| 101 |
void
|
| 102 |
quit( /* quit program */
|
| 103 |
int code
|
| 104 |
)
|
| 105 |
{
|
| 106 |
exit(code);
|
| 107 |
}
|