#!/bin/sh
# Note that lines preceeded by a comment ending in a backslash are interpreted
# by the shell only, not by tksipp.
# ... \
TSIPPwb=`echo $0 | sed 's,/.../TSIPPwb,,'`; export TSIPPwb
# ... \
LD_LIBRARY_PATH=$TSIPPwb/lib; export LD_LIBRARY_PATH
# ... \
TCL_LIBRARY=$TSIPPwb/lib; export TCL_LIBRARY
# ... \
PATH=$TSIPPwb/bin:$PATH; export PATH
# ... \
exec tksipp "$0" "$@"

# -----------------------------------------------------------------------------
# TSIPPwb --
#
#       Entry-point for the TSIPPwb program.  Responsible for loading packages
#       for and creating the megawidgets that comprise the tool.
# -----------------------------------------------------------------------------
# Copyright 2001 Paul Welton
#       Permission to use, copy, modify, and distribute this software and its
#       documentation for any purpose and without fee is hereby granted,
#       provided that this copyright notice appears in all copies.  No
#       representations are made about the suitability of this software for any
#       purpose.  It is provided "as is" without express or implied warranty.
# -----------------------------------------------------------------------------
# Revision:   1.0   : Initial Release
# -----------------------------------------------------------------------------

#  Package selection and autoloader configuration ...
lappend auto_path $env(TSIPPwb)/tcl

#  Create the placard, or "introductory splash screen" which is
#  destroyed once the application is loaded.  This is done as early
#  as possible.
Placard placard TSIPPwb 1.0 "TSIPP Work Bench" "by\nPaul Welton" \
        [file join $::env(TSIPPwb) images workBench.gif] \
        "\251 2001 Paul Welton"

package require Itcl
package require Itk
package require Iwidgets
package require Tclx
package require MultiView

#  The following procedure is likely to be replaced in the user's
#  .tsippwbrc file.
proc debugPrint {msg} {
    puts $msg
}

#  Analyze program arguments
if {$argc > 2} {
    debugPrint {Usage: TSIPPwb [<filename>]}
    exit 1
} elseif {$argc >= 2} {
    set filename [lindex $argv 1]
}

#  Megawidget creation ...
grid [globalEdit .g]_win -row 0 -column 0
grid [multiView  .v]_win -row 0 -column 1

#  Nominate the policy for truncation if the window size is reduced.
grid columnconfigure . 0 -weight 1
grid    rowconfigure . 0 -weight 1

# -----------------------------------------------------------------------------
# bgerror --
#
#       The standard version of this procedure is wrapped so as to cancel
#       the autoRendering mode if it is active.  This is to prevent an
#       infinite loop developing, in which quitting from the standard
#       bgerror confirmation dialog triggers a rendering operation which
#       repeats the loop.
#
# Arguments:
#       err - error message.
#
# Results:
#       Return value of the standard version of bgerror, if any.

catch bgerror
rename bgerror bgerror_standard
proc bgerror {err} {
    .g forceAutoRender off
    return [uplevel bgerror_standard [list $err]]
}

#  Attempt to source the first customization file ".tsippwbrc" found,
#  looking first in the current directory, then the home directory
#  and finally the installation directory
    if {[file exists .tsippwbrc]} {
        source .tsippwbrc
        puts "Sourced \".tsippwbrc\" from current directory"

} elseif {[file exists $env(HOME)/.tsippwbrc]} {
        source $env(HOME)/.tsippwbrc
        puts "Sourced \".tsippwbrc\" from home directory"

} else {
	set installrc $::env(TSIPPwb)/.tsippwbrc
    if {[file exists $installrc]} {
        source $installrc
        puts "Sourced \".tsippwbrc\" from installation directory \"$installrc\""
    }
}

if {[info exists filename]} {
     .g load $filename
}

itcl::delete object placard

# ------------------------------------------------------------------------------
# ENTER THE EVENT LOOP - end of TCL script
# ------------------------------------------------------------------------------
