コード例 #1
0
ファイル: vg_dq_vt_util_em.c プロジェクト: TidyHuang/vizgems
int EMparsenode (
    char *level, char *id, char *str, int dir, int *opip, int *opnp, EMbb_t *bbp
) {
    EMnode_t n, *np;
    XMLnode_t *xp;
    EMrec_t *recs, *drecs;
    int recm, drecm;

    if (!(xp = XMLreadstring (str, "em", TRUE, Vmheap))) {
        SUwarning (0, "EMparsenode", "cannot parse xml spec");
        return 0;
    }
    memset (&n, 0, sizeof (EMnode_t));
    memcpy (n.level, level, SZ_level);
    memcpy (n.id, id, SZ_id);
    if ((np = dtsearch (nodedict, &n)))
        recs = np->recs, recm = np->recm;
    else
        recs = NULL, recm = 0;
    memset (&n, 0, sizeof (EMnode_t));
    strncpy (n.level, "_D_", SZ_level);
    strncpy (n.id, "__DEFAULT__", SZ_id);
    if ((np = dtsearch (nodedict, &n)))
        drecs = np->recs, drecm = np->recm;
    else
        drecs = NULL, drecm = 0;
    *opip = EMopm;
    if (recparse (xp, recs, recm, drecs, drecm, dir, bbp) == -1) {
        SUwarning (0, "EMparsenode", "cannot parse spec");
        return -1;
    }
    *opnp = EMopm - *opip;
    return 0;
}
コード例 #2
0
ファイル: tvthread.c プロジェクト: att/ast
tmain() {
    UNUSED(argc);
    UNUSED(argv);
    pthread_t thread[N_THREADS];
    size_t k, p, n;
    Mydisc_t disc[2];
    Obj_t *o, *list[2], obj;

    topts();

    /* create two dictionaries to volley objects back and forth */
    for (n = 0; n < 2; ++n) {
        if (!(Dict[n] = opendictionary(&disc[n]))) terror("Can't open dictionary %d", n);

        /* make objects */
        if (!(list[n] = malloc((N_OBJ / 2) * sizeof(Obj_t)))) terror("malloc failed %d", n);
        memset(list[n], 0, (N_OBJ / 2) * sizeof(Obj_t));

        for (o = list[n], k = 0; k < N_OBJ / 2; ++k, ++o) {
            o->value = n == 0 ? k : k + N_OBJ / 2;

            if (dtinsert(Dict[n], o) != o) terror("Insert failed n=%d k=%d", n, k);
            if (dtsearch(Dict[n], o) != o) { /* verify insert succeeded */
                terror("Search failed n=%d k=%d", n, k);
            }

            o->ins[n] += 1;
        }
    }

    for (p = 0; p < N_THREADS; ++p) pthread_create(&thread[p], 0, volley, (void *)((long)(p % 2)));

    for (p = 0; p < N_THREADS; ++p) pthread_join(thread[p], 0);

    tinfo("\tCheck integrity");
    n = dtsize(Dict[0]);
    p = dtsize(Dict[1]);
    tinfo("Dict[0]=%d Dict[1]=%d", n, p);
    if ((n + p) != N_OBJ) {
        for (k = 0; k < N_OBJ; ++k) {
            obj.value = k;
            if ((o = dtsearch(Dict[0], &obj))) continue;
            if ((o = dtsearch(Dict[1], &obj))) continue;
            terror("%d not found", k);
            dtsearch(Dict[0], &obj);
            dtsearch(Dict[1], &obj);
        }

        terror("Expecting %d objects but got (Dict[0]=%d + Dict[1]=%d) = %d", N_OBJ, n, p, n + p);
    }

    texit(0);
}
コード例 #3
0
ファイル: ptopen.c プロジェクト: ISLEcode/kornshell
Ptprefix_t*
ptinsert(Pt_t* tab, Ptaddr_t min, Ptaddr_t max)
{
	register Ptprefix_t*	xp;
	register Ptprefix_t*	pp;
	Ptprefix_t		key;

	tab->entries++;
	key.min = key.max = min ? (min - 1) : min;
	if (!(xp = (Ptprefix_t*)dtsearch(tab->dict, &key)))
		xp = (Ptprefix_t*)dtnext(tab->dict, &key);
	key.min = min;
	key.max = max;
	pp = 0;
	if (xp)
	{
		if (key.min >= xp->min && key.max <= xp->max)
			return xp;
		if (key.max >= (xp->min ? (xp->min - 1) : 0))
		{
			if (key.min > xp->min)
				key.min = xp->min;
			do
			{
				max = xp->max;
				pp = xp;
				xp = (Ptprefix_t*)dtnext(tab->dict, xp);
				dtdelete(tab->dict, pp);
			} while (xp && key.max >= (xp->min - 1));
			if (key.max < max)
				key.max = max;
		}
	}
	return (Ptprefix_t*)dtinsert(tab->dict, &key);
}
コード例 #4
0
ファイル: grid.cpp プロジェクト: aosm/graphviz
Cell *Grid::find(int i, int j) {
    Cell key;

    key.p.i = i;
    key.p.j = j;
    return reinterpret_cast<Cell*>(dtsearch(this, &key));
}
コード例 #5
0
ファイル: deglist.c プロジェクト: TidyHuang/vizgems
/* removeDeglist:
 * Remove n from list, if it is in the list.
 */
