tclInitScript.h
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:3k
源码类别:

通讯编程

开发平台:

Visual C++

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