From: Emden Gansner <erg@research.att.com> Date: Tue, 6 Sep 2011 17:57:48 +0000 (-0400) Subject: Cleanup up cgraph code. In particular, add necessary agbindrec calls. X-Git-Tag: LAST_LIBGRAPH~32^2~674^2~1^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=78fad2600edec10a77e2d7b879e816873f4fad8d;p=graphviz Cleanup up cgraph code. In particular, add necessary agbindrec calls. --- diff --git a/lib/circogen/blockpath.c b/lib/circogen/blockpath.c index c01ea1c9e..5844bc03c 100644 --- a/lib/circogen/blockpath.c +++ b/lib/circogen/blockpath.c @@ -170,7 +170,7 @@ static void find_pair_edges(Agraph_t * g, Agnode_t * n, Agraph_t * outg) #ifndef WITH_CGRAPH agedge(g, tp, hp); #else /* WITH_CGRAPH */ - agbindrec(agedge(g, tp, hp, NULL, 1), "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE); //node custom data + agbindrec(agedge(g, tp, hp, NULL, 1), "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE); // edge custom data #endif /* WITH_CGRAPH */ DEGREE(tp)++; @@ -186,7 +186,7 @@ static void find_pair_edges(Agraph_t * g, Agnode_t * n, Agraph_t * outg) agedge(g, tp, hp); #else /* WITH_CGRAPH */ - agbindrec(agedge(g, tp, hp, NULL, 1), "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE); //node custom data + agbindrec(agedge(g, tp, hp, NULL, 1), "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE); // edge custom data #endif /* WITH_CGRAPH */ DEGREE(tp)++; diff --git a/lib/common/htmltable.c b/lib/common/htmltable.c index c0e16a7a4..dc007afe3 100644 --- a/lib/common/htmltable.c +++ b/lib/common/htmltable.c @@ -168,6 +168,7 @@ emit_htextparas(GVJ_t* job, int nparas, htextpara_t* paras, pointf p, tl.str = ti->str; tl.fontname = fname_; tl.fontsize = fsize_; + tl.font = ti->font; tl.yoffset_layout = ti->yoffset_layout; /* tl.yoffset_centerline = ti->yoffset_centerline; */ tl.yoffset_centerline = 1; @@ -1236,6 +1237,7 @@ static void checkChain(graph_t * g) if (!agfindedge(g, t, h)) { #ifdef WITH_CGRAPH e = agedge(g, t, h, NULL, 1); + agbindrec(e, "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE); #else e = agedge(g, t, h); #endif @@ -1273,6 +1275,7 @@ void makeGraphs(htmltbl_t * tbl, graph_t * rowg, graph_t * colg) for (i = 0; i <= tbl->cc; i++) { #ifdef WITH_CGRAPH t = agnode(colg, nToName(i),1); + agbindrec(t, "Agnodeinfo_t", sizeof(Agnodeinfo_t), TRUE); #else t = agnode(colg, nToName(i)); #endif @@ -1289,6 +1292,7 @@ void makeGraphs(htmltbl_t * tbl, graph_t * rowg, graph_t * colg) for (i = 0; i <= tbl->rc; i++) { #ifdef WITH_CGRAPH t = agnode(rowg, nToName(i),1); + agbindrec(t, "Agnodeinfo_t", sizeof(Agnodeinfo_t), TRUE); #else t = agnode(rowg, nToName(i)); #endif @@ -1320,6 +1324,7 @@ void makeGraphs(htmltbl_t * tbl, graph_t * rowg, graph_t * colg) h = agfindnode(colg, nToName(cp->col + cp->cspan)); #ifdef WITH_CGRAPH e = agedge(colg, t, h, NULL, 1); + agbindrec(e, "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE); #else e = agedge(colg, t, h); #endif @@ -1339,6 +1344,7 @@ void makeGraphs(htmltbl_t * tbl, graph_t * rowg, graph_t * colg) h = agfindnode(rowg, nToName(cp->row + cp->rspan)); #ifdef WITH_CGRAPH e = agedge(rowg, t, h, NULL, 1); + agbindrec(e, "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE); #else e = agedge(rowg, t, h); #endif @@ -1416,6 +1422,9 @@ void sizeArray(htmltbl_t * tbl) #else rowg = agopen("rowg", AGDIGRAPH); colg = agopen("colg", AGDIGRAPH); + /* Only need GD_nlist */ + agbindrec(rowg, "Agraphinfo_t", sizeof(Agraphinfo_t), TRUE); // graph custom data + agbindrec(colg, "Agraphinfo_t", sizeof(Agraphinfo_t), TRUE); // graph custom data #endif makeGraphs(tbl, rowg, colg); rank(rowg, 2, INT_MAX); diff --git a/lib/common/utils.c b/lib/common/utils.c index 3d44db954..8b4ee52b6 100644 --- a/lib/common/utils.c +++ b/lib/common/utils.c @@ -305,7 +305,6 @@ char *Fgets(FILE * fp) /* safefile: * Check to make sure it is okay to read in files. - * For normal uses, it is a no-op, and returns the input. * It returns NULL if the filename is trivial. * * If the application has set the SERVER_NAME environment variable, @@ -324,30 +323,67 @@ char *Fgets(FILE * fp) * If filename contains multiple components, the user is * warned, once, that everything to the left is ignored. * + * For non-server applications, we use the path list in Gvimagepath to + * resolve relative pathnames. + * * N.B. safefile uses a fixed buffer, so functions using it should use the * value immediately or make a copy. */ #ifdef WIN32 -#define DIRSEP "\\" #define PATHSEP ";" #else -#define DIRSEP "/" #define PATHSEP ":" #endif +static char** mkDirlist (const char* list, int* maxdirlen) +{ + int cnt = 0; + char* s = strdup (list); + char* dir; + char** dirs = NULL; + int maxlen = 0; + + for (dir = strtok (s, PATHSEP); dir; dir = strtok (NULL, PATHSEP)) { + dirs = ALLOC (cnt+2,dirs,char*); + dirs[cnt++] = dir; + maxlen = MAX(maxlen, strlen (dir)); + } + dirs[cnt] = NULL; + *maxdirlen = maxlen; + return dirs; +} + +static char* findPath (char** dirs, int maxdirlen, const char* str) +{ + static char *safefilename = NULL; + char** dp; + + /* allocate a buffer that we are sure is big enough + * +1 for null character. + * +1 for directory separator character. + */ + safefilename = realloc(safefilename, (maxdirlen + strlen(str) + 2)); + + for (dp = dirs; *dp; dp++) { + sprintf (safefilename, "%s%s%s", *dp, DIRSEP, str); + if (access (safefilename, R_OK) == 0) + return safefilename; + } + return NULL; +} + const char *safefile(const char *filename) { static boolean onetime = TRUE; - static boolean firsttime = TRUE; - static char *safefilename = NULL; + static char *pathlist = NULL; static int maxdirlen; static char** dirs; - char** dp; const char *str, *p; if (!filename || !filename[0]) return NULL; - if (HTTPServerEnVar) { + + if (HTTPServerEnVar) { /* If used as a server */ /* * If we are running in an http server we allow * files only from the directory specified in @@ -363,17 +399,9 @@ const char *safefile(const char *filename) } return NULL; } - if (firsttime) { - int cnt = 0; - char* s = strdup (Gvfilepath); - char* dir; - for (dir = strtok (s, PATHSEP); dir; dir = strtok (NULL, PATHSEP)) { - dirs = ALLOC (cnt+2,dirs,char*); - dirs[cnt++] = dir; - maxdirlen = MAX(maxdirlen, strlen (dir)); - } - dirs[cnt] = NULL; - firsttime = FALSE; + if (!pathlist) { + dirs = mkDirlist (Gvfilepath, &maxdirlen); + pathlist = Gvfilepath; } str = filename; @@ -391,23 +419,24 @@ const char *safefile(const char *filename) onetime = FALSE; } - /* allocate a buffer that we are sure is big enough - * +1 for null character. - * +1 for directory separator character. - */ - safefilename = realloc(safefilename, - (maxdirlen + strlen(str) + 2)); + return findPath (dirs, maxdirlen, str); + } - for (dp = dirs; *dp; dp++) { - sprintf (safefilename, "%s%s%s", *dp, DIRSEP, str); - if (access (safefilename, R_OK) == 0) - return safefilename; + if (pathlist != Gvimagepath) { + if (dirs) { + free (dirs[0]); + free (dirs); + dirs = NULL; } - return NULL; + pathlist = Gvimagepath; + if (pathlist && *pathlist) + dirs = mkDirlist (pathlist, &maxdirlen); } - /* else, not in server, use original filename without modification. */ - else + + if ((*filename == DIRSEP[0]) || !dirs) return filename; + + return findPath (dirs, maxdirlen, filename); } int maptoken(char *p, char **name, int *val) @@ -1048,6 +1077,7 @@ static edge_t *cloneEdge(edge_t * e, node_t * ct, node_t * ch) edge_t *ce = agedge(g, ct, ch); #else /* WITH_CGRAPH */ edge_t *ce = agedge(g, ct, ch,NULL,1); + agbindrec(ce, "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE); #endif /* WITH_CGRAPH */ agcopyattr(e, ce); diff --git a/lib/neatogen/constraint.c b/lib/neatogen/constraint.c index eb4a36db7..578fae6ed 100644 --- a/lib/neatogen/constraint.c +++ b/lib/neatogen/constraint.c @@ -144,6 +144,7 @@ static void mapGraphs(graph_t * g, graph_t * cg, distfn dist) ce = agedge(cg, t, h); #else ce = agedge(cg, t, h, NULL, 1); + agbindrec(ce, "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE); #endif ED_weight(ce) = 1; if (ED_minlen(ce) < delta) { @@ -230,6 +231,7 @@ static graph_t *mkNConstraintG(graph_t * g, Dt_t * list, graph_t *cg = agopen("cg", AGDIGRAPHSTRICT); #else graph_t *cg = agopen("cg", Agstrictdirected, NIL(Agdisc_t *)); + agbindrec(cg, "Agraphinfo_t", sizeof(Agraphinfo_t), TRUE); // graph custom data #endif node_t *n; edge_t *e; @@ -265,6 +267,7 @@ static graph_t *mkNConstraintG(graph_t * g, Dt_t * list, e = agedge(cg, p->cnode, nxp->cnode); #else e = agedge(cg, p->cnode, nxp->cnode, NULL, 1); + agbindrec(e, "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE); // edge custom data #endif assert (delta <= 0xFFFF); ED_minlen(e) = delta; @@ -317,6 +320,7 @@ static graph_t *mkConstraintG(graph_t * g, Dt_t * list, graph_t *cg = agopen("cg", AGDIGRAPHSTRICT); #else graph_t *cg = agopen("cg", Agstrictdirected, NIL(Agdisc_t *)); + agbindrec(cg, "Agraphinfo_t", sizeof(Agraphinfo_t), TRUE); // graph custom data #endif graph_t *vg; node_t *prev = NULL; @@ -375,6 +379,7 @@ static graph_t *mkConstraintG(graph_t * g, Dt_t * list, e = agedge(cg, prev, n); #else e = agedge(cg, prev, n, NULL, 1); + agbindrec(e, "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE); // edge custom data #endif ED_minlen(e) = SCALE; ED_weight(e) = 1; @@ -403,9 +408,8 @@ static graph_t *mkConstraintG(graph_t * g, Dt_t * list, #ifndef WITH_CGRAPH n = agnode(vg, agnameof(p->np)); /* FIX */ #else - n = agnode(cg, agnameof(p->np), 1); /* FIX */ - agbindrec(cg, "Agnodeinfo_t", sizeof(Agnodeinfo_t), TRUE); //node custom data - + n = agnode(vg, agnameof(p->np), 1); /* FIX */ + agbindrec(n, "Agnodeinfo_t", sizeof(Agnodeinfo_t), TRUE); //node custom data #endif p->vnode = n; ND_alg(n) = p; @@ -486,7 +490,7 @@ static graph_t *mkConstraintG(graph_t * g, Dt_t * list, elist_append(e, ND_out(n)); elist_append(e, ND_in(vn)); } -#endif +#endif /* OLD */ return cg; } diff --git a/lib/osage/osageinit.c b/lib/osage/osageinit.c index 81c6d51d7..ac759589a 100644 --- a/lib/osage/osageinit.c +++ b/lib/osage/osageinit.c @@ -73,6 +73,9 @@ static void cluster_init_graph(graph_t * g) } for (n = agfstnode(g); n; n = agnxtnode(g, n)) { for (e = agfstout(g, n); e; e = agnxtout(g, e)) { +#ifdef WITH_CGRAPH + agbindrec(e, "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE); //edge custom data +#endif /* WITH_CGRAPH */ common_init_edge(e); } } @@ -345,6 +348,7 @@ mkClusters (Agraph_t* g, clist_t* pclist, Agraph_t* parent) #ifdef WITH_CGRAPH for (subg = agfstsubg(g); subg; subg = agnxtsubg(subg)) { if (!strncmp(agnameof(subg), "cluster", 7)) { + agbindrec(g, "Agraphinfo_t", sizeof(Agraphinfo_t), TRUE); do_graph_label (subg); addCluster(clist, subg); mkClusters(subg, NULL, subg); diff --git a/lib/patchwork/patchworkinit.c b/lib/patchwork/patchworkinit.c index 316f52095..019e78a78 100644 --- a/lib/patchwork/patchworkinit.c +++ b/lib/patchwork/patchworkinit.c @@ -85,6 +85,7 @@ mkClusters (graph_t * g, clist_t* pclist, graph_t* parent) for (subg = agfstsubg(g); subg; subg = agnxtsubg(subg)) { #endif /* WITH_CGRAPH */ if (!strncmp(agnameof(subg), "cluster", 7)) { + agbindrec(subg, "Agraphinfo_t", sizeof(Agraphinfo_t), TRUE); #ifdef FDP_GEN GD_alg(subg) = (void *) NEW(gdata); /* freed in cleanup_subgs */ GD_ndim(subg) = GD_ndim(parent); @@ -125,6 +126,9 @@ static void patchwork_init_node_edge(graph_t * g) GD_neato_nlist(g) = N_NEW(agnnodes(g) + 1, node_t *); for (n = agfstnode(g); n; n = agnxtnode(g, n)) { +#ifdef WITH_CGRAPH + agbindrec(n, "Agnodeinfo_t", sizeof(Agnodeinfo_t), TRUE); // node custom data +#endif /* WITH_CGRAPH */ ND_alg(n) = alg + i; GD_neato_nlist(g)[i++] = n; patchwork_init_node(n); diff --git a/lib/sfdpgen/sfdpinit.c b/lib/sfdpgen/sfdpinit.c index f8c883e42..d036d3d03 100644 --- a/lib/sfdpgen/sfdpinit.c +++ b/lib/sfdpgen/sfdpinit.c @@ -35,6 +35,9 @@ static void sfdp_init_edge(edge_t * e) { +#ifdef WITH_CGRAPH + agbindrec(e, "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE); //node custom data +#endif /* WITH_CGRAPH */ common_init_edge(e); } diff --git a/lib/twopigen/twopiinit.c b/lib/twopigen/twopiinit.c index 8a0f0f36d..e5d555738 100644 --- a/lib/twopigen/twopiinit.c +++ b/lib/twopigen/twopiinit.c @@ -25,7 +25,7 @@ static void twopi_init_edge(edge_t * e) { #ifdef WITH_CGRAPH - agbindrec(e, "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE); //node custom data + agbindrec(e, "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE); //edge custom data #endif /* WITH_CGRAPH */ common_init_edge(e); ED_factor(e) = late_double(e, E_weight, 1.0, 0.0);