void removeDeglist(deglist_t * list, Agnode_t * n)
{
    degitem key;
    degitem *ip;
    Agnode_t *np;
    Agnode_t *prev;

    key.deg = DEGREE(n);
    ip = (degitem *) dtsearch(list, &key);
    assert(ip);
    if (ip->np == n) {
	ip->np = ND_next(n);
	if (ip->np == NULL)
	    dtdelete(list, ip);
    } else {
	prev = ip->np;
	np = ND_next(prev);
	while (np && (np != n)) {
	    prev = np;
	    np = ND_next(np);
	}
	if (np)
	    ND_next(prev) = ND_next(np);
    }
}
コード例 #6
0
ファイル: pointset.c プロジェクト: BestSean2016/graphviz
int isInPS(PointSet * ps, int x, int y)
{
    pair p;
    p.id.x = x;
    p.id.y = y;
    return ((dtsearch(ps, &p)) ? 1 : 0);
}
コード例 #7
0
IMPLLnd_t *IMPLLfindnd (char *level, char *id) {
    IMPLLnd_t nd;

    memcpy (nd.level, level, SZ_level);
    memcpy (nd.id, id, SZ_id);
    return dtsearch (nddict, &nd);
}
コード例 #8
0
ファイル: grid.c プロジェクト: DaniHaag/jsPlumb_Liviz.js
/* findGrid;
 * Return the cell, if any, corresponding to
 * indices i,j
 */
