From b92edfbe3df08f688a8f325b39d901ac5f23541e Mon Sep 17 00:00:00 2001 From: north Date: Fri, 26 Sep 2008 01:31:11 +0000 Subject: [PATCH] Still fixing Protograph feature. I hope I got it right this time. You can turn the world on with a smile. --- lib/cgraph/attr.c | 56 ++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/lib/cgraph/attr.c b/lib/cgraph/attr.c index 95dd54cdd..009663e6b 100644 --- a/lib/cgraph/attr.c +++ b/lib/cgraph/attr.c @@ -73,6 +73,29 @@ Dict_t *agdictof(Agraph_t * g, int kind) return dict; } +Agsym_t *agnewsym(Agraph_t * g, char *name, char *value, int id, int kind) +{ + Agsym_t *sym; + sym = agalloc(g, sizeof(Agsym_t)); + sym->kind = kind; + sym->name = agstrdup(g, name); + sym->defval = agstrdup(g, value); + sym->id = id; + return sym; +} + +static void agcopydict(Dict_t *src, Dict_t *dest, Agraph_t *g, int kind) +{ + Agsym_t *sym,*newsym; + + assert(dtsize(dest) == 0); + for (sym = (Agsym_t *) dtfirst(src); sym; + sym = (Agsym_t *) dtnext(src, sym)) { + newsym = agnewsym(g, sym->name, sym->defval, sym->id, kind); + dtinsert(dest, newsym); + } +} + static Agdatadict_t *agmakedatadict(Agraph_t * g) { Agraph_t *par; @@ -92,31 +115,17 @@ static Agdatadict_t *agmakedatadict(Agraph_t * g) } else { if (ProtoGraph && (g != ProtoGraph)) { - /* you can't dtview here for several reasons. the proto - graph could change, and it changes the base index for g*/ - Agsym_t *sym; /* this could be written more functionally */ - sym = 0; /* but it's easy to read this way */ - /* can't do graph attrs here because of some horrific recursion */ - while ((sym = agnxtattr(ProtoGraph,AGNODE,sym))) - agattr(g,AGNODE,sym->name,sym->defval); - while ((sym = agnxtattr(ProtoGraph,AGEDGE,sym))) - agattr(g,AGEDGE,sym->name,sym->defval); + /* you can't dtview here for several reasons. the proto + graph could change, and the sym indices don't match */ + parent_dd = agdatadict(ProtoGraph); + agcopydict(parent_dd->dict.n,dd->dict.n,g,AGNODE); + agcopydict(parent_dd->dict.e,dd->dict.e,g,AGEDGE); + agcopydict(parent_dd->dict.g,dd->dict.g,g,AGRAPH); } } return dd; } -Agsym_t *agnewsym(Agraph_t * g, char *name, char *value, int id, int kind) -{ - Agsym_t *sym; - sym = agalloc(g, sizeof(Agsym_t)); - sym->kind = kind; - sym->name = agstrdup(g, name); - sym->defval = agstrdup(g, value); - sym->id = id; - return sym; -} - /* look up or update a value associated with an object. */ Agsym_t *agdictsym(Dict_t * dict, char *name) { @@ -322,13 +331,6 @@ void agraphattr_init(Agraph_t * g) g->desc.has_attrs = 1; /* dd = */ agmakedatadict(g); -/* - if (ProtoGraph && (g != ProtoGraph)) { - Agsym_t *sym = 0; - while ((sym = agnxtattr(ProtoGraph,AGRAPH,sym))) - agattr(g,AGRAPH,sym->name,sym->defval); - } -*/ if (!(context = agparent(g))) { if (ProtoGraph && (g != ProtoGraph)) context = ProtoGraph; else context = g; -- 2.40.0