1 # Defines basic Tcl procs that must exist for OpenOCD scripts to work.
3 # Embedded into OpenOCD executable
6 # All commands are registered with an 'ocd_' prefix, while the "real"
7 # command is a wrapper that calls this function. Its primary purpose is
8 # to discard 'handler' command output.
9 # Due to the two nested proc calls, this wrapper has to explicitly run
10 # the wrapped command in the stack frame two levels above.
11 proc ocd_bouncer {name args} {
12 set cmd [format "ocd_%s" $name]
13 set type [eval ocd_command type $cmd $args]
15 set skiplevel [expr [eval info level] > 1 ? 2 : 1]
16 if {$type == "native"} {
17 return [uplevel $skiplevel $cmd $args]
18 } else {if {$type == "simple"} {
19 set errcode [catch {uplevel $skiplevel $cmd $args}]
23 # 'classic' commands output error message as part of progress output
26 } else {if {$type == "group"} {
27 catch {eval ocd_usage $name $args}
28 set errmsg [format "%s: command requires more arguments" \
29 [concat $name " " $args]]
31 set errmsg [format "invalid subcommand \"%s\"" $args]
33 return -code $errcode $errmsg
36 # Try flipping / and \ to find file if the filename does not
37 # match the precise spelling
38 proc find {filename} {
39 if {[catch {ocd_find $filename} t]==0} {
42 if {[catch {ocd_find [string map {\ /} $filename} t]==0} {
45 if {[catch {ocd_find [string map {/ \\} $filename} t]==0} {
48 # make sure error message matches original input string
49 return -code error "Can't find $filename"
51 add_usage_text find "<file>"
52 add_help_text find "print full path to file according to OpenOCD search rules"
54 # Find and run a script
55 proc script {filename} {
56 uplevel #0 [list source [find $filename]]
58 add_help_text script "filename of OpenOCD script (tcl) to run"
59 add_usage_text script "<file>"