#!/usr/bin/wish


if {$argc != 0} {
    set FileName [lindex $argv 0]
    if {![file exists $FileName.tk]} {
        puts "The file \"$FileName.tk\" does note exist!"
        exit 1
    } else {
        wm title . [file tail $FileName]
        set w .fcanvas
        destroy $w
        frame $w
        pack $w -side top -fill both -expand yes -padx 1m -pady 1m

        set c $w.canvas
        set xscroll $w.xscroll
        set yscroll $w.yscroll
        set canvasDelete $w.button
        canvas $c -bg ivory -relief sunken -borderwidth 2 \
    	    -xscrollcommand "$xscroll set" -yscrollcommand "$yscroll set"

        scrollbar $yscroll -command "$c yview" -width 3.5m
        scrollbar $xscroll -orient horiz -command "$c xview" -width 3.5m

        set DelButton [file join tcl delbutton.gif]
        set ImageCorrupted 1
        if {[file exists $DelButton]} {
            catch {
                image create photo delbutton -file [file join tcl delbutton.gif]
                button $canvasDelete -command {exit 0} -padx 0 -pady 0 \
                    -image delbutton
                set ImageCorrupted 0
            }
        }
        
        if {$ImageCorrupted} {
            button $canvasDelete -command {exit 0} -padx 0 -pady 0 \
                -text x
        }

        grid $c -in $w \
            -row 0 -column 0 -rowspan 1 -columnspan 1 -sticky news
        grid $yscroll \
            -row 0 -column 1 -rowspan 1 -columnspan 1 -sticky news
        grid $xscroll \
            -row 1 -column 0 -rowspan 1 -columnspan 1 -sticky news
        grid $canvasDelete \
            -row 1 -column 1 -rowspan 1 -columnspan 1 -sticky news
        grid rowconfig    $w 0 -weight 1 -minsize 0
        grid columnconfig $w 0 -weight 1 -minsize 0
        
        bind . <Control-q> {exit 0}
    
        set goblinCanvas $c
        source $FileName.tk
    }
} else {
    puts "No trace file specified!"
    exit 1
}

    
