os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/generic/tclInitScript.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/* 
sl@0
     2
 * tclInitScript.h --
sl@0
     3
 *
sl@0
     4
 *	This file contains Unix & Windows common init script
sl@0
     5
 *      It is not used on the Mac. (the mac init script is in tclMacInit.c)
sl@0
     6
 *
sl@0
     7
 * Copyright (c) 1998 Sun Microsystems, Inc.
sl@0
     8
 * Copyright (c) 1999 by Scriptics Corporation.
sl@0
     9
 * All rights reserved.
sl@0
    10
 *
sl@0
    11
 * RCS: @(#) $Id: tclInitScript.h,v 1.13 2001/09/10 21:06:55 dgp Exp $
sl@0
    12
 */
sl@0
    13
sl@0
    14
/*
sl@0
    15
 * In order to find init.tcl during initialization, the following script
sl@0
    16
 * is invoked by Tcl_Init().  It looks in several different directories:
sl@0
    17
 *
sl@0
    18
 *	$tcl_library		- can specify a primary location, if set
sl@0
    19
 *				  no other locations will be checked
sl@0
    20
 *
sl@0
    21
 *	$env(TCL_LIBRARY)	- highest priority so user can always override
sl@0
    22
 *				  the search path unless the application has
sl@0
    23
 *				  specified an exact directory above
sl@0
    24
 *
sl@0
    25
 *	$tclDefaultLibrary	- this value is initialized by TclPlatformInit
sl@0
    26
 *				  from a static C variable that was set at
sl@0
    27
 *				  compile time
sl@0
    28
 *
sl@0
    29
 *	$tcl_libPath		- this value is initialized by a call to
sl@0
    30
 *				  TclGetLibraryPath called from Tcl_Init.
sl@0
    31
 *
sl@0
    32
 * The first directory on this path that contains a valid init.tcl script
sl@0
    33
 * will be set as the value of tcl_library.
sl@0
    34
 *
sl@0
    35
 * Note that this entire search mechanism can be bypassed by defining an
sl@0
    36
 * alternate tclInit procedure before calling Tcl_Init().
sl@0
    37
 */
sl@0
    38
sl@0
    39
static char initScript[] = "if {[info proc tclInit]==\"\"} {\n\
sl@0
    40
  proc tclInit {} {\n\
sl@0
    41
    global tcl_libPath tcl_library errorInfo\n\
sl@0
    42
    global env tclDefaultLibrary\n\
sl@0
    43
    rename tclInit {}\n\
sl@0
    44
    set errors {}\n\
sl@0
    45
    set dirs {}\n\
sl@0
    46
    if {[info exists tcl_library]} {\n\
sl@0
    47
	lappend dirs $tcl_library\n\
sl@0
    48
    } else {\n\
sl@0
    49
	if {[info exists env(TCL_LIBRARY)]} {\n\
sl@0
    50
	    lappend dirs $env(TCL_LIBRARY)\n\
sl@0
    51
	}\n\
sl@0
    52
	catch {\n\
sl@0
    53
	    lappend dirs $tclDefaultLibrary\n\
sl@0
    54
	    unset tclDefaultLibrary\n\
sl@0
    55
	}\n\
sl@0
    56
        set dirs [concat $dirs $tcl_libPath]\n\
sl@0
    57
    }\n\
sl@0
    58
    foreach i $dirs {\n\
sl@0
    59
	set tcl_library $i\n\
sl@0
    60
	set tclfile [file join $i init.tcl]\n\
sl@0
    61
	if {[file exists $tclfile]} {\n\
sl@0
    62
	    if {![catch {uplevel #0 [list source $tclfile]} msg]} {\n\
sl@0
    63
		return\n\
sl@0
    64
	    } else {\n\
sl@0
    65
		append errors \"$tclfile: $msg\n$errorInfo\n\"\n\
sl@0
    66
	    }\n\
sl@0
    67
	}\n\
sl@0
    68
    }\n\
sl@0
    69
    set msg \"Can't find a usable init.tcl in the following directories: \n\"\n\
sl@0
    70
    append msg \"    $dirs\n\n\"\n\
sl@0
    71
    append msg \"$errors\n\n\"\n\
sl@0
    72
    append msg \"This probably means that Tcl wasn't installed properly.\n\"\n\
sl@0
    73
    error $msg\n\
sl@0
    74
  }\n\
sl@0
    75
}\n\
sl@0
    76
tclInit";
sl@0
    77
sl@0
    78
sl@0
    79
/*
sl@0
    80
 * A pointer to a string that holds an initialization script that if non-NULL
sl@0
    81
 * is evaluated in Tcl_Init() prior to the the built-in initialization script
sl@0
    82
 * above.  This variable can be modified by the procedure below.
sl@0
    83
 */
sl@0
    84
 
sl@0
    85
static char *          tclPreInitScript = NULL;
sl@0
    86
sl@0
    87

sl@0
    88
/*
sl@0
    89
 *----------------------------------------------------------------------
sl@0
    90
 *
sl@0
    91
 * TclSetPreInitScript --
sl@0
    92
 *
sl@0
    93
 *	This routine is used to change the value of the internal
sl@0
    94
 *	variable, tclPreInitScript.
sl@0
    95
 *
sl@0
    96
 * Results:
sl@0
    97
 *	Returns the current value of tclPreInitScript.
sl@0
    98
 *
sl@0
    99
 * Side effects:
sl@0
   100
 *	Changes the way Tcl_Init() routine behaves.
sl@0
   101
 *
sl@0
   102
 *----------------------------------------------------------------------
sl@0
   103
 */
sl@0
   104
sl@0
   105
char *
sl@0
   106
TclSetPreInitScript (string)
sl@0
   107
    char *string;		/* Pointer to a script. */
sl@0
   108
{
sl@0
   109
    char *prevString = tclPreInitScript;
sl@0
   110
    tclPreInitScript = string;
sl@0
   111
    return(prevString);
sl@0
   112
}