#! /bin/sh # # Name: mxtclsh_script or mxwish_script # # Purpose: This script initializes MxTcl and then runs a user specified script. # # Author: William Lavender # #--------------------------------------------------------------------------- # # Copyright 2001-2002, 2013 Illinois Institute of Technology # # See the file "LICENSE" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # #--------------------------------------------------------------------------- # # The following bit of shell script allows the same copy of this script to # be executed by 'wish' when invoked as 'mxwish_script' and by 'tclsh' when # invoked as 'mxtclsh_script'. # # \ if [ `basename $0` = mxwish_script ]; then \ exec wish "$0" ${1+"$@"}; \ else \ exec tclsh "$0" ${1+"$@"}; \ fi # From here on, everything is Tcl. set program_name [ file tail $argv0 ] set program_name [ file rootname $program_name ] set script_name [ lindex $argv 0 ] if { $script_name == "" } { puts stderr "Usage: $program_name script_name \[args ...\]" exit 1 } set argv [ lrange $argv 1 end ] set version [info tclversion] if { [ expr $version < 8.3 ] } { puts "Tcl versions older than 8.3 are not supported by $program_name." puts "You have Tcl version $version" puts "Exiting..." exit } # # If the MXDIR environment variable is not defined, set it to the # default value. # if { [ info exists env(MXDIR) ] == 0 } { set env(MXDIR) [ file join "/" "opt" "mx" ] } # # If the MXTEST environment variable is defined, we will look for the MxTcl # package in ../libMxTcl. Otherwise, we look for it in $MXDIR/lib/mxtcl. # set test 0 if [ info exists env(MXTEST) ] { if { $env(MXTEST) != 0 } { set test 1 } } if { $test } { puts stderr "$program_name is in test mode." set mxtcl_package_dir_list [ concat \ [ file join "." ] \ [ file join ".." "libMxTcl" ] ] } else { set mxtcl_package_dir_list [ concat \ [ file join $env(MXDIR) "lib" "mxtcl" ] ] } set auto_path [ concat $mxtcl_package_dir_list $auto_path ] # Load the packages necessary for MxTcl under tclsh. package require Itcl 3.1 if { $program_name == "mxwish_script" } { package require Itk 3.1 if [ catch { package require Iwidgets 4.0 } ] { package require Iwidgets 3.0 } } package require Mx # Initialize the MxTcl library. set status [ catch { ::Mx::init } result ] if { $status != 0 } { puts stderr "The MX initialization procedure Mx::init failed." puts stderr "Traceback = $errorInfo" exit 1 } # # Read the user script. # if [ catch { source $script_name } ] { puts stderr "Cannot execute the user script '$script_name'." puts stderr "Traceback = $errorInfo" exit 1 } # # Read in the MX database. # if [ catch { set mx_database $env(MXDATABASE) } ] { set mx_database [ file join $env(MXDIR) "etc" "mxmotor.dat" ] } if [ catch { Mx::setup_database $mx_database } record_list ] { puts stderr "Cannot setup the MX database '$mx_database'." puts stderr "Traceback = $errorInfo" exit 1 } # Set the plot enable to 'nowait'. $record_list set_plot_enable 2 # # Run the user script # main $record_list $argv