1 # SPDX-License-Identifier: GPL-2.0-or-later
3 # Defines basic Tcl procs that must exist for OpenOCD scripts to work.
5 # Embedded into OpenOCD executable
8 # Try flipping / and \ to find file if the filename does not
9 # match the precise spelling
10 proc find
{filename} {
11 if {[catch {ocd_find
$filename} t
]==0} {
14 if {[catch {ocd_find
[string map
{\ /} $filename} t
]==0} {
17 if {[catch {ocd_find
[string map
{/ \\} $filename} t
]==0} {
20 # make sure error message matches original input string
21 return -code error "Can't find $filename"
23 add_usage_text find
"<file>"
24 add_help_text find
"print full path to file according to OpenOCD search rules"
26 # Find and run a script
27 proc script
{filename} {
28 uplevel #0 [list source [find $filename]]
30 add_help_text script
"filename of OpenOCD script (tcl) to run"
31 add_usage_text script
"<file>"
33 # Run a list of post-init commands
34 # Each command should be added with 'lappend post_init_commands command'
35 lappend _telnet_autocomplete_skip _run_post_init_commands
36 proc _run_post_init_commands
{} {
37 if {[info exists
::post_init_commands]} {
38 foreach cmd
$::post_init_commands {
44 # Run a list of pre-shutdown commands
45 # Each command should be added with 'lappend pre_shutdown_commands command'
46 lappend _telnet_autocomplete_skip _run_pre_shutdown_commands
47 proc _run_pre_shutdown_commands
{} {
48 if {[info exists
::pre_shutdown_commands]} {
49 foreach cmd
$::pre_shutdown_commands {