tcltest: do a better job of cleanup up after tests
[jimtcl.git] / make-index
blob1908d0079bc62af16547268661689c35111530b1
1 #!/usr/bin/env tclsh
2 # vim:se syn=tcl:
4 set filename [lindex $argv 0]
5 set f [open $filename]
7 # Read the file looking for command definitions
8 set lines {}
9 set commands {}
10 array set cdict {}
11 set c 0
13 while {[gets $f buf] >= 0} {
14         if {[string match "~~*" $buf]} {
15                 if {[string match "*: *" $prev]} {
16                         incr c
17                         set target cmd_$c
18                         set lines [linsert $lines end-1 "\[\[$target\]\]"]
19                         set prevlist [split $prev ":, "]
20                 } else {
21                         set target _[string map {:: _} $prev]
22                         set prevlist [list $prev]
23                 }
24                 foreach cmd $prevlist {
25                         set cmd [string trim $cmd]
26                         if {[regexp {^[a-z.:]+$} $cmd]} {
27                                 lappend commands [list $cmd $target]
28                                 set cdict($cmd) $target
29                         }
30                 }
31         }
32         lappend lines $buf
33         set prev $buf
35 close $f
37 # Build the command index in the list: $index
38 lappend index {[frame="none",grid="none"]}
39 lappend index {|=========================}
40 set i 0
41 set row {}
42 foreach command [lsort $commands] {
43         lassign $command cmd target
45         append row "|<<$target,*`$cmd`*>> "
46         incr i
47         if {$i % 8 == 0} {
48                 lappend index $row
49                 set row {}
50         }
52 while {$i % 8 != 0} {
53         incr i
54         append row "| "
56 lappend index $row
57 lappend index {|=========================}
59 # Map all `cmd` to <<$target,`cmd`>>
60 set mapping {}
61 foreach c [array names cdict] {
62         lappend mapping `$c` <<$cdict($c),*`$c`*>>
63         lappend mapping "`$c " "<<$cdict($c),*`$c`*>> `"
66 # And the command index
67 lappend mapping @INSERTINDEX@ [join $index \n]
69 # Output the result
70 foreach line $lines {
71         if {[string first ` $line] >= 0 || [string first @ $line] >= 0} {
72                 puts [string map $mapping $line]
73         } else {
74                 puts $line
75         }