From 09cc6e54395180cbd82f0725647649f533b15af0 Mon Sep 17 00:00:00 2001 From: erg Date: Mon, 8 Sep 2008 17:09:09 +0000 Subject: [PATCH] Add agcontains() function. --- lib/cgraph/cgraph.3 | 2 ++ lib/cgraph/cgraph.h | 1 + lib/cgraph/obj.c | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/lib/cgraph/cgraph.3 b/lib/cgraph/cgraph.3 index 7c7245973..508d7e5e4 100644 --- a/lib/cgraph/cgraph.3 +++ b/lib/cgraph/cgraph.3 @@ -109,6 +109,8 @@ void agfree(Agraph_t *g, void *ptr); .SS "GENERIC OBJECTS" .P0 Agraph_t *agraphof(void*); +Agraph_t *agroot(void*); +int agcontains(Agraph_t*, void*); char *agnameof(void*); void agdelete(Agraph_t *g, void *obj); Agrec_t *AGDATA(void *obj); diff --git a/lib/cgraph/cgraph.h b/lib/cgraph/cgraph.h index 75f3a1c43..5ac5c4dc3 100644 --- a/lib/cgraph/cgraph.h +++ b/lib/cgraph/cgraph.h @@ -294,6 +294,7 @@ extern Agedge_t *agnxtedge(Agraph_t * g, Agedge_t * e, Agnode_t * n); /* generic */ extern Agraph_t *agraphof(void* obj); extern Agraph_t *agroot(void* obj); +extern int agcontains(Agraph_t *, void *); extern char *agnameof(void *); extern int agrelabel(void *obj, char *name); /* scary */ extern int agrelabel_node(Agnode_t * n, char *newname); diff --git a/lib/cgraph/obj.c b/lib/cgraph/obj.c index 857ec4aec..a34d8d31b 100755 --- a/lib/cgraph/obj.c +++ b/lib/cgraph/obj.c @@ -246,6 +246,25 @@ void *aggetuserptr(Agraph_t * g, Agcbdisc_t * cbd) return NIL(void *); } +int agcontains(Agraph_t* g, void* obj) +{ + Agraph_t* subg; + + if (agroot (g) != agroot (obj)) return 0; + switch (AGTYPE(obj)) { + case AGRAPH: + subg = (Agraph_t *) obj; + do { + if (subg == g) return 1; + } while ((subg = agparent (subg))); + return 0; + case AGNODE: + return (agidnode(g, AGID(obj), 0) != 0); + default: + return (agsubedge(g, (Agedge_t *) obj, 0) != 0); + } +} + int agobjkind(void *arg) { return AGTYPE(arg); -- 2.40.0