
# The main driver script for Autohex.
#
# Copyright (c) 1993 ICEM Systems.
# Author:  Wayne A. Christopher, wayne@pmac.com
#          Pacific Marketing and Consulting, Berkeley, California

if ![info exists app_name] {
    if {[lindex $argv 0] == "-app"} {
	set app_name [lindex $argv 1]
	set argv [lrange $argv 2 end]
	incr argc -2
    } elseif [info exists env(AUTOHEX_APP)] {
	set app_name $env(AUTOHEX_APP)
    } else {
	set app_name autohex_generic
    }
}

if {![info exists env(LM_LICENSE_FILE)] && 
    [info exists env(ANSYSLMD_LICENSE_FILE)]} {
    set env(LM_LICENSE_FILE) $env(ANSYSLMD_LICENSE_FILE)
}

set app_dir $autohex_root/lib/$app_name
set app_init $app_dir/init_$app_name.tcl

if {[info commands WinLoadIcon] != ""} {
    if {[catch {WinLoadIcon $app_name}]} {
        catch {WinLoadIcon %default}
    }
}

if {[info commands label] != ""} {
    set please_wait_font [font create -size 20 -weight bold -family helvetica]
    
    if [file exists $app_dir/splash_screen.gif] {
	wm withdraw .
	catch {console hide}
	set im [image create photo -file $app_dir/splash_screen.gif]
	toplevel .startup
	wm withdraw .startup
	label .startup.l -image $im
	pack .startup.l
	wm transient .startup
	wm title .startup "Starting up ..."
	wm geometry .startup +300+300
	wm deiconify .startup
	update
    }
}

set has_blt 0

set guibase_dir ""
foreach dir [list $autohex_root/lib/autohex/guibase \
		  $autohex_root/lib/guibase \
	          $autohex_root/../guibase] {
    if [file exists $dir] {
	set guibase_dir $dir
	break
    }
}
if {$guibase_dir == ""} { error "can't find guibase anywhere" }

set tdv_library ""
foreach dir [list $autohex_root/lib/autohex/tdv \
		  $autohex_root/lib/tdv \
	          $autohex_root/../tdv/lib] {
    if [file exists $dir] {
	set tdv_library $dir
	break
    }
}
if {$tdv_library == ""} { error "can't find tdv library anywhere" }

set autohex_lib_dir $autohex_root/lib/autohex
if {![file exists $autohex_lib_dir] &&
     [file exists $autohex_root/../autohex/lib/autohex]} {
    set autohex_lib_dir $autohex_root/../autohex/lib/autohex
}

incr argc 2
set argv [concat [list -tool $autohex_lib_dir/autohex.tcl] $argv]
source $guibase_dir/guibase.tcl
