| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
#if defined(HAVE_CFBUNDLE) |
| 14 |
#include <CoreFoundation/CoreFoundation.h> |
| 15 |
#endif |
| 16 |
#define NO_UNAME |
| 17 |
|
| 18 |
#include "Lang.h" |
| 19 |
#include "tclInt.h" |
| 20 |
#include "tclPort.h" |
| 21 |
#include <locale.h> |
| 22 |
#ifdef HAVE_LANGINFO |
| 23 |
#include <langinfo.h> |
| 24 |
#endif |
| 25 |
#if defined(__FreeBSD__) |
| 26 |
# include <floatingpoint.h> |
| 27 |
#endif |
| 28 |
#if defined(__bsdi__) |
| 29 |
# include <sys/param.h> |
| 30 |
# if _BSDI_VERSION > 199501 |
| 31 |
# include <dlfcn.h> |
| 32 |
# endif |
| 33 |
#endif |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
#include "tclInitScript.h" |
| 40 |
|
| 41 |
|
| 42 |
static Tcl_Encoding binaryEncoding = NULL; |
| 43 |
|
| 44 |
static int libraryPathEncodingFixed = 0; |
| 45 |
|
| 46 |
#if 0 |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
#ifndef TCL_DEFAULT_ENCODING |
| 54 |
#define TCL_DEFAULT_ENCODING "iso8859-1" |
| 55 |
#endif |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
static char defaultLibraryDir[sizeof(TCL_LIBRARY)+200] = TCL_LIBRARY; |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
static char pkgPath[sizeof(TCL_PACKAGE_PATH)+200] = TCL_PACKAGE_PATH; |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
typedef struct LocaleTable { |
| 81 |
CONST char *lang; |
| 82 |
CONST char *encoding; |
| 83 |
} LocaleTable; |
| 84 |
|
| 85 |
static CONST LocaleTable localeTable[] = { |
| 86 |
#ifdef HAVE_LANGINFO |
| 87 |
{"gb2312-1980", "gb2312"}, |
| 88 |
#ifdef __hpux |
| 89 |
{"SJIS", "shiftjis"}, |
| 90 |
{"eucjp", "euc-jp"}, |
| 91 |
{"euckr", "euc-kr"}, |
| 92 |
{"euctw", "euc-cn"}, |
| 93 |
{"greek8", "cp869"}, |
| 94 |
{"iso88591", "iso8859-1"}, |
| 95 |
{"iso88592", "iso8859-2"}, |
| 96 |
{"iso88595", "iso8859-5"}, |
| 97 |
{"iso88596", "iso8859-6"}, |
| 98 |
{"iso88597", "iso8859-7"}, |
| 99 |
{"iso88598", "iso8859-8"}, |
| 100 |
{"iso88599", "iso8859-9"}, |
| 101 |
{"iso885915", "iso8859-15"}, |
| 102 |
{"roman8", "iso8859-1"}, |
| 103 |
{"tis620", "tis-620"}, |
| 104 |
{"turkish8", "cp857"}, |
| 105 |
{"utf8", "utf-8"}, |
| 106 |
#endif |
| 107 |
#endif |
| 108 |
|
| 109 |
{"ja_JP.SJIS", "shiftjis"}, |
| 110 |
{"ja_JP.EUC", "euc-jp"}, |
| 111 |
{"ja_JP.eucJP", "euc-jp"}, |
| 112 |
{"ja_JP.JIS", "iso2022-jp"}, |
| 113 |
{"ja_JP.mscode", "shiftjis"}, |
| 114 |
{"ja_JP.ujis", "euc-jp"}, |
| 115 |
{"ja_JP", "euc-jp"}, |
| 116 |
{"Ja_JP", "shiftjis"}, |
| 117 |
{"Jp_JP", "shiftjis"}, |
| 118 |
{"japan", "euc-jp"}, |
| 119 |
#ifdef hpux |
| 120 |
{"japanese", "shiftjis"}, |
| 121 |
{"ja", "shiftjis"}, |
| 122 |
#else |
| 123 |
{"japanese", "euc-jp"}, |
| 124 |
{"ja", "euc-jp"}, |
| 125 |
#endif |
| 126 |
{"japanese.sjis", "shiftjis"}, |
| 127 |
{"japanese.euc", "euc-jp"}, |
| 128 |
{"japanese-sjis", "shiftjis"}, |
| 129 |
{"japanese-ujis", "euc-jp"}, |
| 130 |
|
| 131 |
{"ko", "euc-kr"}, |
| 132 |
{"ko_KR", "euc-kr"}, |
| 133 |
{"ko_KR.EUC", "euc-kr"}, |
| 134 |
{"ko_KR.euc", "euc-kr"}, |
| 135 |
{"ko_KR.eucKR", "euc-kr"}, |
| 136 |
{"korean", "euc-kr"}, |
| 137 |
|
| 138 |
{"ru", "iso8859-5"}, |
| 139 |
{"ru_RU", "iso8859-5"}, |
| 140 |
{"ru_SU", "iso8859-5"}, |
| 141 |
|
| 142 |
{"zh", "cp936"}, |
| 143 |
|
| 144 |
{NULL, NULL} |
| 145 |
}; |
| 146 |
|
| 147 |
#ifdef HAVE_CFBUNDLE |
| 148 |
static int Tcl_MacOSXGetLibraryPath(Tcl_Interp *interp, int maxPathLen, char *tclLibPath); |
| 149 |
#endif |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
void |
| 172 |
TclpInitPlatform() |
| 173 |
{ |
| 174 |
tclPlatform = TCL_PLATFORM_UNIX; |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
#ifdef SIGPIPE |
| 187 |
(void) signal(SIGPIPE, SIG_IGN); |
| 188 |
#endif |
| 189 |
|
| 190 |
#ifdef __FreeBSD__ |
| 191 |
fpsetround(FP_RN); |
| 192 |
fpsetmask(0L); |
| 193 |
#endif |
| 194 |
|
| 195 |
#if defined(__bsdi__) && (_BSDI_VERSION > 199501) |
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
(void) dlopen (NULL, RTLD_NOW); |
| 200 |
#endif |
| 201 |
} |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
void |
| 245 |
TclpInitLibraryPath(path) |
| 246 |
CONST char *path; |
| 247 |
|
| 248 |
{ |
| 249 |
#define LIBRARY_SIZE 32 |
| 250 |
Tcl_Obj *pathPtr, *objPtr; |
| 251 |
CONST char *str; |
| 252 |
Tcl_DString buffer, ds; |
| 253 |
int pathc; |
| 254 |
CONST char **pathv; |
| 255 |
char installLib[LIBRARY_SIZE], developLib[LIBRARY_SIZE]; |
| 256 |
|
| 257 |
Tcl_DStringInit(&ds); |
| 258 |
pathPtr = Tcl_NewObj(); |
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
sprintf(installLib, "lib/tcl%s", TCL_VERSION); |
| 268 |
sprintf(developLib, "tcl%s/library", TCL_PATCH_LEVEL); |
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
str = Tcl_GetDefaultEncodingDir(); |
| 275 |
if ((str != NULL) && (str[0] != '\0')) { |
| 276 |
objPtr = Tcl_NewStringObj(str, -1); |
| 277 |
Tcl_ListObjAppendElement(NULL, pathPtr, objPtr); |
| 278 |
} |
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
str = getenv("TCL_LIBRARY"); |
| 288 |
Tcl_ExternalToUtfDString(NULL, str, -1, &buffer); |
| 289 |
str = Tcl_DStringValue(&buffer); |
| 290 |
|
| 291 |
if ((str != NULL) && (str[0] != '\0')) { |
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
objPtr = Tcl_NewStringObj(str, -1); |
| 297 |
Tcl_ListObjAppendElement(NULL, pathPtr, objPtr); |
| 298 |
|
| 299 |
Tcl_SplitPath(str, &pathc, &pathv); |
| 300 |
if ((pathc > 0) && (strcasecmp(installLib + 4, pathv[pathc-1]) != 0)) { |
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
pathv[pathc - 1] = installLib + 4; |
| 310 |
str = Tcl_JoinPath(pathc, pathv, &ds); |
| 311 |
objPtr = Tcl_NewStringObj(str, Tcl_DStringLength(&ds)); |
| 312 |
Tcl_ListObjAppendElement(NULL, pathPtr, objPtr); |
| 313 |
Tcl_DStringFree(&ds); |
| 314 |
} |
| 315 |
ckfree((char *) pathv); |
| 316 |
} |
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
if (path != NULL) { |
| 345 |
int i, origc; |
| 346 |
CONST char **origv; |
| 347 |
|
| 348 |
Tcl_SplitPath(path, &origc, &origv); |
| 349 |
pathc = 0; |
| 350 |
pathv = (CONST char **) ckalloc((unsigned int)(origc * sizeof(char *))); |
| 351 |
for (i=0; i< origc; i++) { |
| 352 |
if (origv[i][0] == '.') { |
| 353 |
if (strcmp(origv[i], ".") == 0) { |
| 354 |
|
| 355 |
} else if (strcmp(origv[i], "..") == 0) { |
| 356 |
pathc--; |
| 357 |
} else { |
| 358 |
pathv[pathc++] = origv[i]; |
| 359 |
} |
| 360 |
} else { |
| 361 |
pathv[pathc++] = origv[i]; |
| 362 |
} |
| 363 |
} |
| 364 |
if (pathc > 2) { |
| 365 |
str = pathv[pathc - 2]; |
| 366 |
pathv[pathc - 2] = installLib; |
| 367 |
path = Tcl_JoinPath(pathc - 1, pathv, &ds); |
| 368 |
pathv[pathc - 2] = str; |
| 369 |
objPtr = Tcl_NewStringObj(path, Tcl_DStringLength(&ds)); |
| 370 |
Tcl_ListObjAppendElement(NULL, pathPtr, objPtr); |
| 371 |
Tcl_DStringFree(&ds); |
| 372 |
} |
| 373 |
if (pathc > 3) { |
| 374 |
str = pathv[pathc - 3]; |
| 375 |
pathv[pathc - 3] = installLib; |
| 376 |
path = Tcl_JoinPath(pathc - 2, pathv, &ds); |
| 377 |
pathv[pathc - 3] = str; |
| 378 |
objPtr = Tcl_NewStringObj(path, Tcl_DStringLength(&ds)); |
| 379 |
Tcl_ListObjAppendElement(NULL, pathPtr, objPtr); |
| 380 |
Tcl_DStringFree(&ds); |
| 381 |
} |
| 382 |
if (pathc > 2) { |
| 383 |
str = pathv[pathc - 2]; |
| 384 |
pathv[pathc - 2] = "library"; |
| 385 |
path = Tcl_JoinPath(pathc - 1, pathv, &ds); |
| 386 |
pathv[pathc - 2] = str; |
| 387 |
objPtr = Tcl_NewStringObj(path, Tcl_DStringLength(&ds)); |
| 388 |
Tcl_ListObjAppendElement(NULL, pathPtr, objPtr); |
| 389 |
Tcl_DStringFree(&ds); |
| 390 |
} |
| 391 |
if (pathc > 3) { |
| 392 |
str = pathv[pathc - 3]; |
| 393 |
pathv[pathc - 3] = "library"; |
| 394 |
path = Tcl_JoinPath(pathc - 2, pathv, &ds); |
| 395 |
pathv[pathc - 3] = str; |
| 396 |
objPtr = Tcl_NewStringObj(path, Tcl_DStringLength(&ds)); |
| 397 |
Tcl_ListObjAppendElement(NULL, pathPtr, objPtr); |
| 398 |
Tcl_DStringFree(&ds); |
| 399 |
} |
| 400 |
if (pathc > 3) { |
| 401 |
str = pathv[pathc - 3]; |
| 402 |
pathv[pathc - 3] = developLib; |
| 403 |
path = Tcl_JoinPath(pathc - 2, pathv, &ds); |
| 404 |
pathv[pathc - 3] = str; |
| 405 |
objPtr = Tcl_NewStringObj(path, Tcl_DStringLength(&ds)); |
| 406 |
Tcl_ListObjAppendElement(NULL, pathPtr, objPtr); |
| 407 |
Tcl_DStringFree(&ds); |
| 408 |
} |
| 409 |
if (pathc > 4) { |
| 410 |
str = pathv[pathc - 4]; |
| 411 |
pathv[pathc - 4] = developLib; |
| 412 |
path = Tcl_JoinPath(pathc - 3, pathv, &ds); |
| 413 |
pathv[pathc - 4] = str; |
| 414 |
objPtr = Tcl_NewStringObj(path, Tcl_DStringLength(&ds)); |
| 415 |
Tcl_ListObjAppendElement(NULL, pathPtr, objPtr); |
| 416 |
Tcl_DStringFree(&ds); |
| 417 |
} |
| 418 |
ckfree((char *) origv); |
| 419 |
ckfree((char *) pathv); |
| 420 |
} |
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
{ |
| 429 |
#ifdef HAVE_CFBUNDLE |
| 430 |
char tclLibPath[MAXPATHLEN + 1]; |
| 431 |
|
| 432 |
if (Tcl_MacOSXGetLibraryPath(NULL, MAXPATHLEN, tclLibPath) == TCL_OK) { |
| 433 |
str = tclLibPath; |
| 434 |
} else |
| 435 |
#endif |
| 436 |
{ |
| 437 |
str = defaultLibraryDir; |
| 438 |
} |
| 439 |
if (str[0] != '\0') { |
| 440 |
objPtr = Tcl_NewStringObj(str, -1); |
| 441 |
Tcl_ListObjAppendElement(NULL, pathPtr, objPtr); |
| 442 |
} |
| 443 |
} |
| 444 |
|
| 445 |
TclSetLibraryPath(pathPtr); |
| 446 |
Tcl_DStringFree(&buffer); |
| 447 |
} |
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
void |
| 474 |
TclpSetInitialEncodings() |
| 475 |
{ |
| 476 |
if (libraryPathEncodingFixed == 0) { |
| 477 |
CONST char *encoding = NULL; |
| 478 |
int i, setSysEncCode = TCL_ERROR; |
| 479 |
Tcl_Obj *pathPtr; |
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
#ifdef HAVE_LANGINFO |
| 487 |
if (setlocale(LC_CTYPE, "") != NULL) { |
| 488 |
Tcl_DString ds; |
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
Tcl_DStringInit(&ds); |
| 496 |
encoding = Tcl_DStringAppend(&ds, nl_langinfo(CODESET), -1); |
| 497 |
|
| 498 |
Tcl_UtfToLower(Tcl_DStringValue(&ds)); |
| 499 |
#ifdef HAVE_LANGINFO_DEBUG |
| 500 |
fprintf(stderr, "encoding '%s'", encoding); |
| 501 |
#endif |
| 502 |
if (encoding[0] == 'i' && encoding[1] == 's' && encoding[2] == 'o' |
| 503 |
&& encoding[3] == '-') { |
| 504 |
char *p, *q; |
| 505 |
|
| 506 |
for(p = Tcl_DStringValue(&ds)+3, q = Tcl_DStringValue(&ds)+4; |
| 507 |
*p; *p++ = *q++); |
| 508 |
} else if (encoding[0] == 'i' && encoding[1] == 'b' |
| 509 |
&& encoding[2] == 'm' && encoding[3] >= '0' |
| 510 |
&& encoding[3] <= '9') { |
| 511 |
char *p, *q; |
| 512 |
|
| 513 |
p = Tcl_DStringValue(&ds); |
| 514 |
*p++ = 'c'; *p++ = 'p'; |
| 515 |
for(q = p+1; *p ; *p++ = *q++); |
| 516 |
} else if ((*encoding == '\0') |
| 517 |
|| !strcmp(encoding, "ansi_x3.4-1968")) { |
| 518 |
|
| 519 |
encoding = "iso8859-1"; |
| 520 |
} |
| 521 |
#ifdef HAVE_LANGINFO_DEBUG |
| 522 |
fprintf(stderr, " ?%s?", encoding); |
| 523 |
#endif |
| 524 |
setSysEncCode = Tcl_SetSystemEncoding(NULL, encoding); |
| 525 |
if (setSysEncCode != TCL_OK) { |
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
for (i = 0; localeTable[i].lang != NULL; i++) { |
| 534 |
if (strcmp(localeTable[i].lang, encoding) == 0) { |
| 535 |
setSysEncCode = Tcl_SetSystemEncoding(NULL, |
| 536 |
localeTable[i].encoding); |
| 537 |
break; |
| 538 |
} |
| 539 |
} |
| 540 |
} |
| 541 |
#ifdef HAVE_LANGINFO_DEBUG |
| 542 |
fprintf(stderr, " => '%s'\n", encoding); |
| 543 |
#endif |
| 544 |
Tcl_DStringFree(&ds); |
| 545 |
} |
| 546 |
#ifdef HAVE_LANGINFO_DEBUG |
| 547 |
else { |
| 548 |
fprintf(stderr, "setlocale returned NULL\n"); |
| 549 |
} |
| 550 |
#endif |
| 551 |
#endif |
| 552 |
|
| 553 |
if (setSysEncCode != TCL_OK) { |
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
char *langEnv = getenv("LC_ALL"); |
| 559 |
encoding = NULL; |
| 560 |
|
| 561 |
if (langEnv == NULL || langEnv[0] == '\0') { |
| 562 |
langEnv = getenv("LC_CTYPE"); |
| 563 |
} |
| 564 |
if (langEnv == NULL || langEnv[0] == '\0') { |
| 565 |
langEnv = getenv("LANG"); |
| 566 |
} |
| 567 |
if (langEnv == NULL || langEnv[0] == '\0') { |
| 568 |
langEnv = NULL; |
| 569 |
} |
| 570 |
|
| 571 |
if (langEnv != NULL) { |
| 572 |
for (i = 0; localeTable[i].lang != NULL; i++) { |
| 573 |
if (strcmp(localeTable[i].lang, langEnv) == 0) { |
| 574 |
encoding = localeTable[i].encoding; |
| 575 |
break; |
| 576 |
} |
| 577 |
} |
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
if (encoding == NULL) { |
| 584 |
char *p; |
| 585 |
for (p = langEnv; *p != '\0'; p++) { |
| 586 |
if (*p == '.') { |
| 587 |
p++; |
| 588 |
break; |
| 589 |
} |
| 590 |
} |
| 591 |
if (*p != '\0') { |
| 592 |
Tcl_DString ds; |
| 593 |
Tcl_DStringInit(&ds); |
| 594 |
encoding = Tcl_DStringAppend(&ds, p, -1); |
| 595 |
|
| 596 |
Tcl_UtfToLower(Tcl_DStringValue(&ds)); |
| 597 |
setSysEncCode = Tcl_SetSystemEncoding(NULL, encoding); |
| 598 |
if (setSysEncCode != TCL_OK) { |
| 599 |
encoding = NULL; |
| 600 |
} |
| 601 |
Tcl_DStringFree(&ds); |
| 602 |
} |
| 603 |
} |
| 604 |
#ifdef HAVE_LANGINFO_DEBUG |
| 605 |
fprintf(stderr, "encoding fallback check '%s' => '%s'\n", |
| 606 |
langEnv, encoding); |
| 607 |
#endif |
| 608 |
} |
| 609 |
if (setSysEncCode != TCL_OK) { |
| 610 |
if (encoding == NULL) { |
| 611 |
encoding = TCL_DEFAULT_ENCODING; |
| 612 |
} |
| 613 |
|
| 614 |
Tcl_SetSystemEncoding(NULL, encoding); |
| 615 |
} |
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
#ifndef HAVE_LANGINFO |
| 627 |
setlocale(LC_CTYPE, ""); |
| 628 |
#endif |
| 629 |
} |
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
setlocale(LC_NUMERIC, "C"); |
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
pathPtr = TclGetLibraryPath(); |
| 663 |
if (pathPtr != NULL) { |
| 664 |
int objc; |
| 665 |
Tcl_Obj **objv; |
| 666 |
|
| 667 |
objc = 0; |
| 668 |
Tcl_ListObjGetElements(NULL, pathPtr, &objc, &objv); |
| 669 |
for (i = 0; i < objc; i++) { |
| 670 |
int length; |
| 671 |
char *string; |
| 672 |
Tcl_DString ds; |
| 673 |
|
| 674 |
string = Tcl_GetStringFromObj(objv[i], &length); |
| 675 |
Tcl_ExternalToUtfDString(NULL, string, length, &ds); |
| 676 |
Tcl_SetStringObj(objv[i], Tcl_DStringValue(&ds), |
| 677 |
Tcl_DStringLength(&ds)); |
| 678 |
Tcl_DStringFree(&ds); |
| 679 |
} |
| 680 |
} |
| 681 |
|
| 682 |
libraryPathEncodingFixed = 1; |
| 683 |
} |
| 684 |
|
| 685 |
|
| 686 |
if (binaryEncoding == NULL) { |
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
binaryEncoding = Tcl_GetEncoding(NULL, "iso8859-1"); |
| 692 |
} |
| 693 |
} |
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
void |
| 715 |
TclpSetVariables(interp) |
| 716 |
Tcl_Interp *interp; |
| 717 |
{ |
| 718 |
#ifndef NO_UNAME |
| 719 |
struct utsname name; |
| 720 |
#endif |
| 721 |
int unameOK; |
| 722 |
CONST char *user; |
| 723 |
Tcl_DString ds; |
| 724 |
|
| 725 |
#ifdef HAVE_CFBUNDLE |
| 726 |
char tclLibPath[MAXPATHLEN + 1]; |
| 727 |
|
| 728 |
if (Tcl_MacOSXGetLibraryPath(interp, MAXPATHLEN, tclLibPath) == TCL_OK) { |
| 729 |
CONST char *str; |
| 730 |
Tcl_DString ds; |
| 731 |
CFBundleRef bundleRef; |
| 732 |
|
| 733 |
Tcl_SetVar(interp, "tclDefaultLibrary", tclLibPath, |
| 734 |
TCL_GLOBAL_ONLY); |
| 735 |
Tcl_SetVar(interp, "tcl_pkgPath", tclLibPath, |
| 736 |
TCL_GLOBAL_ONLY); |
| 737 |
Tcl_SetVar(interp, "tcl_pkgPath", " ", |
| 738 |
TCL_GLOBAL_ONLY | TCL_APPEND_VALUE); |
| 739 |
str = TclGetEnv("DYLD_FRAMEWORK_PATH", &ds); |
| 740 |
if ((str != NULL) && (str[0] != '\0')) { |
| 741 |
char *p = Tcl_DStringValue(&ds); |
| 742 |
|
| 743 |
do { |
| 744 |
if(*p == ':') *p = ' '; |
| 745 |
} while (*p++); |
| 746 |
Tcl_SetVar(interp, "tcl_pkgPath", Tcl_DStringValue(&ds), |
| 747 |
TCL_GLOBAL_ONLY | TCL_APPEND_VALUE); |
| 748 |
Tcl_SetVar(interp, "tcl_pkgPath", " ", |
| 749 |
TCL_GLOBAL_ONLY | TCL_APPEND_VALUE); |
| 750 |
Tcl_DStringFree(&ds); |
| 751 |
} |
| 752 |
if ((bundleRef = CFBundleGetMainBundle())) { |
| 753 |
CFURLRef frameworksURL; |
| 754 |
Tcl_StatBuf statBuf; |
| 755 |
if((frameworksURL = CFBundleCopyPrivateFrameworksURL(bundleRef))) { |
| 756 |
if(CFURLGetFileSystemRepresentation(frameworksURL, TRUE, |
| 757 |
tclLibPath, MAXPATHLEN) && |
| 758 |
! TclOSstat(tclLibPath, &statBuf) && |
| 759 |
S_ISDIR(statBuf.st_mode)) { |
| 760 |
Tcl_SetVar(interp, "tcl_pkgPath", tclLibPath, |
| 761 |
TCL_GLOBAL_ONLY | TCL_APPEND_VALUE); |
| 762 |
Tcl_SetVar(interp, "tcl_pkgPath", " ", |
| 763 |
TCL_GLOBAL_ONLY | TCL_APPEND_VALUE); |
| 764 |
} |
| 765 |
CFRelease(frameworksURL); |
| 766 |
} |
| 767 |
if((frameworksURL = CFBundleCopySharedFrameworksURL(bundleRef))) { |
| 768 |
if(CFURLGetFileSystemRepresentation(frameworksURL, TRUE, |
| 769 |
tclLibPath, MAXPATHLEN) && |
| 770 |
! TclOSstat(tclLibPath, &statBuf) && |
| 771 |
S_ISDIR(statBuf.st_mode)) { |
| 772 |
Tcl_SetVar(interp, "tcl_pkgPath", tclLibPath, |
| 773 |
TCL_GLOBAL_ONLY | TCL_APPEND_VALUE); |
| 774 |
Tcl_SetVar(interp, "tcl_pkgPath", " ", |
| 775 |
TCL_GLOBAL_ONLY | TCL_APPEND_VALUE); |
| 776 |
} |
| 777 |
CFRelease(frameworksURL); |
| 778 |
} |
| 779 |
} |
| 780 |
Tcl_SetVar(interp, "tcl_pkgPath", pkgPath, |
| 781 |
TCL_GLOBAL_ONLY | TCL_APPEND_VALUE); |
| 782 |
} else |
| 783 |
#endif |
| 784 |
{ |
| 785 |
Tcl_SetVar(interp, "tclDefaultLibrary", defaultLibraryDir, |
| 786 |
TCL_GLOBAL_ONLY); |
| 787 |
Tcl_SetVar(interp, "tcl_pkgPath", pkgPath, TCL_GLOBAL_ONLY); |
| 788 |
} |
| 789 |
|
| 790 |
#ifdef DJGPP |
| 791 |
Tcl_SetVar2(interp, "tcl_platform", "platform", "dos", TCL_GLOBAL_ONLY); |
| 792 |
#else |
| 793 |
Tcl_SetVar2(interp, "tcl_platform", "platform", "unix", TCL_GLOBAL_ONLY); |
| 794 |
#endif |
| 795 |
unameOK = 0; |
| 796 |
#ifndef NO_UNAME |
| 797 |
if (uname(&name) >= 0) { |
| 798 |
CONST char *native; |
| 799 |
|
| 800 |
unameOK = 1; |
| 801 |
|
| 802 |
native = Tcl_ExternalToUtfDString(NULL, name.sysname, -1, &ds); |
| 803 |
Tcl_SetVar2(interp, "tcl_platform", "os", native, TCL_GLOBAL_ONLY); |
| 804 |
Tcl_DStringFree(&ds); |
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
if ((strchr(name.release, '.') != NULL) |
| 815 |
|| !isdigit(UCHAR(name.version[0]))) { |
| 816 |
Tcl_SetVar2(interp, "tcl_platform", "osVersion", name.release, |
| 817 |
TCL_GLOBAL_ONLY); |
| 818 |
} else { |
| 819 |
Tcl_SetVar2(interp, "tcl_platform", "osVersion", name.version, |
| 820 |
TCL_GLOBAL_ONLY); |
| 821 |
Tcl_SetVar2(interp, "tcl_platform", "osVersion", ".", |
| 822 |
TCL_GLOBAL_ONLY|TCL_APPEND_VALUE); |
| 823 |
Tcl_SetVar2(interp, "tcl_platform", "osVersion", name.release, |
| 824 |
TCL_GLOBAL_ONLY|TCL_APPEND_VALUE); |
| 825 |
} |
| 826 |
Tcl_SetVar2(interp, "tcl_platform", "machine", name.machine, |
| 827 |
TCL_GLOBAL_ONLY); |
| 828 |
} |
| 829 |
#endif |
| 830 |
if (!unameOK) { |
| 831 |
Tcl_SetVar2(interp, "tcl_platform", "os", "", TCL_GLOBAL_ONLY); |
| 832 |
Tcl_SetVar2(interp, "tcl_platform", "osVersion", "", TCL_GLOBAL_ONLY); |
| 833 |
Tcl_SetVar2(interp, "tcl_platform", "machine", "", TCL_GLOBAL_ONLY); |
| 834 |
} |
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
Tcl_DStringInit(&ds); |
| 841 |
user = TclGetEnv("USER", &ds); |
| 842 |
if (user == NULL) { |
| 843 |
user = TclGetEnv("LOGNAME", &ds); |
| 844 |
if (user == NULL) { |
| 845 |
user = ""; |
| 846 |
} |
| 847 |
} |
| 848 |
Tcl_SetVar2(interp, "tcl_platform", "user", user, TCL_GLOBAL_ONLY); |
| 849 |
Tcl_DStringFree(&ds); |
| 850 |
|
| 851 |
} |
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
int |
| 875 |
TclpFindVariable(name, lengthPtr) |
| 876 |
CONST char *name; |
| 877 |
|
| 878 |
int *lengthPtr; |
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
{ |
| 883 |
int i, result = -1; |
| 884 |
register CONST char *env, *p1, *p2; |
| 885 |
Tcl_DString envString; |
| 886 |
|
| 887 |
Tcl_DStringInit(&envString); |
| 888 |
for (i = 0, env = environ[i]; env != NULL; i++, env = environ[i]) { |
| 889 |
p1 = Tcl_ExternalToUtfDString(NULL, env, -1, &envString); |
| 890 |
p2 = name; |
| 891 |
|
| 892 |
for (; *p2 == *p1; p1++, p2++) { |
| 893 |
|
| 894 |
} |
| 895 |
if ((*p1 == '=') && (*p2 == '\0')) { |
| 896 |
*lengthPtr = p2 - name; |
| 897 |
result = i; |
| 898 |
goto done; |
| 899 |
} |
| 900 |
|
| 901 |
Tcl_DStringFree(&envString); |
| 902 |
} |
| 903 |
|
| 904 |
*lengthPtr = i; |
| 905 |
|
| 906 |
done: |
| 907 |
Tcl_DStringFree(&envString); |
| 908 |
return result; |
| 909 |
} |
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
int |
| 931 |
Tcl_Init(interp) |
| 932 |
Tcl_Interp *interp; |
| 933 |
{ |
| 934 |
Tcl_Obj *pathPtr; |
| 935 |
|
| 936 |
if (tclPreInitScript != NULL) { |
| 937 |
if (Tcl_Eval(interp, tclPreInitScript) == TCL_ERROR) { |
| 938 |
return (TCL_ERROR); |
| 939 |
}; |
| 940 |
} |
| 941 |
|
| 942 |
pathPtr = TclGetLibraryPath(); |
| 943 |
if (pathPtr == NULL) { |
| 944 |
pathPtr = Tcl_NewObj(); |
| 945 |
} |
| 946 |
Tcl_SetVar2Ex(interp, "tcl_libPath", NULL, pathPtr, TCL_GLOBAL_ONLY); |
| 947 |
return Tcl_Eval(interp, initScript); |
| 948 |
} |
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
void |
| 969 |
Tcl_SourceRCFile(interp) |
| 970 |
Tcl_Interp *interp; |
| 971 |
{ |
| 972 |
Tcl_DString temp; |
| 973 |
CONST char *fileName; |
| 974 |
Tcl_Channel errChannel; |
| 975 |
|
| 976 |
fileName = Tcl_GetVar(interp, "tcl_rcFileName", TCL_GLOBAL_ONLY); |
| 977 |
|
| 978 |
if (fileName != NULL) { |
| 979 |
Tcl_Channel c; |
| 980 |
CONST char *fullName; |
| 981 |
|
| 982 |
Tcl_DStringInit(&temp); |
| 983 |
fullName = Tcl_TranslateFileName(interp, fileName, &temp); |
| 984 |
if (fullName == NULL) { |
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
} else { |
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
c = Tcl_OpenFileChannel(NULL, fullName, "r", 0); |
| 997 |
if (c != (Tcl_Channel) NULL) { |
| 998 |
Tcl_Close(NULL, c); |
| 999 |
if (Tcl_EvalFile(interp, fullName) != TCL_OK) { |
| 1000 |
errChannel = Tcl_GetStdChannel(TCL_STDERR); |
| 1001 |
if (errChannel) { |
| 1002 |
Tcl_WriteObj(errChannel, Tcl_GetObjResult(interp)); |
| 1003 |
Tcl_WriteChars(errChannel, "\n", 1); |
| 1004 |
} |
| 1005 |
} |
| 1006 |
} |
| 1007 |
} |
| 1008 |
Tcl_DStringFree(&temp); |
| 1009 |
} |
| 1010 |
} |
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
int |
| 1030 |
TclpCheckStackSpace() |
| 1031 |
{ |
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
return 1; |
| 1037 |
} |
| 1038 |
|
| 1039 |
#ifdef HAVE_CFBUNDLE |
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
static int Tcl_MacOSXGetLibraryPath(Tcl_Interp *interp, int maxPathLen, char *tclLibPath) |
| 1058 |
{ |
| 1059 |
int foundInFramework = TCL_ERROR; |
| 1060 |
if (strcmp(defaultLibraryDir, "@TCL_IN_FRAMEWORK@") == 0) { |
| 1061 |
foundInFramework = Tcl_MacOSXOpenVersionedBundleResources(interp, |
| 1062 |
"com.tcltk.tcllibrary", TCL_VERSION, 0, maxPathLen, tclLibPath); |
| 1063 |
} |
| 1064 |
return foundInFramework; |
| 1065 |
} |
| 1066 |
#endif |
| 1067 |
|
| 1068 |
|