more error message cleanup. invalid args & syntax errors both now print arguments of command.

git-svn-id: svn://svn.berlios.de/openocd/trunk@870 b42882b7-edfa-0310-969c-e2dbd0fdcd60
__archive__
oharboe 2008-07-24 14:50:41 +00:00
parent 161deacc06
commit 74eb754abc
2 changed files with 6 additions and 23 deletions

View File

@ -78,7 +78,7 @@ static int script_command(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
for (i = 0; i < argc; i++) for (i = 0; i < argc; i++)
{ {
int len; int len;
char *w=Jim_GetString(argv[i], &len); const char *w=Jim_GetString(argv[i], &len);
if (*w=='#') if (*w=='#')
{ {
/* hit an end of line comment */ /* hit an end of line comment */
@ -539,7 +539,6 @@ static size_t openocd_jim_fwrite(const void *_ptr, size_t size, size_t n, void *
size_t nbytes; size_t nbytes;
const char *ptr; const char *ptr;
Jim_Interp *interp; Jim_Interp *interp;
command_context_t *context;
/* make it a char easier to read code */ /* make it a char easier to read code */
ptr = _ptr; ptr = _ptr;
@ -549,19 +548,11 @@ static size_t openocd_jim_fwrite(const void *_ptr, size_t size, size_t n, void *
return 0; return 0;
} }
context = Jim_GetAssocData(interp, "context");
if (context == NULL)
{
LOG_ERROR("openocd_jim_fwrite: no command context");
/* TODO: Where should this go? */
return n;
}
/* do we have to chunk it? */ /* do we have to chunk it? */
if (ptr[nbytes] == 0) if (ptr[nbytes] == 0)
{ {
/* no it is a C style string */ /* no it is a C style string */
command_output_text(context, ptr); LOG_USER_N("%s", ptr);
return strlen(ptr); return strlen(ptr);
} }
/* GRR we must chunk - not null terminated */ /* GRR we must chunk - not null terminated */
@ -578,7 +569,7 @@ static size_t openocd_jim_fwrite(const void *_ptr, size_t size, size_t n, void *
/* terminate it */ /* terminate it */
chunk[n] = 0; chunk[n] = 0;
/* output it */ /* output it */
command_output_text(context, chunk); LOG_USER_N("%s", chunk);
ptr += x; ptr += x;
nbytes -= x; nbytes -= x;
} }
@ -597,24 +588,16 @@ static int openocd_jim_vfprintf(void *cookie, const char *fmt, va_list ap)
char *cp; char *cp;
int n; int n;
Jim_Interp *interp; Jim_Interp *interp;
command_context_t *context;
n = -1; n = -1;
interp = cookie; interp = cookie;
if (interp == NULL) if (interp == NULL)
return n; return n;
context = Jim_GetAssocData(interp, "context");
if (context == NULL)
{
LOG_ERROR("openocd_jim_vfprintf: no command context");
return n;
}
cp = alloc_vprintf(fmt, ap); cp = alloc_vprintf(fmt, ap);
if (cp) if (cp)
{ {
command_output_text(context, cp); LOG_USER_N("%s", cp);
n = strlen(cp); n = strlen(cp);
free(cp); free(cp);
} }

View File

@ -109,10 +109,10 @@ extern int debug_level;
* error codes < 100 * error codes < 100
*/ */
#define ERROR_OK (0) #define ERROR_OK (0)
#define ERROR_INVALID_ARGUMENTS (-1) #define ERROR_INVALID_ARGUMENTS ERROR_COMMAND_SYNTAX_ERROR
#define ERROR_NO_CONFIG_FILE (-2) #define ERROR_NO_CONFIG_FILE (-2)
#define ERROR_BUF_TOO_SMALL (-3) #define ERROR_BUF_TOO_SMALL (-3)
/* see "Error:" message for meaningful message to the user. The caller should /* see "Error:" log entry for meaningful message to the user. The caller should
* make no assumptions about what went wrong and try to handle the problem. * make no assumptions about what went wrong and try to handle the problem.
*/ */
#define ERROR_FAIL (-4) #define ERROR_FAIL (-4)