]> granicus.if.org Git - graphviz/commitdiff
stash input filenames for watching for file changes in GUIs
authorellson <devnull@localhost>
Sat, 29 Apr 2006 01:10:02 +0000 (01:10 +0000)
committerellson <devnull@localhost>
Sat, 29 Apr 2006 01:10:02 +0000 (01:10 +0000)
lib/common/emit.c
lib/common/input.c
lib/gvc/gvc.c
lib/gvc/gvc.h
lib/gvc/gvcint.h
lib/gvc/gvcjob.h
lib/gvc/gvcontext.c
lib/gvc/gvcproc.h
lib/gvc/gvjobs.c
lib/gvc/gvrender.c
tclpkg/tcldot/tcldot.c

index 6204aa8d76af75fdaf164b825df9aa15c884f856..84203322ec2ee08644df854f1f54ef64484859f3 100644 (file)
@@ -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;
index 77c8de9a530e3baf5980164562df2e428a0e6408..bb646d2d1b0dbbe06dcd0899ddb2a16114859947 100644 (file)
@@ -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] : "<stdin>");
-    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 : "<stdin>");
+       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
index ee2be9d8bbc14c5f13cfd9648e246a9211f15756..00eee7fb4b1a5de77ebd3423b35e560925935fb2 100644 (file)
@@ -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;
 }
index c4589b6bff58902aae480a63f077b3ec41888a32..d38a92ebe517d3649bb10fd480def591bdabb098 100644 (file)
@@ -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);
index 996539d2efd25c46e98ac39cd393083191ded271..d393036ec9ef45565a5e29d3d4ad5c9472734f15 100644 (file)
@@ -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
index eff43f0c945410aa5b8619f30b790475b4d013ad..742e8cd830334a90f741e4d684a8ea3de7481f3e 100644 (file)
@@ -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;
index c434e65d231ade9049621399ef8d895103c9ae63..762bf200ff2bd7a129ff6e70f646b7f8ef6717f3 100644 (file)
@@ -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());
 }
index b85a4cf0ef94fb5ab3f14ec5b0bdd4eef9e1c41b..8419215b58d1accf2ab838ee7024a6671072e7a7 100644 (file)
@@ -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);
index 9676a0cdcb7a2c4a7a299dbec3022da32b254e75..1824ae3746ccd9e17e1ef77629941640a35b8905 100644 (file)
@@ -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;
 
index 138d304fe9ed7672422eff58fd7b8a70d88c2e71..6577403babeddae894eb0702f6420de5d18fac8f 100644 (file)
@@ -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)
index ca428f264de14cc9ff16e0646656a859d990465f..f6e5b672b343f8eff3492081a2dd8498f1b9d323 100644 (file)
@@ -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 {