summaryrefslogtreecommitdiffstats
path: root/mac/tclMacInit.c
diff options
context:
space:
mode:
authordas <das>2001-12-27 22:46:12 (GMT)
committerdas <das>2001-12-27 22:46:12 (GMT)
commitd279f3a31ab8738baedcb41295db291eb30ab96d (patch)
treea7d7b1a3c9226183e19b18f421be4f6a4e15a52c /mac/tclMacInit.c
parent275fcdde3fa7cacfabb89aaa4b4f6e9c513f217b (diff)
downloadtcl-d279f3a31ab8738baedcb41295db291eb30ab96d.zip
tcl-d279f3a31ab8738baedcb41295db291eb30ab96d.tar.gz
tcl-d279f3a31ab8738baedcb41295db291eb30ab96d.tar.bz2
* mac/tclMacInit.c:
* mac/tclMacTclCode.r: synced up tclInit features to unix/win: implemented TclSetPreInitScript support, use of existing tclInit proc if defined, check of default encoding dir if set. Changed script library resource names to lowercase (i.e. same as corresponding files). Used Tcl_JoinPath instead of string append. Check that system encoding could be loaded before utf translating the LibraryPath. * mac/tclMacApplication.r: * mac/tclMacLibrary.r: * mac/tclMacOSA.r: * mac/tclMacResource.r: minor version resources cleanup
Diffstat (limited to 'mac/tclMacInit.c')
-rw-r--r--mac/tclMacInit.c85
1 files changed, 58 insertions, 27 deletions
diff --git a/mac/tclMacInit.c b/mac/tclMacInit.c
index eb6a066..b10a0bd 100644
--- a/mac/tclMacInit.c
+++ b/mac/tclMacInit.c
@@ -8,7 +8,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclMacInit.c,v 1.5 2001/07/31 19:12:07 vincentdarley Exp $
+ * RCS: @(#) $Id: tclMacInit.c,v 1.6 2001/12/27 22:46:19 das Exp $
*/
#include <AppleEvents.h>
@@ -25,6 +25,7 @@
#include "tclInt.h"
#include "tclMacInt.h"
#include "tclPort.h"
+#include "tclInitScript.h"
/*
* The following string is the startup script executed in new
@@ -33,9 +34,10 @@
* init.tcl script does all of the real work of initialization.
*/
-static char initCmd[] = "\
+static char initCmd[] = "if {[info proc tclInit]==\"\"} {\n\
+proc tclInit {} {\n\
+global tcl_pkgPath env\n\
proc sourcePath {file} {\n\
- set dirs {}\n\
foreach i $::auto_path {\n\
set init [file join $i $file.tcl]\n\
if {[catch {uplevel #0 [list source $init]}] == 0} {\n\
@@ -46,25 +48,28 @@ proc sourcePath {file} {\n\
return\n\
}\n\
rename sourcePath {}\n\
- set msg \"can't find $file resource or a usable $file.tcl file\n\"\n\
- append msg \"in the following directories:\n\"\n\
- append msg \" $::auto_path\n\"\n\
- append msg \" perhaps you need to install Tcl or set your \n\"\n\
- append msg \"TCL_LIBRARY environment variable?\"\n\
+ set msg \"Can't find $file resource or a usable $file.tcl file\"\n\
+ append msg \" in the following directories:\"\n\
+ append msg \" $::auto_path\"\n\
+ append msg \" perhaps you need to install Tcl or set your\"\n\
+ append msg \" TCL_LIBRARY environment variable?\"\n\
error $msg\n\
}\n\
if {[info exists env(EXT_FOLDER)]} {\n\
- lappend tcl_pkgPath [file join $env(EXT_FOLDER) {:Tool Command Language}]\n\
+ lappend tcl_pkgPath [file join $env(EXT_FOLDER) {Tool Command Language}]\n\
}\n\
if {[info exists tcl_pkgPath] == 0} {\n\
set tcl_pkgPath {no extension folder}\n\
}\n\
-sourcePath Init\n\
-sourcePath Auto\n\
-sourcePath Package\n\
-sourcePath History\n\
-sourcePath Word\n\
-rename sourcePath {}";
+sourcePath init\n\
+sourcePath auto\n\
+sourcePath package\n\
+sourcePath history\n\
+sourcePath word\n\
+sourcePath parray\n\
+rename sourcePath {}\n\
+} }\n\
+tclInit";
/*
* The following structures are used to map the script/language codes of a
@@ -356,13 +361,23 @@ TclpInitLibraryPath(argv0)
pathPtr = Tcl_NewObj();
+ /*
+ * Look for the library relative to default encoding dir.
+ */
+
+ str = Tcl_GetDefaultEncodingDir();
+ if ((str != NULL) && (str[0] != '\0')) {
+ objPtr = Tcl_NewStringObj(str, -1);
+ Tcl_ListObjAppendElement(NULL, pathPtr, objPtr);
+ }
+
str = TclGetEnv("TCL_LIBRARY", &ds);
if ((str != NULL) && (str[0] != '\0')) {
/*
* If TCL_LIBRARY is set, search there.
*/
- objPtr = Tcl_NewStringObj(str, -1);
+ objPtr = Tcl_NewStringObj(str, Tcl_DStringLength(&ds));
Tcl_ListObjAppendElement(NULL, pathPtr, objPtr);
Tcl_DStringFree(&ds);
}
@@ -374,18 +389,27 @@ TclpInitLibraryPath(argv0)
/*
* lappend path [file join $env(EXT_FOLDER) \
- * ":Tool Command Language:tcl[info version]"
+ * "Tool Command Language" "tcl[info version]"
*/
str = TclGetEnv("EXT_FOLDER", &ds);
if ((str != NULL) && (str[0] != '\0')) {
- objPtr = Tcl_NewStringObj(str, -1);
- if (str[strlen(str) - 1] != ':') {
- Tcl_AppendToObj(objPtr, ":", 1);
- }
- Tcl_AppendToObj(objPtr, "Tool Command Language:tcl" TCL_VERSION, -1);
- Tcl_ListObjAppendElement(NULL, pathPtr, objPtr);
- Tcl_DStringFree(&ds);
+ Tcl_DString libPath, path;
+ char *argv[3];
+
+ argv[0] = str;
+ argv[1] = "Tool Command Language";
+ Tcl_DStringInit(&libPath);
+ Tcl_DStringAppend(&libPath, "tcl", -1);
+ Tcl_DStringAppend(&libPath, TCL_VERSION, -1);
+ argv[2] = Tcl_DStringValue(&libPath);
+ Tcl_DStringInit(&path);
+ str = Tcl_JoinPath(3, argv, &path);
+ objPtr = Tcl_NewStringObj(str, Tcl_DStringLength(&path));
+ Tcl_ListObjAppendElement(NULL, pathPtr, objPtr);
+ Tcl_DStringFree(&ds);
+ Tcl_DStringFree(&libPath);
+ Tcl_DStringFree(&path);
}
TclSetLibraryPath(pathPtr);
}
@@ -419,7 +443,7 @@ TclpSetInitialEncodings()
{
CONST char *encoding;
Tcl_Obj *pathPtr;
- int fontId;
+ int fontId, err;
fontId = 0;
GetFinderFont(&fontId);
@@ -428,9 +452,9 @@ TclpSetInitialEncodings()
encoding = "macRoman";
}
- Tcl_SetSystemEncoding(NULL, encoding);
+ err = Tcl_SetSystemEncoding(NULL, encoding);
- if (libraryPathEncodingFixed == 0) {
+ if (err == TCL_OK && libraryPathEncodingFixed == 0) {
/*
* Until the system encoding was actually set, the library path was
@@ -472,6 +496,7 @@ TclpSetInitialEncodings()
Tcl_DStringLength(&ds));
Tcl_DStringFree(&ds);
}
+ Tcl_InvalidateStringRep(pathPtr);
}
libraryPathEncodingFixed = 1;
}
@@ -669,6 +694,12 @@ Tcl_Init(
{
Tcl_Obj *pathPtr;
+ if (tclPreInitScript != NULL) {
+ if (Tcl_Eval(interp, tclPreInitScript) == TCL_ERROR) {
+ return (TCL_ERROR);
+ };
+ }
+
/*
* For Macintosh applications the Init function may be contained in
* the application resources. If it exists we use it - otherwise we