cell *findGrid(Grid * g, int i, int j)
{
    cell key;

    key.p.i = i;
    key.p.j = j;
    return ((cell *) dtsearch(g->data, &key));
}
コード例 #9
0
ファイル: tstack.c プロジェクト: ISLEcode/kornshell
tmain()
{
	Dt_t*		dt;

	/* testing Dtstack */
	if(!(dt = dtopen(&Disc,Dtstack)) )
		terror("dtopen stack");
	if((long)dtinsert(dt,1L) != 1)
		terror("Dtstack insert 1");
	if((long)dtinsert(dt,3L) != 3)
		terror("Dtstack insert 3.1");
	if((long)dtinsert(dt,2L) != 2)
		terror("Dtstack insert 2.1");
	if((long)dtinsert(dt,3L) != 3)
		terror("Dtstack insert 3.2");
	if((long)dtinsert(dt,2L) != 2)
		terror("Dtstack insert 2.2");
	if((long)dtinsert(dt,3L) != 3)
		terror("Dtstack insert 3.3");

	if((long)dtlast(dt) != 1)
		terror("Dtstack dtlast");
	if((long)dtprev(dt,1L) != 3)
		terror("Dtstack dtprev 1");
	if((long)dtprev(dt,3L) != 2)
		terror("Dtstack dtprev 3.1");
	if((long)dtprev(dt,2L) != 3)
		terror("Dtstack dtprev 2.1");
	if((long)dtprev(dt,3L) != 2)
		terror("Dtstack dtprev 3.2");
	if((long)dtprev(dt,2L) != 3)
		terror("Dtstack dtprev 2.2");
	if((long)dtprev(dt,3L) != 0)
		terror("Dtstack dtprev 3.2");

	if((long)dtdelete(dt,NIL(Void_t*)) != 3)
		terror("Dtstack pop 3.3");

	/* search to one of the 3 */
	if((long)dtsearch(dt,3L) != 3)
		terror("Dtstack search 3.2");
	if((long)dtdelete(dt,3L) != 3)
		terror("Dtstack delete 3.2");

	if((long)dtdelete(dt,NIL(Void_t*)) != 2)
		terror("Dtstack pop 2.2");
	if((long)dtdelete(dt,NIL(Void_t*)) != 2)
		terror("Dtstack pop 2.1");
	if((long)dtdelete(dt,NIL(Void_t*)) != 3)
		terror("Dtstack pop 3.1");
	if((long)dtdelete(dt,NIL(Void_t*)) != 1)
		terror("Dtstack pop 1");

	if(dtsize(dt) != 0)
		terror("Dtstack size");

	texit(0);
}
コード例 #10
0
ファイル: tigerrecords.c プロジェクト: TidyHuang/vizgems
poly_t *findpoly (int polyid, int cenid) {
    poly_t pmem, *pp;

    pmem.cenid = cenid;
    pmem.polyid = polyid;
    if (!(pp = dtsearch (polydict, &pmem)))
        return NULL;
    return pp;
}
コード例 #11
0
ファイル: regcoll.c プロジェクト: NanXiao/illumos-joyent
static int
initialize(void)
{
	register int		i;
	register Ucs_map_t*	a;
	register Ucs_map_t*	w;

	if (local.fatal)
		return -1;
	local.dtdisc.link = offsetof(Ucs_map_t, link);
	local.dtdisc.key = offsetof(Ucs_map_t, name);
	local.dtdisc.size = -1;
	if (!(w = (Ucs_map_t*)malloc(sizeof(Ucs_map_t) * (elementsof(ucs_attrs) + elementsof(ucs_names)))))
	{
		local.fatal = 1;
		return -1;
	}
	if (!(local.attrs = dtopen(&local.dtdisc, Dttree)))
	{
		free(w);
		local.fatal = 1;
		return -1;
	}
	if (!(local.names = dtopen(&local.dtdisc, Dttree)))
	{
		free(w);
		dtclose(local.attrs);
		local.fatal = 1;
		return -1;
	}
	for (i = 0; i < elementsof(ucs_attrs); i++, w++)
	{
		memcpy(w, &ucs_attrs[i], offsetof(Ucs_dat_t, table));
		w->name = ucs_strings[ucs_attrs[i].table] + ucs_attrs[i].index;
		w->next = 0;
		dtinsert(local.attrs, w);
	}
	for (i = 0; i < elementsof(ucs_names); i++, w++)
	{
		memcpy(w, &ucs_names[i], offsetof(Ucs_dat_t, table));
		w->name = ucs_strings[ucs_names[i].table] + ucs_names[i].index;
		w->next = 0;
		if (a = (Ucs_map_t*)dtsearch(local.names, w))
		{
			while (a->next)
				a = a->next;
			a->next = w;
		}
		else
			dtinsert(local.names, w);
	}
#if CC_NATIVE != CC_ASCII
	local.a2n = ccmap(CC_ASCII, CC_NATIVE);
#endif
	return 0;
}
コード例 #12
0
ファイル: save2_minc.c プロジェクト: AhmedAMohamed/graphviz
static rep_t association(Agraph_t *model, void *obj)
{
	Dict_t *dict;
	repkey_t	key, rv, *p;

	dict = repdict(model);
	key.key = obj;		/* i hate when other people code like this */
	if ((p = dtsearch(dict,&key))) rv = *p;
	else {rv.val.type = 0; rv.val.p = 0;}
	return rv.val;
}
コード例 #13
0
ファイル: vg_dq_vt_util_em.c プロジェクト: TidyHuang/vizgems
int EMparseedge (
    char *level1, char *id1, char *level2, char *id2,
    char *str, int dir, int *opip, int *opnp, EMbb_t *bbp
) {
    EMedge_t e, *ep;
    XMLnode_t *xp;
    EMrec_t *recs, *drecs;
    int recm, drecm;

    if (!(xp = XMLreadstring (str, "em", TRUE, Vmheap))) {
        SUwarning (0, "EMparseedge", "cannot parse xml spec");
        return 0;
    }
    memset (&e, 0, sizeof (EMedge_t));
    memcpy (e.level1, level1, SZ_level);
    memcpy (e.id1, id1, SZ_id);
    memcpy (e.level2, level2, SZ_level);
    memcpy (e.id2, id2, SZ_id);
    if ((ep = dtsearch (edgedict, &e)))
        recs = ep->recs, recm = ep->recm;
    else
        recs = NULL, recm = 0;
    memset (&e, 0, sizeof (EMedge_t));
    memcpy (e.level1, "_D_", SZ_level);
    memcpy (e.id1, "__DEFAULT__", SZ_id);
    memcpy (e.level2, "_D_", SZ_level);
    memcpy (e.id2, "__DEFAULT__", SZ_id);
    if ((ep = dtsearch (edgedict, &e)))
        drecs = ep->recs, drecm = ep->recm;
    else
        drecs = NULL, drecm = 0;
    *opip = EMopm;
    if (recparse (xp, recs, recm, drecs, drecm, dir, bbp) == -1) {
        SUwarning (0, "EMparseedge", "cannot parse spec");
        return -1;
    }
    *opnp = EMopm - *opip;
    return 0;
}
コード例 #14
0
static int findMap(Dt_t * map, int a, int b)
{
    item it;
    item *ip;
    if (a > b) {
	int tmp = a;
	a = b;
	b = tmp;
    }
    it.a[0] = a;
    it.a[1] = b;
    ip = (item *) dtsearch(map, &it);
    assert(ip);
    return ip->t;
}
コード例 #15
0
ファイル: gdgen.c プロジェクト: aosm/graphviz
static gdImagePtr getshapeimage(char *name)
{
	imagerec_t	probe, *val;
    if (!name) return 0;  /* cdt does not like NULL keys */
	if (!ImageDict) ImageDict = dtopen(&ImageDictDisc,Dttree);
	probe.name = name;
	val = dtsearch(ImageDict,&probe);
	if (!val) {
		val = GNEW(imagerec_t);
		val->name = name;
		val->im = loadshapeimage(name);
		dtinsert(ImageDict,val);
	}
	return val->im;
}
コード例 #16
0
ファイル: ptopen.c プロジェクト: ISLEcode/kornshell
int
ptdelete(Pt_t* tab, Ptaddr_t min, Ptaddr_t max)
{
	register Ptprefix_t*	xp;
	Ptprefix_t		key;
	Ptprefix_t		cur;

	tab->entries++;
	key.min = min;
	key.max = max;
	if (xp = (Ptprefix_t*)dtsearch(tab->dict, &key))
	{
		do
		{
			cur.min = xp->min;
			cur.max = xp->max;
			dtdelete(tab->dict, xp);
			if (key.min > cur.min)
			{
				max = cur.max;
				cur.max = key.min - 1;
				if (!dtinsert(tab->dict, &cur))
					goto bad;
				if (key.max < max)
				{
					cur.min = key.max + 1;
					cur.max = max;
					if (!dtinsert(tab->dict, &cur))
						goto bad;
					break;
				}
			}
			else if (key.max < xp->max)
			{
				xp->min = key.max + 1;
				if (!dtinsert(tab->dict, xp))
					goto bad;
			}
		} while (xp = (Ptprefix_t*)dtnext(tab->dict, xp));
	}
	return 0;
 bad:
	if (tab->disc->errorf)
		(*tab->disc->errorf)(NiL, tab->disc, ERROR_SYSTEM|2, "out of space");
	return -1;
}
コード例 #17
0
ファイル: refstr.c プロジェクト: AhmedAMohamed/graphviz
void agstrfree(char *s)
{
    refstr_t *key, *r;

    if ((StringDict == NULL) || (s == NULL))
	return;
    key = (refstr_t *) (s - offsetof(refstr_t, s[0]));
    r = (refstr_t *) dtsearch(StringDict, key);

    if (r) {
	r->refcnt--;
	if ((r->refcnt && CNT_BITS) == 0) {
	    dtdelete(StringDict, r);
	    free(r);
	}
    } else
	agerr(AGERR, "agstrfree lost %s\n", s);
}
コード例 #18
0
ファイル: refstr.c プロジェクト: AhmedAMohamed/graphviz
/* agstrdup_html:
 * For various purposes, including deparsing, we have to recognize
 * strings coming from <...> rather than "...". To do this, we set
 * the top bit of the refcnt field. Since the use of html strings
 * is localized, we allow the application to make the distinction.
 */
