gvpr.1 45 KB

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