| 1 |
(* |
| 2 |
* This module starts a graph viewer. |
| 3 |
* |
| 4 |
* -- Allen |
| 5 |
*) |
| 6 |
|
| 7 |
functor GraphViewer(D : GRAPH_DISPLAY) : GRAPH_VIEWER = |
| 8 |
struct |
| 9 |
|
| 10 |
structure L = GraphLayout |
| 11 |
structure G = Graph |
| 12 |
structure FileSys = OS.FileSys |
| 13 |
|
| 14 |
val tmpName = MLRiscControl.getString "tmpName" |
| 15 |
|
| 16 |
fun display exec (layout as G.GRAPH l) filename = |
| 17 |
let val filename = filename ^ D.suffix() |
| 18 |
val _ = print("[ "^ #name l^": "^ |
| 19 |
D.program() ^ " " ^ filename ^ |
| 20 |
" "^Int.toString(#order l ())^" nodes"^ |
| 21 |
" "^Int.toString(#size l ())^" edges"); |
| 22 |
val file = TextIO.openOut filename |
| 23 |
val out = fn s => TextIO.output(file,s) |
| 24 |
val _ = D.visualize out layout |
| 25 |
val _ = TextIO.closeOut file |
| 26 |
val _ = print(" ]\n") |
| 27 |
val _ = exec filename |
| 28 |
in |
| 29 |
() |
| 30 |
end handle e => |
| 31 |
(print("[Uncaught exception in "^exnName e^" graph viewer]\n"); raise e) |
| 32 |
|
| 33 |
fun system filename = (OS.Process.system |
| 34 |
((D.program()) ^ " " ^ filename); |
| 35 |
FileSys.remove filename) |
| 36 |
|
| 37 |
fun fork filename = (OS.Process.system( |
| 38 |
"(" ^ (D.program()) ^ " " ^ filename ^ |
| 39 |
"; /bin/rm " ^ filename ^ ") &")) |
| 40 |
|
| 41 |
fun getTmpName() = |
| 42 |
if !tmpName = "" then FileSys.tmpName() else !tmpName |
| 43 |
|
| 44 |
fun view layout = display system layout (getTmpName()) |
| 45 |
end |
| 46 |
|