Commit dc796a20 authored by oharboe's avatar oharboe
Browse files

src/helper/configuration.h

	- Log output handlers now get a "const char *line"
	- Added "const" to parameter.

src/helper/command.c
src/helper/command.h
	- New function:  'command_output_text()'
	- Log output handlers now get a "const char *line"
 
src/helper/options.c
	- Log output handlers now get a "const char *line"

src/server/telnet_server.c
	- DO not transmit NULL bytes via TELNET.
	- Log output handlers now get a "const char *line"
	
src/server/gdb_server.c
	- Log output handlers now get a "const char *line"
	
	*** THIS INCLUDES PORTIONS OF A PATCH FROM Oyvind sent 
	previously to the mailing list for TCL users try

src/target/target.c
	*** THIS INCLUDES PORTIONS OF A PATCH FROM Oyvind sent 
	previously to the mailing list for TCL users try
	
src/target/target.h
	*** THIS INCLUDES PORTIONS OF A PATCH FROM Oyvind sent 
	previously to the mailing list for TCL users try

src/openocd.c
    - **MAJOR** Work: New TCL/Jim function: mem2array
	- **MAJOR** Work: Redirect Tcl/Jim stdio output to remote users.
	- Previously: TCL output did not go to GDB.
	- Previously: TCL output did not go to TELNET
	- Previously: TCL output only goes to control console.
	- This fixes that problem.
	+ Created callbacks:
		+openocd_jim_fwrite()	
		+openocd_jim_fread()
		+openocd_jim_vfprintf()
		+openocd_jim_fflush()
		+openocd_jim_fgets()

src/Makefile.am
	- New TCL files.
	- Future note: This should be more automated.  As the list of
	  'tcl' files grows maintaning this list will suck.

src/Jim.c
	- ** THIS INCLUDES A PREVIOUS PATCH I SENT EARLIER **
	- that impliments many [format] specifies JIM did not support.
	- Jim_FormatString() - **MAJOR** work.
	- Previously only supported "%s" "%d" and "%c"
	- And what support existed had bugs.
	- NEW: *MANY* formating parameters are now supported.
	- TODO: The "precision" specifier is not supported.

	** NEW ** This patch.
	
	- Jim_StringToWide() test if no conversion occured.
	- Jim_StringToIndex() test if no conversion occured.
	- Jim_StringToDouble() test if no conversion occured.

	** NEW ** This Patch. Major Work.
	- Previously output from JIM did not get sent to GDB
	- Ditto: Output to Telnet session.
	- Above items are now fixed - By introducing callbacks
	  new function pointers in the "interp" structure.

	- Helpers that call the callbacks.
	
	- New function: Jim_fprintf()
	- New function: Jim_vfprintf()
	- New function: Jim_fwrite()
	- New function: Jim_fread()
	- New function: Jim_fflush()
	- New function: Jim_fgets()

	By default: the output is to STDIO as previous.
	The "openocd.c" - redirects the output as needed.
	
	- Jim_Panic() - Send panic to both STDERR and the interps
	specified STDERR output as a 2nd choice.

	- Now JIM's "stdin/stdout/stderr" paramters are "void *"
	and are no longer "FILE *".

src/Jim.h
	- **MAJOR**
	-  New JIM STDIO callbacks in the "interp" structure.
	-  change: "stdin/stdout/stderr" are now "void *" cookies.
	-  New JIM stdio helper functions.



