static void tcl_output(void *privData, const char *file, int line, const char *function, const char *string)
{
- Jim_Obj *tclOutput=(Jim_Obj *)privData;
+ Jim_Obj *tclOutput = (Jim_Obj *)privData;
Jim_AppendString(interp, tclOutput, string, strlen(string));
}
* to the fn and fish it out manually.
*/
c = interp->cmdPrivData;
- if (c==NULL)
+ if (c == NULL)
{
- LOG_ERROR("BUG: interp->cmdPrivData==NULL");
+ LOG_ERROR("BUG: interp->cmdPrivData == NULL");
return JIM_ERR;
}
target_call_timer_callbacks_now();
for (i = 0; i < argc; i++)
{
int len;
- const char *w=Jim_GetString(argv[i], &len);
+ const char *w = Jim_GetString(argv[i], &len);
if (*w=='#')
{
/* hit an end of line comment */
*return_retval = retval;
}
- return (retval==ERROR_OK)?JIM_OK:JIM_ERR;
+ return (retval == ERROR_OK)?JIM_OK:JIM_ERR;
}
/* nice short description of source file */
}
/* just a placeholder, no handler */
- if (c->handler==NULL)
+ if (c->handler == NULL)
return c;
/* If this is a two level command, e.g. "flash banks", then the
const char *t2="";
const char *t3="";
/* maximum of two levels :-) */
- if (c->parent!=NULL)
+ if (c->parent != NULL)
{
- t1=c->parent->name;
+ t1 = c->parent->name;
t2="_";
}
- t3=c->name;
- const char *full_name=alloc_printf("ocd_%s%s%s", t1, t2, t3);
+ t3 = c->name;
+ const char *full_name = alloc_printf("ocd_%s%s%s", t1, t2, t3);
Jim_CreateCommand(interp, full_name, script_command, c, NULL);
free((void *)full_name);
/* we now need to add an overrideable proc */
- const char *override_name=alloc_printf("proc %s%s%s {args} {if {[catch {eval ocd_%s%s%s $args}]==0} {return \"\"} else { return -code error }", t1, t2, t3, t1, t2, t3);
+ const char *override_name = alloc_printf("proc %s%s%s {args} {if {[catch {eval ocd_%s%s%s $args}]==0} {return \"\"} else { return -code error }", t1, t2, t3, t1, t2, t3);
Jim_Eval_Named(interp, override_name, __THIS__FILE__, __LINE__ );
free((void *)override_name);
/* accumulate help text in Tcl helptext list. */
- Jim_Obj *helptext=Jim_GetGlobalVariableStr(interp, "ocd_helptext", JIM_ERRMSG);
+ Jim_Obj *helptext = Jim_GetGlobalVariableStr(interp, "ocd_helptext", JIM_ERRMSG);
if (Jim_IsShared(helptext))
helptext = Jim_DuplicateObj(interp, helptext);
- Jim_Obj *cmd_entry=Jim_NewListObj(interp, NULL, 0);
+ Jim_Obj *cmd_entry = Jim_NewListObj(interp, NULL, 0);
- Jim_Obj *cmd_list=Jim_NewListObj(interp, NULL, 0);
+ Jim_Obj *cmd_list = Jim_NewListObj(interp, NULL, 0);
/* maximum of two levels :-) */
- if (c->parent!=NULL)
+ if (c->parent != NULL)
{
Jim_ListAppendElement(interp, cmd_list, Jim_NewStringObj(interp, c->parent->name, -1));
}
if (context == NULL)
return ERROR_OK;
- while(NULL != context->commands)
+ while (NULL != context->commands)
{
c = context->commands;
- while(NULL != c->children)
+ while (NULL != c->children)
{
c2 = c->children;
c->children = c->children->next;
/* find command */
c = context->commands;
- while(NULL != c)
+ while (NULL != c)
{
if (strcmp(name, c->name) == 0)
{
}
/* unregister children */
- while(NULL != c->children)
+ while (NULL != c->children)
{
c2 = c->children;
c->children = c->children->next;
void command_output_text(command_context_t *context, const char *data)
{
- if( context && context->output_handler && data ){
- context->output_handler( context, data );
+ if (context && context->output_handler && data ){
+ context->output_handler(context, data );
}
}
int run_command(command_context_t *context, command_t *c, char *words[], int num_words)
{
- int start_word=0;
+ int start_word = 0;
if (!((context->mode == COMMAND_CONFIG) || (c->mode == COMMAND_ANY) || (c->mode == context->mode) ))
{
/* Config commands can not run after the config stage */
const char *t2="";
const char *t3="";
/* maximum of two levels :-) */
- if (c->parent!=NULL)
+ if (c->parent != NULL)
{
- t1=c->parent->name;
+ t1 = c->parent->name;
t2=" ";
}
- t3=c->name;
+ t3 = c->name;
command_run_linef(context, "help {%s%s%s}", t1, t2, t3);
}
else if (retval == ERROR_COMMAND_CLOSE_CONNECTION)
* results
*/
/* run the line thru a script engine */
- int retval=ERROR_FAIL;
+ int retval = ERROR_FAIL;
int retcode;
/* Beware! This code needs to be reentrant. It is also possible
* for OpenOCD commands to be invoked directly from Tcl. This would
Jim_DeleteAssocData(interp, "context");
}
if (retcode == JIM_ERR) {
- if (retval!=ERROR_COMMAND_CLOSE_CONNECTION)
+ if (retval != ERROR_COMMAND_CLOSE_CONNECTION)
{
/* We do not print the connection closed error message */
Jim_PrintErrorMessage(interp);
}
- if (retval==ERROR_OK)
+ if (retval == ERROR_OK)
{
/* It wasn't a low level OpenOCD command that failed */
return ERROR_FAIL;
int reslen;
result = Jim_GetString(Jim_GetResult(interp), &reslen);
- if (reslen>0)
+ if (reslen > 0)
{
int i;
- char buff[256+1];
+ char buff[256 + 1];
for (i = 0; i < reslen; i += 256)
{
int chunk;
chunk = reslen - i;
if (chunk > 256)
chunk = 256;
- strncpy(buff, result+i, chunk);
+ strncpy(buff, result + i, chunk);
buff[chunk] = 0;
LOG_USER_N("%s", buff);
}
LOG_USER_N("%s", "\n");
}
- retval=ERROR_OK;
+ retval = ERROR_OK;
}
return retval;
}
int command_run_linef(command_context_t *context, const char *format, ...)
{
- int retval=ERROR_FAIL;
+ int retval = ERROR_FAIL;
char *string;
va_list ap;
va_start(ap, format);
string = alloc_vprintf(format, ap);
- if (string!=NULL)
+ if (string != NULL)
{
- retval=command_run_line(context, string);
+ retval = command_run_line(context, string);
}
va_end(ap);
return retval;
}
/* GRR we must chunk - not null terminated */
while (nbytes) {
- char chunk[128+1];
+ char chunk[128 + 1];
int x;
x = nbytes;
Jim_RegisterCoreCommands(interp);
#endif
-#if defined( _MSC_VER )
+#if defined(_MSC_VER )
/* WinXX - is generic, the forward
* looking problem is this:
*
* "winxx" is generic.
*/
HostOs = "winxx";
-#elif defined( __LINUX__)
+#elif defined(__LINUX__)
HostOs = "linux";
-#elif defined( __DARWIN__ )
+#elif defined(__DARWIN__ )
HostOs = "darwin";
-#elif defined( __CYGWIN__ )
+#elif defined(__CYGWIN__ )
HostOs = "cygwin";
-#elif defined( __MINGW32__ )
+#elif defined(__MINGW32__ )
HostOs = "mingw32";
#else
HostOs = "other";
#endif
- Jim_SetGlobalVariableStr( interp, "ocd_HOSTOS", Jim_NewStringObj( interp, HostOs , strlen(HostOs)) );
+ Jim_SetGlobalVariableStr(interp, "ocd_HOSTOS", Jim_NewStringObj(interp, HostOs , strlen(HostOs)) );
Jim_CreateCommand(interp, "ocd_find", jim_find, NULL, NULL);
Jim_CreateCommand(interp, "echo", jim_echo, NULL, NULL);
#if !BUILD_ECOSBOARD
Jim_EventLoopOnLoad(interp);
#endif
- if (Jim_Eval_Named(interp, startup_tcl, "embedded:startup.tcl",1)==JIM_ERR)
+ if (Jim_Eval_Named(interp, startup_tcl, "embedded:startup.tcl",1) == JIM_ERR)
{
LOG_ERROR("Failed to run startup.tcl (embedded into OpenOCD compile time)");
Jim_PrintErrorMessage(interp);
int handle_fast_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
{
- if (argc!=1)
+ if (argc != 1)
return ERROR_COMMAND_SYNTAX_ERROR;
- fast_and_dangerous = strcmp("enable", args[0])==0;
+ fast_and_dangerous = strcmp("enable", args[0]) == 0;
return ERROR_OK;
}
if (!recursion)
{
recursion++;
- Jim_ProcessEvents (interp, JIM_ALL_EVENTS|JIM_DONT_WAIT);
+ Jim_ProcessEvents (interp, JIM_ALL_EVENTS | JIM_DONT_WAIT);
recursion--;
}
#endif
/* FIX!!! it would be prettier to invoke add_help_text...
* accumulate help text in Tcl helptext list. */
- Jim_Obj *helptext=Jim_GetGlobalVariableStr(interp, "ocd_helptext", JIM_ERRMSG);
+ Jim_Obj *helptext = Jim_GetGlobalVariableStr(interp, "ocd_helptext", JIM_ERRMSG);
if (Jim_IsShared(helptext))
helptext = Jim_DuplicateObj(interp, helptext);
- Jim_Obj *cmd_entry=Jim_NewListObj(interp, NULL, 0);
+ Jim_Obj *cmd_entry = Jim_NewListObj(interp, NULL, 0);
- Jim_Obj *cmd_list=Jim_NewListObj(interp, NULL, 0);
+ Jim_Obj *cmd_list = Jim_NewListObj(interp, NULL, 0);
Jim_ListAppendElement(interp, cmd_list, Jim_NewStringObj(interp, name, -1));
Jim_ListAppendElement(interp, cmd_entry, cmd_list);
/* return global variable long value or 0 upon failure */
long jim_global_long(const char *variable)
{
- Jim_Obj *objPtr=Jim_GetGlobalVariableStr(interp, variable, JIM_ERRMSG);
+ Jim_Obj *objPtr = Jim_GetGlobalVariableStr(interp, variable, JIM_ERRMSG);
long t;
- if (Jim_GetLong(interp, objPtr, &t)==JIM_OK)
+ if (Jim_GetLong(interp, objPtr, &t) == JIM_OK)
{
return t;
}
*ul = func(str, &end, 0); \
if (*end) \
return ERROR_COMMAND_ARGUMENT_INVALID; \
- if (*ul == max) \
+ if ((max == *ul) && (ERANGE == errno)) \
return ERROR_COMMAND_ARGUMENT_OVERFLOW; \
- if (min && min == *ul) \
+ if (min && (min == *ul) && (ERANGE == errno)) \
return ERROR_COMMAND_ARGUMENT_UNDERFLOW; \
return ERROR_OK; \
}
DEFINE_PARSE_NUM_TYPE(_llong, long long, strtoll, LLONG_MIN, LLONG_MAX)
#define DEFINE_PARSE_WRAPPER(name, type, min, max, functype, funcname) \
- int parse_##name(const char *str, type *ul) \
+ int parse##name(const char *str, type *ul) \
{ \
functype n; \
int retval = parse##funcname(str, &n); \
#define DEFINE_PARSE_ULONG(name, type, min, max) \
DEFINE_PARSE_WRAPPER(name, type, min, max, unsigned long, _ulong)
-DEFINE_PARSE_ULONG(uint, unsigned, 0, UINT_MAX)
-DEFINE_PARSE_ULONG(u32, uint32_t, 0, UINT32_MAX)
-DEFINE_PARSE_ULONG(u16, uint16_t, 0, UINT16_MAX)
-DEFINE_PARSE_ULONG(u8, uint8_t, 0, UINT8_MAX)
+DEFINE_PARSE_ULONG(_uint, unsigned, 0, UINT_MAX)
+DEFINE_PARSE_ULONG(_u32, uint32_t, 0, UINT32_MAX)
+DEFINE_PARSE_ULONG(_u16, uint16_t, 0, UINT16_MAX)
+DEFINE_PARSE_ULONG(_u8, uint8_t, 0, UINT8_MAX)
#define DEFINE_PARSE_LONG(name, type, min, max) \
DEFINE_PARSE_WRAPPER(name, type, min, max, long, _long)
-DEFINE_PARSE_LONG(int, int, n < INT_MIN, INT_MAX)
-DEFINE_PARSE_LONG(s32, int32_t, n < INT32_MIN, INT32_MAX)
-DEFINE_PARSE_LONG(s16, int16_t, n < INT16_MIN, INT16_MAX)
-DEFINE_PARSE_LONG(s8, int8_t, n < INT8_MIN, INT8_MAX)
+DEFINE_PARSE_LONG(_int, int, n < INT_MIN, INT_MAX)
+DEFINE_PARSE_LONG(_s32, int32_t, n < INT32_MIN, INT32_MAX)
+DEFINE_PARSE_LONG(_s16, int16_t, n < INT16_MIN, INT16_MAX)
+DEFINE_PARSE_LONG(_s8, int8_t, n < INT8_MIN, INT8_MAX)