gcat.tcl 894 B

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