]> granicus.if.org Git - graphviz/commitdiff
train -O to work with multiple graphs per input file
authorellson <devnull@localhost>
Tue, 27 Jun 2006 16:57:25 +0000 (16:57 +0000)
committerellson <devnull@localhost>
Tue, 27 Jun 2006 16:57:25 +0000 (16:57 +0000)
lib/common/emit.c
lib/common/input.c

index 9142de56dd6e4b54c0722d7e88c3d14048772d63..2222844bdc5e9df84272f18c7e16688d243b2cf5 100644 (file)
@@ -1809,6 +1809,37 @@ static void init_bb(graph_t *g)
                        init_bb_node(g, n);
 }
 
+static void auto_output_filename(GVJ_t *job)
+{
+    static char *buf;
+    static int bufsz;
+    char gidx[20];
+    char *fn;
+    int len;
+
+    if (job->graph_index)
+       snprintf(gidx, sizeof(gidx), ".%d", job->graph_index + 1);
+    else
+       gidx[0] = '\0';
+    if (!(fn = job->input_filename))
+       fn = "noname.dot";
+    len = strlen(fn)                   /* typically "something.dot" */
+       + strlen(gidx)                  /* "", ".2", ".3", ".4", ... */
+       + 1                             /* "." */
+       + strlen(job->output_langname)  /* e.g. "png" */
+       + 1;                            /* null terminaor */
+    if (bufsz < len) {
+           bufsz = len + 10;
+           buf = realloc(buf, bufsz * sizeof(char));
+    }
+    strcpy(buf, fn);
+    strcat(buf, gidx);
+    strcat(buf, ".");
+    strcat(buf, job->output_langname);
+
+    job->output_filename = buf;
+}
+
 extern gvevent_key_binding_t gvevent_key_binding[];
 extern int gvevent_key_binding_size;
 extern gvdevice_callbacks_t gvdevice_callbacks;
@@ -1816,10 +1847,6 @@ extern gvdevice_callbacks_t gvdevice_callbacks;
 int gvRenderJobs (GVC_t * gvc, graph_t * g)
 {
     GVJ_t *job, *prev_job, *active_job;
-    static char *buf;
-    static int bufsz;
-    int len;
-    char *inf;
 
     if (!GD_drawing(g)) {
         agerr (AGERR, "Layout was not done.  Missing layout plugins? \n");
@@ -1866,26 +1893,12 @@ int gvRenderJobs (GVC_t * gvc, graph_t * g)
         }
 
         if (!job->output_file) {        /* if not yet opened */
-           if (gvc->common.auto_outfile_names) {
-               if (!(inf = job->input_filename))
-                   inf = "noname";
-               len = strlen(inf) + 1 + strlen(job->output_langname) +1;
-               if (bufsz < len) {
-                   bufsz = len + 10;
-                   buf = realloc(buf, bufsz * sizeof(char));
-               }
-               strcpy(buf, inf);
-               strcat(buf, ".");
-               strcat(buf, job->output_langname);
-
-               job->output_filename = buf;
-           }
-
-            if (job->output_filename == NULL) {
-                job->output_file = stdout;
-            } else {
+           if (gvc->common.auto_outfile_names)
+               auto_output_filename(job);
+            if (job->output_filename)
                 job->output_file = file_select(job->output_filename);
-            }
+            else
+                job->output_file = stdout;
         }
 
        if (prev_job)
index d93843db2ee769419d9d9f0bde211ac158b75893..4d013e97656177e67413822afc43aac4e4161076 100644 (file)
@@ -427,7 +427,7 @@ static char *myfgets(char * ubuf, int n, FILE * fp)
 graph_t *gvNextInputGraph(GVC_t *gvc)
 {
     graph_t *g = NULL;
-    char *fn = NULL;
+    static char *fn;
     static FILE *fp;
     static int fidx, gidx;
     GVG_t *gvg;