]> git.sur5r.net Git - openocd/blob - src/helper/startup.tcl
f11d5b6838aa27b3b95f4a087671d905915737ac
[openocd] / src / helper / startup.tcl
1 # Defines basic Tcl procs that must exist for OpenOCD scripts to work.
2 #
3 # Embedded into OpenOCD executable
4 #
5
6
7 # We need to explicitly redirect this to the OpenOCD command
8 # as Tcl defines the exit proc
9 proc exit {} {
10         ocd_throw exit
11 }
12
13 # Try flipping / and \ to find file if the filename does not
14 # match the precise spelling
15 proc find {filename} {
16         if {[catch {ocd_find $filename} t]==0} {
17                 return $t
18         }
19         if {[catch {ocd_find [string map {\ /} $filename} t]==0} {
20                 return $t
21         }
22         if {[catch {ocd_find [string map {/ \\} $filename} t]==0} {
23                 return $t
24         }
25         # make sure error message matches original input string
26         return -code error "Can't find $filename"
27 }
28 add_usage_text find "<file>"
29 add_help_text find "print full path to file according to OpenOCD search rules"
30
31 # Run script
32 proc script {filename} {
33         source [find $filename]
34 }
35 add_help_text script "filename of OpenOCD script (tcl) to run"
36 add_usage_text script "<file>"
37
38 #########
39
40 # catch any exceptions, capture output and return output
41 proc capture_catch {a} {
42         catch {
43                 capture {uplevel $a}
44         } result
45         return $result
46 }