4 * This file contains Unix-specific interpreter initialization
7 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
8 * Copyright 2001, Apple Computer, Inc.
10 * See the file "license.terms" for information on usage and redistribution
11 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
17 #include "tkMacOSXInt.h"
20 * The Init script (common to Windows and Unix platforms) is
21 * defined in tkInitScript.h
23 #include "tkInitScript.h"
26 * The following structures are used to map the script/language codes of a
27 * font to the name that should be passed to Tcl_GetEncoding() to obtain
28 * the encoding for that font. The set of numeric constants is fixed and
37 static Map scriptMap[] = {
38 {smRoman, "macRoman"},
39 {smJapanese, "macJapan"},
40 {smTradChinese, "macChinese"},
41 {smKorean, "macKorean"},
42 {smArabic, "macArabic"},
43 {smHebrew, "macHebrew"},
44 {smGreek, "macGreek"},
45 {smCyrillic, "macCyrillic"},
46 {smRSymbol, "macRSymbol"},
47 {smDevanagari, "macDevanagari"},
48 {smGurmukhi, "macGurmukhi"},
49 {smGujarati, "macGujarati"},
50 {smOriya, "macOriya"},
51 {smBengali, "macBengali"},
52 {smTamil, "macTamil"},
53 {smTelugu, "macTelugu"},
54 {smKannada, "macKannada"},
55 {smMalayalam, "macMalayalam"},
56 {smSinhalese, "macSinhalese"},
57 {smBurmese, "macBurmese"},
58 {smKhmer, "macKhmer"},
59 {smThai, "macThailand"},
60 {smLaotian, "macLaos"},
61 {smGeorgian, "macGeorgia"},
62 {smArmenian, "macArmenia"},
63 {smSimpChinese, "macSimpChinese"},
64 {smTibetan, "macTIbet"},
65 {smMongolian, "macMongolia"},
66 {smGeez, "macEthiopia"},
67 {smEastEurRoman, "macCentEuro"},
68 {smVietnamese, "macVietnam"},
69 {smExtArabic, "macSindhi"},
73 Tcl_Encoding TkMacOSXCarbonEncoding = NULL;
77 *----------------------------------------------------------------------
81 * Performs Mac-specific interpreter initialization related to the
82 * tk_library variable.
85 * Returns a standard Tcl result. Leaves an error message or result
86 * in the interp's result.
89 * Sets "tk_library" Tcl variable, runs "tk.tcl" script.
91 *----------------------------------------------------------------------
100 static int menusInitialized = false;
101 static int carbonEncodingInitialized = false;
104 * Since it is possible for TkInit to be called multiple times
105 * and we don't want to do the menu initialization multiple times
106 * we protect against doing it more than once.
109 if (menusInitialized == false) {
110 menusInitialized = true;
111 Tk_MacOSXSetupTkNotifier();
112 TkMacOSXInitAppleEvents(interp);
113 TkMacOSXInitMenus(interp);
116 if (carbonEncodingInitialized == false) {
117 CFStringEncoding encoding;
118 char *encodingStr = NULL;
121 encoding = CFStringGetSystemEncoding();
123 for (i = 0; scriptMap[i].strKey != NULL; i++) {
124 if (scriptMap[i].numKey == encoding) {
125 encodingStr = scriptMap[i].strKey;
129 if (encodingStr == NULL) {
130 encodingStr = "macRoman";
133 TkMacOSXCarbonEncoding = Tcl_GetEncoding (NULL, encodingStr);
134 if (TkMacOSXCarbonEncoding == NULL) {
135 TkMacOSXCarbonEncoding = Tcl_GetEncoding (NULL, NULL);
140 * When Tk is in a framework, force tcl_findLibrary to look in the
141 * framework scripts directory.
142 * FIXME: Should we come up with a more generic way of doing this?
145 result = Tcl_MacOSXOpenBundleResources(interp, "com.tcltk.tklibrary",
148 if (result != TCL_ERROR) {
149 Tcl_SetVar(interp, "tk_library", tkLibPath, TCL_GLOBAL_ONLY);
152 return Tcl_Eval(interp, initScript);
156 *----------------------------------------------------------------------
160 * Retrieves the name of the current application from a platform
161 * specific location. For Unix, the application name is the tail
162 * of the path contained in the tcl variable argv0.
165 * Returns the application name in the given Tcl_DString.
170 *----------------------------------------------------------------------
174 TkpGetAppName(interp, namePtr)
176 Tcl_DString *namePtr; /* A previously initialized Tcl_DString. */
178 CONST char *p, *name;
180 name = Tcl_GetVar(interp, "argv0", TCL_GLOBAL_ONLY);
181 if ((name == NULL) || (*name == 0)) {
184 p = strrchr(name, '/');
189 Tcl_DStringAppend(namePtr, name, -1);
193 *----------------------------------------------------------------------
195 * TkpDisplayWarning --
197 * This routines is called from Tk_Main to display warning
198 * messages that occur during startup.
204 * Generates messages on stdout.
206 *----------------------------------------------------------------------
210 TkpDisplayWarning(msg, title)
211 CONST char *msg; /* Message to be displayed. */
212 CONST char *title; /* Title of warning. */
214 Tcl_Channel errChannel = Tcl_GetStdChannel(TCL_STDERR);
216 Tcl_WriteChars(errChannel, title, -1);
217 Tcl_WriteChars(errChannel, ": ", 2);
218 Tcl_WriteChars(errChannel, msg, -1);
219 Tcl_WriteChars(errChannel, "\n", 1);