char *agstrdup_html(char *s)
{
    refstr_t *key, *r;

    if (StringDict == NULL)
	initialize_strings();
    if (s == NULL)
	return s;

    key = (refstr_t *) (s - offsetof(refstr_t, s[0]));
    r = (refstr_t *) dtsearch(StringDict, key);
    if (r)
	r->refcnt++;
    else {
	r = (refstr_t *) malloc(sizeof(refstr_t) + strlen(s));
	r->refcnt = 1 | HTML_BIT;
	strcpy(r->s, s);
	dtinsert(StringDict, r);
    }
    return r->s;
}
コード例 #19
0
ファイル: tvthread.c プロジェクト: att/ast
/* swap objects from one dictionary to another */
static void *volley(void *arg) {
    int deldt, insdt, n_move, dir, k;
    Obj_t obj, *o, *rv;

    Nthreads += 1; /* wait until all threads have been started */
    while (Nthreads < N_THREADS) tmsleep(0, 1);

    if ((deldt = (int)((long)arg)) < 0 || deldt > 1) {
        terror("Thread number must be 0 or 1, not %d", deldt);
    }
    insdt = !deldt;

    n_move = 0;
    for (dir = 1; dir >= -1; dir -= 2) {
        for (k = dir > 0 ? 0 : N_OBJ - 1; k >= 0 && k < N_OBJ; k += dir) {
            obj.value = k;
            if (!(o = dtsearch(Dict[deldt], &obj))) continue;

            if ((rv = dtdelete(Dict[deldt], o)) == o) {
                asoincint(&o->del[deldt]);

                if ((rv = dtinsert(Dict[insdt], o)) != o) terror("Insert %d failed", o->value);

                asoincint(&o->ins[insdt]);

                n_move += 1;
            } else if (rv) {
                terror("Unknown object %d", rv->value);
            }

            if (k % 100 == 0) tmsleep(0, 1);
        }
    }
    tinfo("Move %d (Dict[%d] -> Dict[%d])", n_move, deldt, insdt);

    return 0;
}
コード例 #20
0
ファイル: graphio.c プロジェクト: Chaduke/bah.mod
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");
    }
}
コード例 #21
0
ファイル: validate.c プロジェクト: ISLEcode/kornshell
static int
validate_sel(Cx_t* cx, Cxexpr_t* expr, void* data, Cxdisc_t* disc)
{
	register State_t*	state = (State_t*)expr->data;
	register Field_t*	field;
	register Cxconstraint_t*constraint;
	Cxoperand_t		o;
	Cxinstruction_t		x;
	Invalid_t		key;
	Invalid_t*		ip;
	size_t			n;

	for (field = state->field; field; field = field->next)
	{
		x.data.variable = field->variable;
		if ((*state->getf)(cx, &x, &o, NiL, NiL, data, disc))
			return -1;
		if (field->variable->format.map)
		{
			if (cxisstring(field->variable->type))
			{
				if (cxstr2num(cx, &field->variable->format, o.value.string.data, o.value.string.size, NiL))
				{
					if (state->verbose && disc->errorf)
						(*disc->errorf)(NiL, disc, 1, "%s%s: %-.*s: unknown map name", cxlocation(cx, data), field->variable->name, o.value.string.size, o.value.string.data);
					goto invalid;
				}
			}
			else if (cxisnumber(field->variable->type))
			{
				if (cxnum2str(cx, &field->variable->format, (Cxinteger_t)o.value.number, NiL))
				{
					if (state->verbose && disc->errorf)
						(*disc->errorf)(NiL, disc, 1, "%s%s: %I*d: unknown map value", cxlocation(cx, data), field->variable->name, sizeof(Cxinteger_t), (Cxinteger_t)o.value.number);
					goto invalid;
				}
			}
		}
		if (constraint = field->variable->format.constraint)
		{
			if (constraint->constraintf)
				;
			if (cxisnumber(field->variable->type))
			{
				if (constraint->min && o.value.number < constraint->min->number)
				{
					if (state->verbose && disc->errorf)
						(*disc->errorf)(NiL, disc, 1, "%s%s: %1.15Lg violates min constraint %1.15Lg", cxlocation(cx, data), field->variable->name, o.value.number, constraint->min->number);
					goto invalid;
				}
				if (constraint->max && o.value.number > constraint->max->number)
				{
					if (state->verbose && disc->errorf)
						(*disc->errorf)(NiL, disc, 1, "%s%s: %1.15Lg violates max constraint %1.15Lg", cxlocation(cx, data), field->variable->name, o.value.number, constraint->max->number);
					goto invalid;
				}
			}
			if (constraint->expression)
				;
			if (constraint->pattern)
				;
		}
		continue;
	invalid:
		if (state->invalid)
		{
			key.variable = field->variable;
			key.value = o.value;
			if (!(ip = (Invalid_t*)dtsearch(state->invalid, &key)))
			{
				n = cxsize(field->variable->type, &o.value);
				if (!(ip = vmnewof(state->vm, 0, Invalid_t, 1, n)))
				{
					if (disc->errorf)
						(*disc->errorf)(NiL, disc, ERROR_SYSTEM|2, "out of space");
					return -1;
				}
				*ip = key;
				ip->value = o.value;
				if (n)
				{
					ip->value.buffer.data = (void*)(ip + 1);
					memcpy(ip->value.buffer.data, o.value.buffer.data, n);
				}
				dtinsert(state->invalid, ip);
				ip->count = 0;
			}
			ip->count++;
		}
		if (state->setf && constraint && constraint->def)
		{
			o.type = field->variable->type;
			o.value = *constraint->def;
			if ((*state->setf)(cx, &x, &o, &o, NiL, data, disc))
				return -1;
			field->repaired++;
		}
		else if (state->discard)
		{
			field->discarded++;
			return 0;
		}
		else
			field->invalid++;
	}
	return 1;
}
コード例 #22
0
IMPLLnd_t *IMPLLinsertnd (char *level, char *id, short nclass, char *attrstr) {
    IMPLLnd_t nd, *ndp, *ndmem;
    UTattr_t *ap;
    EMbb_t bb;
    char *s1;

    memcpy (nd.level, level, SZ_level);
    memcpy (nd.id, id, SZ_id);
    if ((ndp = dtsearch (nddict, &nd)))
        return ndp;

    if (!(ndmem = vmalloc (Vmheap, sizeof (IMPLLnd_t)))) {
        SUwarning (0, "IMPLLinsertnd", "cannot allocate ndmem");
        return NULL;
    }
    memset (ndmem, 0, sizeof (IMPLLnd_t));
    memcpy (ndmem->level, level, SZ_level);
    memcpy (ndmem->id, id, SZ_id);
    if ((ndp = dtinsert (nddict, ndmem)) != ndmem) {
        SUwarning (0, "IMPLLinsertnd", "cannot insert nd");
        vmfree (Vmheap, ndmem);
        return NULL;
    }
    ndp->nclass = nclass;

    if (UTsplitattr (UT_ATTRGROUP_NODE, attrstr) == -1) {
        SUwarning (0, "IMPLLinsertnd", "cannot parse attrstr");
        return NULL;
    }
    if (UTgetattrs (UT_ATTRGROUP_NODE) == -1) {
        SUwarning (0, "IMPLLinsertnd", "cannot get node attr");
        return NULL;
    }
    ap = &UTattrgroups[UT_ATTRGROUP_NODE][UT_ATTR_WIDTH];
    if (ap->value && ap->value[0])
        ndp->w = atoi (ap->value);
    else
        ndp->w = 100;
    ap = &UTattrgroups[UT_ATTRGROUP_NODE][UT_ATTR_HEIGHT];
    if (ap->value && ap->value[0])
        ndp->h = atoi (ap->value);
    else
        ndp->h = 50;
    ap = &UTattrgroups[UT_ATTRGROUP_NODE][UT_ATTR_LABEL];
    if (
        ap->value &&
        strcmp (ap->name, "label") == 0 &&
        strncmp (ap->value, "EMBED:", 6) == 0
    ) {
        if (EMparsenode (
            ndp->level, ndp->id, ap->value + 6, EM_DIR_V,
            &ndp->opi, &ndp->opn, &bb
        ) == -1) {
            SUwarning (0, "IMPLLinsertnd", "cannot parse node EM contents");
            return NULL;
        }
        if (ndp->w < bb.w)
            ndp->w = bb.w;
        if (ndp->h < bb.h)
            ndp->h = bb.h;
    }
    ap = &UTattrgroups[UT_ATTRGROUP_NODE][UT_ATTR_LINEWIDTH];
    ndp->lw = (ap->value && ap->value[0]) ? atoi (ap->value) : 1;
    ap = &UTattrgroups[UT_ATTRGROUP_NODE][UT_ATTR_BGCOLOR];
    if (!(ndp->bg = vmstrdup (
        Vmheap, (ap->value && ap->value[0]) ? ap->value : "white"
    ))) {
        SUwarning (0, "IMPLLinsertnd", "cannot copy node bgcolor");
        return NULL;
    }
    ap = &UTattrgroups[UT_ATTRGROUP_NODE][UT_ATTR_COLOR];
    if (!(ndp->cl = vmstrdup (
        Vmheap, (ap->value && ap->value[0]) ? ap->value : "black"
    ))) {
        SUwarning (0, "IMPLLinsertnd", "cannot copy node color");
        return NULL;
    }
    ap = &UTattrgroups[UT_ATTRGROUP_NODE][UT_ATTR_FONTNAME];
    if (!(ndp->fn = vmstrdup (
        Vmheap, (ap->value && ap->value[0]) ? ap->value : "abc"
    ))) {
        SUwarning (0, "IMPLLinsertnd", "cannot copy node font name");
        return NULL;
    }
    ap = &UTattrgroups[UT_ATTRGROUP_NODE][UT_ATTR_FONTSIZE];
    if (!(ndp->fs = vmstrdup (
        Vmheap, (ap->value && ap->value[0]) ? ap->value : "10"
    ))) {
        SUwarning (0, "IMPLLinsertnd", "cannot copy node font size");
        return NULL;
    }
    ap = &UTattrgroups[UT_ATTRGROUP_NODE][UT_ATTR_INFO];
    if (!(ndp->info = vmstrdup (
        Vmheap, (ap->value && ap->value[0]) ? ap->value : id
    ))) {
        SUwarning (0, "IMPLLinsertnd", "cannot copy node info");
        return NULL;
    }

    ndp->havecoord = FALSE;
    ap = &UTattrgroups[UT_ATTRGROUP_NODE][UT_ATTR_COORD];
    if (ap->value && ap->value[0] && (s1 = strchr (ap->value, ' '))) {
        *s1 = 0;
        ndp->llx = atof (ap->value), ndp->lly = atof (s1 + 1);
        *s1 = ' ';
        ndp->havecoord = TRUE;
    }

    return ndp;
}
コード例 #23
0
ファイル: tstringset.c プロジェクト: att/ast
tmain() {
    UNUSED(argc);
    UNUSED(argv);
    int i, k;
    Dt_t *dt;
    Dtdisc_t disc;
    char *ks, tmp[16]; /* max 7-digit numbers */

    /* create a permutation of size N_obj */
    for (i = 0; i < N_obj; ++i) Perm[i] = i;
#if RANDOM
    for (i = N_obj; i > 1; --i) {
        k = ((unsigned int)rand()) % i;
        t = Perm[k];
        Perm[k] = Perm[i - 1];
        Perm[i - 1] = t;
    }
#endif

    /* make key */
    for (i = 0; i < N_obj; ++i) sprintf(Key[i], Pat, Perm[i]);

    disc.key = disc.size = 0;
    disc.link = -1;
    disc.makef = 0;
    disc.freef = 0;
    disc.comparf = 0;
    disc.hashf = 0;
    disc.memoryf = 0;
    disc.eventf = 0;
    dt = dtopen(&disc, Dtset);

    /* insert into table */
    for (i = 0; i < N_obj; ++i) {
        dtinsert(dt, Key[i]);
        if (((i + 1) % 1000) == 0) {
            if (dtsize(dt) != i + 1) terror("Bad size=%d, should be %d", k, i + 1);
            for (k = 0; k < 1000; ++k) {
                sprintf(tmp, Pat, ((unsigned int)rand()) % (i + 1));
                if (!(ks = (char *)dtsearch(dt, tmp))) terror("Not finding '%s'", tmp);
            }
        }
    }

    /* search in order of insertion */
    for (Count = 0, i = 0; i < N_obj; ++i) {
        if (!(ks = (char *)dtsearch(dt, Key[i]))) terror("Not finding '%s'", Key[i]);
        if (strcmp(ks, Key[i]) == 0) Count += 1;
    }
    if (Count != N_obj) terror("Count=%d but should be %d", Count, N_obj);

    /* search in a random order */
    for (Count = 0, i = 0; i < N_obj; ++i) {
        sprintf(tmp, Pat, ((unsigned int)rand()) % N_obj);
        if (!(ks = (char *)dtsearch(dt, tmp))) terror("Not finding '%s'", Key[i]);
        if (strcmp(ks, tmp) == 0) Count += 1;
    }
    if (Count != N_obj) terror("Count=%d but should be %d", Count, N_obj);

    /* search in increasing order */
    for (Count = 0, i = 0; i < N_obj; ++i) {
        sprintf(tmp, Pat, i);
        if (!(ks = (char *)dtsearch(dt, tmp))) terror("Not finding '%s'", tmp);
        if (strcmp(ks, tmp) == 0) Count += 1;
    }
    if (Count != N_obj) terror("Count=%d but should be %d", Count, N_obj);

    texit(0);
}
コード例 #24
0
ファイル: vg_dq_vt_util_em.c プロジェクト: TidyHuang/vizgems
static int load (char *id, char *file) {
    EMnode_t n, *np, *nmem;
    EMedge_t e, *ep, *emem;
    EMrec_t *rp, **rsp;
    int *rnp, *rmp;
    Sfio_t *fp;
    char *line, *s1, *s2, *s3, *s4, *s5, *s6, *s7;

    if (!(fp = sfopen (NULL, file, "r"))) {
        SUwarning (0, "load", "cannot open embed info file");
        return 0;
    }
    while ((line = sfgetr (fp, '\n', 1))) {
        np = NULL;
        ep = NULL;
        if (!(s1 = strchr (line, '|'))) {
            SUwarning (0, "load", "bad line(1): %s", line);
            continue;
        }
        *s1++ = 0;
        if (line[0] == 'N' || line[0] == 'n') {
            if (!(s2 = strchr (s1, '|')) || !(s3 = strchr (s2 + 1, '|'))) {
                SUwarning (0, "load", "bad line(2): %s", s1);
                continue;
            }
            *s2++ = 0, *s3++ = 0;
            memset (&n, 0, sizeof (EMnode_t));
            strcpy (n.level, s1);
            strcpy (n.id, s2);
            if (!(np = dtsearch (nodedict, &n))) {
                if (!(nmem = vmalloc (Vmheap, sizeof (EMnode_t)))) {
                    SUwarning (0, "load", "cannot allocate nmem");
                    return -1;
                }
                memset (nmem, 0, sizeof (EMnode_t));
                strcpy (nmem->level, s1);
                strcpy (nmem->id, s2);
                if (!(np = dtinsert (nodedict, nmem))) {
                    SUwarning (0, "load", "cannot insert node");
                    vmfree (Vmheap, nmem);
                    return -1;
                }
            }
            s1 = s3;
            rsp = &np->recs, rnp = &np->recn, rmp = &np->recm;
        } else if (line[0] == 'E' || line[0] == 'e') {
            if (!(s2 = strchr (s1, '|')) || !(s3 = strchr (s2 + 1, '|'))) {
                SUwarning (0, "load", "bad line(3): %s", s1);
                continue;
            }
            *s2++ = *s3++ = 0;
            if (!(s4 = strchr (s3, '|')) || !(s5 = strchr (s4 + 1, '|'))) {
                SUwarning (0, "load", "bad line(4): %s", s3);
                continue;
            }
            *s4++ = 0, *s5++ = 0;
            memset (&e, 0, sizeof (EMedge_t));
            strcpy (e.level1, s1);
            strcpy (e.id1, s2);
            strcpy (e.level2, s3);
            strcpy (e.id2, s4);
            if (!(ep = dtsearch (edgedict, &e))) {
                if (!(emem = vmalloc (Vmheap, sizeof (EMedge_t)))) {
                    SUwarning (0, "load", "cannot allocate emem");
                    return -1;
                }
                memset (emem, 0, sizeof (EMedge_t));
                strcpy (emem->level1, s1);
                strcpy (emem->id1, s2);
                strcpy (emem->level2, s3);
                strcpy (emem->id2, s4);
                if (!(ep = dtinsert (edgedict, emem))) {
                    SUwarning (0, "load", "cannot insert edge");
                    vmfree (Vmheap, emem);
                    return -1;
                }
            }
            s1 = s5;
            rsp = &ep->recs, rnp = &ep->recn, rmp = &ep->recm;
        }
        if (!(s2 = strchr (s1, '|'))) {
            SUwarning (0, "load", "bad line(5): %s", s1);
            continue;
        }
        *s2++ = 0;
        if (*rmp >= *rnp) {
            if (!(*rsp = vmresize (
                Vmheap, *rsp, (*rnp + 5) * sizeof (EMrec_t), VM_RSCOPY
            ))) {
                SUwarning (0, "load", "cannot grow recs array");
                return -1;
            }
            *rnp += 5;
        }
        rp = &(*rsp)[*rmp], (*rmp)++;
        if (!(rp->id = vmstrdup (Vmheap, id))) {
            SUwarning (0, "load", "cannot copy id");
            return -1;
        }
        if (s1[0] == 'I' || s1[0] == 'i') {
            if (!(s3 = strchr (s2, '|'))) {
                SUwarning (0, "load", "bad line(6): %s", s2);
                continue;
            }
            if (!(s4 = strchr (s3 + 1, '|')) || !(s5 = strchr (s4 + 1, '|'))) {
                SUwarning (0, "load", "bad line(7): %s", s3);
                continue;
            }
            if (!(s6 = strchr (s5 + 1, '|')) || !(s7 = strchr (s6 + 1, '|'))) {
                SUwarning (0, "load", "bad line(8): %s", s5);
                continue;
            }
            *s3++ = *s4++ = *s5++ = *s6++ = *s7++ = 0;
            rp->type = EM_TYPE_I;
            if (!(rp->u.i.file = vmstrdup (Vmheap, s2))) {
                SUwarning (0, "load", "cannot copy file");
                return -1;
            }
            rp->u.i.x1 = atoi (s3), rp->u.i.y1 = atoi (s4);
            rp->u.i.x2 = atoi (s5), rp->u.i.y2 = atoi (s6);
        } else if (s1[0] == 'S' || s1[0] == 's') {
            if (!(s3 = strchr (s2, '|'))) {
                SUwarning (0, "load", "bad line(9): %s", s2);
                continue;
            }
            if (!(s4 = strchr (s3 + 1, '|')) || !(s5 = strchr (s4 + 1, '|'))) {
                SUwarning (0, "load", "bad line(10): %s", s3);
                continue;
            }
            if (!(s6 = strchr (s5 + 1, '|')) || !(s7 = strchr (s6 + 1, '|'))) {
                SUwarning (0, "load", "bad line(11): %s", s5);
                continue;
            }
            *s3++ = *s4++ = *s5++ = *s6++ = *s7++ = 0;
            rp->type = EM_TYPE_S;
            if (
                !(rp->u.s.fn = vmstrdup (Vmheap, s2)) ||
                !(rp->u.s.fs = vmstrdup (Vmheap, s3)) ||
                !(rp->u.s.flcl = vmstrdup (Vmheap, s4)) ||
                !(rp->u.s.lncl = vmstrdup (Vmheap, s5)) ||
                !(rp->u.s.fncl = vmstrdup (Vmheap, s6))
            ) {
                SUwarning (0, "load", "cannot copy style");
                return -1;
            }
        }
        if (!(rp->im = vmstrdup (Vmheap, s7))) {
            SUwarning (0, "load", "cannot copy image map");
            return -1;
        }
    }
    sfclose (fp);
    return 0;
}
コード例 #25
0
IMPLLed_t *IMPLLinserted (IMPLLnd_t *ndp1, IMPLLnd_t *ndp2, char *attrstr) {
    IMPLLed_t ed, *edp, *edmem;
    UTattr_t *ap;
    EMbb_t bb;

    ed.ndp1 = ndp1;
    ed.ndp2 = ndp2;
    if ((edp = dtsearch (eddict, &ed)))
        return edp;

    if (!(edmem = vmalloc (Vmheap, sizeof (IMPLLed_t)))) {
        SUwarning (0, "IMPLLinserted", "cannot allocate edmem");
        return NULL;
    }
    memset (edmem, 0, sizeof (IMPLLed_t));
    edmem->ndp1 = ndp1, edmem->ndp2 = ndp2;
    if ((edp = dtinsert (eddict, edmem)) != edmem) {
        SUwarning (0, "IMPLLinserted", "cannot insert ed");
        vmfree (Vmheap, edmem);
        return NULL;
    }

    if (UTsplitattr (UT_ATTRGROUP_EDGE, attrstr) == -1) {
        SUwarning (0, "IMPLLinserted", "cannot parse attrstr");
        return NULL;
    }
    if (UTgetattrs (UT_ATTRGROUP_EDGE) == -1) {
        SUwarning (0, "IMPLLinserted", "cannot get edge attr");
        return NULL;
    }
    ap = &UTattrgroups[UT_ATTRGROUP_EDGE][UT_ATTR_LABEL];
    if (
        ap->value &&
        strcmp (ap->name, "label") == 0 &&
        strncmp (ap->value, "EMBED:", 6) == 0
    ) {
        if (EMparseedge (
            ndp1->level, ndp1->id, ndp2->level, ndp2->id,
            ap->value + 6, EM_DIR_V, &edp->opi, &edp->opn, &bb
        ) == -1) {
            SUwarning (0, "IMPLLinserted", "cannot parse edge EM contents");
            return NULL;
        }
    }
    ap = &UTattrgroups[UT_ATTRGROUP_EDGE][UT_ATTR_LINEWIDTH];
    edp->lw = (ap->value && ap->value[0]) ? atoi (ap->value) : 1;
    ap = &UTattrgroups[UT_ATTRGROUP_EDGE][UT_ATTR_COLOR];
    if (!(edp->cl = vmstrdup (
        Vmheap, (ap->value && ap->value[0]) ? ap->value : "black"
    ))) {
        SUwarning (0, "IMPLLinserted", "cannot copy edge color");
        return NULL;
    }
    ap = &UTattrgroups[UT_ATTRGROUP_EDGE][UT_ATTR_FONTNAME];
    if (!(edp->fn = vmstrdup (
        Vmheap, (ap->value && ap->value[0]) ? ap->value : "abc"
    ))) {
        SUwarning (0, "IMPLLinserted", "cannot copy edge font name");
        return NULL;
    }
    ap = &UTattrgroups[UT_ATTRGROUP_EDGE][UT_ATTR_FONTSIZE];
    if (!(edp->fs = vmstrdup (
        Vmheap, (ap->value && ap->value[0]) ? ap->value : "10"
    ))) {
        SUwarning (0, "IMPLLinserted", "cannot copy edge font size");
        return NULL;
    }
    ap = &UTattrgroups[UT_ATTRGROUP_EDGE][UT_ATTR_INFO];
    if (!(edp->info = vmstrdup (
        Vmheap, (ap->value && ap->value[0]) ? ap->value : ""
    ))) {
        SUwarning (0, "IMPLLinserted", "cannot copy edge info");
        return NULL;
    }

    return edp;
}
コード例 #26
0
ファイル: tlist.c プロジェクト: ISLEcode/kornshell
tmain()
{
	Dt_t*		dt;

	/* testing Dtlist */
	if(!(dt = dtopen(&Disc,Dtlist)) )
		terror("dtopen list");
	if((long)dtinsert(dt,1L) != 1)
		terror("Dtlist insert 1");
	if((long)dtappend(dt,2L) != 2)
		terror("Dtlist append 2");
	if((long)dtappend(dt,3L) != 3)
		terror("Dtlist append 3");
	if((long)dtappend(dt,1L) != 1)
		terror("Dtlist append 1");
	if((long)dtappend(dt,2L) != 2)
		terror("Dtlist append 2");
	if((long)dtappend(dt,3L) != 3)
		terror("Dtlist append 3");

	if((long)dtlast(dt) != 3)
		terror("Dtlist dtlast");
	if((long)dtprev(dt,3L) != 2)
		terror("Dtlist dtprev 2");
	if((long)dtprev(dt,2L) != 1)
		terror("Dtlist dtprev 1");
	if((long)dtprev(dt,1L) != 3)
		terror("Dtlist dtprev 3");
	if((long)dtprev(dt,3L) != 2)
		terror("Dtlist dtprev 2");
	if((long)dtprev(dt,2L) != 1)
		terror("Dtlist dtprev 1");

	/* search to the first 3 */
	if((long)dtfirst(dt) != 1)
		terror("Dtlist dtfirst 1");
	if((long)dtsearch(dt,3L) != 3)
		terror("Dtlist search 3");
	if((long)dtinsert(dt,4L) != 4)
		terror("Dtlist insert 4");
	if((long)dtnext(dt,4L) != 3)
		terror("Dtlist next 3");
	if((long)dtappend(dt,5L) != 5)
		terror("Dtlist append 5");

	if((long)dtfirst(dt) != 1)
		terror("Dtlist dtfirst 1");
	if((long)dtnext(dt,1L) != 2)
		terror("Dtlist next 2");
	if((long)dtnext(dt,2L) != 4)
		terror("Dtlist next 4");
	if((long)dtnext(dt,4L) != 3)
		terror("Dtlist next 3");
	if((long)dtnext(dt,3L) != 5)
		terror("Dtlist next 5");
	if((long)dtnext(dt,5L) != 1)
		terror("Dtlist next 1");
	if((long)dtnext(dt,1L) != 2)
		terror("Dtlist next 2");
	if((long)dtnext(dt,2L) != 3)
		terror("Dtlist next 3");

	texit(0);
}
コード例 #27
0
ファイル: pointset.c プロジェクト: BestSean2016/graphviz
int inPS(PointSet * ps, point pt)
{
    pair p;
    p.id = pt;
    return ((dtsearch(ps, &p)) ? 1 : 0);
}