#include <Files.h>
#include <Gestalt.h>
#include <TextUtils.h>
#include <Resources.h>
#include <Strings.h>
#include "tclInt.h"
#include "tclMacInt.h"
void
TclPlatformInit(
Tcl_Interp *interp)
{
char *libDir;
Tcl_DString path, libPath;
long int gestaltResult;
int minor, major;
char versStr[10];
tclPlatform = TCL_PLATFORM_MAC;
Tcl_SetVar2(interp, "tcl_platform", "platform", "macintosh",
TCL_GLOBAL_ONLY);
Tcl_SetVar2(interp, "tcl_platform", "os", "MacOS", TCL_GLOBAL_ONLY);
Gestalt(gestaltSystemVersion, &gestaltResult);
major = (gestaltResult & 0x0000FF00) >> 8;
minor = (gestaltResult & 0x000000F0) >> 4;
sprintf(versStr, "%d.%d", major, minor);
Tcl_SetVar2(interp, "tcl_platform", "osVersion", versStr, TCL_GLOBAL_ONLY);
#if GENERATINGPOWERPC
Tcl_SetVar2(interp, "tcl_platform", "machine", "ppc", TCL_GLOBAL_ONLY);
#else
Tcl_SetVar2(interp, "tcl_platform", "machine", "68k", TCL_GLOBAL_ONLY);
#endif
Tcl_DStringInit(&path);
libDir = Tcl_GetVar2(interp, "env", "TCL_LIBRARY", TCL_GLOBAL_ONLY);
if (libDir != NULL) {
Tcl_SetVar(interp, "tcl_library", libDir, TCL_GLOBAL_ONLY);
} else {
libDir = Tcl_GetVar2(interp, "env", "EXT_FOLDER", TCL_GLOBAL_ONLY);
if (libDir != NULL) {
Tcl_JoinPath(1, &libDir, &path);
Tcl_DStringInit(&libPath);
Tcl_DStringAppend(&libPath, ":Tool Command Language:tcl", -1);
Tcl_DStringAppend(&libPath, TCL_VERSION, -1);
Tcl_JoinPath(1, &libPath.string, &path);
Tcl_DStringFree(&libPath);
Tcl_SetVar(interp, "tcl_library", path.string, TCL_GLOBAL_ONLY);
} else {
Tcl_SetVar(interp, "tcl_library", "no library", TCL_GLOBAL_ONLY);
}
}
Tcl_DStringSetLength(&path, 0);
libDir = Tcl_GetVar2(interp, "env", "EXT_FOLDER", TCL_GLOBAL_ONLY);
if (libDir != NULL) {
Tcl_JoinPath(1, &libDir, &path);
libDir = ":Tool Command Language:";
Tcl_JoinPath(1, &libDir, &path);
Tcl_SetVar(interp, "tcl_pkgPath", path.string,
TCL_GLOBAL_ONLY|TCL_LIST_ELEMENT);
} else {
Tcl_SetVar(interp, "tcl_pkgPath", "no extension folder",
TCL_GLOBAL_ONLY|TCL_LIST_ELEMENT);
}
Tcl_DStringFree(&path);
}
int
TclpCheckStackSpace()
{
return StackSpace() > TCL_MAC_STACK_THRESHOLD;
}
int
Tcl_Init(
Tcl_Interp *interp)
{
static char initCmd[] =
"if {[catch {source -rsrc Init}] != 0} {\n\
if [file exists [info library]:init.tcl] {\n\
source [info library]:init.tcl\n\
} else {\n\
set msg \"can't find Init resource or [info library]:init.tcl;\"\n\
append msg \" perhaps you need to\\ninstall Tcl or set your \"\n\
append msg \"TCL_LIBRARY environment variable?\"\n\
error $msg\n\
}\n}\n\
if {[catch {source -rsrc History}] != 0} {\n\
if [file exists [info library]:history.tcl] {\n\
source [info library]:history.tcl\n\
} else {\n\
set msg \"can't find History resource or [info library]:history.tcl;\"\n\
append msg \" perhaps you need to\\ninstall Tcl or set your \"\n\
append msg \"TCL_LIBRARY environment variable?\"\n\
error $msg\n\
}\n}\n\
if {[catch {source -rsrc Word}] != 0} {\n\
if [file exists [info library]:word.tcl] {\n\
source [info library]:word.tcl\n\
} else {\n\
set msg \"can't find Word resource or [info library]:word.tcl;\"\n\
append msg \" perhaps you need to\\ninstall Tcl or set your \"\n\
append msg \"TCL_LIBRARY environment variable?\"\n\
error $msg\n\
}\n}";
return Tcl_Eval(interp, initCmd);
}
void
Tcl_SourceRCFile(
Tcl_Interp *interp)
{
Tcl_DString temp;
char *fileName;
Tcl_Channel errChannel;
Handle h;
fileName = Tcl_GetVar(interp, "tcl_rcFileName", TCL_GLOBAL_ONLY);
if (fileName != NULL) {
Tcl_Channel c;
char *fullName;
Tcl_DStringInit(&temp);
fullName = Tcl_TranslateFileName(interp, fileName, &temp);
if (fullName == NULL) {
} else {
c = Tcl_OpenFileChannel(NULL, fullName, "r", 0);
if (c != (Tcl_Channel) NULL) {
Tcl_Close(NULL, c);
if (Tcl_EvalFile(interp, fullName) != TCL_OK) {
errChannel = Tcl_GetStdChannel(TCL_STDERR);
if (errChannel) {
Tcl_Write(errChannel, interp->result, -1);
Tcl_Write(errChannel, "\n", 1);
}
}
}
}
Tcl_DStringFree(&temp);
}
fileName = Tcl_GetVar(interp, "tcl_rcRsrcName", TCL_GLOBAL_ONLY);
if (fileName != NULL) {
c2pstr(fileName);
h = GetNamedResource('TEXT', (StringPtr) fileName);
p2cstr((StringPtr) fileName);
if (h != NULL) {
if (Tcl_MacEvalResource(interp, fileName, 0, NULL) != TCL_OK) {
errChannel = Tcl_GetStdChannel(TCL_STDERR);
if (errChannel) {
Tcl_Write(errChannel, interp->result, -1);
Tcl_Write(errChannel, "\n", 1);
}
}
Tcl_ResetResult(interp);
ReleaseResource(h);
}
}
}