* Written by Emden Gansner
*/
+#include <assert.h>
#include <unistd.h>
#include "builddate.h"
#include <gvpr/gprstate.h>
freeOpts (options* opts)
{
int i;
- if (!opts) return;
+ assert(opts != NULL);
if (opts->outFile != sfstdout)
sfclose (opts->outFile);
free (opts->inFiles);
free (opts->argv[i]);
free (opts->argv);
}
- free (opts);
}
/* scanArgs:
* Parse command line options.
*/
-static options* scanArgs(int argc, char **argv) {
+static options scanArgs(int argc, char **argv) {
int i, nfiles;
char** input_filenames;
char* arg;
- options* opts = newof(0,options,1,0);
+ options opts = {0};
- opts->cmdName = argv[0];
- opts->state = 1;
- opts->readAhead = 1;
- setErrorId (opts->cmdName);
- opts->verbose = 0;
+ opts.cmdName = argv[0];
+ opts.state = 1;
+ opts.readAhead = 1;
+ setErrorId(opts.cmdName);
+ opts.verbose = 0;
/* estimate number of file names */
nfiles = 0;
for (i = 1; i < argc; ) {
arg = argv[i++];
if (*arg == '-') {
- i = doFlags (arg+1, i, argc, argv, opts);
+ i = doFlags(arg+1, i, argc, argv, &opts);
if (i <= 0) {
- opts->state = i;
+ opts.state = i;
goto opts_done;
}
} else if (arg)
}
/* Handle additional semantics */
- if (opts->useFile == 0) {
+ if (opts.useFile == 0) {
if (nfiles == 0) {
error(ERROR_ERROR,
"No program supplied via argument or -f option");
- opts->state = -1;
+ opts.state = -1;
} else {
- opts->program = input_filenames[0];
+ opts.program = input_filenames[0];
for (i = 1; i <= nfiles; i++)
input_filenames[i-1] = input_filenames[i];
nfiles--;
}
}
if (nfiles == 0) {
- opts->inFiles = 0;
+ opts.inFiles = 0;
free (input_filenames);
input_filenames = 0;
}
else
- opts->inFiles = input_filenames;
+ opts.inFiles = input_filenames;
- if (!(opts->outFile))
- opts->outFile = sfstdout;
+ if (!opts.outFile)
+ opts.outFile = sfstdout;
opts_done:
- if (opts->state <= 0) {
- if (opts->state < 0)
+ if (opts.state <= 0) {
+ if (opts.state < 0)
error(ERROR_USAGE|ERROR_ERROR, "%s", usage);
free (input_filenames);
}
Gpr_t *state = 0;
gpr_info info;
int rv = 0;
- options* opts = 0;
int cleanup, i, incoreGraphs;
Agraph_t* nextg = NULL;
if (uopts->err) setDisc (sfstderr, &errdisc, uopts->err);
}
- opts = scanArgs(argc, argv);
- if (opts->state <= 0) {
- rv = opts->state;
+ options opts = scanArgs(argc, argv);
+ if (opts.state <= 0) {
+ rv = opts.state;
goto finish;
}
- if (opts->verbose)
+ if (opts.verbose)
gvstart_timer ();
- prog = parseProg(opts->program, opts->useFile);
+ prog = parseProg(opts.program, opts.useFile);
if (!prog) {
rv = 1;
goto finish;
}
- info.outFile = opts->outFile;
- info.argc = opts->argc;
- info.argv = opts->argv;
+ info.outFile = opts.outFile;
+ info.argc = opts.argc;
+ info.argv = opts.argv;
info.errf = gverrorf;
if (uopts)
info.flags = uopts->flags;
}
if (uopts->bindings)
addBindings (state, uopts->bindings);
- xprog = compileProg(prog, state, opts->compflags);
+ xprog = compileProg(prog, state, opts.compflags);
if (!xprog) {
rv = 1;
goto finish;
else
incoreGraphs = 0;
- if (opts->verbose)
+ if (opts.verbose)
fprintf(stderr, "Parse/compile/init: %.2f secs.\n", gvelapsed_sec());
/* do begin */
if (xprog->begin_stmt)
if (uopts && uopts->ingraphs)
ing = newIngGraphs(0, uopts->ingraphs, &ingDisc);
else
- ing = newIng(0, opts->inFiles, &ingDisc);
+ ing = newIng(0, opts.inFiles, &ingDisc);
- if (opts->verbose) gvstart_timer ();
+ if (opts.verbose) gvstart_timer ();
for (state->curgraph = nextGraph(ing); state->curgraph; state->curgraph = nextg) {
- if (opts->verbose) fprintf(stderr, "Read graph: %.2f secs.\n", gvelapsed_sec());
+ if (opts.verbose) fprintf(stderr, "Read graph: %.2f secs.\n", gvelapsed_sec());
state->infname = fileName(ing);
- if (opts->readAhead)
+ if (opts.readAhead)
nextg = state->nextgraph = nextGraph(ing);
cleanup = 0;
comp_block* bp = xprog->blocks + i;
/* begin graph */
- if (incoreGraphs && (opts->compflags & CLONE))
+ if (incoreGraphs && (opts.compflags & CLONE))
state->curgraph = (Agraph_t*)clone (0, (Agobj_t*)(state->curgraph));
state->curobj = (Agobj_t *) state->curgraph;
state->tvroot = 0;
state->curobj = (Agobj_t *) state->curgraph;
if (xprog->endg_stmt)
exeval(xprog->prog, xprog->endg_stmt, state);
- if (opts->verbose) fprintf(stderr, "Finish graph: %.2f secs.\n", gvelapsed_sec());
+ if (opts.verbose) fprintf(stderr, "Finish graph: %.2f secs.\n", gvelapsed_sec());
/* if $O == $G and $T is empty, delete $T */
if ((state->outgraph == state->curgraph) &&
* be non-empty or the -c option was used.
*/
if (state->outgraph && (agnnodes(state->outgraph)
- || (opts->compflags & SRCOUT))) {
+ || (opts.compflags & SRCOUT))) {
if (uopts && (uopts->flags & GV_USE_OUTGRAPH))
addOutputGraph (state, uopts);
else
- sfioWrite (state->outgraph, opts->outFile, state->dfltIO);
+ sfioWrite (state->outgraph, opts.outFile, state->dfltIO);
}
if (!incoreGraphs)
state->target = 0;
state->outgraph = 0;
- if (opts->verbose) gvstart_timer ();
- if (!opts->readAhead)
+ if (opts.verbose) gvstart_timer ();
+ if (!opts.readAhead)
nextg = nextGraph(ing);
- if (opts->verbose && nextg) fprintf(stderr, "Read graph: %.2f secs.\n", gvelapsed_sec());
+ if (opts.verbose && nextg) fprintf(stderr, "Read graph: %.2f secs.\n", gvelapsed_sec());
}
}
freeCompileProg (xprog);
closeGPRState(state);
if (ing) closeIngraph (ing);
- freeOpts (opts);
+ freeOpts(&opts);
if (uopts) {
if (uopts->out) sfdisc (sfstdout, 0);