File: node.c

package info (click to toggle)
graphviz 2.26.3-5%2Bsqueeze3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze-lts
  • size: 63,044 kB
  • ctags: 25,930
  • sloc: ansic: 212,134; sh: 20,316; cpp: 7,239; makefile: 4,211; yacc: 3,335; xml: 2,450; tcl: 1,900; cs: 1,890; objc: 1,149; perl: 829; lex: 364; awk: 171; python: 41; ruby: 35; php: 26
file content (153 lines) | stat: -rw-r--r-- 3,678 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/* $Id: node.c,v 1.5 2009/06/03 01:10:53 ellson Exp $ $Revision: 1.5 $ */
/* vim:set shiftwidth=4 ts=8: */

/**********************************************************
*      This software is part of the graphviz package      *
*                http://www.graphviz.org/                 *
*                                                         *
*            Copyright (c) 1994-2004 AT&T Corp.           *
*                and is licensed under the                *
*            Common Public License, Version 1.0           *
*                      by AT&T Corp.                      *
*                                                         *
*        Information and Software Systems Research        *
*              AT&T Research, Florham Park NJ             *
**********************************************************/

#include <limits.h>

#include "libgraph.h"

#ifdef DMALLOC
#include "dmalloc.h"
#endif

Agnode_t *agfindnode(Agraph_t * g, char *name)
{
    Agnode_t *rv;

    rv = (Agnode_t *) dtmatch(g->univ->node_dict, name);
    if (rv && (g != g->root))
	rv = (Agnode_t *) dtsearch(g->nodes, rv);
    return rv;
}

Agnode_t *agidnode(Agraph_t * g, int index)
{
    Agnode_t *rv;
    rv = (Agnode_t *) dtmatch(g->nodes, &index);
    return rv;
}

Agnode_t *agnode(Agraph_t * g, char *name)
{
    Agnode_t *n;
    if ((n = agfindnode(g->root, name)) == NULL) {
	n = agNEWnode(g, name, g->proto->n);
	dtinsert(g->univ->node_dict, n);
    }
    agINSnode(g, n);
    return n;
}

void agINSnode(Agraph_t * g, Agnode_t * n)
{
    Agraph_t *meta;
    Agedge_t *e;

    if (agidnode(g, n->id))
	return;
    dtinsert(g->nodes, n);
    if (AG_IS_METAGRAPH(g) == FALSE) {
	meta = g->meta_node->graph;
	for (e = agfstin(meta, g->meta_node); e; e = agnxtin(meta, e))
	    agINSnode(agusergraph(e->tail), n);
    }
}

void agDELnode(Agraph_t * g, Agnode_t * n)
{
    Agedge_t *e, *f;
    Agraph_t *meta, *h;

    for (e = agfstedge(g, n); e; e = f) {
	f = agnxtedge(g, e, n);
	agDELedge(g, e);
    }

    if (AG_IS_METAGRAPH(g) == FALSE) {
	meta = g->meta_node->graph;
	for (e = agfstout(meta, g->meta_node); e; e = agnxtout(meta, e)) {
	    h = agusergraph(e->head);
	    if (dtsearch(h->nodes, n))
		agDELnode(h, n);
	}
    }
    dtdelete(g->nodes, n);
    if (g == g->root)
	agFREEnode(n);
}

Agnode_t *agfstnode(Agraph_t * g)
{
    return (Agnode_t *) dtfirst(g->nodes);
}

Agnode_t *agnxtnode(Agraph_t * g, Agnode_t * n)
{
    return (Agnode_t *) dtnext(g->nodes, n);
}

Agnode_t *aglstnode(Agraph_t * g)
{
    return (Agnode_t *) dtlast(g->nodes);
}

Agnode_t *agprvnode(Agraph_t * g, Agnode_t * n)
{
    return (Agnode_t *) dtprev(g->nodes, n);
}

Agnode_t *agNEWnode(Agraph_t * subg, char *name, Agnode_t * proto)
{
    int i, nobj;
    Agnode_t *n;

    n = (Agnode_t *) calloc(1, AG.node_nbytes);
    n->tag = TAG_NODE;
    n->name = agstrdup(name);
    n->id = subg->univ->max_node_id++;
    n->graph = subg->root;
    nobj = dtsize(subg->univ->nodeattr->dict);
    if (nobj) {
		n->attr = N_NEW(nobj, char *);
		n->didset = N_NEW((nobj + CHAR_BIT - 1) / CHAR_BIT, char);
	}
    else {
		n->attr = NULL;
		n->didset = NULL;
	}
    for (i = 0; i < nobj; i++)
		n->attr[i] = agstrdup(proto ? proto->attr[i] :
			subg->univ->nodeattr->list[i]->value);
    return n;
}

void agFREEnode(Agnode_t * n)
{
    int i, nobj;
    Agdict_t *dict = agdictof(n);

    dict = dict;
    dtdelete(n->graph->univ->node_dict, n);
    TAG_OF(n) = -1;
    agstrfree(n->name);
    if (AG_IS_METAGRAPH(n->graph) == FALSE) {
	nobj = dtsize(n->graph->univ->nodeattr->dict);
	for (i = 0; i < nobj; i++)
	    agstrfree(n->attr[i]);
    }
    free(n->attr);
	free(n->didset);
    free(n);
}