From 451c03038eac54d6905641bce390c97f78920fd1 Mon Sep 17 00:00:00 2001 From: ellson Date: Tue, 27 Jun 2006 16:57:25 +0000 Subject: [PATCH] train -O to work with multiple graphs per input file --- lib/common/emit.c | 59 ++++++++++++++++++++++++++++------------------ lib/common/input.c | 2 +- 2 files changed, 37 insertions(+), 24 deletions(-) diff --git a/lib/common/emit.c b/lib/common/emit.c index 9142de56d..2222844bd 100644 --- a/lib/common/emit.c +++ b/lib/common/emit.c @@ -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) diff --git a/lib/common/input.c b/lib/common/input.c index d93843db2..4d013e976 100644 --- a/lib/common/input.c +++ b/lib/common/input.c @@ -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; -- 2.40.0