- apply correct formatting to openocd.c

- Thanks Charles Hardin

git-svn-id: svn://svn.berlios.de/openocd/trunk@770 b42882b7-edfa-0310-969c-e2dbd0fdcd60
This commit is contained in:
ntfreak 2008-07-08 08:55:53 +00:00
parent 9103bbbcb5
commit 31e2500259
1 changed files with 174 additions and 206 deletions

View File

@ -151,8 +151,7 @@ int handle_init_command(struct command_context_s *cmd_ctx, char *cmd, char **arg
LOG_DEBUG("jtag interface init complete"); LOG_DEBUG("jtag interface init complete");
/* Try to initialize & examine the JTAG chain at this point, but /* Try to initialize & examine the JTAG chain at this point, but
* continue startup regardless * continue startup regardless */
*/
if (jtag_init(cmd_ctx) == ERROR_OK) if (jtag_init(cmd_ctx) == ERROR_OK)
{ {
LOG_DEBUG("jtag init complete"); LOG_DEBUG("jtag init complete");
@ -185,7 +184,6 @@ int handle_init_command(struct command_context_s *cmd_ctx, char *cmd, char **arg
return ERROR_OK; return ERROR_OK;
} }
Jim_Interp *interp; Jim_Interp *interp;
command_context_t *active_cmd_ctx; command_context_t *active_cmd_ctx;
@ -205,7 +203,7 @@ static int new_int_array_element(Jim_Interp * interp, const char *varname, int i
Jim_DecrRefCount(interp, nameObjPtr); Jim_DecrRefCount(interp, nameObjPtr);
Jim_DecrRefCount(interp, valObjPtr); Jim_DecrRefCount(interp, valObjPtr);
free(namebuf); free(namebuf);
// printf( "%s = 0%08x\n", namebuf, val ); /* printf( "%s = 0%08x\n", namebuf, val ); */
return result; return result;
} }
@ -261,32 +259,24 @@ static int Jim_Command_mem2array(Jim_Interp *interp, int argc, Jim_Obj *const *a
width = 4; width = 4;
break; break;
default: default:
Jim_SetResult(interp, Jim_SetResult(interp, Jim_NewEmptyStringObj(interp));
Jim_NewEmptyStringObj(interp)); Jim_AppendStrings( interp, Jim_GetResult(interp), "Invalid width param, must be 8/16/32", NULL );
Jim_AppendStrings( interp, Jim_GetResult(interp),
"Invalid width param, must be 8/16/32", NULL );
return JIM_ERR; return JIM_ERR;
} }
if (len == 0) { if (len == 0) {
Jim_SetResult(interp, Jim_SetResult(interp, Jim_NewEmptyStringObj(interp));
Jim_NewEmptyStringObj(interp)); Jim_AppendStrings(interp, Jim_GetResult(interp), "mem2array: zero width read?", NULL);
Jim_AppendStrings( interp, Jim_GetResult(interp),
"mem2array: zero width read?", NULL );
return JIM_ERR; return JIM_ERR;
} }
if ((addr + (len * width)) < addr) { if ((addr + (len * width)) < addr) {
Jim_SetResult(interp, Jim_SetResult(interp, Jim_NewEmptyStringObj(interp));
Jim_NewEmptyStringObj(interp)); Jim_AppendStrings(interp, Jim_GetResult(interp), "mem2array: addr + len - wraps to zero?", NULL);
Jim_AppendStrings( interp, Jim_GetResult(interp),
"mem2array: addr + len - wraps to zero?", NULL );
return JIM_ERR; return JIM_ERR;
} }
/* absurd transfer size? */ /* absurd transfer size? */
if (len > 65536) { if (len > 65536) {
Jim_SetResult(interp, Jim_SetResult(interp, Jim_NewEmptyStringObj(interp));
Jim_NewEmptyStringObj(interp)); Jim_AppendStrings(interp, Jim_GetResult(interp), "mem2array: absurd > 64K item request", NULL);
Jim_AppendStrings( interp, Jim_GetResult(interp),
"mem2array: absurd > 64K item request", NULL );
return JIM_ERR; return JIM_ERR;
} }
@ -296,14 +286,9 @@ static int Jim_Command_mem2array(Jim_Interp *interp, int argc, Jim_Obj *const *a
/* all is well */ /* all is well */
} else { } else {
char buf[100]; char buf[100];
Jim_SetResult(interp, Jim_SetResult(interp, Jim_NewEmptyStringObj(interp));
Jim_NewEmptyStringObj(interp)); sprintf(buf, "mem2array address: 0x%08x is not aligned for %d byte reads", addr, width);
sprintf( buf, Jim_AppendStrings(interp, Jim_GetResult(interp), buf , NULL);
"mem2array address: 0x%08x is not aligned for %d byte reads",
addr, width );
Jim_AppendStrings( interp, Jim_GetResult(interp),
buf , NULL );
return JIM_ERR; return JIM_ERR;
} }
@ -316,7 +301,6 @@ static int Jim_Command_mem2array(Jim_Interp *interp, int argc, Jim_Obj *const *a
/* assume ok */ /* assume ok */
e = JIM_OK; e = JIM_OK;
while (len) { while (len) {
/* Slurp... in buffer size chunks */ /* Slurp... in buffer size chunks */
count = len; /* in objects.. */ count = len; /* in objects.. */
@ -324,20 +308,13 @@ static int Jim_Command_mem2array(Jim_Interp *interp, int argc, Jim_Obj *const *a
count = (sizeof(buffer)/width); count = (sizeof(buffer)/width);
} }
retval = target->type->read_memory( target, retval = target->type->read_memory( target, addr, width, count, buffer );
addr,
width,
count,
buffer );
if (retval != ERROR_OK) { if (retval != ERROR_OK) {
/* BOO !*/ /* BOO !*/
LOG_ERROR("mem2array: Read @ 0x%08x, w=%d, cnt=%d, failed", LOG_ERROR("mem2array: Read @ 0x%08x, w=%d, cnt=%d, failed", addr, width, count);
addr, width, count ); Jim_SetResult(interp, Jim_NewEmptyStringObj(interp));
Jim_SetResult(interp, Jim_AppendStrings(interp, Jim_GetResult(interp), "mem2array: cannot read memory", NULL);
Jim_NewEmptyStringObj(interp));
Jim_AppendStrings( interp, Jim_GetResult(interp),
"mem2array: cannot read memory", NULL );
e = JIM_ERR; e = JIM_ERR;
len = 0; len = 0;
} else { } else {
@ -359,8 +336,8 @@ static int Jim_Command_mem2array(Jim_Interp *interp, int argc, Jim_Obj *const *a
len -= count; len -= count;
} }
} }
Jim_SetResult(interp,
Jim_NewEmptyStringObj(interp)); Jim_SetResult(interp, Jim_NewEmptyStringObj(interp));
return JIM_OK; return JIM_OK;
} }
@ -373,11 +350,8 @@ static void tcl_output(void *privData, const char *file, int line, const char *f
} }
/* try to execute as Jim command, otherwise fall back to standard command. /* try to execute as Jim command, otherwise fall back to standard command.
* Note that even if the Jim command caused an error, then we succeeded
Note that even if the Jim command caused an error, then we succeeded * to execute it, hence this fn pretty much always returns ERROR_OK. */
to execute it, hence this fn pretty much always returns ERROR_OK.
*/
int jim_command(command_context_t *context, char *line) int jim_command(command_context_t *context, char *line)
{ {
int retval=ERROR_OK; int retval=ERROR_OK;
@ -389,8 +363,7 @@ int jim_command(command_context_t *context, char *line)
if (retcode == JIM_ERR) { if (retcode == JIM_ERR) {
int len, i; int len, i;
LOG_USER_N("Runtime error, file \"%s\", line %d:" JIM_NL, LOG_USER_N("Runtime error, file \"%s\", line %d:" JIM_NL, interp->errorFileName, interp->errorLine);
interp->errorFileName, interp->errorLine);
LOG_USER_N(" %s" JIM_NL, LOG_USER_N(" %s" JIM_NL,
Jim_GetString(interp->result, NULL)); Jim_GetString(interp->result, NULL));
Jim_ListLength(interp, interp->stackTrace, &len); Jim_ListLength(interp, interp->stackTrace, &len);
@ -400,18 +373,15 @@ int jim_command(command_context_t *context, char *line)
Jim_ListIndex(interp, interp->stackTrace, i, &objPtr, JIM_NONE); Jim_ListIndex(interp, interp->stackTrace, i, &objPtr, JIM_NONE);
proc = Jim_GetString(objPtr, NULL); proc = Jim_GetString(objPtr, NULL);
Jim_ListIndex(interp, interp->stackTrace, i+1, &objPtr, Jim_ListIndex(interp, interp->stackTrace, i+1, &objPtr, JIM_NONE);
JIM_NONE);
file = Jim_GetString(objPtr, NULL); file = Jim_GetString(objPtr, NULL);
Jim_ListIndex(interp, interp->stackTrace, i+2, &objPtr, Jim_ListIndex(interp, interp->stackTrace, i+2, &objPtr, JIM_NONE);
JIM_NONE);
line = Jim_GetString(objPtr, NULL); line = Jim_GetString(objPtr, NULL);
LOG_USER_N("In procedure '%s' called at file \"%s\", line %s" JIM_NL, LOG_USER_N("In procedure '%s' called at file \"%s\", line %s" JIM_NL, proc, file, line);
proc, file, line);
} }
} else if (retcode == JIM_EXIT) { } else if (retcode == JIM_EXIT) {
// ignore. /* ignore. */
//exit(Jim_GetExitCode(interp)); /* exit(Jim_GetExitCode(interp)); */
} else { } else {
if (reslen) { if (reslen) {
int i; int i;
@ -443,7 +413,7 @@ static int Jim_Command_openocd_ignore(Jim_Interp *interp, int argc, Jim_Obj *con
if (startLoop) if (startLoop)
{ {
// We don't know whether or not the telnet/gdb server is running... /* We don't know whether or not the telnet/gdb server is running... */
target_call_timer_callbacks_now(); target_call_timer_callbacks_now();
} }
@ -510,7 +480,7 @@ static size_t openocd_jim_fwrite(const void *_ptr, size_t size, size_t n, void *
} }
if (!active_cmd_ctx) { if (!active_cmd_ctx) {
/* FIXME: Where should this go? */ /* TODO: Where should this go? */
return n; return n;
} }
@ -603,7 +573,7 @@ void initJim2(void)
Jim_Eval(interp, "source [find tcl/commands.tcl]"); Jim_Eval(interp, "source [find tcl/commands.tcl]");
} }
command_context_t *setup_command_handler() command_context_t *setup_command_handler(void)
{ {
command_context_t *cmd_ctx; command_context_t *cmd_ctx;
@ -655,11 +625,9 @@ command_context_t *setup_command_handler()
return cmd_ctx; return cmd_ctx;
} }
/* /* normally this is the main() function entry, but if OpenOCD is linked
normally this is the main() function entry, but if OpenOCD is linked * into application, then this fn will not be invoked, but rather that
into application, then this fn will not be invoked, but rather that * application will have it's own implementation of main(). */
application will have it's own implementation of main().
*/
int openocd_main(int argc, char *argv[]) int openocd_main(int argc, char *argv[])
{ {
#ifdef JIM_EMBEDDED #ifdef JIM_EMBEDDED