diff options
author | oharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60> | 2008-07-14 06:34:23 +0000 |
---|---|---|
committer | oharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60> | 2008-07-14 06:34:23 +0000 |
commit | acce2bcccb67252c2ff1bafc14e5417cf2aaf0f0 (patch) | |
tree | 9d0381a61f346514c043d7e4251d2b4f0ab51876 | |
parent | 696a20fea495b589305abe6cbd4cbfeb498a33a6 (diff) | |
download | riscv-openocd-acce2bcccb67252c2ff1bafc14e5417cf2aaf0f0.zip riscv-openocd-acce2bcccb67252c2ff1bafc14e5417cf2aaf0f0.tar.gz riscv-openocd-acce2bcccb67252c2ff1bafc14e5417cf2aaf0f0.tar.bz2 |
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
-rw-r--r-- | src/helper/configuration.c | 2 | ||||
-rw-r--r-- | src/helper/configuration.h | 2 | ||||
-rw-r--r-- | src/openocd.c | 43 |
3 files changed, 34 insertions, 13 deletions
diff --git a/src/helper/configuration.c b/src/helper/configuration.c index e9a13ea..6c2bf47 100644 --- a/src/helper/configuration.c +++ b/src/helper/configuration.c @@ -55,7 +55,7 @@ void add_config_command (const char *cfg) } /* return full path or NULL according to search rules */ -char *find_file(char *file) +char *find_file(const char *file) { FILE *fp = NULL; char **search_dirs = script_search_dirs; diff --git a/src/helper/configuration.h b/src/helper/configuration.h index d1f537d..e29ef73 100644 --- a/src/helper/configuration.h +++ b/src/helper/configuration.h @@ -29,7 +29,7 @@ extern void add_config_command (const char *cfg); extern void add_script_search_dir (const char *dir); extern int configuration_output_handler(struct command_context_s *context, const char* line); extern FILE *open_file_from_path (char *file, char *mode); -extern char *find_file(char *name); +extern char *find_file(const char *name); int add_default_dirs(void); #endif /* CONFIGURATION_H */ diff --git a/src/openocd.c b/src/openocd.c index 2698b72..b36347c 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); |