From 8d3d5e7b494c3cd5cc328fa60b4261fc83109454 Mon Sep 17 00:00:00 2001 From: erg Date: Tue, 14 Jun 2005 16:03:17 +0000 Subject: [PATCH] Add agcopyattr to libgraph; use in utils.c (and dotsplines.c, to be committed later). Expose agstrdup and agstrfree in graph.h; remove raw declarations from emit.c --- lib/common/emit.c | 4 ---- lib/common/utils.c | 10 +--------- lib/graph/attribs.c | 25 +++++++++++++++++++++++++ lib/graph/graph.h | 4 ++++ lib/graph/libgraph.h | 2 -- 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/lib/common/emit.c b/lib/common/emit.c index 1ae457d47..eab23b82e 100644 --- a/lib/common/emit.c +++ b/lib/common/emit.c @@ -1292,10 +1292,6 @@ void emit_graph(GVJ_t * job, graph_t * g) } /* support for stderr_once */ -/* #include "libgraph.h" to get agstrdup, agstrfree */ -extern char *agstrdup(char *); -extern void agstrfree(char *); - static void free_string_entry(Dict_t * dict, char *key, Dtdisc_t * disc) { agstrfree(key); diff --git a/lib/common/utils.c b/lib/common/utils.c index 794a78101..ae67a9b7c 100644 --- a/lib/common/utils.c +++ b/lib/common/utils.c @@ -1483,17 +1483,9 @@ static Dtdisc_t mapDisc = { */ static edge_t *cloneEdge(edge_t * e, node_t * ct, node_t * ch) { - extern Agdict_t *agdictof(void *); - Agdict_t *d = agdictof(e); - Agsym_t **list = d->list; - Agsym_t *sym; graph_t *g = ct->graph; edge_t *ce = agedge(g, ct, ch); - - while ((sym = *list++)) { - if (sym->index == 0) continue; - agxset(ce, sym->index, agxget(e, sym->index)); - } + agcopyattr(e, ce); return ce; } diff --git a/lib/graph/attribs.c b/lib/graph/attribs.c index a7b5b8b26..18910260a 100644 --- a/lib/graph/attribs.c +++ b/lib/graph/attribs.c @@ -326,3 +326,28 @@ int agxset(void *obj, int index, char *buf) } else return -1; } + +/* agcopyattr: + * Assumes attributes have already been declared. + * Do not copy key attribute for edges, as this must be distinct. + * Returns non-zero on failure or if objects have different type. + */ +int agcopyattr(void *oldobj, void *newobj) +{ + Agdict_t *d = agdictof(oldobj); + Agsym_t **list = d->list; + Agsym_t *sym; + Agsym_t *newsym; + int r = 0; + int isEdge = (TAG_OF(oldobj) == TAG_EDGE); + + if (TAG_OF(oldobj) != TAG_OF(newobj)) return 1; + while (!r && (sym = *list++)) { + if (isEdge && sym->index == KEYX) continue; + newsym = agfindattr(newobj,sym->name); + if (!newsym) return 1; + r = agxset(newobj, newsym->index, agxget(oldobj, sym->index)); + } + return r; +} + diff --git a/lib/graph/graph.h b/lib/graph/graph.h index 31de58417..b323ba49e 100644 --- a/lib/graph/graph.h +++ b/lib/graph/graph.h @@ -183,6 +183,7 @@ extern "C" { extern Agsym_t *agnodeattr(Agraph_t *, char *, char *); extern Agsym_t *agedgeattr(Agraph_t *, char *, char *); extern Agsym_t *agfindattr(void *, char *); + extern int agcopyattr(void *, void *); typedef enum { AGWARN, AGERR, AGMAX, AGPREV } agerrlevel_t; extern agerrlevel_t agerrno; @@ -192,6 +193,9 @@ extern "C" { extern void agerrorf(char *fmt, ...); extern void agwarningf(char *fmt, ...); + extern char *agstrdup(char *); + extern void agstrfree(char *); + typedef enum { AGNODE = 1, AGEDGE, AGGRAPH } agobjkind_t; #define agobjkind(p) ((agobjkind_t)(((Agraph_t*)(p))->tag)) diff --git a/lib/graph/libgraph.h b/lib/graph/libgraph.h index c0924c5fe..a40d2785d 100644 --- a/lib/graph/libgraph.h +++ b/lib/graph/libgraph.h @@ -160,9 +160,7 @@ extern "C" { int agparse(void); void agpopproto(Agraph_t *); void agpushproto(Agraph_t *); - char *agstrdup(char *); char *agstrdup_html(char *s); - void agstrfree(char *); int agtoken(char *); void agwredge(Agraph_t *, FILE *, Agedge_t *, int); void agwrnode(Agraph_t *, FILE *, Agnode_t *, int, int); -- 2.40.0