From: Matthew Fernandez Date: Sat, 22 Oct 2022 20:26:07 +0000 (-0700) Subject: graphml2gv: remove dead code handling ending of 'attr' attribute X-Git-Tag: 7.0.1~14^2~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4c1b08b0aa631474e09749f9e8b32240fb4b89b3;p=graphviz graphml2gv: remove dead code handling ending of 'attr' attribute The code in the last branch in `endElementHandler` was dealing with a closing `` tag in the input GraphML. However, the preceding `startElementHandler` callback rejects an opening `` tag. So there is no way to reach this closing logic. This change removes not only the local unreachable code but several transitively unreachable functions. As an aside, this was only discovered while trying to construct a test case to provoke #2300. One path to `dict_relabel` is through `graphml2gv`, by handling a closing `` tag. So I looked online for sample GraphML using `attr`. I could not find any. So I went to the GraphML specification¹ and there discovered `attr` is not a valid GraphML tag. So I thought, fine, I will figure out how `graphml2gv` expects this non-standard tag to appear. And that is when I discovered none of this logic is reachable. This does not appear to be the result of changes. The very first revision of `graphml2gv`, 1d28d7d2b4d2b2551bd1f432aa175f54a69364a4, seems to have this limitation already. I can only conclude this was copy-pasted from gxl2gv without taking into account the differences between GXL and GraphML. Gitlab: #2300 ¹ http://graphml.graphdrawing.org/xmlns/1.1/graphml.xsd --- diff --git a/cmd/tools/graphml2gv.c b/cmd/tools/graphml2gv.c index 57018e09b..601763568 100644 --- a/cmd/tools/graphml2gv.c +++ b/cmd/tools/graphml2gv.c @@ -146,17 +146,6 @@ static void freeUserdata(userdata_t * ud) free(ud); } -static void addToMap(Dt_t * map, char *name, char *uniqueName) -{ - namev_t obj; - namev_t *objp; - - obj.name = name; - objp = dtinsert(map, &obj); - assert(objp->unique_name == 0); - objp->unique_name = gv_strdup(uniqueName); -} - static char *mapLookup(Dt_t *nm, const char *name) { namev_t *objp = dtmatch(nm, name); if (objp) @@ -234,35 +223,8 @@ static int get_xml_attr(char *attrname, const char **atts) return -1; } -static void setName(Dt_t * names, Agobj_t * n, char *value) -{ - Agsym_t *ap; - char *oldName; - - ap = agattr(root, AGTYPE(n), GRAPHML_ID, ""); - agxset(n, ap, agnameof(n)); - oldName = agxget(n, ap); /* set/get gives us new copy */ - addToMap(names, oldName, value); - agrename(n, value); -} - static char *defval = ""; -static void -setNodeAttr(Agnode_t * np, char *name, char *value, userdata_t * ud) -{ - Agsym_t *ap; - - if (strcmp(name, "name") == 0) { - setName(ud->nameMap, (Agobj_t *) np, value); - } else { - ap = agattr(root, AGNODE, name, 0); - if (!ap) - ap = agattr(root, AGNODE, name, defval); - agxset(np, ap, value); - } -} - static void setEdgeAttr(Agedge_t * ep, char *name, char *value, userdata_t * ud) { @@ -295,43 +257,6 @@ setEdgeAttr(Agedge_t * ep, char *name, char *value, userdata_t * ud) } } -static void -setGraphAttr(Agraph_t * g, char *name, char *value, userdata_t * ud) -{ - Agsym_t *ap; - - if ((g == root) && !strcmp(name, "strict") && !strcmp(value, "true")) { - g->desc.strict = 1; - } else if (strcmp(name, "name") == 0) - setName(ud->nameMap, (Agobj_t *) g, value); - else { - ap = agattr(root, AGRAPH, name, 0); - if (ap) - agxset(g, ap, value); - else if (g == root) - agattr(root, AGRAPH, name, value); - else { - ap = agattr(root, AGRAPH, name, defval); - agxset(g, ap, value); - } - } -} - -static void setAttr(char *name, char *value, userdata_t * ud) -{ - switch (Current_class) { - case TAG_GRAPH: - setGraphAttr(G, name, value, ud); - break; - case TAG_NODE: - setNodeAttr(N, name, value, ud); - break; - case TAG_EDGE: - setEdgeAttr(E, name, value, ud); - break; - } -} - /*------------- expat handlers ----------------------------------*/ static void @@ -476,14 +401,7 @@ static void endElementHandler(void *userData, const char *name) E = 0; ud->closedElementType = TAG_EDGE; ud->edgeinverted = FALSE; - } else if (strcmp(name, "attr") == 0) { - char *name = ""; - char *value = ""; - - ud->closedElementType = TAG_NONE; - - setAttr(name, value, ud); - } + } } static Agraph_t *graphml_to_gv(char* gname, FILE * graphmlFile, int* rv)