git-svn-id: svn://svn.berlios.de/openocd/trunk@755 b42882b7-edfa-0310-969c-e2dbd0fdcd60
parent 71460ba9
...@@ -81,4 +81,20 @@ openocd_LDADD = $(top_builddir)/src/xsvf/libxsvf.a \ ...@@ -81,4 +81,20 @@ openocd_LDADD = $(top_builddir)/src/xsvf/libxsvf.a \
nobase_dist_pkglib_DATA = tcl/commands.tcl nobase_dist_pkglib_DATA = \
tcl/commands.tcl \
tcl/bitsbytes.tcl \
tcl/chip/atmel/at91/aic.tcl \
tcl/chip/atmel/at91/at91sam7x128.tcl \
tcl/chip/atmel/at91/at91sam7x256.tcl \
tcl/chip/atmel/at91/pmc.tcl \
tcl/chip/atmel/at91/rtt.tcl \
tcl/chip/atmel/at91/usarts.tcl \
tcl/cpu/arm/arm7tdmi.tcl \
tcl/cpu/arm/arm920.tcl \
tcl/cpu/arm/arm946.tcl \
tcl/cpu/arm/arm966.tcl \
tcl/memory.tcl \
tcl/mmr_helpers.tcl \
tcl/readable.tcl
...@@ -621,7 +621,7 @@ int command_print_help(command_context_t* context, char* name, char** args, int ...@@ -621,7 +621,7 @@ int command_print_help(command_context_t* context, char* name, char** args, int
return command_print_help_match(context, context->commands, name, args, argc); return command_print_help_match(context, context->commands, name, args, argc);
} }
void command_set_output_handler(command_context_t* context, int (*output_handler)(struct command_context_s *context, char* line), void *priv) void command_set_output_handler(command_context_t* context, int (*output_handler)(struct command_context_s *context, const char* line), void *priv)
{ {
context->output_handler = output_handler; context->output_handler = output_handler;
context->output_handler_priv = priv; context->output_handler_priv = priv;
...@@ -720,3 +720,10 @@ int handle_time_command(struct command_context_s *cmd_ctx, char *cmd, char **arg ...@@ -720,3 +720,10 @@ int handle_time_command(struct command_context_s *cmd_ctx, char *cmd, char **arg
return retval; return retval;
} }
/*
* Local Variables: **
* tab-width: 4 **
* c-basic-offset: 4 **
* End: **
*/
...@@ -48,7 +48,7 @@ typedef struct command_context_s ...@@ -48,7 +48,7 @@ typedef struct command_context_s
* Returning ERROR_COMMAND_SYNTAX_ERROR will have the effect of * Returning ERROR_COMMAND_SYNTAX_ERROR will have the effect of
* printing out the syntax of the command. * printing out the syntax of the command.
*/ */
int (*output_handler)(struct command_context_s *context, char* line); int (*output_handler)(struct command_context_s *context, const char* line);
void *output_handler_priv; void *output_handler_priv;
} command_context_t; } command_context_t;
...@@ -67,7 +67,7 @@ typedef struct command_s ...@@ -67,7 +67,7 @@ typedef struct command_s
extern command_t* register_command(command_context_t *context, command_t *parent, char *name, int (*handler)(struct command_context_s *context, char* name, char** args, int argc), enum command_mode mode, char *help); extern command_t* register_command(command_context_t *context, command_t *parent, char *name, int (*handler)(struct command_context_s *context, char* name, char** args, int argc), enum command_mode mode, char *help);
extern int unregister_command(command_context_t *context, char *name); extern int unregister_command(command_context_t *context, char *name);
extern int unregister_all_commands(command_context_t *context); extern int unregister_all_commands(command_context_t *context);
extern void command_set_output_handler(command_context_t* context, int (*output_handler)(struct command_context_s *context, char* line), void *priv); extern void command_set_output_handler(command_context_t* context, int (*output_handler)(struct command_context_s *context, const char* line), void *priv);
extern command_context_t* copy_command_context(command_context_t* context); extern command_context_t* copy_command_context(command_context_t* context);
extern command_context_t* command_init(); extern command_context_t* command_init();
extern int command_done(command_context_t *context); extern int command_done(command_context_t *context);
...@@ -86,3 +86,11 @@ extern int command_run_file(command_context_t *context, FILE *file, enum command ...@@ -86,3 +86,11 @@ extern int command_run_file(command_context_t *context, FILE *file, enum command
extern int fast_and_dangerous; extern int fast_and_dangerous;
#endif /* COMMAND_H */ #endif /* COMMAND_H */
/*
* Local Variables: **
* tab-width: 4 **
* c-basic-offset: 4 **
* End: **
*/
...@@ -27,7 +27,7 @@ extern int parse_cmdline_args(struct command_context_s *cmd_ctx, int argc, char ...@@ -27,7 +27,7 @@ extern int parse_cmdline_args(struct command_context_s *cmd_ctx, int argc, char
extern int parse_config_file(struct command_context_s *cmd_ctx); extern int parse_config_file(struct command_context_s *cmd_ctx);
extern void add_config_command (const char *cfg); extern void add_config_command (const char *cfg);
extern void add_script_search_dir (const char *dir); extern void add_script_search_dir (const char *dir);
extern int configuration_output_handler(struct command_context_s *context, char* line); extern int configuration_output_handler(struct command_context_s *context, const char* line);
extern FILE *open_file_from_path (char *file, char *mode); extern FILE *open_file_from_path (char *file, char *mode);
extern char *find_file(char *name); extern char *find_file(char *name);
......
...@@ -45,7 +45,7 @@ static struct option long_options[] = ...@@ -45,7 +45,7 @@ static struct option long_options[] =
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
int configuration_output_handler(struct command_context_s *context, char* line) int configuration_output_handler(struct command_context_s *context, const char* line)
{ {
LOG_INFO_N(line); LOG_INFO_N(line);
......
...@@ -363,7 +363,7 @@ int Jim_StringToWide(const char *str, jim_wide *widePtr, int base) ...@@ -363,7 +363,7 @@ int Jim_StringToWide(const char *str, jim_wide *widePtr, int base)
#else #else
*widePtr = strtol(str, &endptr, base); *widePtr = strtol(str, &endptr, base);
#endif #endif
if (str[0] == '\0') if ((str[0] == '\0') || (str == endptr) )
return JIM_ERR; return JIM_ERR;
if (endptr[0] != '\0') { if (endptr[0] != '\0') {
while(*endptr) { while(*endptr) {
...@@ -380,7 +380,7 @@ int Jim_StringToIndex(const char *str, int *intPtr) ...@@ -380,7 +380,7 @@ int Jim_StringToIndex(const char *str, int *intPtr)
char *endptr; char *endptr;
*intPtr = strtol(str, &endptr, 10); *intPtr = strtol(str, &endptr, 10);
if (str[0] == '\0') if ( (str[0] == '\0') || (str == endptr) )
return JIM_ERR; return JIM_ERR;
if (endptr[0] != '\0') { if (endptr[0] != '\0') {
while(*endptr) { while(*endptr) {
...@@ -437,7 +437,7 @@ int Jim_StringToDouble(const char *str, double *doublePtr) ...@@ -437,7 +437,7 @@ int Jim_StringToDouble(const char *str, double *doublePtr)
char *endptr; char *endptr;
*doublePtr = strtod(str, &endptr); *doublePtr = strtod(str, &endptr);
if (str[0] == '\0' || endptr[0] != '\0') if (str[0] == '\0' || endptr[0] != '\0' || (str == endptr) )
return JIM_ERR; return JIM_ERR;
return JIM_OK; return JIM_OK;
} }
...@@ -460,13 +460,16 @@ static jim_wide JimPowWide(jim_wide b, jim_wide e) ...@@ -460,13 +460,16 @@ static jim_wide JimPowWide(jim_wide b, jim_wide e)
void Jim_Panic(Jim_Interp *interp, const char *fmt, ...) void Jim_Panic(Jim_Interp *interp, const char *fmt, ...)
{ {
va_list ap; va_list ap;
FILE *fp = interp ? interp->stderr_ : stderr;
va_start(ap, fmt); va_start(ap, fmt);
fprintf(fp, JIM_NL "JIM INTERPRETER PANIC: "); /*
vfprintf(fp, fmt, ap); * Send it here first.. Assuming STDIO still works
fprintf(fp, JIM_NL JIM_NL); */
fprintf(stderr, JIM_NL "JIM INTERPRETER PANIC: ");
vfprintf(stderr, fmt, ap);
fprintf(stderr, JIM_NL JIM_NL);
va_end(ap); va_end(ap);
#ifdef HAVE_BACKTRACE #ifdef HAVE_BACKTRACE
{ {
void *array[40]; void *array[40];
...@@ -481,6 +484,13 @@ void Jim_Panic(Jim_Interp *interp, const char *fmt, ...) ...@@ -481,6 +484,13 @@ void Jim_Panic(Jim_Interp *interp, const char *fmt, ...)
fprintf(fp,"[backtrace] of 'nm <executable>' in the bug report." JIM_NL); fprintf(fp,"[backtrace] of 'nm <executable>' in the bug report." JIM_NL);
} }
#endif #endif
/* This may actually crash... we do it last */
if( interp && interp->cookie_stderr ){
Jim_fprintf( interp, interp->cookie_stderr, JIM_NL "JIM INTERPRETER PANIC: ");
Jim_vfprintf( interp, interp->cookie_stderr, fmt, ap );
Jim_fprintf( interp, interp->cookie_stderr, JIM_NL JIM_NL );
}
abort(); abort();
} }
...@@ -2136,21 +2146,36 @@ static Jim_Obj *JimStringToUpper(Jim_Interp *interp, Jim_Obj *strObjPtr) ...@@ -2136,21 +2146,36 @@ static Jim_Obj *JimStringToUpper(Jim_Interp *interp, Jim_Obj *strObjPtr)
} }
/* This is the core of the [format] command. /* This is the core of the [format] command.
* TODO: Export it, make it real... for now only %s and %% * TODO: Lots of things work - via a hack
* specifiers supported. */ * However, no format item can be >= JIM_MAX_FMT
*/
Jim_Obj *Jim_FormatString(Jim_Interp *interp, Jim_Obj *fmtObjPtr, Jim_Obj *Jim_FormatString(Jim_Interp *interp, Jim_Obj *fmtObjPtr,
int objc, Jim_Obj *const *objv) int objc, Jim_Obj *const *objv)
{ {
const char *fmt; const char *fmt, *_fmt;
int fmtLen; int fmtLen;
Jim_Obj *resObjPtr; Jim_Obj *resObjPtr;
fmt = Jim_GetString(fmtObjPtr, &fmtLen); fmt = Jim_GetString(fmtObjPtr, &fmtLen);
_fmt = fmt;
resObjPtr = Jim_NewStringObj(interp, "", 0); resObjPtr = Jim_NewStringObj(interp, "", 0);
while (fmtLen) { while (fmtLen) {
const char *p = fmt; const char *p = fmt;
char spec[2], c; char spec[2], c;
jim_wide wideValue; jim_wide wideValue;
double doubleValue;
/* we cheat and use Sprintf()! */
#define JIM_MAX_FMT 2048
char sprintf_buf[JIM_MAX_FMT];
char fmt_str[100];
char *cp;
int width;
int ljust;
int zpad;
int spad;
int altfm;
int forceplus;
while (*fmt != '%' && fmtLen) { while (*fmt != '%' && fmtLen) {
fmt++; fmtLen--; fmt++; fmtLen--;
...@@ -2159,38 +2184,191 @@ Jim_Obj *Jim_FormatString(Jim_Interp *interp, Jim_Obj *fmtObjPtr, ...@@ -2159,38 +2184,191 @@ Jim_Obj *Jim_FormatString(Jim_Interp *interp, Jim_Obj *fmtObjPtr,
if (fmtLen == 0) if (fmtLen == 0)
break; break;
fmt++; fmtLen--; /* skip '%' */ fmt++; fmtLen--; /* skip '%' */
if (*fmt != '%') { zpad = 0;
spad = 0;
width = -1;
ljust = 0;
altfm = 0;
forceplus = 0;
next_fmt:
if( fmtLen <= 0 ){
break;
}
switch( *fmt ){
/* terminals */
case 'b': /* binary - not all printfs() do this */
case 's': /* string */
case 'i': /* integer */
case 'd': /* decimal */
case 'x': /* hex */
case 'X': /* CAP hex */
case 'c': /* char */
case 'o': /* octal */
case 'u': /* unsigned */
case 'f': /* float */
break;
/* non-terminals */
case '0': /* zero pad */
zpad = 1;
*fmt++; fmtLen--;
goto next_fmt;
break;
case '+':
forceplus = 1;
*fmt++; fmtLen--;
goto next_fmt;
break;
case ' ': /* sign space */
spad = 1;
*fmt++; fmtLen--;
goto next_fmt;
break;
case '-':
ljust = 1;
*fmt++; fmtLen--;
goto next_fmt;
break;
case '#':
altfm = 1;
*fmt++; fmtLen--;
goto next_fmt;
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
width = 0;
while( isdigit(*fmt) && (fmtLen > 0) ){
width = (width * 10) + (*fmt - '0');
fmt++; fmtLen--;
}
goto next_fmt;
case '*':
/* suck up the next item as an integer */
*fmt++; fmtLen--;
objc--;
if( objc <= 0 ){
goto not_enough_args;
}
if( Jim_GetWide(interp,objv[0],&wideValue )== JIM_ERR ){
Jim_FreeNewObj(interp, resObjPtr );
return NULL;
}
width = wideValue;
if( width < 0 ){
ljust = 1;
width = -width;
}
objv++;
goto next_fmt;
break;
}
if (*fmt != '%') {
if (objc == 0) { if (objc == 0) {
not_enough_args:
Jim_FreeNewObj(interp, resObjPtr); Jim_FreeNewObj(interp, resObjPtr);
Jim_SetResultString(interp, Jim_SetResultString(interp,
"not enough arguments for all format specifiers", -1); "not enough arguments for all format specifiers", -1);
return NULL; return NULL;
} else { } else {
objc--; objc--;
} }
} }
/*
* Create the formatter
* cause we cheat and use sprintf()
*/
cp = fmt_str;
*cp++ = '%';
if( altfm ){
*cp++ = '#';
}
if( forceplus ){
*cp++ = '+';
} else if( spad ){
/* PLUS overrides */
*cp++ = ' ';
}
if( ljust ){
*cp++ = '-';
}
if( zpad ){
*cp++ = '0';
}
if( width > 0 ){
sprintf( cp, "%d", width );
/* skip ahead */
cp = strchr(cp,0);
}
*cp = 0;
/* here we do the work */
/* actually - we make sprintf() do it for us */
switch(*fmt) { switch(*fmt) {
case 's': case 's':
Jim_AppendObj(interp, resObjPtr, objv[0]); *cp++ = 's';
objv++; *cp = 0;
/* BUG: we do not handled embeded NULLs */
snprintf( sprintf_buf, JIM_MAX_FMT, fmt_str, Jim_GetString( objv[0], NULL ));
break; break;
case 'c': case 'c':
*cp++ = 'c';
*cp = 0;
if (Jim_GetWide(interp, objv[0], &wideValue) == JIM_ERR) { if (Jim_GetWide(interp, objv[0], &wideValue) == JIM_ERR) {
Jim_FreeNewObj(interp, resObjPtr); Jim_FreeNewObj(interp, resObjPtr);
return NULL; return NULL;
} }
c = (char) wideValue; c = (char) wideValue;
Jim_AppendString(interp, resObjPtr, &c, 1); snprintf( sprintf_buf, JIM_MAX_FMT, fmt_str, c );
break; break;
case 'f':
case 'F':
case 'g':
case 'G':
case 'e':
case 'E':
*cp++ = *fmt;
*cp = 0;
if( Jim_GetDouble( interp, objv[0], &doubleValue ) == JIM_ERR ){
Jim_FreeNewObj( interp, resObjPtr );
return NULL;
}
snprintf( sprintf_buf, JIM_MAX_FMT, fmt_str, doubleValue );
break;
case 'b':
case 'd': case 'd':
case 'i':
case 'u':
case 'x':
case 'X':
/* jim widevaluse are 64bit */
if( sizeof(jim_wide) == sizeof(long long) ){
*cp++ = 'l';
*cp++ = 'l';
} else {
*cp++ = 'l';
}
*cp++ = *fmt;
*cp = 0;
if (Jim_GetWide(interp, objv[0], &wideValue) == JIM_ERR) { if (Jim_GetWide(interp, objv[0], &wideValue) == JIM_ERR) {
Jim_FreeNewObj(interp, resObjPtr); Jim_FreeNewObj(interp, resObjPtr);
return NULL; return NULL;
} }
Jim_AppendObj(interp, resObjPtr, objv[0]); snprintf(sprintf_buf, JIM_MAX_FMT, fmt_str, wideValue );
break; break;
case '%': case '%':
Jim_AppendString(interp, resObjPtr, "%" , 1); sprintf_buf[0] = '%';
sprintf_buf[1] = 0;
objv--; /* undo the objv++ below */
break; break;
default: default:
spec[0] = *fmt; spec[1] = '\0'; spec[0] = *fmt; spec[1] = '\0';
...@@ -2200,6 +2378,16 @@ Jim_Obj *Jim_FormatString(Jim_Interp *interp, Jim_Obj *fmtObjPtr, ...@@ -2200,6 +2378,16 @@ Jim_Obj *Jim_FormatString(Jim_Interp *interp, Jim_Obj *fmtObjPtr,
"bad field specifier \"", spec, "\"", NULL); "bad field specifier \"", spec, "\"", NULL);
return NULL; return NULL;
} }
/* force terminate */
#if 0
printf("FMT was: %s\n", fmt_str );
printf("RES was: |%s|\n", sprintf_buf );
#endif
sprintf_buf[ JIM_MAX_FMT - 1] = 0;
Jim_AppendString( interp, resObjPtr, sprintf_buf, strlen(sprintf_buf) );
/* next obj */
objv++;
fmt++; fmt++;
fmtLen--; fmtLen--;
} }
...@@ -3910,7 +4098,7 @@ int Jim_Collect(Jim_Interp *interp) ...@@ -3910,7 +4098,7 @@ int Jim_Collect(Jim_Interp *interp)
Jim_AddHashEntry(&marks, Jim_AddHashEntry(&marks,
&objPtr->internalRep.refValue.id, NULL); &objPtr->internalRep.refValue.id, NULL);
#ifdef JIM_DEBUG_GC #ifdef JIM_DEBUG_GC
fprintf(interp->stdout_, Jim_fprintf(interp,interp->cookie_stdout,
"MARK (reference): %d refcount: %d" JIM_NL, "MARK (reference): %d refcount: %d" JIM_NL,
(int) objPtr->internalRep.refValue.id, (int) objPtr->internalRep.refValue.id,
objPtr->refCount); objPtr->refCount);
...@@ -3949,7 +4137,7 @@ int Jim_Collect(Jim_Interp *interp) ...@@ -3949,7 +4137,7 @@ int Jim_Collect(Jim_Interp *interp)
* was found. Mark it. */ * was found. Mark it. */
Jim_AddHashEntry(&marks, &id, NULL); Jim_AddHashEntry(&marks, &id, NULL);
#ifdef JIM_DEBUG_GC #ifdef JIM_DEBUG_GC
fprintf(interp->stdout_,"MARK: %d" JIM_NL, (int)id); Jim_fprintf(interp,interp->cookie_stdout,"MARK: %d" JIM_NL, (int)id);
#endif #endif
p += JIM_REFERENCE_SPACE; p += JIM_REFERENCE_SPACE;
} }
...@@ -3969,7 +4157,7 @@ int Jim_Collect(Jim_Interp *interp) ...@@ -3969,7 +4157,7 @@ int Jim_Collect(Jim_Interp *interp)
* this reference. */ * this reference. */
if (Jim_FindHashEntry(&marks, refId) == NULL) { if (Jim_FindHashEntry(&marks, refId) == NULL) {
#ifdef JIM_DEBUG_GC #ifdef JIM_DEBUG_GC
fprintf(interp->stdout_,"COLLECTING %d" JIM_NL, (int)*refId); Jim_fprintf(interp,interp->cookie_stdout,"COLLECTING %d" JIM_NL, (int)*refId);
#endif #endif
collected++; collected++;
/* Drop the reference, but call the /* Drop the reference, but call the
...@@ -4057,9 +4245,14 @@ Jim_Interp *Jim_CreateInterp(void) ...@@ -4057,9 +4245,14 @@ Jim_Interp *Jim_CreateInterp(void)
i->freeFramesList = NULL; i->freeFramesList = NULL;
i->prngState = NULL; i->prngState = NULL;
i->evalRetcodeLevel = -1; i->evalRetcodeLevel = -1;
i->stdin_ = stdin; i->cookie_stdin = stdin;
i->stdout_ = stdout; i->cookie_stdout = stdout;
i->stderr_ = stderr; i->cookie_stderr = stderr;
i->cb_fwrite = ((size_t (*)( const void *, size_t, size_t, void *))(fwrite));
i->cb_fread = ((size_t (*)( void *, size_t, size_t, void *))(fread));
i->cb_vfprintf = ((int (*)( void *, const char *fmt, va_list ))(vfprintf));
i->cb_fflush = ((int (*)( void *))(fflush));
i->cb_fgets = ((char * (*)( char *, int, void *))(fgets));
/* Note that we can create objects only after the /* Note that we can create objects only after the
* interpreter liveList and freeList pointers are * interpreter liveList and freeList pointers are
...@@ -4128,23 +4321,23 @@ void Jim_FreeInterp(Jim_Interp *i) ...@@ -4128,23 +4321,23 @@ void Jim_FreeInterp(Jim_Interp *i)
if (i->liveList != NULL) { if (i->liveList != NULL) {
Jim_Obj *objPtr = i->liveList; Jim_Obj *objPtr = i->liveList;
fprintf(i->stdout_,JIM_NL "-------------------------------------" JIM_NL); Jim_fprintf( i, i->cookie_stdout,JIM_NL "-------------------------------------" JIM_NL);
fprintf(i->stdout_,"Objects still in the free list:" JIM_NL); Jim_fprintf( i, i->cookie_stdout,"Objects still in the free list:" JIM_NL);
while(objPtr) { while(objPtr) {
const char *type = objPtr->typePtr ? const char *type = objPtr->typePtr ?
objPtr->typePtr->name : ""; objPtr->typePtr->name : "";
fprintf(i->stdout_,"%p \"%-10s\": '%.20s' (refCount: %d)" JIM_NL, Jim_fprintf( i, i->cookie_stdout,"%p \"%-10s\": '%.20s' (refCount: %d)" JIM_NL,
objPtr, type, objPtr, type,
objPtr->bytes ? objPtr->bytes objPtr->bytes ? objPtr->bytes
: "(null)", objPtr->refCount); : "(null)", objPtr->refCount);
if (objPtr->typePtr == &sourceObjType) { if (objPtr->typePtr == &sourceObjType) {
fprintf(i->stdout_, "FILE %s LINE %d" JIM_NL, Jim_fprintf( i, i->cookie_stdout, "FILE %s LINE %d" JIM_NL,
objPtr->internalRep.sourceValue.fileName, objPtr->internalRep.sourceValue.fileName,
objPtr->internalRep.sourceValue.lineNumber); objPtr->internalRep.sourceValue.lineNumber);
} }
objPtr = objPtr->nextObjPtr; objPtr = objPtr->nextObjPtr;
} }
fprintf(stdout, "-------------------------------------" JIM_NL JIM_NL); Jim_fprintf( i, i->cookie_stdout, "-------------------------------------" JIM_NL JIM_NL);
Jim_Panic(i,"Live list non empty freeing the interpreter! Leak?"); Jim_Panic(i,"Live list non empty freeing the interpreter! Leak?");
} }
/* Free all the freed objects. */ /* Free all the freed objects. */
...@@ -4330,22 +4523,22 @@ int Jim_GetExitCode(Jim_Interp *interp) { ...@@ -4330,22 +4523,22 @@ int Jim_GetExitCode(Jim_Interp *interp) {
return interp->exitCode; return interp->exitCode;
} }
FILE *Jim_SetStdin(Jim_Interp *interp, FILE *fp) void *Jim_SetStdin(Jim_Interp *interp, void *fp)
{ {
if (fp != NULL) interp->stdin_ = fp; if (fp != NULL) interp->cookie_stdin = fp;
return interp->stdin_; return interp->cookie_stdin;
} }
FILE *Jim_SetStdout(Jim_Interp *interp, FILE *fp) void *Jim_SetStdout(Jim_Interp *interp, void *fp)
{ {
if (fp != NULL) interp->stdout_ = fp; if (fp != NULL) interp->cookie_stdout = fp;
return interp->stdout_; return interp->cookie_stdout;
} }
FILE *Jim_SetStderr(Jim_Interp *interp, FILE *fp) void *Jim_SetStderr(Jim_Interp *interp, void *fp)
{ {
if (fp != NULL) interp->stderr_ = fp; if (fp != NULL) interp->cookie_stderr = fp;
return interp->stderr_; return interp->cookie_stderr;
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
...@@ -8478,7 +8671,7 @@ int Jim_EvalObjBackground(Jim_Interp *interp, Jim_Obj *scriptObjPtr) ...@@ -8478,7 +8671,7 @@ int Jim_EvalObjBackground(Jim_Interp *interp, Jim_Obj *scriptObjPtr)
Jim_IncrRefCount(objv[1]); Jim_IncrRefCount(objv[1]);
if (Jim_EvalObjVector(interp, 2, objv) != JIM_OK) { if (Jim_EvalObjVector(interp, 2, objv) != JIM_OK) {
/* Report the error to stderr. */ /* Report the error to stderr. */
fprintf(interp->stderr_, "Background error:" JIM_NL);