| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#include "tcl.h" |
| 17 |
#include "tclInt.h" |
| 18 |
|
| 19 |
# undef TCL_STORAGE_CLASS |
| 20 |
# define TCL_STORAGE_CLASS DLLEXPORT |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
#if !defined(MAC_TCL) |
| 29 |
extern int isatty _ANSI_ARGS_((int fd)); |
| 30 |
#else |
| 31 |
#include <unistd.h> |
| 32 |
#endif |
| 33 |
|
| 34 |
static Tcl_Obj *tclStartupScriptPath = NULL; |
| 35 |
|
| 36 |
static Tcl_MainLoopProc *mainLoopProc = NULL; |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
typedef enum { |
| 45 |
PROMPT_NONE, |
| 46 |
PROMPT_START, |
| 47 |
PROMPT_CONTINUE |
| 48 |
} PromptType; |
| 49 |
|
| 50 |
typedef struct InteractiveState { |
| 51 |
Tcl_Channel input; |
| 52 |
|
| 53 |
int tty; |
| 54 |
|
| 55 |
|
| 56 |
Tcl_Obj *commandPtr; |
| 57 |
|
| 58 |
PromptType prompt; |
| 59 |
Tcl_Interp *interp; |
| 60 |
|
| 61 |
} InteractiveState; |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
static void Prompt _ANSI_ARGS_((Tcl_Interp *interp, |
| 68 |
PromptType *promptPtr)); |
| 69 |
static void StdinProc _ANSI_ARGS_((ClientData clientData, |
| 70 |
int mask)); |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
void TclSetStartupScriptPath(pathPtr) |
| 91 |
Tcl_Obj *pathPtr; |
| 92 |
{ |
| 93 |
if (tclStartupScriptPath != NULL) { |
| 94 |
Tcl_DecrRefCount(tclStartupScriptPath); |
| 95 |
} |
| 96 |
tclStartupScriptPath = pathPtr; |
| 97 |
if (tclStartupScriptPath != NULL) { |
| 98 |
Tcl_IncrRefCount(tclStartupScriptPath); |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
Tcl_Obj *TclGetStartupScriptPath() |
| 120 |
{ |
| 121 |
return tclStartupScriptPath; |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
void TclSetStartupScriptFileName(fileName) |
| 143 |
CONST char *fileName; |
| 144 |
{ |
| 145 |
Tcl_Obj *pathPtr = Tcl_NewStringObj(fileName,-1); |
| 146 |
TclSetStartupScriptPath(pathPtr); |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
CONST char *TclGetStartupScriptFileName() |
| 167 |
{ |
| 168 |
Tcl_Obj *pathPtr = TclGetStartupScriptPath(); |
| 169 |
|
| 170 |
if (pathPtr == NULL) { |
| 171 |
return NULL; |
| 172 |
} |
| 173 |
return Tcl_GetString(pathPtr); |
| 174 |
} |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
void |
| 198 |
Tcl_Main(argc, argv, appInitProc) |
| 199 |
int argc; |
| 200 |
char **argv; |
| 201 |
Tcl_AppInitProc *appInitProc; |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
{ |
| 207 |
Tcl_Obj *resultPtr; |
| 208 |
Tcl_Obj *commandPtr = NULL; |
| 209 |
char buffer[TCL_INTEGER_SPACE + 5], *args; |
| 210 |
PromptType prompt = PROMPT_START; |
| 211 |
int code, length, tty; |
| 212 |
int exitCode = 0; |
| 213 |
Tcl_Channel inChannel, outChannel, errChannel; |
| 214 |
Tcl_Interp *interp; |
| 215 |
Tcl_DString argString; |
| 216 |
|
| 217 |
Tcl_FindExecutable(argv[0]); |
| 218 |
|
| 219 |
interp = Tcl_CreateInterp(); |
| 220 |
Tcl_InitMemory(interp); |
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
if (TclGetStartupScriptPath() == NULL) { |
| 229 |
if ((argc > 1) && (argv[1][0] != '-')) { |
| 230 |
TclSetStartupScriptFileName(argv[1]); |
| 231 |
argc--; |
| 232 |
argv++; |
| 233 |
} |
| 234 |
} |
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
args = Tcl_Merge(argc-1, (CONST char **)argv+1); |
| 243 |
Tcl_ExternalToUtfDString(NULL, args, -1, &argString); |
| 244 |
Tcl_SetVar(interp, "argv", Tcl_DStringValue(&argString), TCL_GLOBAL_ONLY); |
| 245 |
Tcl_DStringFree(&argString); |
| 246 |
ckfree(args); |
| 247 |
|
| 248 |
if (TclGetStartupScriptPath() == NULL) { |
| 249 |
Tcl_ExternalToUtfDString(NULL, argv[0], -1, &argString); |
| 250 |
} else { |
| 251 |
TclSetStartupScriptFileName(Tcl_ExternalToUtfDString(NULL, |
| 252 |
TclGetStartupScriptFileName(), -1, &argString)); |
| 253 |
} |
| 254 |
|
| 255 |
TclFormatInt(buffer, (long) argc-1); |
| 256 |
Tcl_SetVar(interp, "argc", buffer, TCL_GLOBAL_ONLY); |
| 257 |
Tcl_SetVar(interp, "argv0", Tcl_DStringValue(&argString), TCL_GLOBAL_ONLY); |
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
tty = isatty(0); |
| 264 |
Tcl_SetVar(interp, "tcl_interactive", |
| 265 |
((TclGetStartupScriptPath() == NULL) && tty) ? "1" : "0", |
| 266 |
TCL_GLOBAL_ONLY); |
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
Tcl_Preserve((ClientData) interp); |
| 273 |
if ((*appInitProc)(interp) != TCL_OK) { |
| 274 |
errChannel = Tcl_GetStdChannel(TCL_STDERR); |
| 275 |
if (errChannel) { |
| 276 |
Tcl_WriteChars(errChannel, |
| 277 |
"application-specific initialization failed: ", -1); |
| 278 |
Tcl_WriteObj(errChannel, Tcl_GetObjResult(interp)); |
| 279 |
Tcl_WriteChars(errChannel, "\n", 1); |
| 280 |
} |
| 281 |
} |
| 282 |
if (Tcl_InterpDeleted(interp)) { |
| 283 |
goto done; |
| 284 |
} |
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
if (TclGetStartupScriptPath() != NULL) { |
| 292 |
code = Tcl_FSEvalFile(interp, TclGetStartupScriptPath()); |
| 293 |
if (code != TCL_OK) { |
| 294 |
errChannel = Tcl_GetStdChannel(TCL_STDERR); |
| 295 |
if (errChannel) { |
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
Tcl_AddErrorInfo(interp, ""); |
| 303 |
Tcl_WriteObj(errChannel, Tcl_GetVar2Ex(interp, "errorInfo", |
| 304 |
NULL, TCL_GLOBAL_ONLY)); |
| 305 |
Tcl_WriteChars(errChannel, "\n", 1); |
| 306 |
} |
| 307 |
exitCode = 1; |
| 308 |
} |
| 309 |
goto done; |
| 310 |
} |
| 311 |
Tcl_DStringFree(&argString); |
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
Tcl_SourceRCFile(interp); |
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
commandPtr = Tcl_NewObj(); |
| 327 |
Tcl_IncrRefCount(commandPtr); |
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
Tcl_LinkVar(interp, "tcl_interactive", (char *) &tty, TCL_LINK_BOOLEAN); |
| 333 |
inChannel = Tcl_GetStdChannel(TCL_STDIN); |
| 334 |
outChannel = Tcl_GetStdChannel(TCL_STDOUT); |
| 335 |
while ((inChannel != (Tcl_Channel) NULL) && !Tcl_InterpDeleted(interp)) { |
| 336 |
if (tty) { |
| 337 |
Prompt(interp, &prompt); |
| 338 |
if (Tcl_InterpDeleted(interp)) { |
| 339 |
break; |
| 340 |
} |
| 341 |
inChannel = Tcl_GetStdChannel(TCL_STDIN); |
| 342 |
if (inChannel == (Tcl_Channel) NULL) { |
| 343 |
break; |
| 344 |
} |
| 345 |
} |
| 346 |
if (Tcl_IsShared(commandPtr)) { |
| 347 |
Tcl_DecrRefCount(commandPtr); |
| 348 |
commandPtr = Tcl_DuplicateObj(commandPtr); |
| 349 |
Tcl_IncrRefCount(commandPtr); |
| 350 |
} |
| 351 |
length = Tcl_GetsObj(inChannel, commandPtr); |
| 352 |
if (length < 0) { |
| 353 |
if (Tcl_InputBlocked(inChannel)) { |
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
continue; |
| 365 |
} |
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
break; |
| 372 |
} |
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
if (Tcl_IsShared(commandPtr)) { |
| 379 |
Tcl_DecrRefCount(commandPtr); |
| 380 |
commandPtr = Tcl_DuplicateObj(commandPtr); |
| 381 |
Tcl_IncrRefCount(commandPtr); |
| 382 |
} |
| 383 |
Tcl_AppendToObj(commandPtr, "\n", 1); |
| 384 |
if (!TclObjCommandComplete(commandPtr)) { |
| 385 |
prompt = PROMPT_CONTINUE; |
| 386 |
continue; |
| 387 |
} |
| 388 |
|
| 389 |
prompt = PROMPT_START; |
| 390 |
code = Tcl_RecordAndEvalObj(interp, commandPtr, TCL_EVAL_GLOBAL); |
| 391 |
inChannel = Tcl_GetStdChannel(TCL_STDIN); |
| 392 |
outChannel = Tcl_GetStdChannel(TCL_STDOUT); |
| 393 |
errChannel = Tcl_GetStdChannel(TCL_STDERR); |
| 394 |
Tcl_DecrRefCount(commandPtr); |
| 395 |
commandPtr = Tcl_NewObj(); |
| 396 |
Tcl_IncrRefCount(commandPtr); |
| 397 |
if (code != TCL_OK) { |
| 398 |
if (errChannel) { |
| 399 |
Tcl_WriteObj(errChannel, Tcl_GetObjResult(interp)); |
| 400 |
Tcl_WriteChars(errChannel, "\n", 1); |
| 401 |
} |
| 402 |
} else if (tty) { |
| 403 |
resultPtr = Tcl_GetObjResult(interp); |
| 404 |
Tcl_IncrRefCount(resultPtr); |
| 405 |
Tcl_GetStringFromObj(resultPtr, &length); |
| 406 |
if ((length > 0) && outChannel) { |
| 407 |
Tcl_WriteObj(outChannel, resultPtr); |
| 408 |
Tcl_WriteChars(outChannel, "\n", 1); |
| 409 |
} |
| 410 |
Tcl_DecrRefCount(resultPtr); |
| 411 |
} |
| 412 |
if (mainLoopProc != NULL) { |
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
InteractiveState *isPtr = NULL; |
| 421 |
|
| 422 |
if (inChannel) { |
| 423 |
if (tty) { |
| 424 |
Prompt(interp, &prompt); |
| 425 |
} |
| 426 |
isPtr = (InteractiveState *) |
| 427 |
ckalloc((int) sizeof(InteractiveState)); |
| 428 |
isPtr->input = inChannel; |
| 429 |
isPtr->tty = tty; |
| 430 |
isPtr->commandPtr = commandPtr; |
| 431 |
isPtr->prompt = prompt; |
| 432 |
isPtr->interp = interp; |
| 433 |
|
| 434 |
Tcl_UnlinkVar(interp, "tcl_interactive"); |
| 435 |
Tcl_LinkVar(interp, "tcl_interactive", (char *) &(isPtr->tty), |
| 436 |
TCL_LINK_BOOLEAN); |
| 437 |
|
| 438 |
Tcl_CreateChannelHandler(inChannel, TCL_READABLE, StdinProc, |
| 439 |
(ClientData) isPtr); |
| 440 |
} |
| 441 |
|
| 442 |
(*mainLoopProc)(); |
| 443 |
mainLoopProc = NULL; |
| 444 |
|
| 445 |
if (inChannel) { |
| 446 |
tty = isPtr->tty; |
| 447 |
Tcl_UnlinkVar(interp, "tcl_interactive"); |
| 448 |
Tcl_LinkVar(interp, "tcl_interactive", (char *) &tty, |
| 449 |
TCL_LINK_BOOLEAN); |
| 450 |
prompt = isPtr->prompt; |
| 451 |
commandPtr = isPtr->commandPtr; |
| 452 |
if (isPtr->input != (Tcl_Channel) NULL) { |
| 453 |
Tcl_DeleteChannelHandler(isPtr->input, StdinProc, |
| 454 |
(ClientData) isPtr); |
| 455 |
} |
| 456 |
ckfree((char *)isPtr); |
| 457 |
} |
| 458 |
inChannel = Tcl_GetStdChannel(TCL_STDIN); |
| 459 |
outChannel = Tcl_GetStdChannel(TCL_STDOUT); |
| 460 |
errChannel = Tcl_GetStdChannel(TCL_STDERR); |
| 461 |
} |
| 462 |
#ifdef TCL_MEM_DEBUG |
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
if (tclMemDumpFileName != NULL) { |
| 470 |
mainLoopProc = NULL; |
| 471 |
Tcl_DeleteInterp(interp); |
| 472 |
} |
| 473 |
#endif |
| 474 |
} |
| 475 |
|
| 476 |
done: |
| 477 |
if ((exitCode == 0) && (mainLoopProc != NULL)) { |
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
(*mainLoopProc)(); |
| 486 |
mainLoopProc = NULL; |
| 487 |
} |
| 488 |
if (commandPtr != NULL) { |
| 489 |
Tcl_DecrRefCount(commandPtr); |
| 490 |
} |
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
if (!Tcl_InterpDeleted(interp)) { |
| 499 |
sprintf(buffer, "exit %d", exitCode); |
| 500 |
Tcl_Eval(interp, buffer); |
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
if (!Tcl_InterpDeleted(interp)) { |
| 510 |
Tcl_DeleteInterp(interp); |
| 511 |
} |
| 512 |
} |
| 513 |
TclSetStartupScriptPath(NULL); |
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
Tcl_Release((ClientData) interp); |
| 521 |
Tcl_Exit(exitCode); |
| 522 |
} |
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
void |
| 542 |
Tcl_SetMainLoop(proc) |
| 543 |
Tcl_MainLoopProc *proc; |
| 544 |
{ |
| 545 |
mainLoopProc = proc; |
| 546 |
} |
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
static void |
| 570 |
StdinProc(clientData, mask) |
| 571 |
ClientData clientData; |
| 572 |
int mask; |
| 573 |
{ |
| 574 |
InteractiveState *isPtr = (InteractiveState *) clientData; |
| 575 |
Tcl_Channel chan = isPtr->input; |
| 576 |
Tcl_Obj *commandPtr = isPtr->commandPtr; |
| 577 |
Tcl_Interp *interp = isPtr->interp; |
| 578 |
int code, length; |
| 579 |
|
| 580 |
if (Tcl_IsShared(commandPtr)) { |
| 581 |
Tcl_DecrRefCount(commandPtr); |
| 582 |
commandPtr = Tcl_DuplicateObj(commandPtr); |
| 583 |
Tcl_IncrRefCount(commandPtr); |
| 584 |
} |
| 585 |
length = Tcl_GetsObj(chan, commandPtr); |
| 586 |
if (length < 0) { |
| 587 |
if (Tcl_InputBlocked(chan)) { |
| 588 |
return; |
| 589 |
} |
| 590 |
if (isPtr->tty) { |
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
Tcl_Exit(0); |
| 597 |
} |
| 598 |
Tcl_DeleteChannelHandler(chan, StdinProc, (ClientData) isPtr); |
| 599 |
return; |
| 600 |
} |
| 601 |
|
| 602 |
if (Tcl_IsShared(commandPtr)) { |
| 603 |
Tcl_DecrRefCount(commandPtr); |
| 604 |
commandPtr = Tcl_DuplicateObj(commandPtr); |
| 605 |
Tcl_IncrRefCount(commandPtr); |
| 606 |
} |
| 607 |
Tcl_AppendToObj(commandPtr, "\n", 1); |
| 608 |
if (!TclObjCommandComplete(commandPtr)) { |
| 609 |
isPtr->prompt = PROMPT_CONTINUE; |
| 610 |
goto prompt; |
| 611 |
} |
| 612 |
isPtr->prompt = PROMPT_START; |
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
Tcl_CreateChannelHandler(chan, 0, StdinProc, (ClientData) isPtr); |
| 623 |
code = Tcl_RecordAndEvalObj(interp, commandPtr, TCL_EVAL_GLOBAL); |
| 624 |
isPtr->input = chan = Tcl_GetStdChannel(TCL_STDIN); |
| 625 |
Tcl_DecrRefCount(commandPtr); |
| 626 |
isPtr->commandPtr = commandPtr = Tcl_NewObj(); |
| 627 |
Tcl_IncrRefCount(commandPtr); |
| 628 |
if (chan != (Tcl_Channel) NULL) { |
| 629 |
Tcl_CreateChannelHandler(chan, TCL_READABLE, StdinProc, |
| 630 |
(ClientData) isPtr); |
| 631 |
} |
| 632 |
if (code != TCL_OK) { |
| 633 |
Tcl_Channel errChannel = Tcl_GetStdChannel(TCL_STDERR); |
| 634 |
if (errChannel != (Tcl_Channel) NULL) { |
| 635 |
Tcl_WriteObj(errChannel, Tcl_GetObjResult(interp)); |
| 636 |
Tcl_WriteChars(errChannel, "\n", 1); |
| 637 |
} |
| 638 |
} else if (isPtr->tty) { |
| 639 |
Tcl_Obj *resultPtr = Tcl_GetObjResult(interp); |
| 640 |
Tcl_Channel outChannel = Tcl_GetStdChannel(TCL_STDOUT); |
| 641 |
Tcl_IncrRefCount(resultPtr); |
| 642 |
Tcl_GetStringFromObj(resultPtr, &length); |
| 643 |
if ((length >0) && (outChannel != (Tcl_Channel) NULL)) { |
| 644 |
Tcl_WriteObj(outChannel, resultPtr); |
| 645 |
Tcl_WriteChars(outChannel, "\n", 1); |
| 646 |
} |
| 647 |
Tcl_DecrRefCount(resultPtr); |
| 648 |
} |
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
prompt: |
| 655 |
if (isPtr->tty && (isPtr->input != (Tcl_Channel) NULL)) { |
| 656 |
Prompt(interp, &(isPtr->prompt)); |
| 657 |
isPtr->input = Tcl_GetStdChannel(TCL_STDIN); |
| 658 |
} |
| 659 |
} |
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
static void |
| 680 |
Prompt(interp, promptPtr) |
| 681 |
Tcl_Interp *interp; |
| 682 |
PromptType *promptPtr; |
| 683 |
|
| 684 |
|
| 685 |
{ |
| 686 |
Tcl_Obj *promptCmdPtr; |
| 687 |
int code; |
| 688 |
Tcl_Channel outChannel, errChannel; |
| 689 |
|
| 690 |
if (*promptPtr == PROMPT_NONE) { |
| 691 |
return; |
| 692 |
} |
| 693 |
|
| 694 |
promptCmdPtr = Tcl_GetVar2Ex(interp, |
| 695 |
((*promptPtr == PROMPT_CONTINUE) ? "tcl_prompt2" : "tcl_prompt1"), |
| 696 |
NULL, TCL_GLOBAL_ONLY); |
| 697 |
if (Tcl_InterpDeleted(interp)) { |
| 698 |
return; |
| 699 |
} |
| 700 |
if (promptCmdPtr == NULL) { |
| 701 |
defaultPrompt: |
| 702 |
outChannel = Tcl_GetStdChannel(TCL_STDOUT); |
| 703 |
if ((*promptPtr == PROMPT_START) |
| 704 |
&& (outChannel != (Tcl_Channel) NULL)) { |
| 705 |
Tcl_WriteChars(outChannel, "% ", 2); |
| 706 |
} |
| 707 |
} else { |
| 708 |
code = Tcl_EvalObjEx(interp, promptCmdPtr, TCL_EVAL_GLOBAL); |
| 709 |
if (code != TCL_OK) { |
| 710 |
Tcl_AddErrorInfo(interp, |
| 711 |
"\n (script that generates prompt)"); |
| 712 |
errChannel = Tcl_GetStdChannel(TCL_STDERR); |
| 713 |
if (errChannel != (Tcl_Channel) NULL) { |
| 714 |
Tcl_WriteObj(errChannel, Tcl_GetObjResult(interp)); |
| 715 |
Tcl_WriteChars(errChannel, "\n", 1); |
| 716 |
} |
| 717 |
goto defaultPrompt; |
| 718 |
} |
| 719 |
} |
| 720 |
outChannel = Tcl_GetStdChannel(TCL_STDOUT); |
| 721 |
if (outChannel != (Tcl_Channel) NULL) { |
| 722 |
Tcl_Flush(outChannel); |
| 723 |
} |
| 724 |
*promptPtr = PROMPT_NONE; |
| 725 |
} |