Debian Codegraph @

tclpkg/tcldot/demo/gcat.tcl

raw
1 #!/bin/sh
2 # next line is a comment in tcl \
3 exec tclsh "$0" ${1+"$@"}
4
5 package require Tcldot
6
7 # gcat f1 [f2 ... ]
8 #
9 # merge a number of digraphs into one and output to stdout
10 #
11 # John Ellson <[email protected]>
12 #
13
14 # merge graph $g2 into $g
15 proc merge {g g2} {
16 foreach i [$g2 listnodes] {
17 set n [$g addnode [$i showname]]
18 $n setattributes [$i queryattributevalues [$i listattributes]]
19 }
20 foreach i [$g2 listedges] {
21 foreach {t h} [$i listnodes] {break}
22 set e [$g addedge [$t showname] [$h showname]]
23 $e setattributes [$i queryattributevalues [$i listattributes]]
24 }
25 }
26
27 set g [dotnew digraph]
28 if {$argc} {
29 foreach file $argv {
30 set f [open $file r]
31 if {[catch {dotread $f} g2]} {
32 puts stderr $g2
33 exit
34 }
35 merge $g $g2
36 close $f
37 }
38 } {
39 while {![catch {dotread stdin} g2]} {
40 merge $g $g2
41 }
42 if {![eof stdin]} {
43 puts stderr $g2
44 exit
45 }
46 }
47 $g write stdout CANON