*** mac/tkMacInit.c.orig	Fri Apr 16 03:51:31 1999
--- mac/tkMacInit.c	Sun Jan 16 17:43:06 2000
***************
*** 32,37 ****
--- 32,170 ----
  QDGlobalsPtr tcl_macQdPtr = NULL;
  
  /*
+  * Default directory in which to look for libraries:
+  */
+ 
+ #ifndef TK_LIBRARY
+ #define TK_LIBRARY "."
+ #endif
+ 
+ static char defaultLibraryDir[200] = TK_LIBRARY;
+ 
+ /*
+  * The following string is the startup script executed in new
+  * interpreters.  It looks on disk in several different directories
+  * for a script "tk.tcl" that is compatible with this version
+  * of Tk.  The tk.tcl script does all of the real work of
+  * initialization.
+  */
+ 
+ static char initScript[] =
+ "proc tkInit {} {\n\
+     global tk_library tk_version tk_patchLevel env\n\
+     set errors \"\"\n\
+     rename tkInit {}\n\
+     set dirs {}\n\
+     if [info exists env(TK_LIBRARY)] {\n\
+ 	lappend dirs $env(TK_LIBRARY)\n\
+     }\n\
+     lappend dirs $tk_library\n\
+     set tk_library {}\n\
+     if ![catch {uplevel #0 source -rsrc tk}] {\n\
+ 	uplevel #0 {\n\
+     	    source -rsrc button\n\
+     	    source -rsrc entry\n\
+     	    source -rsrc listbox\n\
+     	    source -rsrc menu\n\
+     	    source -rsrc scale\n\
+     	    source -rsrc scrollbar\n\
+     	    source -rsrc text\n\
+     	    source -rsrc dialog\n\
+     	    source -rsrc focus\n\
+     	    source -rsrc optionMenu\n\
+     	    source -rsrc palette\n\
+     	    source -rsrc tearoff\n\
+     	    source -rsrc tkerror\n\
+     	    source -rsrc comdlg\n\
+     	    source -rsrc msgbox\n\\n\
+ 	}\n\
+ 	return\n\
+     }\n\
+     lappend dirs [file join [file dirname [info library]] tk$tk_version]\n\
+     set parentDir [file dirname [file dirname [info nameofexecutable]]]\n\
+     lappend dirs [file join $parentDir lib tk$tk_version]\n\
+     if {![regexp {.*[ab][12345]} $tk_patchLevel version]} {\n\
+ 	set version $tk_version\n\
+     }\n\
+     lappend dirs [file join [file dirname $parentDir] tk$version library]\n\
+     lappend dirs [file join $parentDir library]\n\
+     foreach i $dirs {\n\
+ 	set tk_library $i\n\
+ 	if ![catch {uplevel #0 source [list [file join $i tk.tcl]]}] {\n\
+ 	    return\n\
+ 	} else {\n\
+ 	    append errors \"[file join $i tk.tcl]: $msg\n$errorInfo\n\"\n\
+ 	}\n\
+     }\n\
+     set tk_library {}\n\
+     set msg \"Can't find a usable tk.tcl in the following directories: \n\"\n\
+     append msg \"    $dirs\n\"\n\
+     append msg \"This probably means that Tk wasn't installed properly.\n\"\n\
+     error $msg\n\
+ }\n\
+ tkInit";
+ 
+ /*
+  * The following script is used to initialize Tk in a safe interpreter.
+  */
+ 
+ static char safeInitScript[] =
+ "proc tkInit {} {\n\
+     global tk_library tk_version tk_patchLevel env\n\
+     set errors \"\"\n\
+     rename tkInit {}\n\
+     set dirs {}\n\
+     if [info exists env(TK_LIBRARY)] {\n\
+ 	lappend dirs $env(TK_LIBRARY)\n\
+     }\n\
+     lappend dirs $tk_library\n\
+     set tk_library {}\n\
+     if ![catch {uplevel #0 source -rsrc tk}] {\n\
+ 	uplevel #0 {\n\
+     	    source -rsrc button\n\
+     	    source -rsrc entry\n\
+     	    source -rsrc listbox\n\
+     	    source -rsrc menu\n\
+     	    source -rsrc scale\n\
+     	    source -rsrc scrollbar\n\
+     	    source -rsrc text\n\
+     	    source -rsrc dialog\n\
+     	    source -rsrc focus\n\
+     	    source -rsrc optionMenu\n\
+     	    source -rsrc palette\n\
+     	    source -rsrc tearoff\n\
+     	    source -rsrc tkerror\n\
+     	    source -rsrc comdlg\n\
+     	    source -rsrc msgbox\n\\n\
+ 	}\n\
+ 	return\n\
+     }\n\
+     lappend dirs [file join [file dirname [info library]] tk$tk_version]\n\
+     set parentDir [file dirname [file dirname [info nameofexecutable]]]\n\
+     lappend dirs [file join $parentDir lib tk$tk_version]\n\
+     if {![regexp {.*[ab][1-9]} $tk_patchLevel version]} {\n\
+ 	set version $tk_version\n\
+     }\n\
+     lappend dirs [file join [file dirname [file dirname [info library]]] tk$version library]\n\
+     foreach i $dirs {\n\
+ 	set tk_library $i\n\
+ 	if ![catch {uplevel #0 source [list [file join $i tk.tcl]]}] {\n\
+ 	    return\n\
+ 	} else {\n\
+ 	    append errors \"[file join $i tk.tcl]: $msg\n$errorInfo\n\"\n\
+ 	}\n\
+     }\n\
+     set tk_library {}\n\
+     set msg \"Can't find a usable tk.tcl in the following directories: \n\"\n\
+     append msg \"    $dirs\n\n\"\n\
+     append msg \"$errors\n\n\"\n\
+     append msg \"This probably means that Tk wasn't installed properly.\n\"\n\
+     error $msg\n\
+ }\n\
+ tkInit";
+ 
+ 
+ /*
   *----------------------------------------------------------------------
   *
   * TkpInit --
***************
*** 58,102 ****
      Tcl_DString path;
      int result;
  
-     /*
-      * The following does not work with
-      * safe interps because file exists is restricted.
-      * to be fixed using [interp issafe] like in Unix & Windows.
-      */
-     static char initCmd[] =
- 	"if [file exists $tk_library:tk.tcl] {\n\
- 	    source $tk_library:tk.tcl\n\
- 	    source $tk_library:button.tcl\n\
- 	    source $tk_library:entry.tcl\n\
- 	    source $tk_library:listbox.tcl\n\
- 	    source $tk_library:menu.tcl\n\
- 	    source $tk_library:scale.tcl\n\
- 	    source $tk_library:scrlbar.tcl\n\
- 	    source $tk_library:text.tcl\n\
- 	    source $tk_library:comdlg.tcl\n\
- 	    source $tk_library:msgbox.tcl\n\
- 	} else {\n\
- 	    set msg \"can't find tk resource or $tk_library:tk.tcl;\"\n\
- 	    append msg \" perhaps you need to\\ninstall Tk or set your \"\n\
- 	    append msg \"TK_LIBRARY environment variable?\"\n\
- 	    error $msg\n\
- 	}";
- 
      Tcl_DStringInit(&path);
  
      /*
       * The tk_library path can be found in several places.  Here is the order
       * in which the are searched.
       *		1) the variable may already exist
!      *		2) env array
!      *		3) System Folder:Extensions:Tool Command Language:
       */
