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__archive__
parent
696a20fea4
commit
acce2bcccb
|
@ -55,7 +55,7 @@ void add_config_command (const char *cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return full path or NULL according to search rules */
|
/* return full path or NULL according to search rules */
|
||||||
char *find_file(char *file)
|
char *find_file(const char *file)
|
||||||
{
|
{
|
||||||
FILE *fp = NULL;
|
FILE *fp = NULL;
|
||||||
char **search_dirs = script_search_dirs;
|
char **search_dirs = script_search_dirs;
|
||||||
|
|
|
@ -29,7 +29,7 @@ extern void add_config_command (const char *cfg);
|
||||||
extern void add_script_search_dir (const char *dir);
|
extern void add_script_search_dir (const char *dir);
|
||||||
extern int configuration_output_handler(struct command_context_s *context, const char* line);
|
extern int configuration_output_handler(struct command_context_s *context, const char* line);
|
||||||
extern FILE *open_file_from_path (char *file, char *mode);
|
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);
|
int add_default_dirs(void);
|
||||||
|
|
||||||
#endif /* CONFIGURATION_H */
|
#endif /* CONFIGURATION_H */
|
||||||
|
|
|
@ -595,7 +595,7 @@ static int Jim_Command_find(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
|
||||||
{
|
{
|
||||||
if (argc != 2)
|
if (argc != 2)
|
||||||
return JIM_ERR;
|
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);
|
char *full_path = find_file(file);
|
||||||
if (full_path == NULL)
|
if (full_path == NULL)
|
||||||
return JIM_ERR;
|
return JIM_ERR;
|
||||||
|
@ -615,6 +615,36 @@ static int Jim_Command_echo(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
|
||||||
return JIM_OK;
|
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)
|
static size_t openocd_jim_fwrite(const void *_ptr, size_t size, size_t n, void *cookie)
|
||||||
{
|
{
|
||||||
size_t nbytes;
|
size_t nbytes;
|
||||||
|
@ -722,6 +752,7 @@ void initJim(void)
|
||||||
Jim_CreateCommand(interp, "openocd_throw", Jim_Command_openocd_throw, NULL, NULL);
|
Jim_CreateCommand(interp, "openocd_throw", Jim_Command_openocd_throw, NULL, NULL);
|
||||||
Jim_CreateCommand(interp, "find", Jim_Command_find, NULL, NULL);
|
Jim_CreateCommand(interp, "find", Jim_Command_find, NULL, NULL);
|
||||||
Jim_CreateCommand(interp, "echo", Jim_Command_echo, 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, "mem2array", Jim_Command_mem2array, NULL, NULL );
|
||||||
Jim_CreateCommand(interp, "array2mem", Jim_Command_array2mem, 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 *setup_command_handler(void)
|
||||||
{
|
{
|
||||||
command_context_t *cmd_ctx;
|
command_context_t *cmd_ctx;
|
||||||
|
@ -772,7 +794,6 @@ command_context_t *setup_command_handler(void)
|
||||||
tcl_register_commands(cmd_ctx); /* tcl server commands */
|
tcl_register_commands(cmd_ctx); /* tcl server commands */
|
||||||
log_register_commands(cmd_ctx);
|
log_register_commands(cmd_ctx);
|
||||||
jtag_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);
|
xsvf_register_commands(cmd_ctx);
|
||||||
target_register_commands(cmd_ctx);
|
target_register_commands(cmd_ctx);
|
||||||
flash_register_commands(cmd_ctx);
|
flash_register_commands(cmd_ctx);
|
||||||
|
|
Loading…
Reference in New Issue