int agwrite(Agraph_t * g, FILE * fp) { printdict_t *p; char *t0, *t1; /* write the graph header */ t0 = (AG_IS_STRICT(g)) ? "strict " : ""; t1 = (AG_IS_DIRECTED(g)) ? "digraph" : "graph"; if (strncmp(g->name, "_anonymous", 10)) fprintf(fp, "%s%s %s {\n", t0, t1, agcanonical(g->name)); else fprintf(fp, "%s%s {\n", t0, t1); /* write the top level attribute defs */ write_dict(g->univ->globattr, fp); write_dict(g->univ->nodeattr, fp); write_dict(g->univ->edgeattr, fp); /* write the graph contents */ p = new_printdict_t(g); write_subg(g, fp, (Agraph_t *) 0, 0, p); fprintf(fp, "}\n"); free_printdict_t(p); return ferror(fp); }
static int write_subgs(Agraph_t * g, GVJ_t * job, int top, state_t* sp) { Agraph_t* sg; int not_first = 0; sg = agfstsubg(g); if (!sg) return 0; gvputs(job, ",\n"); indent(job, sp->Level++); if (top) gvputs(job, "\"objects\": [\n"); else { gvputs(job, "\"subgraphs\": [\n"); indent(job, sp->Level); } for (; sg; sg = agnxtsubg(sg)) { if (not_first) gvputs(job, ",\n"); else not_first = 1; if (top) write_subg (sg, job, sp); else gvprintf(job, "%d", GD_gid(sg)); } if (!top) { sp->Level--; gvputs(job, "\n"); indent(job, sp->Level); gvputs(job, "]"); } return 1; }
static void write_subg(Agraph_t * g, GVJ_t * job, state_t* sp) { Agraph_t* sg; write_graph (g, job, FALSE, sp); for (sg = agfstsubg(g); sg; sg = agnxtsubg(sg)) { gvputs(job, ",\n"); write_subg(sg, job, sp); } }
int agwrite(Agraph_t * g, FILE * fp) { printdict_t *p; if (AG.fwrite == NULL) { AG.fwrite = fwrite; /* init to system version of fwrite() */ } if (AG.ferror == NULL) { #ifdef ferror #undef ferror /* if ferror is a macro, then use our wrapper function, but * undef the macro first so it doesn't subst in "AG.ferror" */ AG.ferror = agferror; /* init to ferror macro wrapper function */ #else AG.ferror = ferror; /* init to system version of ferror() */ #endif } /* write the graph header */ agputs((AG_IS_STRICT(g)) ? "strict " : "", fp); agputs((AG_IS_DIRECTED(g)) ? "digraph" : "graph", fp); if (strncmp(g->name, "_anonymous", 10)) { agputc(' ', fp); agputs(agcanonical(g->name), fp); } agputs(" {\n", fp); /* write the top level attribute defs */ write_dict(g->univ->globattr, fp); write_dict(g->univ->nodeattr, fp); write_dict(g->univ->edgeattr, fp); /* write the graph contents */ p = new_printdict_t(g); write_subg(g, fp, (Agraph_t *) 0, 0, p); agputs("}\n", fp); free_printdict_t(p); return AG.ferror(fp); }
static void write_subg(Agraph_t * g, FILE * fp, Agraph_t * par, int indent, printdict_t * state) { Agraph_t *subg, *meta; Agnode_t *n, *pn; Agedge_t *e, *pe; Dict_t *save_e, *save_n; if (indent) { tabover(fp, indent++); if (dtsearch(state->subgleft, g->meta_node)) { if (strncmp(g->name, "_anonymous", 10)) fprintf(fp, "subgraph %s {\n", agcanonical(g->name)); else fprintf(fp, "{\n"); /* no name printed for anonymous subg */ write_diffattr(fp, indent, g, par, g->univ->globattr); /* The root node and edge environment use the dictionaries, * not the proto node or edge, so the next level down must * record differences with the dictionaries. */ if (par == g->root) { pn = NULL; pe = NULL; } else { pn = par->proto->n; pe = par->proto->e; } write_diffattr(fp, indent, g->proto->n, pn, g->univ->nodeattr); write_diffattr(fp, indent, g->proto->e, pe, g->univ->edgeattr); dtdelete(state->subgleft, g->meta_node); } else { fprintf(fp, "subgraph %s;\n", agcanonical(g->name)); return; } } else write_diffattr(fp, ++indent, g, NULL, g->univ->globattr); save_n = state->n_insubg; save_e = state->e_insubg; meta = g->meta_node->graph; state->n_insubg = dtopen(&agNamedisc, Dttree); state->e_insubg = dtopen(&agOutdisc, Dttree); for (e = agfstout(meta, g->meta_node); e; e = agnxtout(meta, e)) { subg = agusergraph(e->head); write_subg(subg, fp, g, indent, state); } for (n = agfstnode(g); n; n = agnxtnode(g, n)) { if (dtsearch(state->nodesleft, n)) { agwrnode(g, fp, n, TRUE, indent); dtdelete(state->nodesleft, n); } else { if (dtsearch(state->n_insubg, n) == NULL) { agwrnode(g, fp, n, FALSE, indent); } } dtinsert(save_n, n); } dtdisc(g->outedges, &agEdgedisc, 0); /* sort by id */ for (e = (Agedge_t *) dtfirst(g->outedges); e; e = (Agedge_t *) dtnext(g->outedges, e)) { if (dtsearch(state->edgesleft, e)) { tabover(fp, indent); agwredge(g, fp, e, TRUE); dtdelete(state->edgesleft, e); } else { if (dtsearch(state->e_insubg, e) == NULL) { tabover(fp, indent); agwredge(g, fp, e, FALSE); } } dtinsert(save_e, e); } dtdisc(g->outedges, &agOutdisc, 0); /* sort by name */ dtclose(state->n_insubg); state->n_insubg = save_n; dtclose(state->e_insubg); state->e_insubg = save_e; if (indent > 1) { tabover(fp, indent - 1); fprintf(fp, "}\n"); } }