]> git.sur5r.net Git - openocd/blob - testing/tcl_test.tcl
build: add missing files to make dist
[openocd] / testing / tcl_test.tcl
1 if { $argc != 1 } {
2         puts "Usage: test_tcl.tcl <ipaddress>"
3         exit 1
4 }
5
6 puts $argv
7
8 # Simple tcl client to connect to openocd
9 global fo
10 set fo [socket $argv 6666]
11
12 # If a fn is unknown to Tcl, send it off to OpenOCD
13 proc unknown args {     
14         global fo
15         puts $fo $args
16         flush $fo
17         gets $fo line
18         return $line
19 }
20
21
22
23 #Print help text for a command. Word wrap
24 #help text that is too wide inside column.
25 proc pc_help {args} {
26         global ocd_helptext
27         set cmd $args
28         foreach a [lsort $ocd_helptext] {
29                 if {[string length $cmd]==0||[string first $cmd $a]!=-1||[string first $cmd [lindex $a 1]]!=-1} {
30                         set w 50
31                         set cmdname [lindex $a 0]
32                         set h [lindex $a 1]
33                         set n 0
34                         while 1 {
35                                 if {$n > [string length $h]} {break}
36                                 
37                                 set next_a [expr $n+$w]
38                                 if {[string length $h]>$n+$w} {
39                                         set xxxx [string range $h $n [expr $n+$w]]
40                                         for {set lastpos [expr [string length $xxxx]-1]} {$lastpos>=0&&[string compare [string range $xxxx $lastpos $lastpos] " "]!=0} {set lastpos [expr $lastpos-1]} {
41                                         }
42                                         #set next_a -1
43                                         if {$lastpos!=-1} {
44                                                 set next_a [expr $lastpos+$n+1]
45                                         }
46                                 }
47                                 
48                                 
49                                 puts [format "%-25s %s" $cmdname [string range $h $n [expr $next_a-1]] ]
50                                 set cmdname ""
51                                 set n [expr $next_a]
52                         }
53                 }
54         }
55 }
56
57 puts "Running flash_banks"
58 puts [flash_banks]
59 puts "Running help on PC using data from OpenOCD"
60 global ocd_helptext
61 set ocd_helptext [get_help_text]
62 puts [pc_help]
63
64
65