]> git.sur5r.net Git - openocd/commitdiff
Fixes to \ and / handling for OpenOCD
authoroharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Wed, 16 Jul 2008 20:20:15 +0000 (20:20 +0000)
committeroharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Wed, 16 Jul 2008 20:20:15 +0000 (20:20 +0000)
git-svn-id: svn://svn.berlios.de/openocd/trunk@815 b42882b7-edfa-0310-969c-e2dbd0fdcd60

src/helper/options.c
src/openocd.c
src/startup.tcl

index 5ec558cfe01c7c6d8713be5692f2bcf0a7568070..75d4f2e9b217bcd5959ae44dcdb2eaa2ab5ee88e 100644 (file)
@@ -110,7 +110,7 @@ int parse_cmdline_args(struct command_context_s *cmd_ctx, int argc, char *argv[]
                                break;
                        case 'f':       /* --file | -f */
                        {
-                               snprintf(command_buffer, 128, "script %s", optarg);
+                               snprintf(command_buffer, 128, "script {%s}", optarg);
                                add_config_command(command_buffer);
                                break;
                        }
index e535b9fe2797f20846e3e3c45eadb8081dee90e4..3090bc4429574acfceac257ee1cfbfbd82cd8b00 100644 (file)
@@ -614,34 +614,6 @@ 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)
@@ -752,9 +724,8 @@ void initJim(void)
 {      
        Jim_CreateCommand(interp, "openocd", Jim_Command_openocd, 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, "openocd_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 );
 
index 5fe7c8fe73ffb0067c52a084721fdb4e12506d99..abdf58ff42b00c5f13e80ce48092c48368b3949b 100644 (file)
@@ -134,6 +134,29 @@ proc target_script {target_num eventname scriptname} {
        
 }
 
-#add_help_text target_script "xxx"
+# Try flipping / and \ to find file if the filename does not
+# match the precise spelling
+proc find {filename} {
+       if {[catch {openocd_find $filename} t]==0} {
+               return $t
+       }  
+       if {[catch {openocd_find [string map {\ /} $filename} t]==0} {
+               return $t
+       }  
+       if {[catch {openocd_find [string map {/ \\} $filename} t]==0} {
+               return $t
+       }  
+       # make sure error message matches original input string
+       return [openocd_find $filename]
+}
+add_help_text find "<file> - print full path to file according to OpenOCD search rules"
+
+# Run script
+proc script {filename} {
+       source [find $filename]
+}
+
+add_help_text script "<filename> - filename of OpenOCD script (tcl) to run"
+
 add_help_text target_script "<target#> <event=reset/pre_reset/post_halt/pre_resume/gdb_program_config> <script_file>"