1 # Defines basic Tcl procs that must exist for OpenOCD scripts to work.
3 # Embedded into OpenOCD executable
7 # We need to explicitly redirect this to the OpenOCD command
8 # as Tcl defines the exit proc
13 # All commands are registered with an 'ocd_' prefix, while the "real"
14 # command is a wrapper that calls this function. Its primary purpose is
15 # to discard 'handler' command output,
16 proc ocd_bouncer {name args} {
17 set cmd [format "ocd_%s" $name]
18 set type [eval ocd_command type $cmd $args]
20 if {$type == "native"} {
21 return [eval $cmd $args]
22 } else {if {$type == "simple"} {
23 set errcode [catch {eval $cmd $args}]
27 # 'classic' commands output error message as part of progress output
30 } else {if {$type == "group"} {
31 catch {eval ocd_usage $name $args}
32 set errmsg [format "%s: command requires more arguments" \
33 [concat $name " " $args]]
35 set errmsg [format "invalid subcommand \"%s\"" $args]
37 return -code $errcode $errmsg
40 # Try flipping / and \ to find file if the filename does not
41 # match the precise spelling
42 proc find {filename} {
43 if {[catch {ocd_find $filename} t]==0} {
46 if {[catch {ocd_find [string map {\ /} $filename} t]==0} {
49 if {[catch {ocd_find [string map {/ \\} $filename} t]==0} {
52 # make sure error message matches original input string
53 return -code error "Can't find $filename"
55 add_usage_text find "<file>"
56 add_help_text find "print full path to file according to OpenOCD search rules"
58 # Find and run a script
59 proc script {filename} {
60 uplevel #0 [list source [find $filename]]
62 add_help_text script "filename of OpenOCD script (tcl) to run"
63 add_usage_text script "<file>"