comparison toolboxes/graph_visualisation/share/man/man1/gvpr.1 @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 .de TQ
2 . br
3 . ns
4 . TP \\$1
5 ..
6 .TH GVPR 1 "24 April 2008"
7 .SH NAME
8 gvpr \- graph pattern scanning and processing language
9 .br
10 ( previously known as
11 .B gpr
12 )
13 .SH SYNOPSIS
14 .B gvpr
15 [\fB\-icqV?\fP]
16 [
17 .BI \-o
18 .I outfile
19 ]
20 [
21 .BI \-a
22 .I args
23 ]
24 [
25 .I 'prog'
26 |
27 .BI \-f
28 .I progfile
29 ]
30 [
31 .I files
32 ]
33 .SH DESCRIPTION
34 .B gvpr
35 is a graph stream editor inspired by \fBawk\fP.
36 It copies input graphs to its
37 output, possibly transforming their structure and attributes,
38 creating new graphs, or printing arbitrary information.
39 The graph model is that provided by
40 .IR libcgraph (3).
41 In particular, \fBgvpr\fP reads and writes graphs using the
42 dot language.
43 .PP
44 Basically,
45 .B gvpr
46 traverses each input graph, denoted by \fB$G\fP, visiting each node and edge,
47 matching it with the predicate\(hyaction rules supplied in the input program.
48 The rules are evaluated in order.
49 For each predicate evaluating to true, the corresponding
50 action is performed.
51 During the traversal, the current node or edge being visited
52 is denoted by \fB$\fP.
53 .PP
54 For each input graph, there is a target subgraph, denoted by
55 \fB$T\fP, initially empty and used to accumulate
56 chosen entities, and an output graph, \fB$O\fP, used for final processing
57 and then written to output.
58 By default, the output graph is the target graph.
59 The output graph can be set in the program or, in a limited sense,
60 on the command line.
61 .SH OPTIONS
62 The following options are supported:
63 .TP
64 .BI \-a " args"
65 The string \fIargs\fP is split into whitespace\(hyseparated tokens,
66 with the individual tokens
67 available as strings in the \fBgvpr\fP program
68 as \fBARGV[\fI0\fP],...,ARGV[ARGC\-1]\fR.
69 Whitespace characters within single or double quoted substrings, or
70 preceded by a backslash, are ignored as separators.
71 In general, a backslash character turns off any special meaning of the
72 following character.
73 Note that the tokens derived from multiple \fB\-a\fP flags are concatenated.
74 .TP
75 .B \-c
76 Use the source graph as the output graph.
77 .TP
78 .B \-i
79 Derive the node\(hyinduced subgraph extension of the output graph in the context
80 of its root graph.
81 .TP
82 .BI \-o " outfile"
83 Causes the output stream to be written to the specified file; by default,
84 output is written to \fBstdout\fP.
85 .TP
86 .BI \-f " progfile"
87 Use the contents of the specified file as the program to execute
88 on the input. If \fIprogfile\fP contains a slash character, the name is taken
89 as the pathname of the file. Otherwise, \fBgvpr\fP will use the
90 directories specified in the environment variable \fBGPRPATH\fP to look
91 for the file. If
92 .B \-f
93 is not given,
94 .B gvpr
95 will use the first non\(hyoption argument as the program.
96 .TP
97 .B \-q
98 Turns off warning messages.
99 .TP
100 .B \-V
101 Causes the program to print version information and exit.
102 .TP
103 .B \-?
104 Causes the program to print usage information and exit.
105 .SH OPERANDS
106 The following operand is supported:
107 .TP 8
108 .I files
109 Names of files containing 1 or more graphs in the dot language.
110 If no
111 .B \-f
112 option is given, the first name is removed from the list and used
113 as the input program. If the list of files is empty, \fBstdin\fP will be used.
114 .SH PROGRAMS
115 A
116 .B gvpr
117 program consists of a list of predicate\(hyaction clauses, having one
118 of the forms:
119 .IP
120 .BI "BEGIN { " action " }"
121 .IP
122 .BI "BEG_G { " action " }"
123 .IP
124 .BI "N [ " predicate " ] { " action " }
125 .IP
126 .BI "E [ " predicate " ] { " action " }
127 .IP
128 .BI "END_G { " action " }"
129 .IP
130 .BI "END { " action " }"
131 .PP
132 A program can contain at most one of each of the \fBBEGIN\fP, \fBBEG_G\fP,
133 \fBEND_G\fP and \fBEND\fP clauses.
134 There can be any number of \fBN\fP and \fBE\fP statements,
135 the first applied to nodes, the second to edges.
136 The top\(hylevel semantics of a \fBgvpr\fP program are:
137 .PP
138 .ta \w'\f(CWdelete array[expression]'u
139 .RS
140 .nf
141 Evaluate the \fBBEGIN\fP clause, if any.
142 For each input graph \fIG\fP {
143 Set \fIG\fP as the current graph and current object.
144 Evaluate the \fBBEG_G\fP clause, if any.
145 For each node and edge in \fIG\fP {
146 Set the node or edge as the current object.
147 Evaluate the \fBN\fP or \fBE\fP clauses, as appropriate.
148 }
149 Set \fIG\fP as the current object.
150 Evaluate the \fBEND_G\fP clause, if any.
151 }
152 Evaluate the \fBEND\fP clause, if any.
153 .fi
154 .RE
155 .DT
156 .PP
157 The actions of the \fBBEGIN\fP, \fBBEG_G\fP, \fBEND_G\fP and \fBEND\fP clauses
158 are performed when the clauses are evaluated.
159 For \fBN\fP or \fBE\fP clauses,
160 either the predicate or action may be omitted.
161 If there is no predicate with an action, the action is
162 performed on every node or edge, as appropriate.
163 If there is no action and the predicate evaluates to true,
164 the associated node or edge is added to the target graph.
165 .PP
166 Predicates and actions are sequences of statements in the C dialect
167 supported by the
168 .IR libexpr (3)
169 library.
170 The only difference between predicates and actions is that the former
171 must have a type that may interpreted as either true or false.
172 Here the usual C convention is followed, in which a non\(hyzero value is
173 considered true. This would include non\(hyempty strings and non\(hyempty
174 references to nodes, edges, etc. However, if a string can be
175 converted to an integer, this value is used.
176 .PP
177 In addition to the usual C base types
178 (\fBvoid\fP, \fBint\fP, \fBchar\fP, \fBfloat\fP, \fBlong\fP,
179 \fBunsigned\fP and \fBdouble\fP),
180 \fBgvpr\fP \fRprovides \fBstring\fP as a synonym for \fBchar*\fP, and
181 the graph\(hybased types \fBnode_t\fP,
182 \fBedge_t\fP, \fBgraph_t\fP and \fBobj_t\fP.
183 The \fBobj_t\fP type can be viewed as a supertype of the other 3 concrete types;
184 the correct base type is maintained dynamically.
185 Besides these base types, the only other supported type expressions
186 are (associative) arrays.
187 .PP
188 Constants follow C syntax, but strings may be quoted with either
189 \fB"..."\fP or \fB'...'\fP. In certain contexts, string values are
190 interpreted as patterns for the purpose of regular expression matching.
191 Patterns use
192 .IR ksh (1)
193 file match pattern syntax.
194 \fBgvpr\fP accepts C++ comments as well as cpp\(hytype comments.
195 For the latter, if a line begins with a '#' character, the rest of
196 the line is ignored.
197 .PP
198 A statement can be a declaration of a function, a variable
199 or an array, or an executable statement. For declarations, there
200 is a single scope. Array declarations have the form:
201 .PP
202 .ta \w'\f(CWdelete array[expression]'u
203 .RS
204 .nf
205 \fI type array \fB[\fP type0 \fB]\fR
206 .fi
207 .RE
208 .DT
209 .PP
210 where \fI type0 \fP is optional. If it is supplied, the parser will
211 enforce that all array subscripts have the specified type. If it is
212 not supplied, objects of all types can be used as subscripts.
213 As in C, variables and arrays must
214 be declared. In particular, an undeclared variable will be interpreted
215 as the name of an attribute of a node, edge or graph, depending on the
216 context.
217 .PP
218 Executable statements can be one of the following:
219 .ta \w'\f(CWdelete array[expression]'u
220 .RS
221 .nf
222 \fB{\fR [\fI statement ... \fR] \fB}\fR
223 \fIexpression\fP \fR// commonly\fP\fI var \fB=\fP expression\fR
224 \fBif(\fI expression \fP)\fI statement \fR[ \fBelse\fI statement \fR]
225 \fBfor(\fI expression \fP;\fI expression \fP;\fI expression \fP)\fI statement\fP
226 \fBfor(\fI array \fP[\fI var \fP])\fI statement\fP
227 \fBwhile(\fI expression \fP)\fI statement\fP
228 \fBswitch(\fI expression \fP)\fI case statements\fP
229 \fBbreak [\fI expression \fP]
230 \fBcontinue [\fI expression \fP]
231 \fBreturn [\fI expression \fP]\fR
232 .fi
233 .RE
234 .ST
235 Items in brackets are optional.
236 .PP
237 In the second form of the \fBfor\fP statement, the variable \fIvar\fP
238 is set to each value used as an index in the specified array and then
239 the associated \fIstatement\fP is evaluated. Function definitions can
240 only appear in the \fBBEGIN\fP clause.
241 .PP
242 Expressions include the usual C expressions.
243 String comparisons using \fB==\fP and \fB!=\fP
244 treat the right hand operand as a pattern.
245 \fBgvpr\fP will attempt to use an expression as a string or numeric value
246 as appropriate.
247 .PP
248 Expressions of graphical type (i.e., \fBgraph_t, node_t,
249 edge_t, obj_t\fP) may be followed by a field reference in the
250 form of \fB.\fP\fIname\fP. The resulting value is the value
251 of the attribute named \fIname\fP of the given object.
252 In addition, in certain contexts an undeclared, unmodified
253 identifier is taken to be an
254 attribute name. Specifically, such identifiers denote attributes
255 of the current node or edge, respectively, in \fBN\fP
256 and \fBE\fP clauses, and the current graph in \fBBEG_G\fP and \fBEND_G\fP
257 clauses.
258 .PP
259 As usual in the
260 .IR libcgraph (3)
261 model, attributes are string\(hyvalued.
262 In addition,
263 .B gvpr
264 supports certain pseudo\(hyattributes of graph objects, not necessarily
265 string\(hyvalued. These reflect intrinsic properties of the graph objects
266 and cannot be set by the user.
267 .TP
268 \fBhead\fR : \fBnode_t\fR
269 the head of an edge.
270 .TP
271 \fBtail\fR : \fBnode_t\fR
272 the tail of an edge.
273 .TP
274 \fBname\fR : \fBstring\fR
275 the name of an edge, node or graph. The name of an edge has the
276 form "\fI<tail\(hyname><edge\(hyop><head\(hyname>\fB[\fI<key>\fB]\fR",
277 where \fI<edge\(hyop>\fP is "\fB\->\fP" or "\fB\-\-\fP" depending on
278 whether the graph is directed or not. The bracket part \fB[\fI<key>\fB]\fR
279 only appears if the edge has a non\(hytrivial key.
280 .TP
281 \fBindegree\fR : \fBint\fR
282 the indegree of a node.
283 .TP
284 \fBoutdegree\fR : \fBint\fR
285 the outdegree of a node.
286 .TP
287 \fBdegree\fR : \fBint\fR
288 the degree of a node.
289 .TP
290 \fBroot\fR : \fBgraph_t\fR
291 the root graph of an object. The root of a root graph
292 is itself.
293 .TP
294 \fBparent\fR : \fBgraph_t\fR
295 the parent graph of a subgraph. The parent of a root graph
296 is \fBNULL\fP
297 .TP
298 \fBn_edges\fR : \fBint\fR
299 the number of edges in the graph
300 .TP
301 \fBn_nodes\fR : \fBint\fR
302 the number of nodes in the graph
303 .TP
304 \fBdirected\fR : \fBint\fR
305 true (non\(hyzero) if the graph is directed
306 .TP
307 \fBstrict\fR : \fBint\fR
308 true (non\(hyzero) if the graph is strict
309 .SH "BUILT\(hyIN FUNCTIONS"
310 .PP
311 The following functions are built into \fBgvpr\fP. Those functions
312 returning references to graph objects return \fBNULL\fP in case of failure.
313 .SS "Graphs and subgraph"
314 .TP
315 \fBgraph\fP(\fIs\fP : \fBstring\fP, \fIt\fP : \fBstring\fP) : \fBgraph_t\fP
316 creates a graph whose name is \fIs\fP and whose type is
317 specified by the string \fIt\fP. Ignoring case, the characters
318 \fBU, D, S, N\fR have the interpretation undirected, directed,
319 strict, and non\(hystrict, respectively. If \fIt\fP is empty,
320 a directed, non\(hystrict graph is generated.
321 .TP
322 \fBsubg\fP(\fIg\fP : \fBgraph_t\fP, \fIs\fP : \fBstring\fP) : \fBgraph_t\fP
323 creates a subgraph in graph \fIg\fP with name \fIs\fP. If the subgraph
324 already exists, it is returned.
325 .TP
326 \fBisSubg\fP(\fIg\fP : \fBgraph_t\fP, \fIs\fP : \fBstring\fP) : \fBgraph_t\fP
327 returns the subgraph in graph \fIg\fP with name \fIs\fP, if it exists,
328 or \fBNULL\fP otherwise.
329 .TP
330 \fBfstsubg\fP(\fIg\fP : \fBgraph_t\fP) : \fBgraph_t\fP
331 returns the first subgraph in graph \fIg\fP, or \fBNULL\fP if none exists.
332 .TP
333 \fBnxtsubg\fP(\fIsg\fP : \fBgraph_t\fP) : \fBgraph_t\fP
334 returns the next subgraph after \fIsg\fP, or \fBNULL\fP.
335 .TP
336 \fBisDirect\fP(\fIg\fP : \fBgraph_t\fP) : \fBint\fP
337 returns true if and only if \fIg\fP is directed.
338 .TP
339 \fBisStrict\fP(\fIg\fP : \fBgraph_t\fP) : \fBint\fP
340 returns true if and only if \fIg\fP is strict.
341 .TP
342 \fBnNodes\fP(\fIg\fP : \fBgraph_t\fP) : \fBint\fP
343 returns the number of nodes in \fIg\fP.
344 .TP
345 \fBnEdges\fP(\fIg\fP : \fBgraph_t\fP) : \fBint\fP
346 returns the number of edges in \fIg\fP.
347 .SS "Nodes"
348 .TP
349 \fBnode\fP(\fIsg\fP : \fBgraph_t\fP, \fIs\fP : \fBstring\fP) : \fBnode_t\fP
350 creates a node in graph \fIg\fP of name \fIs\fP. If such a node
351 already exists, it is returned.
352 .TP
353 \fBsubnode\fP(\fIsg\fP : \fBgraph_t\fP, \fIn\fP : \fBnode_t\fP) : \fBnode_t\fP
354 inserts the node \fIn\fP into the subgraph \fIg\fP. Returns the node.
355 .TP
356 \fBfstnode\fP(\fIg\fP : \fBgraph_t\fP) : \fBnode_t\fP
357 returns the first node in graph \fIg\fP, or \fBNULL\fP if none exists.
358 .TP
359 \fBnxtnode\fP(\fIn\fP : \fBnode_t\fP) : \fBnode_t\fP
360 returns the next node after \fIn\fP in the root graph, or \fBNULL\fP.
361 .TP
362 \fBnxtnode_sg\fP(\fIsg\fP : \fBgraph_t\fP, \fIn\fP : \fBnode_t\fP) : \fBnode_t\fP
363 returns the next node after \fIn\fP in \fIsg\fP, or \fBNULL\fP.
364 .TP
365 \fBisNode\fP(\fIsg\fP : \fBgraph_t\fP, \fIs\fP : \fBstring\fP) : \fBnode_t\fP
366 looks for a node in (sub)graph \fIsg\fP of name \fIs\fP. If such a node
367 exists, it is returned. Otherwise, \fBNULL\fP is returned.
368 .TP
369 \fBisSubnode\fP(\fIsg\fP : \fBgraph_t\fP, \fIn\fP : \fBnode_t\fP) : \fBint\fP
370 returns non-zero if node \fIn\fP is in (sub)graph \fIsg\fP, or zero
371 otherwise.
372 .TP
373 \fBindegreeOf\fP(\fIsg\fP : \fBgraph_t\fP, \fIn\fP : \fBnode_t\fP) : \fBint\fP
374 returns the indegree of node \fIn\fP in (sub)graph \fIsg\fP.
375 .TP
376 \fBoutdegreeOf\fP(\fIsg\fP : \fBgraph_t\fP, \fIn\fP : \fBnode_t\fP) : \fBint\fP
377 returns the outdegree of node \fIn\fP in (sub)graph \fIsg\fP.
378 .TP
379 \fBdegreeOf\fP(\fIsg\fP : \fBgraph_t\fP, \fIn\fP : \fBnode_t\fP) : \fBint\fP
380 returns the degree of node \fIn\fP in (sub)graph \fIsg\fP.
381 .SS "Edges"
382 .TP
383 \fBedge\fP(\fIt\fP : \fBnode_t\fP, \fIh\fP : \fBnode_t\fP, \fIs\fP : \fBstring\fP) : \fBedge_t\fP
384 creates an edge with tail node \fIt\fP, head node \fIh\fP and
385 name \fIs\fP in the root graph. If the graph is undirected, the
386 distinction between head and tail nodes is unimportant.
387 If such an edge already exists, it is returned.
388 .TP
389 \fBedge_sg\fP(\fIsg\fP : \fBgraph_t\fP, \fIt\fP : \fBnode_t\fP, \fIh\fP : \fBnode_t\fP, \fIs\fP : \fBstring\fP) : \fBedge_t\fP
390 creates an edge with tail node \fIt\fP, head node \fIh\fP and name \fIs\fP
391 in (sub)graph \fIsg\fP (and all parent graphs). If the graph is undirected, the distinction between
392 head and tail nodes is unimportant.
393 If such an edge already exists, it is returned.
394 .TP
395 \fBsubedge\fP(\fIg\fP : \fBgraph_t\fP, \fIe\fP : \fBedge_t\fP) : \fBedge_t\fP
396 inserts the edge \fIe\fP into the subgraph \fIg\fP. Returns the edge.
397 .TP
398 \fBisEdge\fP(\fIt\fP : \fBnode_t\fP, \fIh\fP : \fBnode_t\fP, \fIs\fP : \fBstring\fP) : \fBedge_t\fP
399 looks for an edge with tail node \fIt\fP, head node \fIh\fP and
400 name \fIs\fP. If the graph is undirected, the distinction between
401 head and tail nodes is unimportant.
402 If such an edge exists, it is returned. Otherwise, \fBNULL\fP is returned.
403 .TP
404 \fBisEdge_sg\fP(\fIsg\fP : \fBgraph_t\fP, \fIt\fP : \fBnode_t\fP, \fIh\fP : \fBnode_t\fP, \fIs\fP : \fBstring\fP) : \fBedge_t\fP
405 looks for an edge with tail node \fIt\fP, head node \fIh\fP and
406 name \fIs\fP in (sub)graph \fIsg\fP. If the graph is undirected, the distinction between
407 head and tail nodes is unimportant.
408 If such an edge exists, it is returned. Otherwise, \fBNULL\fP is returned.
409 .TP
410 \fBisSubedge\fP(\fIg\fP : \fBgraph_t\fP, \fIe\fP : \fBedge_t\fP) : \fBint\fP
411 returns non-zero if edge \fIe\fP is in (sub)graph \fIsg\fP, or zero
412 otherwise.
413 .TP
414 \fBfstout\fP(\fIn\fP : \fBnode_t\fP) : \fBedge_t\fP
415 returns the first outedge of node \fIn\fP in the root graph.
416 .TP
417 \fBfstout_sg\fP(\fIsg\fP : \fBgraph_t\fP, \fIn\fP : \fBnode_t\fP) : \fBedge_t\fP
418 returns the first outedge of node \fIn\fP in (sub)graph \fIsg\fP.
419 .TP
420 \fBnxtout\fP(\fIe\fP : \fBedge_t\fP) : \fBedge_t\fP
421 returns the next outedge after \fIe\fP in the root graph.
422 .TP
423 \fBnxtout_sg\fP(\fIsg\fP : \fBgraph_t\fP, \fIe\fP : \fBedge_t\fP) : \fBedge_t\fP
424 returns the next outedge after \fIe\fP in graph \fIsg\fP.
425 .TP
426 \fBfstin\fP(\fIn\fP : \fBnode_t\fP) : \fBedge_t\fP
427 returns the first inedge of node \fIn\fP in the root graph.
428 .TP
429 \fBfstin_sg\fP(\fIsg\fP : \fBgraph_t\fP, \fIn\fP : \fBnode_t\fP) : \fBedge_t\fP
430 returns the first inedge of node \fIn\fP in graph \fIsg\fP.
431 .TP
432 \fBnxtin\fP(\fIe\fP : \fBedge_t\fP) : \fBedge_t\fP
433 returns the next inedge after \fIe\fP in the root graph.
434 .TP
435 \fBnxtin_sg\fP(\fIsg\fP : \fBgraph_t\fP, \fIe\fP : \fBedge_t\fP) : \fBedge_t\fP
436 returns the next inedge after \fIe\fP in graph \fIsg\fP.
437 .TP
438 \fBfstedge\fP(\fIn\fP : \fBnode_t\fP) : \fBedge_t\fP
439 returns the first edge of node \fIn\fP in the root graph.
440 .TP
441 \fBfstedge_sg\fP(\fIsg\fP : \fBgraph_t\fP, \fIn\fP : \fBnode_t\fP) : \fBedge_t\fP
442 returns the first edge of node \fIn\fP in graph \fIsg\fP.
443 .TP
444 \fBnxtedge\fP(\fIe\fP : \fBedge_t\fP, \fBnode_t\fP) : \fBedge_t\fP
445 returns the next edge after \fIe\fP in the root graph.
446 .TP
447 \fBnxtedge_sg\fP(\fIsg\fP : \fBgraph_t\fP, \fIe\fP : \fBedge_t\fP, \fBnode_t\fP) : \fBedge_t\fP
448 returns the next edge after \fIe\fP in the graph \fIsg\fP.
449 .SS "Graph I/O"
450 .TP
451 \fBwrite\fP(\fIg\fP : \fBgraph_t\fP) : \fBvoid\fP
452 prints \fIg\fP in dot format onto the output stream.
453 .TP
454 \fBwriteG\fP(\fIg\fP : \fBgraph_t\fP, \fIfname\fP : \fBstring\fP) : \fBvoid\fP
455 prints \fIg\fP in dot format into the file \fIfname\fP.
456 .TP
457 \fBfwriteG\fP(\fIg\fP : \fBgraph_t\fP, \fIfd\fP : \fBint\fP) : \fBvoid\fP
458 prints \fIg\fP in dot format onto the open stream denoted
459 by the integer \fIfd\fP.
460 .TP
461 \fBreadG\fP(\fIfname\fP : \fBstring\fP) : \fBgraph_t\fP
462 returns a graph read from the file \fIfname\fP. The graph should be
463 in dot format. If no graph can be read, \fBNULL\fP is returned.
464 .TP
465 \fBfreadG\fP(\fIfd\fP : \fBint\fP) : \fBgraph_t\fP
466 returns the next graph read from the open stream \fIfd\fP.
467 Returns \fBNULL\fP at end of file.
468 .SS "Graph miscellany"
469 .TP
470 \fBdelete\fP(\fIg\fP : \fBgraph_t\fP, \fIx\fP : \fBobj_t\fP) : \fBvoid\fP
471 deletes object \fIx\fP from graph \fIg\fP.
472 If \fIg\fP is \fBNULL\fP, the function uses the root graph of \fIx\fP.
473 If \fIx\fP is a graph or subgraph, it is closed unless \fIx\fP is locked.
474 .TP
475 \fBisIn\fP(\fIg\fP : \fBgraph_t\fP, \fIx\fP : \fBobj_t\fP) : \fBint\fP
476 returns true if \fIx\fP is in subgraph \fIg\fP.
477 .TP
478 \fBclone\fP(\fIg\fP : \fBgraph_t\fP, \fIx\fP : \fBobj_t\fP) : \fBobj_t\fP
479 creates a clone of object \fIx\fP in graph \fIg\fP.
480 In particular, the new object has the same name/value attributes
481 and structure as the original object.
482 If an object with the same key as \fIx\fP already exists, its attributes
483 are overlaid by those of \fIx\fP and the object is returned.
484 If an edge is cloned, both endpoints are implicitly cloned.
485 If a graph is cloned, all nodes, edges and subgraphs are implicitly
486 cloned.
487 If \fIx\fP is a graph, \fIg\fP may be \fBNULL\fP, in which case the cloned
488 object will be a new root graph.
489 .TP
490 \fBcopy\fP(\fIg\fP : \fBgraph_t\fP, \fIx\fP : \fBobj_t\fP) : \fBobj_t\fP
491 creates a copy of object \fIx\fP in graph \fIg\fP,
492 where the new object has the same name/value attributes
493 as the original object.
494 If an object with the same key as \fIx\fP already exists, its attributes
495 are overlaid by those of \fIx\fP and the object is returned.
496 Note that this is a shallow copy. If \fIx\fP is a graph, none of its nodes,
497 edges or subgraphs are copied into the new graph. If \fIx\fP is an edge,
498 the endpoints are created if necessary, but they are not cloned.
499 If \fIx\fP is a graph, \fIg\fP may be \fBNULL\fP, in which case the cloned
500 object will be a new root graph.
501 .TP
502 \fBcopyA\fP(\fIsrc\fP : \fBobj_t\fP, \fItgt\fP : \fBobj_t\fP) : \fBint\fP
503 copies the attributes of object \fIsrc\fP to object \fItgt\fP, overwriting
504 any attribute values \fItgt\fP may initially have.
505 .TP
506 \fBinduce\fP(\fIg\fP : \fBgraph_t\fP) : \fBvoid\fP
507 extends \fIg\fP to its node\(hyinduced subgraph extension in its root graph.
508 .TP
509 \fBhasAttr\fP(\fIsrc\fP : \fBobj_t\fP, \fIname\fP : \fBstring\fP) : \fBint\fP
510 returns non-zero if object \fIsrc\fP has an attribute whose name is
511 \fIname\fP. It returns 0 otherwise.
512 .TP
513 \fBisAttr\fP(\fIg\fP : \fBgraph_t\fP, \fIkind\fP : \fBstring\fP, \fIname\fP : \fBstring\fP) : \fBint\fP
514 returns non-zero if an attribute \fIname\fP has been defined in \fIg\fP
515 for objects of the given \fIkind\fP. For nodes, edges, and graphs, \fIkind\fP
516 should be "N", "E", and "G", respectively.
517 It returns 0 otherwise.
518 .TP
519 \fBaget\fP(\fIsrc\fP : \fBobj_t\fP, \fIname\fP : \fBstring\fP) : \fBstring\fP
520 returns the value of attribute \fIname\fP in object \fIsrc\fP. This is
521 useful for those cases when \fIname\fP conflicts with one of the keywords
522 such as "head" or "root".
523 If the attribute has not been declared in the graph, the function will
524 initialize it with a default value of "". To avoid this, one should use
525 the \fBhasAttr\fP or \fBisAttr\fP function to check that the attribute exists.
526 .TP
527 \fBaset\fP(\fIsrc\fP : \fBobj_t\fP, \fIname\fP : \fBstring\fP, \fIvalue\fP : \fBstring\fP) : \fBint\fP
528 sets the value of attribute \fIname\fP in object \fIsrc\fP to \fIvalue\fP.
529 Returns 0 on success, non\(hyzero on failure. See \fBaget\fP above.
530 .TP
531 \fBgetDflt\fP(\fIg\fP : \fBgraph_t\fP, \fIkind\fP : \fBstring\fP, \fIname\fP : \fBstring\fP) : \fBstring\fP
532 returns the default value of attribute \fIname\fP in objects in \fIg\fP of
533 the given \fIkind\fP. For nodes, edges, and graphs, \fIkind\fP
534 should be "N", "E", and "G", respectively.
535 If the attribute has not been declared in the graph, the function will
536 initialize it with a default value of "". To avoid this, one should use
537 the \fBisAttr\fP function to check that the attribute exists.
538 .TP
539 \fBsetDflt\fP(\fIg\fP : \fBgraph_t\fP, \fIkind\fP : \fBstring\fP, \fIname\fP : \fBstring\fP, \fIvalue\fP : \fBstring\fP) : \fBint\fP
540 sets the default value of attribute \fIname\fP to \fIvalue\fP in
541 objects in \fIg\fP of
542 the given \fIkind\fP. For nodes, edges, and graphs, \fIkind\fP
543 should be "N", "E", and "G", respectively.
544 Returns 0 on success, non\(hyzero on failure. See \fBgetDflt\fP above.
545 .TP
546 \fBfstAttr\fP(\fIg\fP : \fBgraph_t\fP, \fIkind\fP : \fBstring\fP) : \fBstring\fP
547 returns the name of the first attribute of objects in \fIg\fP of
548 the given \fIkind\fP. For nodes, edges, and graphs, \fIkind\fP
549 should be "N", "E", and "G", respectively.
550 If there are no attributes, the string "" is returned.
551 .TP
552 \fBnxtAttr\fP(\fIg\fP : \fBgraph_t\fP, \fIkind\fP : \fBstring\fP, \fIname\fP : \fBstring\fP) : \fBstring\fP
553 returns the name of the next attribute of objects in \fIg\fP of
554 the given \fIkind\fP after the attribute \fIname\fP.
555 The argument \fIname\fP must be the name of an existing attribute; it will
556 typically be the return value of an previous call to \fBfstAttr\fP or
557 \fBnxtAttr\fP.
558 For nodes, edges, and graphs, \fIkind\fP
559 should be "N", "E", and "G", respectively.
560 If there are no attributes left, the string "" is returned.
561 .TP
562 \fBcompOf\fP(\fIg\fP : \fBgraph_t\fP, \fIn\fP : \fBnode_t\fP) : \fBgraph_t\fP
563 returns the connected component of the graph \fIg\fP containing node \fIn\fP,
564 as a subgraph of \fIg\fP. The subgraph only contains the nodes. One can
565 use \fIinduce\fP to add the edges. The function fails and returns \fBNULL\fP
566 if \fIn\fP is not in \fIg\fP. Connectivity is based on the underlying
567 undirected graph of \fIg\fP.
568 .TP
569 \fBkindOf\fP(\fIobj\fP : \fBobj_t\fP) : \fBstring\fP
570 returns an indication of what kind of graph object is the argument.
571 For nodes, edges, and graphs, it returns
572 should be "N", "E", and "G", respectively.
573 .TP
574 \fBlock\fP(\fIg\fP : \fBgraph_t\fP, \fIv\fP : \fBint\fP) : \fBint\fP
575 implements graph locking on root graphs. If the integer \fIv\fP is positive, the
576 graph is set so that future calls to \fBdelete\fP have no immediate effect.
577 If \fIv\fP is zero, the graph is unlocked. If there has been a call
578 to delete the graph while it was locked, the graph is closed.
579 If \fIv\fP is negative, nothing is done.
580 In all cases, the previous lock value is returned.
581 .SS "Strings"
582 .TP
583 \fBsprintf\fP(\fIfmt\fP : \fBstring\fP, \fI...\fP) : \fBstring\fP
584 returns the string resulting from formatting
585 the values of the expressions occurring after \fIfmt\fP
586 according to the
587 .IR printf (3)
588 format
589 .I fmt
590 .TP
591 \fBgsub\fP(\fIstr\fP : \fBstring\fP, \fIpat\fP : \fBstring\fP) : \fBstring\fP
592 .TP
593 \fBgsub\fP(\fIstr\fP : \fBstring\fP, \fIpat\fP : \fBstring\fP, \fIrepl\fP : \fBstring\fP) : \fBstring\fP
594 returns \fIstr\fP with all substrings matching \fIpat\fP
595 deleted or replaced by \fIrepl\fP, respectively.
596 .TP
597 \fBsub\fP(\fIstr\fP : \fBstring\fP, \fIpat\fP : \fBstring\fP) : \fBstring\fP
598 .TP
599 \fBsub\fP(\fIstr\fP : \fBstring\fP, \fIpat\fP : \fBstring\fP, \fIrepl\fP : \fBstring\fP) : \fBstring\fP
600 returns \fIstr\fP with the leftmost substring matching \fIpat\fP
601 deleted or replaced by \fIrepl\fP, respectively. The
602 characters '^' and '$'
603 may be used at the beginning and end, respectively,
604 of \fIpat\fP to anchor the pattern to the beginning or end of \fIstr\fP.
605 .TP
606 \fBsubstr\fP(\fIstr\fP : \fBstring\fP, \fIidx\fP : \fBint\fP) : \fBstring\fP
607 .TP
608 \fBsubstr\fP(\fIstr\fP : \fBstring\fP, \fIidx\fP : \fBint\fP, \fIlen\fP : \fBint\fP) : \fBstring\fP
609 returns the substring of \fIstr\fP starting at position \fIidx\fP to
610 the end of the string or of length \fIlen\fP, respectively.
611 Indexing starts at 0. If \fIidx\fP is negative or \fIidx\fP is greater than
612 the length of \fIstr\fP, a fatal error occurs. Similarly, in the second
613 case, if \fIlen\fP is negative or \fIidx\fP + \fIlen\fP is greater than the
614 length of \fIstr\fP, a fatal error occurs.
615 .TP
616 \fBlength\fP(\fIs\fP : \fBstring\fP) : \fBint\fP
617 returns the length of the string \fIs\fP.
618 .TP
619 \fBindex\fP(\fIs\fP : \fBstring\fP, \fIt\fP : \fBstring\fP) : \fBint\fP
620 .TP
621 \fBrindex\fP(\fIs\fP : \fBstring\fP, \fIt\fP : \fBstring\fP) : \fBint\fP
622 returns the index of the character in string \fIs\fP where the leftmost
623 (rightmost) copy of string \fIt\fP can be found, or \-1 if \fIt\fP is not a
624 substring of \fIs\fP.
625 .TP
626 \fBmatch\fP(\fIs\fP : \fBstring\fP, \fIp\fP : \fBstring\fP) : \fBint\fP
627 returns the index of the character in string \fIs\fP where the leftmost
628 match of pattern \fIp\fP can be found, or \-1 if no substring of \fIs\fP
629 matches \fIp\fP.
630 .TP
631 \fBcanon\fP(\fIs\fP : \fBstring\fP) : \fBstring\fP
632 returns a version of \fIs\fP appropriate to be used as an identifier
633 in a dot file.
634 .TP
635 \fBxOf\fP(\fIs\fP : \fBstring\fP) : \fBstring\fP
636 returns the string "\fIx\fP" if \fIs\fP has the form "\fIx\fP,\fIy\fP",
637 where both \fIx\fP and \fIy\fP are numeric.
638 .TP
639 \fByOf\fP(\fIs\fP : \fBstring\fP) : \fBstring\fP
640 returns the string "\fIy\fP" if \fIs\fP has the form "\fIx\fP,\fIy\fP",
641 where both \fIx\fP and \fIy\fP are numeric.
642 .TP
643 \fBllOf\fP(\fIs\fP : \fBstring\fP) : \fBstring\fP
644 returns the string "\fIllx\fP,\fIlly\fP" if \fIs\fP has the form
645 "\fIllx\fP,\fIlly\fP,\fIurx\fP,\fIury\fP",
646 where all of \fIllx\fP, \fIlly\fP, \fIurx\fP, and \fIury\fP are numeric.
647 .TP
648 .BI urOf( s )
649 \fBurOf\fP(\fIs\fP : \fBstring\fP) : \fBstring\fP
650 returns the string "\fIurx\fP,\fIury\fP" if \fIs\fP has the form
651 "\fIllx\fP,\fIlly\fP,\fIurx\fP,\fIury\fP",
652 where all of \fIllx\fP, \fIlly\fP, \fIurx\fP, and \fIury\fP are numeric.
653 .TP
654 \fBsscanf\fP(\fIs\fP : \fBstring\fP, \fIfmt\fP : \fBstring\fP, \fI...\fP) : \fBint\fP
655 scans the string \fIs\fP, extracting values
656 according to the
657 .IR sscanf (3)
658 format
659 .IR fmt .
660 The values are stored in the addresses following \fIfmt\fP,
661 addresses having the form \fB&\fP\fIv\fP, where \fIv\fP is some declared
662 variable of the correct type.
663 Returns the number of items successfully scanned.
664 .SS "I/O"
665 .TP
666 \fBprint\fP(\fI...\fP) : \fBvoid\fP
667 .BI print( " expr" , " ...\fB )
668 prints a string representation of each argument in turn onto
669 \fBstdout\fP, followed by a newline.
670 .TP
671 \fBprintf\fP(\fIfmt\fP : \fBstring\fP, \fI...\fP) : \fBint\fP
672 .TP
673 \fBprintf\fP(\fIfd\fP : \fBint\fP, \fIfmt\fP : \fBstring\fP, \fI...\fP) : \fBint\fP
674 prints the string resulting from formatting
675 the values of the expressions following \fIfmt\fP
676 according to the
677 .IR printf (3)
678 format
679 .IR fmt .
680 Returns 0 on success.
681 By default, it prints on \fBstdout\fP.
682 If the optional integer \fIfd\fP is given, output is written on the open
683 stream associated with \fIfd\fP.
684 .TP
685 \fBscanf\fP(\fIfmt\fP : \fBstring\fP, \fI...\fP) : \fBint\fP
686 .TP
687 \fBscanf\fP(\fIfd\fP : \fBint\fP, \fIfmt\fP : \fBstring\fP, \fI...\fP) : \fBint\fP
688 scans in values from an input stream according to the
689 .IR scanf (3)
690 format
691 .IR fmt .
692 The values are stored in the addresses following \fIfmt\fP,
693 addresses having the form \fB&\fP\fIv\fP, where \fIv\fP is some declared
694 variable of the correct type.
695 By default, it reads from \fBstdin\fP.
696 If the optional integer \fIfd\fP is given, input is read from the open
697 stream associated with \fIfd\fP.
698 Returns the number of items successfully scanned.
699 .TP
700 \fBopenF\fP(\fIs\fP : \fBstring\fP, \fIt\fP : \fBstring\fP) : \fBint\fP
701 opens the file \fIs\fP as an I/O stream. The string argument \fIt\fP
702 specifies how the file is opened. The arguments are the same as for
703 the C function
704 .IR fopen (3).
705 It returns an integer denoting the stream, or \-1 on error.
706 .sp
707 As usual, streams 0, 1 and 2 are already open as \fBstdin\fP, \fBstdout\fP,
708 and \fBstderr\fP, respectively. Since \fBgvpr\fP may use \fBstdin\fP to
709 read the input graphs, the user should avoid using this stream.
710 .TP
711 \fBcloseF\fP(\fIfd\fP : \fBint\fP) : \fBint\fP
712 closes the open stream denoted by the integer \fIfd\fP.
713 Streams 0, 1 and 2 cannot be closed.
714 Returns 0 on success.
715 .TP
716 \fBreadL\fP(\fIfd\fP : \fBint\fP) : \fBstring\fP
717 returns the next line read from the input stream \fIfd\fP. It returns
718 the empty string "" on end of file. Note that the newline character is
719 left in the returned string.
720 .SS "Math"
721 .TP
722 \fBexp\fP(\fId\fP : \fBdouble\fP) : \fBdouble\fP
723 returns e to the \fId\fPth power.
724 .TP
725 \fBlog\fP(\fId\fP : \fBdouble\fP) : \fBdouble\fP
726 returns the natural log of \fId\fP.
727 .TP
728 \fBsqrt\fP(\fId\fP : \fBdouble\fP) : \fBdouble\fP
729 returns the square root of the double \fId\fP.
730 .TP
731 \fBpow\fP(\fId\fP : \fBdouble\fP, \fIx\fP : \fBdouble\fP) : \fBdouble\fP
732 returns \fId\fP raised to the \fIx\fPth power.
733 .TP
734 \fBcos\fP(\fId\fP : \fBdouble\fP) : \fBdouble\fP
735 returns the cosine of \fId\fP.
736 .TP
737 \fBsin\fP(\fId\fP : \fBdouble\fP) : \fBdouble\fP
738 returns the sine of \fId\fP.
739 .TP
740 \fBatan2\fP(\fIy\fP : \fBdouble\fP, \fIx\fP : \fBdouble\fP) : \fBdouble\fP
741 returns the arctangent of \fIy/x\fP in the range \-pi to pi.
742 .TP
743 \fBMIN\fP(\fIy\fP : \fBdouble\fP, \fIx\fP : \fBdouble\fP) : \fBdouble\fP
744 returns the minimum of \fIy\fP and \fIx\fP.
745 .TP
746 \fBMAX\fP(\fIy\fP : \fBdouble\fP, \fIx\fP : \fBdouble\fP) : \fBdouble\fP
747 returns the maximum of \fIy\fP and \fIx\fP.
748 .SS "Miscellaneous"
749 .TP
750 \fBexit\fP(\fIv\fP : \fBint\fP) : \fBvoid\fP
751 causes
752 .B gvpr
753 to exit with the exit code
754 .IR v .
755 .TP
756 \fBsystem\fP(\fIcmd\fP : \fBstring\fP) : \fBint\fP
757 provides the standard C function
758 .IR system (3).
759 It executes \fIcmd\fP if the user's shell environment, and
760 returns the exit status of the shell.
761 .TP
762 \fBrand\fP() : \fBdouble\fP
763 returns a pseudo\(hyrandom double between 0 and 1.
764 .TP
765 \fBsrand\fP() : \fBint\fP
766 .TP
767 \fBsrand\fP(\fIv\fP : \fBint\fP) : \fBint\fP
768 sets a seed for the random number generator. The optional argument gives
769 the seed; if it is omitted, the current time is used. The previous seed
770 value is returned. \fBsrand\fP should be called before any calls to
771 \fBrand\fP.
772 .SH "BUILT\(hyIN VARIABLES"
773 .PP
774 .B gvpr
775 provides certain special, built\(hyin variables, whose values are set
776 automatically by \fBgvpr\fP depending on the context. Except as noted,
777 the user cannot modify their values.
778 .TP
779 \fB$\fP : \fBobj_t\fP
780 denotes the current object (node, edge, graph) depending on the
781 context. It is not available in \fBBEGIN\fP or \fBEND\fP clauses.
782 .TP
783 \fB$F\fP : \fBstring\fP
784 is the name of the current input file.
785 .TP
786 \fB$G\fP : \fBgraph_t\fP
787 denotes the current graph being processed. It is not available
788 in \fBBEGIN\fP or \fBEND\fP clauses.
789 .TP
790 \fB$O\fP : \fBgraph_t\fP
791 denotes the output graph. Before graph traversal, it is initialized
792 to the target graph. After traversal and any \fBEND_G\fP actions,
793 if it refers to a non\(hyempty graph, that graph is printed onto the output stream.
794 It is only valid in \fBN\fP, \fBE\fP and \fBEND_G\fP clauses.
795 The output graph may be set by the user.
796 .TP
797 \fB$T\fP : \fBgraph_t\fP
798 denotes the current target graph. It is a subgraph of \fB$G\fP
799 and is available only in \fBN\fP, \fBE\fP and \fBEND_G\fP clauses.
800 .TP
801 \fB$tgtname\fP : \fBstring\fP
802 denotes the name of the target graph.
803 By default, it is set to \fB"gvpr_result"\fP.
804 If used multiple times during the execution of
805 .BR gvpr ,
806 the name will be appended with an integer.
807 This variable may be set by the user.
808 .TP
809 \fB$tvroot\fP : \fBnode_t\fP
810 indicates the starting node for a (directed or undirected)
811 depth\(hyfirst traversal of the
812 graph (cf. \fB$tvtype\fP below).
813 The default value is \fBNULL\fP for each input graph.
814 .TP
815 \fB$tvtype\fP : \fBtvtype_t\fP
816 indicates how \fBgvpr\fP traverses a graph. It can only take
817 one of the constant values with the previx "TV_" described below.
818 \fBTV_flat\fP is the default.
819 .IP
820 In the underlying graph library
821 .IR cgraph (3),
822 edges in undirected graphs are given an arbitrary direction. This is
823 used for traversals, such as \fBTV_fwd\fR, requiring directed edges.
824 .
825 .TP
826 \fBARGC\fP : \fBint\fP
827 denotes the number of arguments specified by the
828 \fB\-a\fP \fIargs\fP command\(hyline argument.
829 .TP
830 \fBARGV\fP : \fBstring array\fP
831 denotes the array of arguments specified by the
832 \fB\-a\fP \fIargs\fP
833 command\(hyline argument. The \fIi\fPth argument is given
834 by \fBARGV[\fIi\fP]\fR.
835 .SH "BUILT\(hyIN CONSTANTS"
836 .PP
837 There are several symbolic constants defined by \fBgvpr\fP.
838 .TP
839 \fBNULL\fR : \fIobj_t\fR
840 a null object reference, equivalent to 0.
841 .TP
842 \fBTV_flat\fR : \fItvtype_t\fR
843 a simple, flat traversal, with graph objects visited in
844 seemingly arbitrary order.
845 .TP
846 \fBTV_ne\fR : \fItvtype_t\fR
847 a traversal which first visits all of the nodes, then all
848 of the edges.
849 .TP
850 \fBTV_en\fR : \fItvtype_t\fR
851 a traversal which first visits all of the edges, then all
852 of the nodes.
853 .TP
854 \fBTV_dfs\fR : \fItvtype_t\fR
855 .TQ
856 \fBTV_postdfs\fR : \fItvtype_t\fR
857 .TQ
858 \fBTV_prepostdfs\fR : \fItvtype_t\fR
859 a traversal of the graph using a depth\(hyfirst search on the
860 underlying undirected graph.
861 To do the traversal, \fBgvpr\fP will check the value of
862 \fB$tvroot\fP. If this has the same value that it had previously
863 (at the start, the previous value is initialized to \fBNULL\fP.), \fBgvpr\fP
864 will simply look for some unvisited node and traverse its connected
865 component. On the other hand, if \fB$tvroot\fP has changed, its connected
866 component will be toured, assuming it has not been previously visited or,
867 if \fB$tvroot\fP is \fBNULL\fP, the traversal will stop. Note that using
868 \fBTV_dfs\fP and \fB$tvroot\fP, it is possible to create an infinite loop.
869 .
870 .IP
871 By default, the traversal is done in pre-order. That is, a node is
872 visited before all of its unvisited edges. For \fBTV_postdfs\fR,
873 all of a node's unvisited edges are visited before the node. For
874 \fBTV_prepostdfs\fR, a node is visited twice, before and after all of
875 its unvisited edges.
876 .
877 .TP
878 \fBTV_fwd\fR : \fItvtype_t\fR
879 .TQ
880 \fBTV_postfwd\fR : \fItvtype_t\fR
881 .TQ
882 \fBTV_prepostfwd\fR : \fItvtype_t\fR
883 A traversal of the graph using a depth\(hyfirst search on the
884 graph following only forward arcs.
885 The choice of roots for the traversal is the
886 same as described for \fBTV_dfs\fR above.
887 The different order of visitation specified by \fBTV_fwd\fR,
888 \fBTV_postfwd\fR and \fBTV_prepostfwd\fR are the same as those
889 specified by the analogous traversals \fBTV_dfs\fR,
890 \fBTV_postdfs\fR and \fBTV_prepostdfs\fR.
891 .TP
892 \fBTV_rev\fR : \fItvtype_t\fR
893 .TQ
894 \fBTV_postrev\fR : \fItvtype_t\fR
895 .TQ
896 \fBTV_prepostrev\fR : \fItvtype_t\fR
897 A traversal of the graph using a depth\(hyfirst search on the
898 graph following only reverse arcs.
899 The choice of roots for the traversal is the
900 same as described for \fBTV_dfs\fR above.
901 The different order of visitation specified by \fBTV_rev\fR,
902 \fBTV_postrev\fR and \fBTV_prepostrev\fR are the same as those
903 specified by the analogous traversals \fBTV_dfs\fR,
904 \fBTV_postdfs\fR and \fBTV_prepostdfs\fR.
905 .TP
906 \fBTV_bfs\fR : \fItvtype_t\fR
907 A traversal of the graph using a bread\(hyfirst search on the
908 graph ignoring edge directions. See the item on \fBTV_dfs\fR above
909 for the role of \fB$tvroot\fP.
910 .SH EXAMPLES
911 .PP
912 .ta \w'\f(CWdelete array[expression]'u
913 .RS
914 .nf
915 \fBgvpr \-i 'N[color=="blue"]' file.dot\fP
916 .fi
917 .RE
918 .DT
919 .PP
920 Generate the node\(hyinduced subgraph of all nodes with color blue.
921 .PP
922 .ta \w'\f(CWdelete array[expression]'u
923 .RS
924 .nf
925 \fBgvpr \-c 'N[color=="blue"]{color = "red"}' file.dot\fP
926 .fi
927 .RE
928 .DT
929 .PP
930 Make all blue nodes red.
931 .PP
932 .ta \w'\f(CWdelete array[expression]'u
933 .RS
934 .nf
935 \fBBEGIN { int n, e; int tot_n = 0; int tot_e = 0; }
936 BEG_G {
937 n = nNodes($G);
938 e = nEdges($G);
939 printf ("%d nodes %d edges %s\n", n, e, $G.name);
940 tot_n += n;
941 tot_e += e;
942 }
943 END { printf ("%d nodes %d edges total\n", tot_n, tot_e) }\fP
944 .fi
945 .RE
946 .DT
947 .PP
948 Version of the program \fBgc\fP.
949 .PP
950 .ta \w'\f(CWdelete array[expression]'u
951 .RS
952 .nf
953 \fBgvpr \-c ""\fP
954 .fi
955 .RE
956 .DT
957 .PP
958 Equivalent to \fBnop\fP.
959 .PP
960 .ta \w'\f(CWdelete array[expression]'u
961 .RS
962 .nf
963 \fBBEG_G { graph_t g = graph ("merge", "S"); }
964 E {
965 node_t h = clone(g,$.head);
966 node_t t = clone(g,$.tail);
967 edge_t e = edge(t,h,"");
968 e.weight = e.weight + 1;
969 }
970 END_G { $O = g; }\fP
971 .fi
972 .RE
973 .DT
974 .PP
975 Produces a strict version of the input graph, where the weight attribute
976 of an edge indicates how many edges from the input graph the edge represents.
977 .PP
978 .ta \w'\f(CWdelete array[expression]'u
979 .RS
980 .nf
981 \fBBEGIN {node_t n; int deg[]}
982 E{deg[head]++; deg[tail]++; }
983 END_G {
984 for (deg[n]) {
985 printf ("deg[%s] = %d\n", n.name, deg[n]);
986 }
987 }\fP
988 .fi
989 .RE
990 .DT
991 .PP
992 Computes the degrees of nodes with edges.
993 .SH ENVIRONMENT
994 .TP
995 .B GPRPATH
996 Colon\(hyseparated list of directories to be searched to find
997 the file specified by the \-f option.
998 .SH BUGS AND WARNINGS
999 When the program is given as a command line argument, the usual
1000 shell interpretation takes place, which may affect some of the
1001 special names in \fBgvpr\fP. To avoid this, it is best to wrap the
1002 program in single quotes.
1003 .PP
1004 As of 24 April 2008, \fBgvpr\fP switched to using a new, underlying
1005 graph library, which uses the simpler model that there is only one
1006 copy of a node, not one copy for each subgraph logically containing
1007 it. This means that iterators such as \Inxtnode\P cannot traverse
1008 a subgraph using just a node argument. For this reason, subgraph
1009 traversal requires new functions ending in "_sg", which also take
1010 a subgraph argument. The versions without that suffix will always
1011 traverse the root graph.
1012 .PP
1013 There is a single global scope, except for formal function parameters,
1014 and even these can interfere with the type system. Also, the
1015 extent of all variables is the entire life of the program.
1016 It might be preferable for scope
1017 to reflect the natural nesting of the clauses, or for the program
1018 to at least reset locally declared variables.
1019 For now, it is advisable to use distinct names for all variables.
1020 .PP
1021 If a function ends with a complex statement, such as an
1022 IF statement, with each branch doing a return, type checking may fail.
1023 Functions should use a return at the end.
1024 .PP
1025 The expr library does not support string values of (char*)0.
1026 This means we can't distinguish between "" and (char*)0 edge keys.
1027 For the purposes of looking up and creating edges, we translate ""
1028 to be (char*)0, since this latter value is
1029 necessary in order to look up any edge with a matching head and tail.
1030 .PP
1031 Related to this, strings converted to integers act like char pointers,
1032 getting the value 0 or 1 depending on whether the string consists
1033 solely of zeroes or not. Thus, the ((int)"2") evaluates to 1.
1034 .PP
1035 The language inherits the usual C problems such as dangling references
1036 and the confusion between '=' and '=='.
1037 .SH AUTHOR
1038 Emden R. Gansner <erg@research.att.com>
1039 .SH "SEE ALSO"
1040 .PP
1041 awk(1), gc(1), dot(1), nop(1), libexpr(3), libcgraph(3)