!      
      libDir = Tcl_GetVar(interp, "tk_library", TCL_GLOBAL_ONLY);
      if (libDir == NULL) {
- 	libDir = Tcl_GetVar2(interp, "env", "TK_LIBRARY", TCL_GLOBAL_ONLY);
-     }
-     if (libDir == NULL) {
  	tempPath = Tcl_GetVar2(interp, "env", "EXT_FOLDER", TCL_GLOBAL_ONLY);
  	if (tempPath != NULL) {
  	    Tcl_DString libPath;
--- 191,208 ----
      Tcl_DString path;
      int result;
  
      Tcl_DStringInit(&path);
  
      /*
       * The tk_library path can be found in several places.  Here is the order
       * in which the are searched.
       *		1) the variable may already exist
!      *		2) System Folder:Extensions:Tool Command Language:
!      *		3) env array
       */
! 
      libDir = Tcl_GetVar(interp, "tk_library", TCL_GLOBAL_ONLY);
      if (libDir == NULL) {
  	tempPath = Tcl_GetVar2(interp, "env", "EXT_FOLDER", TCL_GLOBAL_ONLY);
  	if (tempPath != NULL) {
  	    Tcl_DString libPath;
***************
*** 112,118 ****
  	}
      }
      if (libDir == NULL) {
! 	libDir = "no library";
      }
  
      /*
--- 218,224 ----
  	}
      }
      if (libDir == NULL) {
! 	libDir = "";
      }
  
      /*
***************
*** 121,151 ****
      Tcl_SetVar(interp, "tk_library", libDir, TCL_GLOBAL_ONLY);
      Tcl_DStringFree(&path);
  
!     /*
!      * Source the needed Tk libraries from the resource
!      * fork of the application.
!      */
!     result = Tcl_MacEvalResource(interp, "tk", 0, NULL);
!     result |= Tcl_MacEvalResource(interp, "button", 0, NULL);
!     result |= Tcl_MacEvalResource(interp, "entry", 0, NULL);
!     result |= Tcl_MacEvalResource(interp, "listbox", 0, NULL);
!     result |= Tcl_MacEvalResource(interp, "menu", 0, NULL);
!     result |= Tcl_MacEvalResource(interp, "scale", 0, NULL);
!     result |= Tcl_MacEvalResource(interp, "scrollbar", 0, NULL);
!     result |= Tcl_MacEvalResource(interp, "text", 0, NULL);
!     result |= Tcl_MacEvalResource(interp, "dialog", 0, NULL);
!     result |= Tcl_MacEvalResource(interp, "focus", 0, NULL);
!     result |= Tcl_MacEvalResource(interp, "optionMenu", 0, NULL);
!     result |= Tcl_MacEvalResource(interp, "palette", 0, NULL);
!     result |= Tcl_MacEvalResource(interp, "tearoff", 0, NULL);
!     result |= Tcl_MacEvalResource(interp, "tkerror", 0, NULL);
!     result |= Tcl_MacEvalResource(interp, "comdlg", 0, NULL);
!     result |= Tcl_MacEvalResource(interp, "msgbox", 0, NULL);
! 
!     if (result != TCL_OK) {
! 	result = Tcl_Eval(interp, initCmd);
      }
!     return result;
  }
  
  /*
--- 227,236 ----
      Tcl_SetVar(interp, "tk_library", libDir, TCL_GLOBAL_ONLY);
      Tcl_DStringFree(&path);
  
!     if (doSafe) {
! 	return Tcl_Eval(interp, safeInitScript);
      }
!     return Tcl_Eval(interp, initScript);
  }
  
  /*
