예제 #1
0
void printstats (void) {
    SUmessage (
        1, "printstats", "%d strings, %d vertices, %d edges, %d polys",
        dtsize (stringdict), dtsize (vertexdict),
        dtsize (edgedict), dtsize (polydict)
    );
}
예제 #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
파일: gv.cpp 프로젝트: Goettsch/game-editor
Agsym_t *nextattr(Agraph_t *g, Agsym_t *a)
{
    int i;

    if (!g || !a)
        return NULL;
    g = g->root;
    for (i = 0; i < dtsize(g->univ->globattr->dict); i++)
	if (a == g->univ->globattr->list[i])
	    break;
    i++;
    if (i > dtsize(g->univ->globattr->dict))
        return NULL;
    return g->univ->globattr->list[i];
}
예제 #4
0
파일: graphio.c 프로젝트: TidyHuang/vizgems
static void write_diffattr(FILE * fp, int indent, void *obj, void *par,
			   Agdict_t * dict)
{
    Agsym_t *a;
    int i;
    char *p, *q;
    int cnt = 0;

    for (i = 0; i < dtsize(dict->dict); i++) {
	a = dict->list[i];
	if (a->printed == FALSE)
	    continue;
	p = agxget(obj, a->index);
	if (par)
	    q = agxget(par, a->index);
	else
	    q = a->value;
	if (strcmp(p, q)) {
	    if (cnt++ == 0) {
		tabover(fp, indent);
	        agputs(dict->name, fp);
	        agputs(" [", fp);
	    } else {
	        agputs(",\n", fp);
		tabover(fp, indent + 1);
	    }
	    agputs(agcanonical(a->name), fp);
	    agputc('=', fp);
	    agputs(agcanonical(p), fp);
	}
    }
    if (cnt > 0)
	agputs("];\n", fp);
}
예제 #5
0
파일: gv.cpp 프로젝트: Goettsch/game-editor
Agsym_t *nextattr(Agedge_t *e, Agsym_t *a)
{
    Agraph_t *g;
    int i;

    if (!e || !a)
        return NULL;
    g = e->tail->graph;
    for (i = 0; i < dtsize(g->univ->edgeattr->dict); i++)
	if (a == g->univ->edgeattr->list[i])
	    break;
    i++;
    if (i > dtsize(g->univ->edgeattr->dict))
        return NULL;
    return g->univ->edgeattr->list[i];
}
예제 #6
0
파일: graphio.c 프로젝트: Chaduke/bah.mod
static void write_diffattr(FILE * fp, int indent, void *obj, void *par,
			   Agdict_t * dict)
{
    Agsym_t *a;
    int i;
    char *p, *q;
    int cnt = 0;

    for (i = 0; i < dtsize(dict->dict); i++) {
	a = dict->list[i];
	if (a->printed == FALSE)
	    continue;
	p = agxget(obj, a->index);
	if (par)
	    q = agxget(par, a->index);
	else
	    q = a->value;
	if (strcmp(p, q)) {
	    if (cnt++ == 0) {
		tabover(fp, indent);
		fprintf(fp, "%s [", dict->name);
	    } else {
		fprintf(fp, ",\n");
		tabover(fp, indent + 1);
	    }
	    fprintf(fp, "%s=", agcanonical(a->name));
	    fprintf(fp, "%s", agcanonical(p));
	}
    }
    if (cnt > 0)
	fprintf(fp, "];\n");
}
예제 #7
0
파일: dtclose.c 프로젝트: ellert/graphviz
/*	Close a dictionary
**
**	Written by Kiem-Phong Vo (05/25/96)
*/
int dtclose(reg Dt_t* dt)
{
	Dtdisc_t	*disc;
	int		ev = 0;

	if(!dt || dt->nview > 0 ) /* can't close if being viewed */
		return -1;

	/* announce the close event to see if we should continue */
	disc = dt->disc;
	if(disc->eventf &&
	   (ev = (*disc->eventf)(dt,DT_CLOSE,NIL(void*),disc)) < 0)
		return -1;

	if(dt->view)	/* turn off viewing */
		dtview(dt,NIL(Dt_t*));

	if(ev == 0) /* release all allocated data */
	{	(void)(*(dt->meth->searchf))(dt,NIL(void*),DT_CLEAR);
		if(dtsize(dt) > 0)
			return -1;

		if(dt->data->ntab > 0)
			(*dt->memoryf)(dt,(void*)dt->data->htab,0,disc);
		(*dt->memoryf)(dt,(void*)dt->data,0,disc);
	}
예제 #8
0
파일: graphio.c 프로젝트: TidyHuang/vizgems
void agwredge(Agraph_t * g, FILE * fp, Agedge_t * e, int list_all)
{
    char *myval, *defval, *tport, *hport;
    int i, nprint = 0;
    Agdict_t *d = e->tail->graph->univ->edgeattr;
    Agsym_t *a;

    if (e->attr) {
	tport = e->attr[TAILX];
	hport = e->attr[HEADX];
    }
    else tport = hport = "";
    writenodeandport(fp, e->tail->name, tport);
    agputs(((g->kind & AGFLAG_DIRECTED) ? " -> " : " -- "), fp);
    writenodeandport(fp, e->head->name, hport);
    if (list_all) {
	for (i = 0; i < dtsize(d->dict); i++) {
	    a = d->list[i];
	    if ((a->printed == FALSE)
		|| ((i == KEYX) && (e->printkey != MUSTPRINT)))
		continue;
	    myval = agget(e, a->name);
	    if (g == g->root)
		defval = a->value;
	    else
		defval = agget(g->proto->e, a->name);
	    if (strcmp(defval, myval))
		writeattr(fp, &nprint, a->name, myval);
	}
    }
    agputs(nprint > 0 ? "];\n" : ";\n", fp);
}
예제 #9
0
파일: gv.cpp 프로젝트: Goettsch/game-editor
Agsym_t *nextattr(Agnode_t *n, Agsym_t *a)
{
    Agraph_t *g;
    int i;

    if (!n || !a)
        return NULL;
    g = n->graph;
    for (i = 0; i < dtsize(g->univ->nodeattr->dict); i++)
	if (a == g->univ->nodeattr->list[i])
	    break;
    i++;
    if (i > dtsize(g->univ->nodeattr->dict))
        return NULL;
    return g->univ->nodeattr->list[i];
}
예제 #10
0
파일: tqueue.c 프로젝트: att/ast
tmain() {
    UNUSED(argc);
    UNUSED(argv);
    Dt_t *dt;

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

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

    if ((long)dtdelete(dt, NULL) != 1) terror("Dtqueue pop 1");
    if ((long)dtdelete(dt, NULL) != 3) terror("Dtqueue delete 3.1");
    if ((long)dtdelete(dt, NULL) != 2) terror("Dtqueue delete 2");
    if ((long)dtdelete(dt, NULL) != 3) terror("Dtqueue delete 3.2");
    if ((long)dtdelete(dt, NULL) != 2) terror("Dtqueue delete 2.1");
    if ((long)dtdelete(dt, NULL) != 3) terror("Dtqueue delete 3.3");

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

    texit(0);
}
예제 #11
0
파일: graph.c 프로젝트: ellert/graphviz
static int cnt(Dict_t * d, Dtlink_t ** set)
{
	int rv;
    dtrestore(d, *set);
    rv = dtsize(d);
    *set = dtextract(d);
	return rv;
}
예제 #12
0
파일: compound.c 프로젝트: emdenrg/graphviz
static void dump(Dt_t* map)
{
  clust_t* p;  
  fprintf (stderr, "# in map: %d\n", dtsize(map));
  for (p=(clust_t*)dtfirst(map);p; p = (clust_t*)dtnext(map,p)) {
    fprintf (stderr, "  %s\n", p->name);
 }
}
예제 #13
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);
}
예제 #14
0
파일: gv.cpp 프로젝트: Goettsch/game-editor
Agsym_t *firstattr(Agraph_t *g)
{
    if (!g)
	return NULL;
    g = g->root;
    if (dtsize(g->univ->globattr->dict) == 0)
	return NULL;
    return g->univ->globattr->list[0];
}
예제 #15
0
파일: gv.cpp 프로젝트: Goettsch/game-editor
Agsym_t *firstattr(Agedge_t *e)
{
    Agraph_t *g;

    if (!e)
	return NULL;
    g = e->tail->graph;
    if (dtsize(g->univ->edgeattr->dict) == 0)
	return NULL;
    return g->univ->edgeattr->list[0];
}
예제 #16
0
파일: gv.cpp 프로젝트: Goettsch/game-editor
Agsym_t *firstattr(Agnode_t *n)
{
    Agraph_t *g;

    if (!n)
	return NULL;
    g = n->graph;
    if (dtsize(g->univ->nodeattr->dict) == 0)
	return NULL;
    return g->univ->nodeattr->list[0];
}
예제 #17
0
tmain()
{
	Dt_t*	dt;
	Obj_t	*o, proto;
	long	i, k, count, n;

	for(i = 0; i < N_OBJ; i = k)
	{	for(k = i; k < i+R_OBJ && k < N_OBJ; ++k)
		{	Obj[k].key = i;
			Obj[k].ord = k;
		}
	}

	for(k = 0; k < 2; ++k)
	{	if(!(dt = dtopen(&Disc, k == 0 ? Dtrhbag : Dtobag)) )
			terror("Opening dictionary");
		dtcustomize(dt, DT_SHARE, 1); /* turn on sharing */

		for(i = 0; i < N_OBJ; ++i)
		{	if(dtinsert(dt, Obj+i) != Obj+i)
				terror("Insert %d,%d", Obj[i].key, Obj[i].ord);

			if(i > 0 && (i%N_CHK) == 0)
				if((count = dtsize(dt)) != i+1)
					terror("Bad size %d (need %d)", count, i+1);
		}

		count = n = 0; /* count the group of elements with key == 0 */
		for(o = (Obj_t*)dtflatten(dt); o; o = (Obj_t*)dtlink(dt,o), count += 1)
			if(o->key == 0)
				n += 1;
		if(count != N_OBJ || n != R_OBJ)
			terror("flatten %s: count=%d(need=%d) n=%d(need=%d)",
				k == 0 ? "bag" : "obag", count, N_OBJ, n, R_OBJ);

		/* delete a bunch of objects */
		for(n = 0, i = 0; i < N_OBJ; i += R_OBJ, n += 1)
			if(!dtdelete(dt, Obj+i))
				terror("delete %s: i=%d",
					k == 0 ? "bag" : "obag", i);

		count = 0; /* count the left over */
		for(o = (Obj_t*)dtflatten(dt); o; o = (Obj_t*)dtlink(dt,o))
			count += 1;
		if(count != N_OBJ-n)
			terror("%s wrong count %d",
				k == 0 ? "bag" : "obag", count);

		dtclose(dt);
	}

	texit(0);
}
예제 #18
0
main()
{
	Dt_t*		dt;

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

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

	if((long)dtdelete(dt,NIL(Void_t*)) != 1)
		terror("Dtqueue pop 1");
	if((long)dtdelete(dt,NIL(Void_t*)) != 3)
		terror("Dtqueue delete 3.1");
	if((long)dtdelete(dt,NIL(Void_t*)) != 2)
		terror("Dtqueue delete 2");
	if((long)dtdelete(dt,NIL(Void_t*)) != 3)
		terror("Dtqueue delete 3.2");
	if((long)dtdelete(dt,NIL(Void_t*)) != 2)
		terror("Dtqueue delete 2.1");
	if((long)dtdelete(dt,NIL(Void_t*)) != 3)
		terror("Dtqueue delete 3.3");

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

	return 0;
}
예제 #19
0
point *pointsOf(PointSet * ps)
{
    int n = dtsize(ps);
    point *pts = N_NEW(n, point);
    pair *p;
    point *pp = pts;

    for (p = (pair *) dtflatten(ps); p;
	 p = (pair *) dtlink(ps, (Dtlink_t *) p)) {
	*pp++ = p->id;
    }

    return pts;
}
예제 #20
0
int IMPLLflatten (void) {
    IMPLLnd_t *ndp;
    int ndi;
    IMPLLed_t *edp;
    int edi;

    IMPLLndn = dtsize (nddict);
    if (!(IMPLLnds = vmalloc (Vmheap, sizeof (IMPLLnd_t *) * IMPLLndn))) {
        SUwarning (0, "IMPLLflatten", "cannot allocate IMPLLnds array");
        return -1;
    }
    for (ndi = 0, ndp = dtfirst (nddict); ndp; ndp = dtnext (nddict, ndp))
        IMPLLnds[ndi++] = ndp;

    IMPLLedn = dtsize (eddict);
    if (!(IMPLLeds = vmalloc (Vmheap, sizeof (IMPLLed_t *) * IMPLLedn))) {
        SUwarning (0, "IMPLLflatten", "caenot allocate IMPLLeds array");
        return -1;
    }
    for (edi = 0, edp = dtfirst (eddict); edp; edp = dtnext (eddict, edp))
        IMPLLeds[edi++] = edp;

    return 0;
}
예제 #21
0
파일: attribs.c 프로젝트: Chaduke/bah.mod
Agsym_t *agNEWsym(Agdict_t * dict, char *name, char *value)
{
    Agsym_t *a;
    int i;

    a = NEW(Agsym_t);
    a->name = agstrdup(name);
    a->value = agstrdup(value);
    a->printed = TRUE;
    i = a->index = dtsize(dict->dict);
    dict->list = ALLOC(i + 2, dict->list, Agsym_t *);
    dict->list[i++] = a;
    dict->list[i++] = NULL;
    dtinsert(dict->dict, a);
    return a;
}
예제 #22
0
int main(int argc, char **argv)
{
    Agraph_t *g;
    Agnode_t *u, *v;
	int rv;

	g = agread(stdin,0);
	if (argc >= 3) {
		u = agnode(g,argv[1],FALSE);
		v = agnode(g,argv[2],FALSE);
		rv = agnodebefore(u,v);
		fprintf(stderr,"agnodebefore returns %d\n",rv);
		fprintf(stderr,"dtsize %d\n",dtsize(g->n_seq));
	}
	agwrite(g,stdout);
}
예제 #23
0
static void getDefAttrs(void *obj, int *n, char*** attr_name, char*** attr_defval)
{
    Agdict_t *dict = agdictof(obj);
    int i;

    if ( (*n = dtsize(dict->dict)) )
    {
       *attr_name = Calloc(*n, char*);
       *attr_defval = Calloc(*n, char*);

       for ( i = 0; i < *n; i++ )
       {
          (*attr_defval)[i] = dict->list[i]->value;
          (*attr_name)[i] = dict->list[i]->name;
       }
    }
예제 #24
0
파일: attribs.c 프로젝트: Chaduke/bah.mod
void agcopydict(Agdict_t * to_dict, Agdict_t * from_dict)
{
    int i, n;
    Agsym_t *a, *b;

    n = dtsize(from_dict->dict);
    for (i = 0; i < n; i++) {
	a = from_dict->list[i];
	b = agNEWsym(to_dict, a->name, a->value);
	b->printed = a->printed;
	b->fixed = a->fixed;
#ifdef WIN32
	/* Microsoft C is a thing of wonder. */
	fprintf(stderr, "", a->name, a->value);
#endif
    }
}
예제 #25
0
파일: graphio.c 프로젝트: Chaduke/bah.mod
static void write_dict(Agdict_t * dict, FILE * fp)
{
    int i, cnt = 0;
    Agsym_t *a;

    for (i = 0; i < dtsize(dict->dict); i++) {
	a = dict->list[i];
	if (ISEMPTYSTR(a->value) == FALSE) {
	    if (cnt++ == 0)
		fprintf(fp, "\t%s [", dict->name);
	    else
		fprintf(fp, ", ");
	    fprintf(fp, "%s=%s", a->name, agcanonical(a->value));
	}
    }
    if (cnt > 0)
	fprintf(fp, "];\n");
}
예제 #26
0
static int
validate_end(Cx_t* cx, Cxexpr_t* expr, void* data, Cxdisc_t* disc)
{
	register State_t*	state = (State_t*)expr->data;
	register Field_t*	field;
	Invalid_t*		ip;
	Cxoperand_t		val;
	int			heading;

	if (state->summary)
	{
		heading = 1;
		if (state->invalid && dtsize(state->invalid))
		{
			heading = 0;
			sfprintf(expr->op, "%16s  %11s  %s\n", "FIELD", "COUNT", "VALUE");
			for (ip = (Invalid_t*)dtfirst(state->invalid); ip; ip = (Invalid_t*)dtnext(state->invalid, ip))
			{
				val.type = ip->variable->type;
				val.value = ip->value;
				if (!cxcast(cx, &val, NiL, cx->state->type_string, NiL, NiL))
					sfprintf(expr->op, "%16s  %11I*u  %*.*s\n", ip->variable->name, sizeof(ip->count), ip->count, val.value.string.size, val.value.string.size, val.value.string.data);
			}
		}
		if (!heading)
		{
			heading = 1;
			sfprintf(expr->op, "\n");
		}
		for (field = state->field; field; field = field->next)
			if (field->invalid || field->discarded || field->repaired)
			{
				if (heading)
				{
					heading = 0;
					sfprintf(expr->op, "%16s  %11s %11s %11s\n", "FIELD", "INVALID", "DISCARDED", "REPAIRED");
				}
				sfprintf(expr->op, "%16s  %11I*u %11I*u %11I*u\n", field->variable->name, sizeof(field->invalid), field->invalid, sizeof(field->discarded), field->discarded, sizeof(field->repaired), field->repaired);
			}
	}
	vmclose(state->vm);
	return 0;
}
예제 #27
0
string_t *createstring (char *str) {
    string_t *smemp, *sp;
    char *s1, *s2;
    int i;

    for (s2 = &str[strlen (str) - 1]; s2 >= str && *s2 == ' '; s2--)
        ;
    for (s1 = &str[0]; s1 <= s2 && *s1 == ' '; s1++)
        ;
    smemp = sp = NULL;
    if (
        !(smemp = vmalloc (svm, sizeof (string_t))) ||
        !(smemp->str = vmalloc (svm, (s2 - s1 + 2) * sizeof (char)))
    )
        goto abortcreatestring;
    for (i = 0; s1 <= s2; s1++, i++)
        smemp->str[i] = *s1;
    smemp->str[i] = 0;
    smemp->id = dtsize (stringdict);
    smemp->refcount = 1;
    if (!(sp = dtinsert (stringdict, smemp)))
        goto abortcreatestring;
    if (sp != smemp) {
        vmfree (svm, smemp->str);
        vmfree (svm, smemp);
        sp->refcount++;
        return sp;
    }
    return sp;

abortcreatestring:
    SUwarning (1, "createstring", "create failed for string %s", str);
    if (sp)
        if (sp == smemp)
            dtdelete (stringdict, sp);
    if (smemp) {
        if (smemp->str)
            vmfree (svm, smemp->str);
        vmfree (svm, smemp);
    }
    return NULL;
}
예제 #28
0
파일: ortho.c 프로젝트: TidyHuang/vizgems
static void
dumpChanG (channel* cp, int v)
{
  int k;
  intitem* ip;
  Dt_t* adj;

  if (cp->cnt < 2) return;
  fprintf (stderr, "channel %d (%f,%f)\n", v, cp->p.p1, cp->p.p2);
  for (k=0;k<cp->cnt;k++) {
    adj = cp->G->vertices[k].adj_list;
    if (dtsize(adj) == 0) continue;
    putSeg (stderr, cp->seg_list[k]);
    fputs (" ->\n", stderr);
    for (ip = (intitem*)dtfirst(adj); ip; ip = (intitem*)dtnext(adj, ip)) {
      fputs ("     ", stderr);
      putSeg (stderr, cp->seg_list[ip->id]);
      fputs ("\n", stderr);
    }
  }
}
예제 #29
0
파일: graphio.c 프로젝트: TidyHuang/vizgems
void agwrnode(Agraph_t * g, FILE * fp, Agnode_t * n, int full, int indent)
{
    char *myval, *defval;
    int i, didwrite = FALSE;
    int nprint = 0;
    Agdict_t *d = n->graph->univ->nodeattr;
    Agsym_t *a;

    if (full) {
	for (i = 0; i < dtsize(d->dict); i++) {
	    a = d->list[i];
	    if (a->printed == FALSE)
		continue;
	    myval = agget(n, a->name);
	    if (g == n->graph)
		defval = a->value;
	    else
		defval = agget(g->proto->n, a->name);
	    if (strcmp(defval, myval)) {
		if (didwrite == FALSE) {
		    tabover(fp, indent);
		    agputs(agcanonical(n->name), fp);
		    didwrite = TRUE;
		}
		writeattr(fp, &nprint, a->name, myval);
	    }
	}
	if (didwrite) {
	    agputs(nprint > 0 ? "];\n" : ";\n", fp);
	    return;
	}
    }
    if ((agfstout(g, n) == NULL) && (agfstin(g, n) == NULL)) {
	tabover(fp, indent);
	agputs(agcanonical(n->name), fp);
	agputs(";\n", fp);
    }
}
예제 #30
0
파일: graphio.c 프로젝트: TidyHuang/vizgems
static void write_dict(Agdict_t * dict, FILE * fp)
{
    int i, cnt = 0;
    Agsym_t *a;

    for (i = 0; i < dtsize(dict->dict); i++) {
	a = dict->list[i];
	if (ISEMPTYSTR(a->value) == FALSE) {
	    if (cnt++ == 0) {
		agputc('\t', fp);
		agputs(dict->name, fp);
		agputs(" [", fp);
	    }
	    else {
		agputs(", ", fp);
            }
	    agputs(a->name, fp);
	    agputc('=', fp);
	    agputs(agcanonical(a->value), fp);
	}
    }
    if (cnt > 0)
	agputs("];\n", fp);
}