sl@0: /* sl@0: * tclInitScript.h -- sl@0: * sl@0: * This file contains Unix & Windows common init script sl@0: * It is not used on the Mac. (the mac init script is in tclMacInit.c) sl@0: * sl@0: * Copyright (c) 1998 Sun Microsystems, Inc. sl@0: * Copyright (c) 1999 by Scriptics Corporation. sl@0: * All rights reserved. sl@0: * sl@0: * RCS: @(#) $Id: tclInitScript.h,v 1.13 2001/09/10 21:06:55 dgp Exp $ sl@0: */ sl@0: sl@0: /* sl@0: * In order to find init.tcl during initialization, the following script sl@0: * is invoked by Tcl_Init(). It looks in several different directories: sl@0: * sl@0: * $tcl_library - can specify a primary location, if set sl@0: * no other locations will be checked sl@0: * sl@0: * $env(TCL_LIBRARY) - highest priority so user can always override sl@0: * the search path unless the application has sl@0: * specified an exact directory above sl@0: * sl@0: * $tclDefaultLibrary - this value is initialized by TclPlatformInit sl@0: * from a static C variable that was set at sl@0: * compile time sl@0: * sl@0: * $tcl_libPath - this value is initialized by a call to sl@0: * TclGetLibraryPath called from Tcl_Init. sl@0: * sl@0: * The first directory on this path that contains a valid init.tcl script sl@0: * will be set as the value of tcl_library. sl@0: * sl@0: * Note that this entire search mechanism can be bypassed by defining an sl@0: * alternate tclInit procedure before calling Tcl_Init(). sl@0: */ sl@0: sl@0: static char initScript[] = "if {[info proc tclInit]==\"\"} {\n\ sl@0: proc tclInit {} {\n\ sl@0: global tcl_libPath tcl_library errorInfo\n\ sl@0: global env tclDefaultLibrary\n\ sl@0: rename tclInit {}\n\ sl@0: set errors {}\n\ sl@0: set dirs {}\n\ sl@0: if {[info exists tcl_library]} {\n\ sl@0: lappend dirs $tcl_library\n\ sl@0: } else {\n\ sl@0: if {[info exists env(TCL_LIBRARY)]} {\n\ sl@0: lappend dirs $env(TCL_LIBRARY)\n\ sl@0: }\n\ sl@0: catch {\n\ sl@0: lappend dirs $tclDefaultLibrary\n\ sl@0: unset tclDefaultLibrary\n\ sl@0: }\n\ sl@0: set dirs [concat $dirs $tcl_libPath]\n\ sl@0: }\n\ sl@0: foreach i $dirs {\n\ sl@0: set tcl_library $i\n\ sl@0: set tclfile [file join $i init.tcl]\n\ sl@0: if {[file exists $tclfile]} {\n\ sl@0: if {![catch {uplevel #0 [list source $tclfile]} msg]} {\n\ sl@0: return\n\ sl@0: } else {\n\ sl@0: append errors \"$tclfile: $msg\n$errorInfo\n\"\n\ sl@0: }\n\ sl@0: }\n\ sl@0: }\n\ sl@0: set msg \"Can't find a usable init.tcl in the following directories: \n\"\n\ sl@0: append msg \" $dirs\n\n\"\n\ sl@0: append msg \"$errors\n\n\"\n\ sl@0: append msg \"This probably means that Tcl wasn't installed properly.\n\"\n\ sl@0: error $msg\n\ sl@0: }\n\ sl@0: }\n\ sl@0: tclInit"; sl@0: sl@0: sl@0: /* sl@0: * A pointer to a string that holds an initialization script that if non-NULL sl@0: * is evaluated in Tcl_Init() prior to the the built-in initialization script sl@0: * above. This variable can be modified by the procedure below. sl@0: */ sl@0: sl@0: static char * tclPreInitScript = NULL; sl@0: sl@0: sl@0: /* sl@0: *---------------------------------------------------------------------- sl@0: * sl@0: * TclSetPreInitScript -- sl@0: * sl@0: * This routine is used to change the value of the internal sl@0: * variable, tclPreInitScript. sl@0: * sl@0: * Results: sl@0: * Returns the current value of tclPreInitScript. sl@0: * sl@0: * Side effects: sl@0: * Changes the way Tcl_Init() routine behaves. sl@0: * sl@0: *---------------------------------------------------------------------- sl@0: */ sl@0: sl@0: char * sl@0: TclSetPreInitScript (string) sl@0: char *string; /* Pointer to a script. */ sl@0: { sl@0: char *prevString = tclPreInitScript; sl@0: tclPreInitScript = string; sl@0: return(prevString); sl@0: }