From: Stephen C North Date: Sun, 10 May 2015 00:36:28 +0000 (-0400) Subject: Added agnodebefore() primitive X-Git-Tag: TRAVIS_CI_BUILD_EXPERIMENTAL~115 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5c388fb6afe1078931868beb9d509aa3da99cbeb;p=graphviz Added agnodebefore() primitive --- diff --git a/lib/cgraph/cgraph.h b/lib/cgraph/cgraph.h index 80b3a600b..b0b287fa1 100644 --- a/lib/cgraph/cgraph.h +++ b/lib/cgraph/cgraph.h @@ -281,6 +281,7 @@ extern Agnode_t *aglstnode(Agraph_t * g); extern Agnode_t *agprvnode(Agraph_t * g, Agnode_t * n); extern Agsubnode_t *agsubrep(Agraph_t * g, Agnode_t * n); +extern int agnodebefore(Agnode_t *u, Agnode_t *v); /* we have no shame */ /* edges */ extern Agedge_t *agedge(Agraph_t * g, Agnode_t * t, Agnode_t * h, diff --git a/lib/cgraph/main3.c b/lib/cgraph/main3.c index 7c196d6bd..f72a2ad08 100644 --- a/lib/cgraph/main3.c +++ b/lib/cgraph/main3.c @@ -1,24 +1,19 @@ #include #include "cgraph.h" -#include "bla.h" int main(int argc, char **argv) { Agraph_t *g; - Agnode_t *n; - Agnoderef_t *nref; - Agedge_t *e; - Agedgeref_t *eref; + Agnode_t *u, *v; + int rv; g = agread(stdin,0); - for (nref = FIRSTNREF(g); nref; nref = NEXTNREF(nref)) { - n = NODEOF(nref); - fprintf(stderr,"%s\n",agnameof(n)); - for (eref = FIRSTOUTREF(g,nref); eref; eref = NEXTEREF(nref,eref)) { - e = EDGEOF(nref,eref); - fprintf(stderr,"\t %s ", agnameof(agtail(e))); - fprintf(stderr,"-> %s\n", agnameof(aghead(e))); - } + if (argc >= 3) { + u = agnode(g,argv[1],FALSE); + v = agnode(g,argv[2],FALSE); + rv = agnodebefore(u,v); + fprintf(stderr,"agnodebefore returns %d\n",rv); + fprintf(stderr,"dtsize %d\n",dtsize(g->n_seq)); } - return 1; + agwrite(g,stdout); } diff --git a/lib/cgraph/node.c b/lib/cgraph/node.c index 3d9c483ba..04ddf02e8 100644 --- a/lib/cgraph/node.c +++ b/lib/cgraph/node.c @@ -330,3 +330,47 @@ Dtdisc_t Ag_subnode_seq_disc = { agdictobjmem, NIL(Dtevent_f) }; + +void agnodesetfinger(Agraph_t * g, Agnode_t * n, void *ignored) +{ + static Agsubnode_t template; + template.node = n; + dtsearch(g->n_seq,&template); + NOTUSED(ignored); +} + +void agnoderenew(Agraph_t * g, Agnode_t * n, void *ignored) +{ + dtrenew(g->n_seq, dtfinger(g->n_seq)); + NOTUSED(n); + NOTUSED(ignored); +} + +int agnodebefore(Agnode_t *fst, Agnode_t *snd) +{ + Agraph_t *g; + Agnode_t *n, *nxt; + + + g = agroot(fst); + if (AGSEQ(fst) > AGSEQ(snd)) return SUCCESS; + + /* move snd out of the way somewhere */ + n = snd; + if (agapply (g, (Agobj_t *) n, (agobjfn_t) agnodesetfinger, n, FALSE) != SUCCESS) return FAILURE; + AGSEQ(snd) = (g->clos->seq[AGNODE] + 2); + if (agapply (g, (Agobj_t *) n, (agobjfn_t) agnoderenew, n, FALSE) != SUCCESS) return FAILURE; + n = agprvnode(g,snd); + do { + nxt = agprvnode(g,n); + if (agapply (g, (Agobj_t *) n, (agobjfn_t) agnodesetfinger, n, FALSE) != SUCCESS) return FAILURE; + AGSEQ(n) = AGSEQ(n) + 1; + if (agapply (g, (Agobj_t *) n, (agobjfn_t) agnoderenew, n, FALSE) != SUCCESS) return FAILURE; + if (n == fst) break; + n = nxt; + } while (n); + if (agapply (g, (Agobj_t *) snd, (agobjfn_t) agnodesetfinger, n, FALSE) != SUCCESS) return FAILURE; + AGSEQ(snd) = AGSEQ(fst) - 1; + if (agapply (g, (Agobj_t *) snd, (agobjfn_t) agnoderenew, snd, FALSE) != SUCCESS) return FAILURE; + return SUCCESS; +}