27#define EMPTY(s) ((s == 0) || (*s == '\0'))
28#define SLEN(s) (sizeof(s)-1)
30#define GXL_ATTR "_gxl_"
31#define GXL_ROLE "_gxl_role"
32#define GXL_HYPER "_gxl_hypergraph"
33#define GXL_ID "_gxl_id"
34#define GXL_FROM "_gxl_fromorder"
35#define GXL_TO "_gxl_toorder"
36#define GXL_TYPE "_gxl_type"
37#define GXL_COMP "_gxl_composite_"
38#define GXL_LOC "_gxl_locator_"
40#define GXL_COMP_LEN (SLEN(GXL_COMP))
87 offsetof(
idv_t, name),
89 offsetof(
idv_t, link),
124 while ((c = *
id++)) {
125 if (!
gv_isalnum(c) && c !=
'_' && c !=
':' && c !=
'-' && c !=
'.')
133static inline int put(
void *stream,
const char *
s) {
134 return fputs(
s, stream);
138static inline int xml_puts(FILE *stream,
const char *
s) {
174 static int graphIdCounter = 0;
179 agxbprint(&buf,
"G_%d", graphIdCounter++);
182 char *rv =
addid(ids, name);
189 static int nodeIdCounter = 0;
194 agxbprint(&buf,
"N_%d", nodeIdCounter++);
197 char *rv =
addid(ids, name);
225 int edgeIdCounter = 1;
255 fprintf(gxlFile,
" role=\"");
257 fprintf(gxlFile,
"\"");
261 fprintf(gxlFile,
" hypergraph=\"");
263 fprintf(gxlFile,
"\"");
271 fprintf(gxlFile,
" id=\"");
273 fprintf(gxlFile,
"\"");
277 fprintf(gxlFile,
" fromorder=\"");
279 fprintf(gxlFile,
"\"");
283 fprintf(gxlFile,
" toorder=\"");
285 fprintf(gxlFile,
"\"");
295 fprintf(gxlFile,
"\t<type xlink:href=\"");
297 fprintf(gxlFile,
"\">\n");
299 fprintf(gxlFile,
"\t</type>\n");
309 if (
EMPTY(sym->defval)) {
319 char *locatorVal = sym->defval + strlen(
GXL_LOC);
322 fprintf(gxlFile,
"\t<attr name=\"");
324 fprintf(gxlFile,
"\">\n");
326 fprintf(gxlFile,
"\t\t<locator xlink:href=\"");
328 fprintf(gxlFile,
"\"/>\n");
330 fprintf(gxlFile,
"\t</attr>\n");
334 fprintf(gxlFile,
"\t<attr name=\"");
336 fprintf(gxlFile,
"\" ");
337 fprintf(gxlFile,
"kind=\"");
339 fprintf(gxlFile,
"\">\n");
342 fprintf(gxlFile,
"\t<attr name=\"");
344 fprintf(gxlFile,
":");
346 fprintf(gxlFile,
"\" kind=\"");
348 fprintf(gxlFile,
"\">\n");
351 fprintf(gxlFile,
"\t\t<string>");
353 fprintf(gxlFile,
"</string>\n");
355 fprintf(gxlFile,
"\t</attr>\n");
360 if (
EMPTY(sym->defval)) {
369 fprintf(gxlFile,
"\t<attr name=\"");
371 fprintf(gxlFile,
"\" ");
372 fprintf(gxlFile,
"kind=\"");
374 fprintf(gxlFile,
"\">\n");
376 fprintf(gxlFile,
"\t\t");
378 fprintf(gxlFile,
"\n");
380 fprintf(gxlFile,
"\t</attr>\n");
422 fprintf(gxlFile,
"<node id=\"%s\">\n", bp);
432 fprintf(gxlFile,
"<graph id=\"%s\" edgeids=\"true\" edgemode=\"%s\"",
435 fprintf(gxlFile,
">\n");
437 if (uniqueName && (strcmp(name, uniqueName) != 0)) {
439 fprintf(gxlFile,
"\t<attr name=\"name\">\n");
441 fprintf(gxlFile,
"\t\t<string>");
443 fprintf(gxlFile,
"</string>\n");
445 fprintf(gxlFile,
"\t</attr>\n");
450 fprintf(gxlFile,
"\t<attr name=\"strict\">\n");
452 fprintf(gxlFile,
"\t\t<string>true</string>\n");
454 fprintf(gxlFile,
"\t</attr>\n");
464 fprintf(gxlFile,
"</graph>\n");
468 fprintf(gxlFile,
"</node>\n");
477 writeHdr(stp, subg, gxlFile,
false);
487 fprintf(gxlFile,
"\t<attr name=\"key\">\n");
489 fprintf(gxlFile,
"\t\t<string>");
491 fprintf(gxlFile,
"</string>\n");
493 fprintf(gxlFile,
"\t</attr>\n");
514 if (
data->str[sym->id] != sym->defval) {
516 if (strcmp(
data->str[sym->id],
"") == 0)
520 char *locatorVal =
data->str[sym->id] + strlen(
GXL_LOC);
523 fprintf(gxlFile,
"\t<attr name=\"");
525 fprintf(gxlFile,
"\">\n");
527 fprintf(gxlFile,
"\t\t<locator xlink:href=\"");
529 fprintf(gxlFile,
"\"/>\n");
531 fprintf(gxlFile,
"\t</attr>\n");
534 fprintf(gxlFile,
"\t<attr name=\"");
536 fprintf(gxlFile,
"\"");
539 fprintf(gxlFile,
" kind=\"HTML-like string\"");
541 fprintf(gxlFile,
">\n");
543 fprintf(gxlFile,
"\t\t<string>");
545 fprintf(gxlFile,
"</string>\n");
547 fprintf(gxlFile,
"\t</attr>\n");
553 if (
data->str[sym->id] != sym->defval) {
556 fprintf(gxlFile,
"\t<attr name=\"");
558 fprintf(gxlFile,
"\">\n");
560 fprintf(gxlFile,
"\t\t");
562 fprintf(gxlFile,
"\n");
564 fprintf(gxlFile,
"\t</attr>\n");
581 char *uniqueName =
nodeID(stp, n);
584 fprintf(gxlFile,
"<node id=\"%s\">\n", uniqueName);
588 if (strcmp(name, uniqueName)) {
590 fprintf(gxlFile,
"\t<attr name=\"name\">\n");
592 fprintf(gxlFile,
"\t\t<string>");
594 fprintf(gxlFile,
"</string>\n");
596 fprintf(gxlFile,
"\t</attr>\n");
602 fprintf(gxlFile,
"</node>\n");
608 char *val =
agget(e, name);
611 fprintf(gxlFile,
"\t<attr name=\"");
613 fprintf(gxlFile,
"\">\n");
615 fprintf(gxlFile,
"\t\t<string>");
617 fprintf(gxlFile,
"</string>\n");
619 fprintf(gxlFile,
"\t</attr>\n");
640 fprintf(gxlFile,
"<edge from=\"%s\" ",
nodeID(stp, t));
641 fprintf(gxlFile,
"to=\"%s\"",
nodeID(stp, h));
645 fprintf(gxlFile,
" isdirected=\"true\"");
647 fprintf(gxlFile,
" isdirected=\"false\"");
651 if (!
EMPTY(edge_id)) {
652 fprintf(gxlFile,
">\n");
655 fprintf(gxlFile,
" id=\"%s\">\n", bp);
667 fprintf(gxlFile,
"</edge>\n");
672#define writeval(n) (((Local_Agnodeinfo_t*)((n)->base.data))->written)
771 fprintf(gxlFile,
"<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n");
772 fprintf(gxlFile,
"<gxl>\n");
778 fprintf(gxlFile,
"</gxl>\n");
static void agxbfree(agxbuf *xb)
free any malloced resources
static int agxbprint(agxbuf *xb, const char *fmt,...)
Printf-style output to an agxbuf.
static WUR char * agxbuse(agxbuf *xb)
Memory allocation wrappers that exit on failure.
static char * gv_strdup(const char *original)
static void * gv_alloc(size_t size)
CDT_API Dt_t * dtview(Dt_t *, Dt_t *)
CDT_API int dtclose(Dt_t *)
CDT_API Dtmethod_t * Dtoset
ordered set (self-adjusting tree)
CDT_API Dt_t * dtopen(Dtdisc_t *, Dtmethod_t *)
DOT-GXL converter API for gxl2gv.c and gv2gxl.c.
Agattr_t * agattrrec(void *obj)
Agsym_t * agattr(Agraph_t *g, int kind, char *name, const char *value)
creates or looks up attributes of a graph
char * agget(void *obj, char *name)
Agdatadict_t * agdatadict(Agraph_t *g, bool cflag)
Agedge_t * agsubedge(Agraph_t *g, Agedge_t *e, int createflag)
Agedge_t * agfstout(Agraph_t *g, Agnode_t *n)
Agedge_t * agnxtout(Agraph_t *g, Agedge_t *e)
int agisdirected(Agraph_t *g)
int agisstrict(Agraph_t *g)
Agnode_t * agnxtnode(Agraph_t *g, Agnode_t *n)
Agnode_t * agfstnode(Agraph_t *g)
Agnode_t * agidnode(Agraph_t *g, IDTYPE id, int createflag)
char * agnameof(void *)
returns a string descriptor for the object.
#define AGID(obj)
returns the unique integer ID associated with the object
#define AGTYPE(obj)
returns AGRAPH, AGNODE, or AGEDGE depending on the type of the object
void aginit(Agraph_t *g, int kind, const char *rec_name, int rec_size, int move_to_front)
attach new records to objects of specified kind
int aghtmlstr(const char *)
Agraph_t * agparent(Agraph_t *g)
Agraph_t * agfstsubg(Agraph_t *g)
Agraph_t * agnxtsubg(Agraph_t *subg)
static Agsym_t * Headport
static void writeNondefaultAttr(void *obj, FILE *gxlFile, Dict_t *defdict)
static void writeTrl(Agraph_t *g, FILE *gxlFile, bool top)
static void writeDicts(Agraph_t *g, FILE *gxlFile)
static void writeNode(gxlstate_t *stp, Agnode_t *n, FILE *gxlFile, Dict_t *d)
static char * nodeID(gxlstate_t *stp, Agnode_t *n)
static char * mapLookup(Dt_t *nm, char *name)
static void printHref(FILE *gxlFile, void *n)
static bool isGxlGrammar(const char *name)
static char * createEdgeId(gxlstate_t *stp, Agedge_t *e)
static void * make_nitem(void *p, Dtdisc_t *disc)
static void writePort(Agedge_t *e, FILE *gxlFile, char *name)
static bool idexists(Dt_t *ids, char *id)
static bool attrs_written(gxlstate_t *stp, void *obj)
static void graphAttrs(FILE *gxlFile, Agraph_t *g)
static bool legalGXLName(const char *id)
static int xml_puts(FILE *stream, const char *s)
static int put(void *stream, const char *s)
static void writeBody(gxlstate_t *, Agraph_t *g, FILE *gxlFile)
static void writeHdr(gxlstate_t *stp, Agraph_t *g, FILE *gxlFile, bool top)
static void addToMap(Dt_t *map, char *name, char *uniqueName)
static void freeState(gxlstate_t stp)
void gv_to_gxl(Agraph_t *g, FILE *gxlFile)
static char * createGraphId(Dt_t *ids)
static void writeSubgs(gxlstate_t *stp, Agraph_t *g, FILE *gxlFile)
static bool isLocatorType(const char *name)
static void free_iditem(void *idv)
static void iterateHdr(gxlstate_t *stp, Agraph_t *g)
static void edgeAttrs(FILE *gxlFile, Agedge_t *e)
static int xml_url_puts(FILE *f, const char *s)
static void writeEdgeName(Agedge_t *e, FILE *gxlFile)
static void writeEdge(gxlstate_t *stp, Agedge_t *e, FILE *gxlFile, Dict_t *d)
static void writeDict(FILE *gxlFile, const char *name, Dict_t *dict, bool isGraph)
static Agsym_t * Tailport
static char * createNodeId(Dt_t *ids)
static gxlstate_t initState(Agraph_t *g)
static bool writeEdgeTest(Agraph_t *g, Agedge_t *e)
static void tabover(FILE *gxlFile)
static char * addid(Dt_t *ids, const char *id)
static void iterateBody(gxlstate_t *stp, Agraph_t *g)
static void iterate_subgs(gxlstate_t *stp, Agraph_t *g)
replacements for ctype.h functions
static bool gv_isalnum(int c)
static bool gv_isalpha(int c)
static Agedge_t * top(edge_stack_t *sp)
static bool startswith(const char *s, const char *prefix)
does the string s begin with the string prefix?
string attribute container
struct Agdatadict_s::@64 dict
implementation of Agrec_t
graphs, nodes and edges info: Agraphinfo_t, Agnodeinfo_t and Agedgeinfo_t
int xml_escape(const char *s, xml_flags_t flags, int(*cb)(void *state, const char *s), void *state)