Esempio n. 1
0
Agedge_t *agnxtin(Agraph_t * g, Agedge_t * e)
{
    Agnode_t *n;
    Agsubnode_t *sn;
    Agedge_t *f = NILedge;

    n = AGHEAD(e);
    sn = agsubrep(g, n);
	if (sn) {
		dtrestore(g->e_seq, sn->in_seq);
		f = (Agedge_t *) dtnext(g->e_seq, e);
		sn->in_seq = dtextract(g->e_seq);
	}
	return f;
}
Esempio n. 2
0
File: dtmethod.c Progetto: att/ast
Dtmethod_t *dtmethod(Dt_t *dt, Dtmethod_t *meth) {
    Dtlink_t *list;
    Dtdisc_t *disc = dt->disc;
    Dtmethod_t *oldmt = dt->meth;
    Dtdata_t *newdt, *olddt = dt->data;

    if (!meth || meth == oldmt) return oldmt;

    /* ask discipline if switching to new method is ok */
    if (disc->eventf && (*disc->eventf)(dt, DT_METH, (void *)meth, disc) < 0) return NULL;

    list = dtextract(dt); /* extract elements out of dictionary */

    /* try to create internal structure for new method */
    if (dt->searchf == oldmt->searchf) { /* ie, not viewpathing */
        dt->searchf = meth->searchf;
    }
    dt->meth = meth;
    dt->data = NULL;
    if ((*dt->meth->eventf)(dt, DT_OPEN, NULL) < 0) {
        newdt = NULL;
    } else {
        newdt = dt->data;
    }

    /* see what need to be done to data of the old method */
    if (dt->searchf == meth->searchf) dt->searchf = oldmt->searchf;
    dt->meth = oldmt;
    dt->data = olddt;
    if (newdt) {  // switch was successful, remove old data
        (void)(*dt->meth->eventf)(dt, DT_CLOSE, NULL);

        if (dt->searchf == oldmt->searchf) dt->searchf = meth->searchf;
        dt->meth = meth;
        dt->data = newdt;
        dtrestore(dt, list);
        return oldmt;
    }

    // Switch failed, restore dictionary to previous states.
    dtrestore(dt, list);
    return NULL;
}