225
231
/* if errorInfo has something, print it */
226
/* else use what's in interp->result */
232
/* else use what's in the interp result */
228
234
msg = Tcl_GetVar(interp,"errorInfo",TCL_GLOBAL_ONLY);
229
if (!msg) msg = interp->result;
235
if (!msg) msg = Tcl_GetStringResult (interp);
230
236
else if (check_for_nostack) {
231
237
/* suppress errorInfo if generated via */
232
238
/* error ... -nostack */
275
281
Tcl_Channel inChannel, outChannel;
276
282
ExpState *esPtr = expStdinoutGet();
277
283
/* int fd = fileno(stdin);*/
281
286
commandPtr = Tcl_NewObj();
282
287
Tcl_IncrRefCount(commandPtr);
291
if (Tcl_IsShared(commandPtr)) {
292
Tcl_DecrRefCount(commandPtr);
293
commandPtr = Tcl_DuplicateObj(commandPtr);
294
Tcl_IncrRefCount(commandPtr);
286
296
outChannel = expStdinoutGet()->channel;
287
297
if (outChannel) {
288
298
Tcl_Flush(outChannel);
352
362
* Add the newline removed by Tcl_GetsObj back to the string.
365
if (Tcl_IsShared(commandPtr)) {
366
Tcl_DecrRefCount(commandPtr);
367
commandPtr = Tcl_DuplicateObj(commandPtr);
368
Tcl_IncrRefCount(commandPtr);
355
370
Tcl_AppendToObj(commandPtr, "\n", 1);
356
371
if (!TclObjCommandComplete(commandPtr)) {
361
376
Tcl_AppendToObj(commandPtr, "\n", 1);
362
377
if (!TclObjCommandComplete(commandPtr)) {
369
384
if (tty_changed) exp_tty_set(interp,&tty_old,was_raw,was_echo);
371
386
code = Tcl_RecordAndEvalObj(interp, commandPtr, 0);
372
Tcl_SetObjLength(commandPtr, 0);
387
Tcl_DecrRefCount(commandPtr);
388
commandPtr = Tcl_NewObj();
389
Tcl_IncrRefCount(commandPtr);
414
Exp_ExpVersionCmd(clientData, interp, argc, argv)
431
Exp_ExpVersionObjCmd(clientData, interp, objc, objv)
415
432
ClientData clientData;
416
433
Tcl_Interp *interp;
435
Tcl_Obj *CONST objv[]; /* Argument objects. */
420
437
int emajor, umajor;
421
438
char *user_version; /* user-supplied version string */
424
441
Tcl_SetResult(interp,exp_version,TCL_STATIC);
428
445
exp_error(interp,"usage: expect_version [[-exit] version]");
429
446
return(TCL_ERROR);
432
user_version = argv[argc==2?1:2];
449
user_version = Tcl_GetString (objv[objc==2?1:2]);
433
450
emajor = atoi(exp_version);
434
451
umajor = atoi(user_version);
475
492
lappend auto_path $exp_exec_library\n\
496
DeleteCmdInfo (clientData, interp)
497
ClientData clientData;
479
505
Expect_Init(interp)
480
506
Tcl_Interp *interp;
482
508
static int first_time = TRUE;
510
Tcl_CmdInfo* close_info = NULL;
511
Tcl_CmdInfo* return_info = NULL;
484
513
if (first_time) {
514
#ifndef USE_TCL_STUBS
485
515
int tcl_major = atoi(TCL_VERSION);
486
516
char *dot = strchr(TCL_VERSION,'.');
487
517
int tcl_minor = atoi(dot+1);
489
519
if (tcl_major < NEED_TCL_MAJOR ||
490
520
(tcl_major == NEED_TCL_MAJOR && tcl_minor < NEED_TCL_MINOR)) {
491
sprintf(interp->result,
492
"%s compiled with Tcl %d.%d but needs at least Tcl %d.%d\n",
493
exp_argv0,tcl_major,tcl_minor,
494
NEED_TCL_MAJOR,NEED_TCL_MINOR);
524
Tcl_Obj* s = Tcl_NewStringObj (exp_argv0,-1);
526
sprintf(bufa,"%d.%d",tcl_major,tcl_minor);
527
sprintf(bufb,"%d.%d",NEED_TCL_MAJOR,NEED_TCL_MINOR);
529
Tcl_AppendStringsToObj (s,
530
" compiled with Tcl ", bufa,
531
" but needs at least Tcl ", bufb,
533
Tcl_SetObjResult (interp, s);
495
534
return TCL_ERROR;
539
#ifndef USE_TCL_STUBS
499
540
if (Tcl_PkgRequire(interp, "Tcl", TCL_VERSION, 0) == NULL) {
500
541
return TCL_ERROR;
502
if (Tcl_PkgProvide(interp, "Expect", EXP_VERSION) != TCL_OK) {
544
if (Tcl_InitStubs(interp, "8.1", 0) == NULL) {
550
* Save initial close and return for later use
553
close_info = (Tcl_CmdInfo*) ckalloc (sizeof (Tcl_CmdInfo));
554
if (Tcl_GetCommandInfo(interp, "close", close_info) == 0) {
555
ckfree ((char*) close_info);
558
return_info = (Tcl_CmdInfo*) ckalloc (sizeof (Tcl_CmdInfo));
559
if (Tcl_GetCommandInfo(interp, "return", return_info) == 0){
560
ckfree ((char*) close_info);
561
ckfree ((char*) return_info);
564
Tcl_SetAssocData (interp, EXP_CMDINFO_CLOSE, DeleteCmdInfo, (ClientData) close_info);
565
Tcl_SetAssocData (interp, EXP_CMDINFO_RETURN, DeleteCmdInfo, (ClientData) return_info);
568
* Expect redefines close so we need to save the original (pre-expect)
569
* definition so it can be restored before exiting.
571
* Needed when expect is dynamically loaded after close has
572
* been redefined e.g. the virtual file system in tclkit
574
if (TclRenameCommand(interp, "close", "_close.pre_expect") != TCL_OK) {
578
if (Tcl_PkgProvide(interp, "Expect", PACKAGE_VERSION) != TCL_OK) {
503
579
return TCL_ERROR;
812
909
expErrorLog("error executing system initialization file: %s\r\n",file);
813
910
if (rc != TCL_ERROR)
814
911
expErrorLog("Tcl_Eval = %d\r\n",rc);
815
if (*interp->result != 0) {
816
expErrorLogU(interp->result);
817
expErrorLogU("\r\n");
819
/* SF #439042 -- Allow overide of "exit" by user / script
822
char buffer [] = "exit 1";
823
Tcl_Eval(interp, buffer);
912
print_result (interp);
840
929
expErrorLog("error executing file: %s\r\n",file);
841
930
if (rc != TCL_ERROR)
842
931
expErrorLog("Tcl_Eval = %d\r\n",rc);
843
if (*interp->result != 0) {
844
expErrorLogU(interp->result);
845
expErrorLogU("\r\n");
847
/* SF #439042 -- Allow overide of "exit" by user / script
850
char buffer [] = "exit 1";
851
Tcl_Eval(interp, buffer);
932
print_result (interp);
922
1003
static struct exp_cmd_data cmd_data[] = {
923
{"exp_version", exp_proc(Exp_ExpVersionCmd), 0, 0},
924
{"prompt1", exp_proc(Exp_Prompt1Cmd), 0, EXP_NOPREFIX},
925
{"prompt2", exp_proc(Exp_Prompt2Cmd), 0, EXP_NOPREFIX},
1004
{"exp_version", Exp_ExpVersionObjCmd, 0, 0, 0},
1005
{"prompt1", Exp_Prompt1ObjCmd, 0, 0, EXP_NOPREFIX},
1006
{"prompt2", Exp_Prompt2ObjCmd, 0, 0, EXP_NOPREFIX},