Debian Codegraph @

cmd/gvpr/gvpr.1

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