Dt_t* _dtnew(Vmalloc_t* vm, Dtdisc_t* disc, Dtmethod_t* meth, unsigned long version) { Dt_t* dt; Dc_t dc; dc.odisc = disc; dc.ndisc = *disc; dc.ndisc.eventf = eventf; if (!dc.ndisc.memoryf) dc.ndisc.memoryf = memoryf; dc.vm = vm; if (dt = _dtopen(&dc.ndisc, meth, version)) dtdisc(dt, disc, DT_SAMECMP|DT_SAMEHASH); return dt; }
tmain() { Dt_t *dt; long k; chkevent(-1); if(!(dt = dtopen(&Disc,Dtset)) ) terror("Opening Dtset"); if(chkevent(DT_OPEN) != 1 ) terror("Bad count of DT_OPEN event"); if(chkevent(DT_ENDOPEN) != 1 ) terror("Bad count of DT_ENDOPEN event"); dtinsert(dt, 1); if(chkevent(DT_HASHSIZE) != 1 ) terror("No hash table size event"); chkevent(-1); dtmethod(dt,Dtoset); if(chkevent(DT_METH) < 1 ) terror("No meth event"); chkevent(-1); dtdisc(dt,&Disc,0); if(chkevent(DT_DISC) < 1 ) terror("No disc event"); chkevent(-1); dtclose(dt); if(chkevent(DT_CLOSE) != 1 ) terror("Bad count of DT_CLOSE event"); if(chkevent(DT_ENDCLOSE) != 1 ) terror("Bad count of DT_ENDCLOSE event"); texit(0); }
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"); } }