summaryrefslogtreecommitdiff
path: root/src/openocd.c
diff options
context:
space:
mode:
authoroharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60>2008-07-14 06:34:23 +0000
committeroharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60>2008-07-14 06:34:23 +0000
commitacce2bcccb67252c2ff1bafc14e5417cf2aaf0f0 (patch)
tree9d0381a61f346514c043d7e4251d2b4f0ab51876 /src/openocd.c
parent696a20fea495b589305abe6cbd4cbfeb498a33a6 (diff)
downloadopenocd+libswd-acce2bcccb67252c2ff1bafc14e5417cf2aaf0f0.tar.gz
openocd+libswd-acce2bcccb67252c2ff1bafc14e5417cf2aaf0f0.tar.bz2
openocd+libswd-acce2bcccb67252c2ff1bafc14e5417cf2aaf0f0.tar.xz
openocd+libswd-acce2bcccb67252c2ff1bafc14e5417cf2aaf0f0.zip
Charles Hardin <ckhardin@gmail.com>
This evaluates the file at the correct level for the interpreter and the sets and all the globals are then done as expected. added a const to find_file function to avoid typecasting git-svn-id: svn://svn.berlios.de/openocd/trunk@806 b42882b7-edfa-0310-969c-e2dbd0fdcd60
Diffstat (limited to 'src/openocd.c')
-rw-r--r--src/openocd.c43
1 files changed, 32 insertions, 11 deletions
diff --git a/src/openocd.c b/src/openocd.c
index 2698b724..b36347cd 100644
--- a/src/openocd.c
+++ b/src/openocd.c
@@ -595,7 +595,7 @@ static int Jim_Command_find(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
if (argc != 2)
return JIM_ERR;
- char *file = (char*)Jim_GetString(argv[1], NULL);
+ const char *file = Jim_GetString(argv[1], NULL);
char *full_path = find_file(file);
if (full_path == NULL)
return JIM_ERR;
@@ -615,6 +615,36 @@ static int Jim_Command_echo(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
return JIM_OK;
}
+static int Jim_Command_script(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
+{
+ int retval;
+ const char *file;
+ char *full_path;
+
+ if (argc != 2)
+ {
+ Jim_WrongNumArgs(interp, 1, argv, "file name missing");
+ return JIM_ERR;
+ }
+
+ /* Run a tcl script file */
+ file = Jim_GetString(argv[1], NULL);
+ full_path = find_file(file);
+ if (full_path == NULL)
+ {
+ Jim_SetResult(interp, Jim_NewEmptyStringObj(interp));
+ Jim_AppendStrings(interp, Jim_GetResult(interp), "script: could not open file", file, NULL);
+ return JIM_ERR;
+ }
+ retval = Jim_EvalFile(interp, full_path);
+ free(full_path);
+ /* convert a return to ok */
+ if (retval == JIM_RETURN)
+ return JIM_OK;
+ return retval;
+}
+
+
static size_t openocd_jim_fwrite(const void *_ptr, size_t size, size_t n, void *cookie)
{
size_t nbytes;
@@ -722,6 +752,7 @@ void initJim(void)
Jim_CreateCommand(interp, "openocd_throw", Jim_Command_openocd_throw, NULL, NULL);
Jim_CreateCommand(interp, "find", Jim_Command_find, NULL, NULL);
Jim_CreateCommand(interp, "echo", Jim_Command_echo, NULL, NULL);
+ Jim_CreateCommand(interp, "script", Jim_Command_script, NULL, NULL);
Jim_CreateCommand(interp, "mem2array", Jim_Command_mem2array, NULL, NULL );
Jim_CreateCommand(interp, "array2mem", Jim_Command_array2mem, NULL, NULL );
@@ -745,15 +776,6 @@ void initJim(void)
}
}
-int handle_script_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
-{
- if (argc != 1)
- return ERROR_COMMAND_SYNTAX_ERROR;
-
- /* Run a tcl script file */
- return command_run_linef(cmd_ctx, "source [find {%s}]", args[0]);
-}
-
command_context_t *setup_command_handler(void)
{
command_context_t *cmd_ctx;
@@ -772,7 +794,6 @@ command_context_t *setup_command_handler(void)
tcl_register_commands(cmd_ctx); /* tcl server commands */
log_register_commands(cmd_ctx);
jtag_register_commands(cmd_ctx);
- register_command(cmd_ctx, NULL, "script", handle_script_command, COMMAND_ANY, "execute commands from <file>");
xsvf_register_commands(cmd_ctx);
target_register_commands(cmd_ctx);
flash_register_commands(cmd_ctx);