root/tcl-8.0/tags/rat_4_2_17/generic/tclInitScript.h @ 1172

Revision 1172, 5.0 KB (checked in by anonymous, 14 years ago)

This commit was manufactured by cvs2svn to create tag 'rat_4_2_17'.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/*
2 * tclInitScript.h --
3 *
4 *      This file contains Unix & Windows common init script
5 *      It is not used on the Mac. (the mac init script is in tclMacInit.c)
6 *      This file should only be included once in the entire set of C
7 *      source files for Tcl (by the respective platform initialization
8 *      C source file, tclUnixInit.c and tclWinInit.c) and thus the
9 *      presence of the routine, TclSetPreInitScript, below, should be
10 *      harmless.
11 *
12 * Copyright (c) 1998 Sun Microsystems, Inc.
13 *
14 * See the file "license.terms" for information on usage and redistribution
15 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
16 *
17 * SCCS: @(#) tclInitScript.h 1.6 98/08/07 11:02:49
18 */
19
20/*
21 * In order to find init.tcl during initialization, the following script
22 * is invoked by Tcl_Init().  It looks in several different directories:
23 *
24 *      $tcl_library            - can specify a primary location, if set
25 *                                no other locations will be checked
26 *
27 *      $env(TCL_LIBRARY)       - highest priority so user can always override
28 *                                the search path unless the application has
29 *                                specified an exact directory above
30 *
31 *      $tclDefaultLibrary      - this value is initialized by TclPlatformInit
32 *                                from a static C variable that was set at
33 *                                compile time
34 *
35 *      <executable directory>/../lib/tcl$tcl_version
36 *                              - look for a lib/tcl<ver> in a sibling of
37 *                                the bin directory (e.g. install hierarchy)
38 *
39 *      <executable directory>/../../lib/tcl$tcl_version
40 *                              - look for a lib/tcl<ver> in a sibling of
41 *                                the bin/arch directory
42 *
43 *      <executable directory>/../library
44 *                              - look in build directory
45 *
46 *      <executable directory>/../../library
47 *                              - look in build directory from unix/arch
48 *
49 *      <executable directory>/../../tcl$tcl_patchLevel/library
50 *                              - look for tcl build directory relative
51 *                                to a parallel build directory (e.g. Tk)
52 *
53 *      <executable directory>/../../../tcl$tcl_patchLevel/library
54 *                              - look for tcl build directory relative
55 *                                to a parallel build directory from
56 *                                down inside unix/arch directory
57 *
58 * The first directory on this path that contains a valid init.tcl script
59 * will be appended to tcl_pkgPath and set as the value of tcl_library.
60 *
61 * Note that this entire search mechanism can be bypassed by defining an
62 * alternate tclInit procedure before calling Tcl_Init().
63 */
64
65static char initScript[] = "\
66    global tcl_library tcl_version tcl_patchLevel errorInfo\n\
67    global tcl_pkgPath env tclDefaultLibrary\n\
68    set tcl_library {}\n\
69    set tcl_pkgPath {}\n\
70";
71       
72#ifdef NDEF
73static char initScript[] = "if {[info proc tclInit]==\"\"} {\n\
74  proc tclInit {} {\n\
75    global tcl_library tcl_version tcl_patchLevel errorInfo\n\
76    global tcl_pkgPath env tclDefaultLibrary\n\
77    rename tclInit {}\n\
78    set errors {}\n\
79    set dirs {}\n\
80    if {[info exists tcl_library]} {\n\
81        lappend dirs $tcl_library\n\
82    } else {\n\
83        if {[info exists env(TCL_LIBRARY)]} {\n\
84            lappend dirs $env(TCL_LIBRARY)\n\
85        }\n\
86        lappend dirs $tclDefaultLibrary\n\
87        unset tclDefaultLibrary\n\
88        set parentDir [file dirname [file dirname [info nameofexecutable]]]\n\
89        lappend dirs [file join $parentDir lib tcl$tcl_version]\n\
90        lappend dirs [file join [file dirname $parentDir] lib tcl$tcl_version]\n\
91        lappend dirs [file join $parentDir library]\n\
92        lappend dirs [file join [file dirname $parentDir] library]\n\
93        if {[string match {*[ab]*} $tcl_patchLevel]} {\n\
94            set ver $tcl_patchLevel\n\
95        } else {\n\
96            set ver $tcl_version\n\
97        }\n\
98        lappend dirs [file join [file dirname $parentDir] tcl$ver library]\n\
99        lappend dirs [file join [file dirname [file dirname $parentDir]] tcl$ver library]\n\
100    }\n\
101    foreach i $dirs {\n\
102        set tcl_library $i\n\
103        set tclfile [file join $i init.tcl]\n\
104        if {[file exists $tclfile]} {\n\
105            if {![catch {uplevel #0 [list source $tclfile]} msg]} {\n\
106                lappend tcl_pkgPath [file dirname $i]\n\
107                return\n\
108            } else {\n\
109                append errors \"$tclfile: $msg\n$errorInfo\n\"\n\
110            }\n\
111        }\n\
112    }\n\
113    set msg \"Can't find a usable init.tcl in the following directories: \n\"\n\
114    append msg \"    $dirs\n\n\"\n\
115    append msg \"$errors\n\n\"\n\
116    append msg \"This probably means that Tcl wasn't installed properly.\n\"\n\
117    error $msg\n\
118  }\n\
119}\n\
120tclInit";
121#endif
122
123/*
124 * A pointer to a string that holds an initialization script that if non-NULL
125 * is evaluated in Tcl_Init() prior to the the built-in initialization script
126 * above.  This variable can be modified by the procedure below.
127 */
128 
129static char *          tclPreInitScript = NULL;
130
131
132/*
133 *----------------------------------------------------------------------
134 *
135 * TclSetPreInitScript --
136 *
137 *      This routine is used to change the value of the internal
138 *      variable, tclPreInitScript.
139 *
140 * Results:
141 *      Returns the current value of tclPreInitScript.
142 *
143 * Side effects:
144 *      Changes the way Tcl_Init() routine behaves.
145 *
146 *----------------------------------------------------------------------
147 */
148
149char *
150TclSetPreInitScript (string)
151    char *string;               /* Pointer to a script. */
152{
153    char *prevString = tclPreInitScript;
154    tclPreInitScript = string;
155    return(prevString);
156}
Note: See TracBrowser for help on using the browser.