]> granicus.if.org Git - graphviz/commitdiff
Add agsafeset, utility function to handle attribute assignment,
authorellson <devnull@localhost>
Tue, 18 Oct 2005 21:11:01 +0000 (21:11 +0000)
committerellson <devnull@localhost>
Tue, 18 Oct 2005 21:11:01 +0000 (21:11 +0000)
checking that the attribute is first declared.

lib/graph/attribs.c
lib/graph/graph.h

index 18910260ada4d4e420a6541e23aea5638882070a..fc82f280e0c30bd8da3ba02f07fb980b323543dc 100644 (file)
@@ -327,6 +327,27 @@ int agxset(void *obj, int index, char *buf)
        return -1;
 }
 
+int agsafeset(void* obj, char* name, char* value, char* def)
+{
+    Agsym_t* a = agfindattr(obj, name);
+
+    if (a == NULL) {
+       if (!def) def = "";
+       switch (TAG_OF(obj)) {
+       case TAG_GRAPH:
+           agraphattr((Agraph_t*)obj, name, def);
+           break;
+       case TAG_NODE:
+           agnodeattr(((Agnode_t*)obj)->graph, name, def);
+           break;
+       case TAG_EDGE:
+           agedgeattr(((Agedge_t*)obj)->head->graph, name, def);
+           break;
+       }
+    }
+    return agxset(obj, a->index, value);
+}
+
 /* agcopyattr:
  * Assumes attributes have already been declared.
  * Do not copy key attribute for edges, as this must be distinct.
index b323ba49e6257be78cd90a2986e2aa6c697c751f..b81e057416b9f6d725868cd653749604caeb1d35 100644 (file)
@@ -137,6 +137,7 @@ extern "C" {
     extern char *agget(void *, char *);
     extern char *agxget(void *, int);
     extern int agset(void *, char *, char *);
+    extern int agsafeset(void *, char *, char *, char*);
     extern int agxset(void *, int, char *);
     extern int agindex(void *, char *);