ARGSUSED */
| 398 | |
| 399 | /* ARGSUSED */ |
| 400 | static void |
| 401 | StdinProc(ClientData clientData, int mask) |
| 402 | { |
| 403 | static int gotPartial = 0; |
| 404 | char *cmd; |
| 405 | int code, count; |
| 406 | Tcl_Channel chan = (Tcl_Channel) clientData; |
| 407 | ThreadSpecificData *tsdPtr = (ThreadSpecificData *) |
| 408 | Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); |
| 409 | Tcl_Interp *interp = tsdPtr->interp; |
| 410 | |
| 411 | count = Tcl_Gets(chan, &tsdPtr->line); |
| 412 | |
| 413 | if (count < 0) { |
| 414 | if (!gotPartial) { |
| 415 | if (tsdPtr->tty) { |
| 416 | Tcl_Exit(0); |
| 417 | } else { |
| 418 | Tcl_DeleteChannelHandler(chan, StdinProc, (ClientData) chan); |
| 419 | } |
| 420 | return; |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | (void) Tcl_DStringAppend(&tsdPtr->command, Tcl_DStringValue( |
| 425 | &tsdPtr->line), -1); |
| 426 | cmd = Tcl_DStringAppend(&tsdPtr->command, "\n", -1); |
| 427 | Tcl_DStringFree(&tsdPtr->line); |
| 428 | if (!Tcl_CommandComplete(cmd)) { |
| 429 | gotPartial = 1; |
| 430 | goto prompt; |
| 431 | } |
| 432 | gotPartial = 0; |
| 433 | |
| 434 | /* |
| 435 | * Disable the stdin channel handler while evaluating the command; |
| 436 | * otherwise if the command re-enters the event loop we might |
| 437 | * process commands from stdin before the current command is |
| 438 | * finished. Among other things, this will trash the text of the |
| 439 | * command being evaluated. |
| 440 | */ |
| 441 | |
| 442 | Tcl_CreateChannelHandler(chan, 0, StdinProc, (ClientData) chan); |
| 443 | code = Tcl_RecordAndEval(interp, cmd, TCL_EVAL_GLOBAL); |
| 444 | |
| 445 | chan = Tcl_GetStdChannel(TCL_STDIN); |
| 446 | if (chan) { |
| 447 | Tcl_CreateChannelHandler(chan, TCL_READABLE, StdinProc, |
| 448 | (ClientData) chan); |
| 449 | } |
| 450 | Tcl_DStringFree(&tsdPtr->command); |
| 451 | if (Tcl_GetStringResult(interp)[0] != '\0') { |
| 452 | if ((code != TCL_OK) || (tsdPtr->tty)) { |
| 453 | chan = Tcl_GetStdChannel(TCL_STDOUT); |
| 454 | if (chan) { |
| 455 | Tcl_WriteObj(chan, Tcl_GetObjResult(interp)); |
| 456 | Tcl_WriteChars(chan, "\n", 1); |
| 457 | } |