221 int ( *appInitProc )( Tcl_Interp *interp ) )
224 Tcl_Obj *commandPtr = NULL;
225 char buffer[1000], *args;
226 int code, gotPartial, tty;
229 Tcl_Channel inChannel, outChannel, errChannel;
231 Tcl_DString argString;
235 Tcl_FindExecutable( argv[0] );
236 interp = Tcl_CreateInterp();
237 Tcl_InitMemory( interp );
241 sprintf( usage,
"\nUsage:\n %s [filename] [options]\n", argv[0] );
254 if ( ( argc > 1 ) && ( argv[1][0] !=
'-' ) )
261 args = Tcl_Merge( argc - 1, (
const char *
const * )argv + 1 );
262 Tcl_ExternalToUtfDString( NULL, args, -1, &argString );
263 Tcl_SetVar( interp,
"argv", Tcl_DStringValue( &argString ), TCL_GLOBAL_ONLY );
264 Tcl_DStringFree( &argString );
269 Tcl_ExternalToUtfDString( NULL, argv[0], -1, &argString );
278 Tcl_SetVar( interp,
"argc", buffer, TCL_GLOBAL_ONLY );
279 Tcl_SetVar( interp,
"argv0", Tcl_DStringValue( &argString ), TCL_GLOBAL_ONLY );
286 Tcl_SetVar( interp,
"tcl_interactive",
294 if ( ( *appInitProc )( interp ) != TCL_OK )
296 errChannel = Tcl_GetStdChannel( TCL_STDERR );
299 Tcl_WriteChars( errChannel,
300 "application-specific initialization failed: ", -1 );
301 Tcl_WriteObj( errChannel, Tcl_GetObjResult( interp ) );
302 Tcl_WriteChars( errChannel,
"\n", 1 );
313 if ( code != TCL_OK )
315 fprintf( stderr,
"%s\n", Tcl_GetStringResult( interp ) );
328 if ( code != TCL_OK )
330 errChannel = Tcl_GetStdChannel( TCL_STDERR );
338 Tcl_AddErrorInfo( interp,
"" );
339 Tcl_WriteObj( errChannel, Tcl_GetVar2Ex( interp,
"errorInfo",
340 NULL, TCL_GLOBAL_ONLY ) );
341 Tcl_WriteChars( errChannel,
"\n", 1 );
347 Tcl_DStringFree( &argString );
354 Tcl_SourceRCFile( interp );
362 commandPtr = Tcl_NewObj();
363 Tcl_IncrRefCount( commandPtr );
365 inChannel = Tcl_GetStdChannel( TCL_STDIN );
366 outChannel = Tcl_GetStdChannel( TCL_STDOUT );
372 Tcl_Obj *promptCmdPtr;
374 promptCmdPtr = Tcl_GetVar2Ex( interp,
375 ( gotPartial ?
"tcl_prompt2" :
"tcl_prompt1" ),
376 NULL, TCL_GLOBAL_ONLY );
377 if ( promptCmdPtr == NULL )
380 if ( !gotPartial && outChannel )
382 Tcl_WriteChars( outChannel,
"% ", 2 );
387 code = Tcl_EvalObjEx( interp, promptCmdPtr, 0 );
388 inChannel = Tcl_GetStdChannel( TCL_STDIN );
389 outChannel = Tcl_GetStdChannel( TCL_STDOUT );
390 errChannel = Tcl_GetStdChannel( TCL_STDERR );
391 if ( code != TCL_OK )
395 Tcl_WriteObj( errChannel, Tcl_GetObjResult( interp ) );
396 Tcl_WriteChars( errChannel,
"\n", 1 );
398 Tcl_AddErrorInfo( interp,
399 "\n (script that generates prompt)" );
405 Tcl_Flush( outChannel );
412 length = Tcl_GetsObj( inChannel, commandPtr );
417 if ( ( length == 0 ) && Tcl_Eof( inChannel ) && ( !gotPartial ) )
426 Tcl_AppendToObj( commandPtr,
"\n", 1 );
427 if ( !Tcl_CommandComplete( Tcl_GetString( commandPtr ) ) )
434 code = Tcl_RecordAndEvalObj( interp, commandPtr, 0 );
435 inChannel = Tcl_GetStdChannel( TCL_STDIN );
436 outChannel = Tcl_GetStdChannel( TCL_STDOUT );
437 errChannel = Tcl_GetStdChannel( TCL_STDERR );
438 Tcl_DecrRefCount( commandPtr );
439 commandPtr = Tcl_NewObj();
440 Tcl_IncrRefCount( commandPtr );
445 ( *tclErrorHandler )( interp, code, tty );
451 ( *tclPrepOutputHandler )( interp, code, tty );
453 if ( code != TCL_OK )
457 Tcl_WriteObj( errChannel, Tcl_GetObjResult( interp ) );
458 Tcl_WriteChars( errChannel,
"\n", 1 );
463 resultPtr = Tcl_GetObjResult( interp );
464 Tcl_GetStringFromObj( resultPtr, &length );
465 if ( ( length > 0 ) && outChannel )
467 Tcl_WriteObj( outChannel, resultPtr );
468 Tcl_WriteChars( outChannel,
"\n", 1 );
481 if ( commandPtr != NULL )
483 Tcl_DecrRefCount( commandPtr );
485 sprintf( buffer,
"exit %d", exitCode );
486 Tcl_Eval( interp, buffer );
static const char * pltcl_notes[]
void(*) tclErrorHandler(Tcl_Interp *interp, int code, int tty)
char * strcpy(char *dst, const char *src)
static void plPrepOutputHandler(Tcl_Interp *interp, int code, int tty)
static PLOptionTable options[]
#define TclFormatInt(buf, n)
void(*) tclPrepOutputHandler(Tcl_Interp *interp, int code, int tty)