OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tcl/] [generic/] [tclInitScript.h] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/*
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
 * RCS: @(#) $Id: tclInitScript.h,v 1.1.1.1 2002-01-16 10:25:27 markom Exp $
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 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
 
65
static char initScript[] = "if {[info proc tclInit]==\"\"} {\n\
66
  proc tclInit {} {\n\
67
    global tcl_library tcl_version tcl_patchLevel errorInfo\n\
68
    global tcl_pkgPath env tclDefaultLibrary\n\
69
    global tcl_platform\n\
70
    rename tclInit {}\n\
71
    set errors {}\n\
72
    set dirs {}\n\
73
    if {[info exists tcl_library]} {\n\
74
        lappend dirs $tcl_library\n\
75
    } else {\n\
76
        if {[info exists env(TCL_LIBRARY)]} {\n\
77
            lappend dirs $env(TCL_LIBRARY)\n\
78
        }\n\
79
        # CYGNUS LOCAL: I've changed this alot.  \n\
80
        # Basically we only care about two cases,\n\
81
        # if we are installed, and if we are in the devo tree...\n\
82
        # The next few are for if we are installed:\n\
83
        # NB. We also want this to work if the user is actually\n\
84
        # running a link and not the actual program.  So look for a\n\
85
        # link and chase it down to its source.\n\
86
        set execName [info nameofexecutable]\n\
87
        if {[string compare [file type $execName] \"link\"] == 0} {\n\
88
            set execName [file readlink $execName]\n\
89
            if {[string compare [file pathtype $execName] \"relative\"] == 0} {\n\
90
              set execName [file join [pwd] $execName]\n\
91
            }\n\
92
        }\n\
93
        set parentDir [file dirname [file dirname $execName]]\n\
94
        lappend dirs [file join $parentDir share tcl$tcl_version]\n\
95
        lappend dirs [file join $parentDir \"usr\" share tcl$tcl_version]\n\
96
        lappend dirs [file join [file dirname $parentDir] share tcl$tcl_version]\n\
97
        # NOW, let's try to find it in the build tree...\n\
98
        # Rather than play all the games Scriptics does, if we are in the build\n\
99
        # tree there will be a tclConfig.sh relative to the executible's directory, and we \n\
100
        # can read it and get the source dir from there...\n\
101
        #\n\
102
        # We duplicate all the directories in the search, one w/o the version and one with.\n\
103
        # Most modules use ../../tcl/{unix,win}\n\
104
        lappend configDirs [file join [file dirname $parentDir] tcl$tcl_version $tcl_platform(platform)]\n\
105
        lappend configDirs [file join [file dirname $parentDir] tcl             $tcl_platform(platform)]\n\
106
        # This one gets tclsh...\n\
107
        lappend configDirs $execName \n\
108
        # This one is for gdb, and any other app which has its executible in the top directory.\n\
109
        lappend configDirs [file join $parentDir tcl$tcl_version $tcl_platform(platform)]\n\
110
        lappend configDirs [file join $parentDir tcl             $tcl_platform(platform)]\n\
111
        # This last will handle itclsh & itkwish (../../../tcl/{unix,win}):\n\
112
        lappend configDirs [file join [file dirname [file dirname $parentDir]] tcl$tcl_version $tcl_platform(platform)]\n\
113
        lappend configDirs [file join [file dirname [file dirname $parentDir]] tcl             $tcl_platform(platform)]\n\
114
        \n\
115
        foreach i $configDirs {\n\
116
            set configFile [file join $i tclConfig.sh]\n\
117
            if {[file exists $configFile]} {\n\
118
                if {![catch {open $configFile r} fileH]} {\n\
119
                    set srcDir {}\n\
120
                    while {[gets $fileH line] >= 0} {\n\
121
                        if {[regexp {^TCL_SRC_DIR='([^']*)'} $line dummy srcDir]} {\n\
122
                            break\n\
123
                        }\n\
124
                    }\n\
125
                    close $fileH\n\
126
                    if {$srcDir != \"\"} {\n\
127
                        lappend dirs [file join $srcDir library]\n\
128
                        break\n\
129
                    }\n\
130
                }\n\
131
            }\n\
132
        }\n\
133
    }\n\
134
    # I also moved this from just after TCL_LIBRARY to last.\n\
135
    # I only want to use the compiled in library if I am really lost, because\n\
136
    # otherwise if I have installed once, but am working in the build directory,\n\
137
    # I will always pick up the installed files, which will be very confusing...\n\
138
    lappend dirs $tclDefaultLibrary\n\
139
    unset tclDefaultLibrary\n\
140
    foreach i $dirs {\n\
141
        set tcl_library $i\n\
142
        set tclfile [file join $i init.tcl]\n\
143
        if {[file exists $tclfile]} {\n\
144
            if {![catch {uplevel #0 [list source $tclfile]} msg]} {\n\
145
                return\n\
146
            } else {\n\
147
                append errors \"$tclfile: $msg\n$errorInfo\n\"\n\
148
            }\n\
149
            set tcl_pkgPath [lreplace $tcl_pkgPath end end]\n\
150
        }\n\
151
    }\n\
152
    set msg \"Can't find a usable init.tcl in the following directories: \n\"\n\
153
    append msg \"    $dirs\n\n\"\n\
154
    append msg \"$errors\n\n\"\n\
155
    append msg \"This probably means that Tcl wasn't installed properly.\n\"\n\
156
    error $msg\n\
157
  }\n\
158
}\n\
159
tclInit";
160
 
161
/*
162
 * A pointer to a string that holds an initialization script that if non-NULL
163
 * is evaluated in Tcl_Init() prior to the the built-in initialization script
164
 * above.  This variable can be modified by the procedure below.
165
 */
166
 
167
static char *          tclPreInitScript = NULL;
168
 
169
 
170
/*
171
 *----------------------------------------------------------------------
172
 *
173
 * TclSetPreInitScript --
174
 *
175
 *      This routine is used to change the value of the internal
176
 *      variable, tclPreInitScript.
177
 *
178
 * Results:
179
 *      Returns the current value of tclPreInitScript.
180
 *
181
 * Side effects:
182
 *      Changes the way Tcl_Init() routine behaves.
183
 *
184
 *----------------------------------------------------------------------
185
 */
186
 
187
char *
188
TclSetPreInitScript (string)
189
    char *string;               /* Pointer to a script. */
190
{
191
    char *prevString = tclPreInitScript;
192
    tclPreInitScript = string;
193
    return(prevString);
194
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.