FeelUs
September 4, 2025, 9:41pm
1
How does agattr/agattr_text(g,AGNODE,"name",NULL)
behave if the nodes of the graph do not have the “name” attribute?
If some nodes of the graph have the “name” attribute, what will be the default value for nodes without the “name” attribute?
Documentation says only
agattr creates or looks up attributes. kind may be AGRAPH, AGNODE, or AGEDGE.
If value is (char*)0), the request is to search for an existing attribute of the given kind and name. Otherwise, if the attribute already exists, its default for creating new objects is set to the given value;
if it does not exist, a new attribute is created with the given default, and the default is applied to all pre-existing objects of the given kind.
If g is NULL, the default is set for all graphs created subsequently.
FeelUs
September 4, 2025, 10:42pm
2
I make test:
#include <stdio.h>
#include <graphviz/cgraph.h>
void test(Agraph_t * g, const char * name1) {
// ??? how should I check cgraph-version ?
Agsym_t * s1 = agattr(g, AGNODE, name1, NULL);
//Agsym_t * s1 = agattr_text(g, AGNODE, name1, NULL);
if(s1==NULL){
printf("sym for %s is NULL\n",name1);
}
else{
printf("%s default: '%s'\n", name1, s1->defval);
}
for(Agnode_t * n = agfstnode(g); n; n=agnxtnode(g,n)){
printf("%s: %s = '%s' = '%s'\n",agnameof(n),name1,agget(n,name1),s1 ? agxget(n,s1):"<NULL>");
}
}
int main(int argc, char ** argv){
Agraph_t * g;
FILE * f;
const char * fname = argc>1 ? argv[1] : "test-attr.dot";
if(!(f = fopen(fname,"r"))){
printf("can't open %s\n",fname);
return 1;
}
g = agread(f,NULL);
fclose(f);
test(g,"name1");
test(g,"name2");
agclose(g);
}
for next dot file:
digraph G {
a [name2=124];
b;
}
I get (for agattr):
sym for name1 is NULL
a: name1 = '(null)' = '<NULL>'
b: name1 = '(null)' = '<NULL>'
name2 default: ''
a: name2 = '124' = '124'
b: name2 = '' = ''
but for graphviz 13.1 for agattr_text I get
sym for name1 is NULL
a: name1 = '(null)' = '<NULL>'
b: name1 = '(null)' = '<NULL>'
segmentation fault (core dumped)
FeelUs
September 5, 2025, 9:31am
3
Can I switch type of attribute from html to text and viceversa?
Next examle:
#include <stdio.h>
#include <graphviz/cgraph.h>
int main(int argc, char ** argv){
//test_attr1(argc, argv);
Agraph_t * g = agopen("G",Agdirected,NULL);
Agnode_t * n = agnode(g,"node",1);
Agsym_t * A_html = agattr_html(g, AGNODE, "html", "qwe");
printf("html attr: %d %d\n",aghtmlstr(agget(n,"html")),aghtmlstr(agxget(n,A_html)));
Agsym_t * A_text = agattr_text(g, AGNODE, "html", "qwe");
printf("text attr: %d %d\n",aghtmlstr(agget(n,"html")),aghtmlstr(agxget(n,A_text)));
A_text = agattr_text(g, AGNODE, "text", "qwe");
printf("text attr: %d %d\n",aghtmlstr(agget(n,"text")),aghtmlstr(agxget(n,A_text)));
A_html = agattr_html(g, AGNODE, "text", "qwe");
printf("html attr: %d %d\n",aghtmlstr(agget(n,"text")),aghtmlstr(agxget(n,A_html)));
agclose(g);
}
get:
html attr: 1 1
text attr: 1 1
text attr: 0 0
html attr: 0 0
FeelUs
September 5, 2025, 9:34pm
4
for graphviz 13.1 for agattr_text I get
…
segmentation fault (core dumped)
for last version from git it behaves good, like agattr
smattr
September 6, 2025, 12:16am
5
Yes, but not through the agattr_* APIs. You want to use something like the agset_* APIs like this .
FeelUs
September 6, 2025, 10:08am
6
how can I check presence of agattr_text, agset_text, agsafeset_text?
smattr
September 6, 2025, 1:38pm
7
Not easily unfortunately. We’re working on a way to address that .