Accessing Gnocl Modules from their Regular Installation Directories with Scripts Compiled using FreeWrap

WJG (30/Dec/2009) Recently I've been using freewrapTCLSH to produce executables from Tcl/Gnocl scripts running on my OpenSuse workstation. Because FreeWrap doesn't rely upon any pre-installed interpretor to find any installed Gnocl modules, these are typically included in the same directory with the executable and accessed by using either the 'load' command for *.so files or 'source' for *.tcl. Not wanting to have too many spare copies of shared modules and packages floating around on my file system, I worked out a way of accessing packages installed in their usual locations (ie. under /usr/lib/tcl/) hence the following routine. When called using the familiar 'package require Gnocl 0.9.94', the exisiting Tcl installation will be examined for the needed packages. If these are not present,then the directory containing the executable itself will be searched. If the module cannot be found anywhere, the program will terminate.

#---------------
# create some pseudo system variables
#---------------
set sys(tcl_library) /usr/lib/tcl
set sys(tcl_version) tcl8.5

#--------------------
# New package loader for shared modules as an alternative to: load ./gnocl.so etc..
#--------------------
proc package {keyword pkg vers} {
    global sys
    switch $keyword {
        require {
            set pkg [string tolower $pkg 0 3]
            if { [catch { load "$sys(tcl_library)/$sys(tcl_version)/${pkg}${vers}/${pkg}.so" } ] } {
                if { [catch { load ./${pkg}.so } ] } {
                    puts stderr "Critical Error: ${pkg}.so not found\n"
                    exit
                    }
            }
        }
        default {
            puts "Syntax Error! package $keyword $pkg $vers  -Should be: package require <package-name> <version>"
            exit
            }
    }
}

package require Gnocl 0.9.94
package require GnoclSourceView 0.9.94
package require GnoclCanvas 0.9.94 
package require GnoclVTE 0.9.94