26#define EMPTY(s) ((s == 0) || (*s == '\0'))
27#define SLEN(s) (sizeof(s)-1)
29#define GXL_ATTR "_gxl_"
30#define GXL_ROLE "_gxl_role"
31#define GXL_HYPER "_gxl_hypergraph"
32#define GXL_ID "_gxl_id"
33#define GXL_FROM "_gxl_fromorder"
34#define GXL_TO "_gxl_toorder"
35#define GXL_TYPE "_gxl_type"
36#define GXL_COMP "_gxl_composite_"
37#define GXL_LOC "_gxl_locator_"
39#define GXL_COMP_LEN (SLEN(GXL_COMP))
86 offsetof(
idv_t, name),
88 offsetof(
idv_t, link),
123 while ((c = *
id++)) {
124 if (!
gv_isalnum(c) && c !=
'_' && c !=
':' && c !=
'-' && c !=
'.')
132static inline int put(
void *stream,
const char *
s) {
133 return fputs(
s, stream);
137static inline int xml_puts(FILE *stream,
const char *
s) {
173 static int graphIdCounter = 0;
178 agxbprint(&buf,
"G_%d", graphIdCounter++);
181 char *rv =
addid(ids, name);
188 static int nodeIdCounter = 0;
193 agxbprint(&buf,
"N_%d", nodeIdCounter++);
196 char *rv =
addid(ids, name);
224 int edgeIdCounter = 1;
254 fprintf(gxlFile,
" role=\"");
256 fprintf(gxlFile,
"\"");
260 fprintf(gxlFile,
" hypergraph=\"");
262 fprintf(gxlFile,
"\"");
270 fprintf(gxlFile,
" id=\"");
272 fprintf(gxlFile,
"\"");
276 fprintf(gxlFile,
" fromorder=\"");
278 fprintf(gxlFile,
"\"");
282 fprintf(gxlFile,
" toorder=\"");
284 fprintf(gxlFile,
"\"");
294 fprintf(gxlFile,
"\t<type xlink:href=\"");
296 fprintf(gxlFile,
"\">\n");
298 fprintf(gxlFile,
"\t</type>\n");
308 if (
EMPTY(sym->defval)) {
318 char *locatorVal = sym->defval + strlen(
GXL_LOC);
321 fprintf(gxlFile,
"\t<attr name=\"");
323 fprintf(gxlFile,
"\">\n");
325 fprintf(gxlFile,
"\t\t<locator xlink:href=\"");
327 fprintf(gxlFile,
"\"/>\n");
329 fprintf(gxlFile,
"\t</attr>\n");
333 fprintf(gxlFile,
"\t<attr name=\"");
335 fprintf(gxlFile,
"\" ");
336 fprintf(gxlFile,
"kind=\"");
338 fprintf(gxlFile,
"\">\n");
341 fprintf(gxlFile,
"\t<attr name=\"");
343 fprintf(gxlFile,
":");
345 fprintf(gxlFile,
"\" kind=\"");
347 fprintf(gxlFile,
"\">\n");
350 fprintf(gxlFile,
"\t\t<string>");
352 fprintf(gxlFile,
"</string>\n");
354 fprintf(gxlFile,
"\t</attr>\n");
359 if (
EMPTY(sym->defval)) {
368 fprintf(gxlFile,
"\t<attr name=\"");
370 fprintf(gxlFile,
"\" ");
371 fprintf(gxlFile,
"kind=\"");
373 fprintf(gxlFile,
"\">\n");
375 fprintf(gxlFile,
"\t\t");
377 fprintf(gxlFile,
"\n");
379 fprintf(gxlFile,
"\t</attr>\n");
421 fprintf(gxlFile,
"<node id=\"%s\">\n", bp);
431 fprintf(gxlFile,
"<graph id=\"%s\" edgeids=\"true\" edgemode=\"%s\"",
434 fprintf(gxlFile,
">\n");
436 if (uniqueName && (strcmp(name, uniqueName) != 0)) {
438 fprintf(gxlFile,
"\t<attr name=\"name\">\n");
440 fprintf(gxlFile,
"\t\t<string>");
442 fprintf(gxlFile,
"</string>\n");
444 fprintf(gxlFile,
"\t</attr>\n");
449 fprintf(gxlFile,
"\t<attr name=\"strict\">\n");
451 fprintf(gxlFile,
"\t\t<string>true</string>\n");
453 fprintf(gxlFile,
"\t</attr>\n");
463 fprintf(gxlFile,
"</graph>\n");
467 fprintf(gxlFile,
"</node>\n");
476 writeHdr(stp, subg, gxlFile,
false);
486 fprintf(gxlFile,
"\t<attr name=\"key\">\n");
488 fprintf(gxlFile,
"\t\t<string>");
490 fprintf(gxlFile,
"</string>\n");
492 fprintf(gxlFile,
"\t</attr>\n");
513 if (
data->str[sym->id] != sym->defval) {
515 if (strcmp(
data->str[sym->id],
"") == 0)
519 char *locatorVal =
data->str[sym->id] + strlen(
GXL_LOC);
522 fprintf(gxlFile,
"\t<attr name=\"");
524 fprintf(gxlFile,
"\">\n");
526 fprintf(gxlFile,
"\t\t<locator xlink:href=\"");
528 fprintf(gxlFile,
"\"/>\n");
530 fprintf(gxlFile,
"\t</attr>\n");
533 fprintf(gxlFile,
"\t<attr name=\"");
535 fprintf(gxlFile,
"\"");
538 fprintf(gxlFile,
" kind=\"HTML-like string\"");
540 fprintf(gxlFile,
">\n");
542 fprintf(gxlFile,
"\t\t<string>");
544 fprintf(gxlFile,
"</string>\n");
546 fprintf(gxlFile,
"\t</attr>\n");
552 if (
data->str[sym->id] != sym->defval) {
555 fprintf(gxlFile,
"\t<attr name=\"");
557 fprintf(gxlFile,
"\">\n");
559 fprintf(gxlFile,
"\t\t");
561 fprintf(gxlFile,
"\n");
563 fprintf(gxlFile,
"\t</attr>\n");
580 char *uniqueName =
nodeID(stp, n);
583 fprintf(gxlFile,
"<node id=\"%s\">\n", uniqueName);
587 if (strcmp(name, uniqueName)) {
589 fprintf(gxlFile,
"\t<attr name=\"name\">\n");
591 fprintf(gxlFile,
"\t\t<string>");
593 fprintf(gxlFile,
"</string>\n");
595 fprintf(gxlFile,
"\t</attr>\n");
601 fprintf(gxlFile,
"</node>\n");
607 char *val =
agget(e, name);
610 fprintf(gxlFile,
"\t<attr name=\"");
612 fprintf(gxlFile,
"\">\n");
614 fprintf(gxlFile,
"\t\t<string>");
616 fprintf(gxlFile,
"</string>\n");
618 fprintf(gxlFile,
"\t</attr>\n");
639 fprintf(gxlFile,
"<edge from=\"%s\" ",
nodeID(stp, t));
640 fprintf(gxlFile,
"to=\"%s\"",
nodeID(stp, h));
644 fprintf(gxlFile,
" isdirected=\"true\"");
646 fprintf(gxlFile,
" isdirected=\"false\"");
650 if (!
EMPTY(edge_id)) {
651 fprintf(gxlFile,
">\n");
654 fprintf(gxlFile,
" id=\"%s\">\n", bp);
666 fprintf(gxlFile,
"</edge>\n");
671#define writeval(n) (((Local_Agnodeinfo_t*)((n)->base.data))->written)
770 fprintf(gxlFile,
"<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n");
771 fprintf(gxlFile,
"<gxl>\n");
777 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_text(Agraph_t *g, int kind, char *name, const char *value)
creates or looks up text 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::@65 dict
implementation of Agrec_t
options to tweak the behavior of XML escaping
int gv_xml_escape(const char *s, xml_flags_t flags, int(*cb)(void *state, const char *s), void *state)
XML escaping functionality.