From: ellson Date: Sat, 29 Apr 2006 01:10:02 +0000 (+0000) Subject: stash input filenames for watching for file changes in GUIs X-Git-Tag: LAST_LIBGRAPH~32^2~6643 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b3dc634555a08249e4afa5e7cf69714eb3145ee3;p=graphviz stash input filenames for watching for file changes in GUIs --- diff --git a/lib/common/emit.c b/lib/common/emit.c index 6204aa8d7..84203322e 100644 --- a/lib/common/emit.c +++ b/lib/common/emit.c @@ -1414,7 +1414,7 @@ void emit_jobs_eof(GVC_t * gvc) { GVJ_t *job; - for (job = gvrender_first_job(gvc); job; job = gvrender_next_job(gvc)) { + for (job = gvjobs_first(gvc); job; job = gvjobs_next(gvc)) { if (job->output_file) { if (gvc->viewNum > 0) { gvrender_end_job(job); @@ -1900,7 +1900,7 @@ int gvRenderJobs (GVC_t * gvc, graph_t * g) gvc->numkeys = gvevent_key_binding_size; gvc->active_jobs = NULL; /* clear active list */ prev_job = NULL; - for (job = gvrender_first_job(gvc); job; job = gvrender_next_job(gvc)) { + for (job = gvjobs_first(gvc); job; job = gvjobs_next(gvc)) { if (!job->output_file) { /* if not yet opened */ if (job->output_filename == NULL) { job->output_file = stdout; diff --git a/lib/common/input.c b/lib/common/input.c index 77c8de9a5..bb646d2d1 100644 --- a/lib/common/input.c +++ b/lib/common/input.c @@ -171,7 +171,7 @@ void dotneato_args_initialize(GVC_t * gvc, int argc, char **argv) for (i = 1; i < argc; i++) if (argv[i] && argv[i][0] != '-') nfiles++; - Files = N_NEW(nfiles + 1, char *); + gvc->input_filenames = N_NEW(nfiles + 1, char *); nfiles = 0; for (i = 1; i < argc; i++) { if (argv[i] && argv[i][0] == '-') { @@ -208,7 +208,7 @@ void dotneato_args_initialize(GVC_t * gvc, int argc, char **argv) dotneato_usage(1); exit(1); } - v = gvrender_output_langname_job(gvc, val); + v = gvjobs_output_langname(gvc, val); if (!v) { fprintf(stderr, "Renderer type: \"%s\" not recognized. Use one of:%s\n", val, gvplugin_list(gvc, API_render, val)); @@ -244,7 +244,7 @@ void dotneato_args_initialize(GVC_t * gvc, int argc, char **argv) break; case 'o': val = getFlagOpt(argc, argv, &i); - gvrender_output_filename_job(gvc, val); + gvjobs_output_filename(gvc, val); break; case 'q': if (*rest) { @@ -292,12 +292,12 @@ void dotneato_args_initialize(GVC_t * gvc, int argc, char **argv) dotneato_usage(1); } } else if (argv[i]) - Files[nfiles++] = argv[i]; + gvc->input_filenames[nfiles++] = argv[i]; } /* if no -Txxx, then set default format */ if (!gvc->jobs || !gvc->jobs->output_langname) { - v = gvrender_output_langname_job(gvc, "dot"); + v = gvjobs_output_langname(gvc, "dot"); assert(v); /* "dot" should always be available as an output format */ } @@ -358,48 +358,48 @@ void getdouble(graph_t * g, char *name, double *result) } } -static FILE *next_input_file(void) +graph_t *gvNextInputGraph(GVC_t *gvc) { - static int ctr = 0; - FILE *rv = NULL; - - if (Files[0] == NULL) { - if (ctr++ == 0) - rv = stdin; - } else { - rv = NULL; - while (Files[ctr]) { - if ((rv = fopen(Files[ctr++], "r"))) - break; + graph_t *g = NULL; + char *fn = NULL; + static FILE *fp; + static int fidx, gidx; + GVG_t *gvg; + + while (!g) { + if (!fp) { + if (!(fn = gvc->input_filenames[0])) { + if (fidx++ == 0) + fp = stdin; + } else { - agerr(AGERR, "%s: can't open %s\n", CmdName, - Files[ctr - 1]); - graphviz_errors++; + while ((fn = gvc->input_filenames[fidx++]) && !(fp = fopen(fn, "r"))) { + agerr(AGERR, "%s: can't open %s\n", CmdName, fn); + graphviz_errors++; + } } } - } - if (rv) - agsetfile(Files[0] ? Files[ctr - 1] : ""); - return rv; -} - -graph_t *next_input_graph(void) -{ - graph_t *g; - static FILE *fp; - - if (fp == NULL) - fp = next_input_file(); - g = NULL; - - while (fp != NULL) { - if ((g = agread(fp))) + if (fp == NULL) break; - fp = next_input_file(); + agsetfile(fn ? fn : ""); + if ((g = agread(fp))) { + gvg = zmalloc(sizeof(GVG_t)); + if (!gvc->gvgs) + gvc->gvgs = gvg; + else + gvc->gvg->next = gvg; + gvc->gvg = gvg; + gvg->gvc = gvc; + gvg->g = g; + gvg->input_filename = fn; + gvg->graph_index = gidx++; + break; + } + fp = NULL; + gidx = 0; } return g; } - /* findCharset: * Check if the charset attribute is defined for the graph and, if * so, return the corresponding internal value. If undefined, return diff --git a/lib/gvc/gvc.c b/lib/gvc/gvc.c index ee2be9d8b..00eee7fb4 100644 --- a/lib/gvc/gvc.c +++ b/lib/gvc/gvc.c @@ -90,7 +90,7 @@ int gvRender(GVC_t *gvc, graph_t *g, char *format, FILE *out) g = g->root; /* create a job for the required format */ - rc = gvrender_output_langname_job(gvc, format); + rc = gvjobs_output_langname(gvc, format); if (rc == NO_SUPPORT) { agerr (AGERR, "Renderer type: \"%s\" not recognized. Use one of:%s\n", format, gvplugin_list(gvc, API_render, format)); @@ -107,7 +107,7 @@ int gvRender(GVC_t *gvc, graph_t *g, char *format, FILE *out) gvRenderJobs(gvc, g); if (gvc->active_jobs) gvdevice_finalize(gvc); - gvrender_delete_jobs(gvc); + gvjobs_delete(gvc); return 0; } @@ -121,7 +121,7 @@ int gvRenderFilename(GVC_t *gvc, graph_t *g, char *format, char *filename) g = g->root; /* create a job for the required format */ - rc = gvrender_output_langname_job(gvc, format); + rc = gvjobs_output_langname(gvc, format); if (rc == NO_SUPPORT) { agerr(AGERR, "Renderer type: \"%s\" not recognized. Use one of:%s\n", format, gvplugin_list(gvc, API_render, format)); return -1; @@ -133,11 +133,11 @@ int gvRenderFilename(GVC_t *gvc, graph_t *g, char *format, char *filename) fprintf(stderr, "Layout was not done\n"); return -1; } - gvrender_output_filename_job(gvc, filename); + gvjobs_output_filename(gvc, filename); gvRenderJobs(gvc, g); if (gvc->active_jobs) gvdevice_finalize(gvc); - gvrender_delete_jobs(gvc); + gvjobs_delete(gvc); return 0; } diff --git a/lib/gvc/gvc.h b/lib/gvc/gvc.h index c4589b6bf..d38a92ebe 100644 --- a/lib/gvc/gvc.h +++ b/lib/gvc/gvc.h @@ -47,11 +47,11 @@ extern "C" { #define gvCleanup gvCleanup_DEPRECATED_BY_gvFreeContext #define dotneato_terminate dotneato_terminate_DEPRECATED_BY_gvFreeContext +#define next_input_graph next_input_graph_DEPRECATED_BY_gvNextInputGraph /* misc */ -/* FIXME - these need eliminating or renaming */ +/* FIXME - this needs eliminating or renaming */ extern void gvToggle(int); -extern graph_t *next_input_graph(void); /* set up a graphviz context */ extern GVC_t *gvNEWcontext(char **info, char *user); @@ -63,6 +63,7 @@ extern GVC_t *gvContext(void); /* parse command line args - minimally argv[0] sets layout engine */ extern int gvParseArgs(GVC_t *gvc, int argc, char **argv); +extern graph_t *gvNextInputGraph(GVC_t *gvc); /* Compute a layout using a specified engine */ extern int gvLayout(GVC_t *gvc, graph_t *g, char *engine); diff --git a/lib/gvc/gvcint.h b/lib/gvc/gvcint.h index 996539d2e..d393036ec 100644 --- a/lib/gvc/gvcint.h +++ b/lib/gvc/gvcint.h @@ -64,6 +64,17 @@ extern "C" { or NULL if not yet loaded */ }; + typedef struct GVG_s GVG_t; + + struct GVG_s { + GVC_t *gvc; /* parent gvc */ + GVG_t *next; /* next gvg in list */ + + char *input_filename; /* or NULL if stdin */ + int graph_index; /* index of graph within input_file */ + graph_t *g; + }; + #define MAXNEST 4 struct GVC_s { @@ -74,16 +85,14 @@ extern "C" { char *config_path; bool config_found; - /* gvrender_config() */ - GVJ_t *jobs; /* linked list of jobs */ - GVJ_t *job; /* current job */ void (*errorfn) (char *fmt, ...); - int emit_state; /* current emit_state */ - graph_t *g; /* current graph */ - graph_t *sg; /* current subgraph/cluster */ - node_t *n; /* current node */ - edge_t *e; /* current edge */ + /* gvParseArgs */ + char **input_filenames; /* null terminated array of input filenames */ + + /* gvNextInputGraph() */ + GVG_t *gvgs; /* linked list of graphs */ + GVG_t *gvg; /* current graph */ /* plugins */ #define ELEM(x) +1 @@ -92,6 +101,23 @@ extern "C" { gvplugin_available_t *api[ APIS ]; /* array of current plugins per api */ #undef ELEM + /* keybindings for keyboard events */ + gvevent_key_binding_t *keybindings; + int numkeys; + void *keycodes; + +/* FIXME - everything below should probably move to GVG_t */ + + /* gvrender_config() */ + GVJ_t *jobs; /* linked list of jobs */ + GVJ_t *job; /* current job */ + + int emit_state; /* current emit_state */ + graph_t *g; /* current graph */ + graph_t *sg; /* current subgraph/cluster */ + node_t *n; /* current node */ + edge_t *e; /* current edge */ + /* gvrender_begin_job() */ gvplugin_active_textlayout_t textlayout; gvplugin_active_usershape_t usershape; @@ -131,11 +157,6 @@ extern "C" { /* render defaults set from graph */ gvcolor_t bgcolor; /* background color */ - - /* keybindings for keyboard events */ - gvevent_key_binding_t *keybindings; - int numkeys; - void *keycodes; }; #ifdef __cplusplus diff --git a/lib/gvc/gvcjob.h b/lib/gvc/gvcjob.h index eff43f0c9..742e8cd83 100644 --- a/lib/gvc/gvcjob.h +++ b/lib/gvc/gvcjob.h @@ -137,6 +137,10 @@ extern "C" { GVC_t *gvc; /* parent gvc */ GVJ_t *next; /* linked list of jobs */ GVJ_t *next_active; /* linked list of active jobs (e.g. multiple windows) */ + + char *input_filename; + int graph_index; + char *output_filename; char *output_langname; FILE *output_file; diff --git a/lib/gvc/gvcontext.c b/lib/gvc/gvcontext.c index c434e65d2..762bf200f 100644 --- a/lib/gvc/gvcontext.c +++ b/lib/gvc/gvcontext.c @@ -55,12 +55,21 @@ GVC_t *gvNEWcontext(char **info, char *user) int gvFreeContext(GVC_t * gvc) { + GVG_t *gvg, *gvg_next; + if (gvc->active_jobs) gvdevice_finalize(gvc); emit_jobs_eof(gvc); - gvrender_delete_jobs(gvc); + gvg_next = gvc->gvgs; + while ((gvg = gvg_next)) { + gvg_next = gvg->next; + free(gvg); + } + gvjobs_delete(gvc); if (gvc->config_path) free(gvc->config_path); + if (gvc->input_filenames) + free(gvc->input_filenames); free(gvc); return (graphviz_errors + agerrors()); } diff --git a/lib/gvc/gvcproc.h b/lib/gvc/gvcproc.h index b85a4cf0e..8419215b5 100644 --- a/lib/gvc/gvcproc.h +++ b/lib/gvc/gvcproc.h @@ -45,11 +45,11 @@ extern "C" { /* job */ - extern void gvrender_output_filename_job(GVC_t * gvc, char *name); - extern bool gvrender_output_langname_job(GVC_t * gvc, char *name); - extern GVJ_t *gvrender_first_job(GVC_t * gvc); - extern GVJ_t *gvrender_next_job(GVC_t * gvc); - extern void gvrender_delete_jobs(GVC_t * gvc); + extern void gvjobs_output_filename(GVC_t * gvc, char *name); + extern bool gvjobs_output_langname(GVC_t * gvc, char *name); + extern GVJ_t *gvjobs_first(GVC_t * gvc); + extern GVJ_t *gvjobs_next(GVC_t * gvc); + extern void gvjobs_delete(GVC_t * gvc); /* emit */ extern void gvemit_graph(GVC_t * gvc, graph_t * g); diff --git a/lib/gvc/gvjobs.c b/lib/gvc/gvjobs.c index 9676a0cdc..1824ae374 100644 --- a/lib/gvc/gvjobs.c +++ b/lib/gvc/gvjobs.c @@ -46,7 +46,7 @@ static GVJ_t *output_langname_job; */ /* -o switches */ -void gvrender_output_filename_job(GVC_t * gvc, char *name) +void gvjobs_output_filename(GVC_t * gvc, char *name) { if (!gvc->jobs) { output_filename_job = gvc->job = gvc->jobs = @@ -67,7 +67,7 @@ void gvrender_output_filename_job(GVC_t * gvc, char *name) } /* -T switches */ -bool gvrender_output_langname_job(GVC_t * gvc, char *name) +bool gvjobs_output_langname(GVC_t * gvc, char *name) { if (!gvc->jobs) { output_langname_job = gvc->job = gvc->jobs = @@ -92,12 +92,12 @@ bool gvrender_output_langname_job(GVC_t * gvc, char *name) return FALSE; } -GVJ_t *gvrender_first_job(GVC_t * gvc) +GVJ_t *gvjobs_first(GVC_t * gvc) { return (gvc->job = gvc->jobs); } -GVJ_t *gvrender_next_job(GVC_t * gvc) +GVJ_t *gvjobs_next(GVC_t * gvc) { GVJ_t *job = gvc->job->next; @@ -140,7 +140,7 @@ void gv_argvlist_free(gv_argvlist_t *list) free(list); } -void gvrender_delete_jobs(GVC_t * gvc) +void gvjobs_delete(GVC_t * gvc) { GVJ_t *job, *j; diff --git a/lib/gvc/gvrender.c b/lib/gvc/gvrender.c index 138d304fe..6577403ba 100644 --- a/lib/gvc/gvrender.c +++ b/lib/gvc/gvrender.c @@ -126,7 +126,8 @@ void gvrender_begin_job(GVJ_t * job) { GVC_t *gvc = job->gvc; gvrender_engine_t *gvre = job->render.engine; - + job->input_filename = gvc->gvg->input_filename; + job->graph_index = gvc->gvg->graph_index; job->bb = gvc->bb; if (gvre) { if (gvre->begin_job) diff --git a/tclpkg/tcldot/tcldot.c b/tclpkg/tcldot/tcldot.c index ca428f264..f6e5b672b 100644 --- a/tclpkg/tcldot/tcldot.c +++ b/tclpkg/tcldot/tcldot.c @@ -1079,7 +1079,7 @@ static int graphcmd(ClientData clientData, Tcl_Interp * interp, } tkgendata.interp = interp; - rc = gvrender_output_langname_job(gvc, "tk"); + rc = gvjobs_output_langname(gvc, "tk"); if (rc == NO_SUPPORT) { Tcl_AppendResult(interp, " Renderer type: \"tk\" not recognized.\n", (char *) 0); @@ -1098,7 +1098,7 @@ static int graphcmd(ClientData clientData, Tcl_Interp * interp, /* render graph TK canvas commands */ gvRenderJobs(gvc, g); - gvrender_delete_jobs(gvc); + gvjobs_delete(gvc); return TCL_OK; } else if ((c == 'r') && (strncmp(argv[1], "rendergd", length) == 0)) { @@ -1110,7 +1110,7 @@ static int graphcmd(ClientData clientData, Tcl_Interp * interp, (char *) NULL); return TCL_ERROR; } - rc = gvrender_output_langname_job(gvc, "gd"); + rc = gvjobs_output_langname(gvc, "gd"); if (rc == NO_SUPPORT) { Tcl_AppendResult(interp, " Renderer type: \"gd\" not recognized.\n", (char *) 0); @@ -1132,7 +1132,7 @@ static int graphcmd(ClientData clientData, Tcl_Interp * interp, gvRenderJobs(gvc, g); - gvrender_delete_jobs(gvc); + gvjobs_delete(gvc); Tcl_AppendResult(interp, argv[2], (char *) NULL); return TCL_OK; @@ -1244,9 +1244,9 @@ static int graphcmd(ClientData clientData, Tcl_Interp * interp, /* process lang first to create job */ if (argc < 4) { - i = gvrender_output_langname_job(gvc, "dot"); + i = gvjobs_output_langname(gvc, "dot"); } else { - i = gvrender_output_langname_job(gvc, argv[3]); + i = gvjobs_output_langname(gvc, argv[3]); } if (i == NO_SUPPORT) { const char *s = gvplugin_list(gvc, API_render, argv[3]); @@ -1272,7 +1272,7 @@ static int graphcmd(ClientData clientData, Tcl_Interp * interp, gvRenderJobs(gvc, g); - gvrender_delete_jobs(gvc); + gvjobs_delete(gvc); return TCL_OK; } else {