Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 77 lines (68 sloc) 1.584 kb
cba565f @msteveb Autogenerate the command index in the documentation
authored
1 #!/usr/bin/env tclsh
2 # vim:se syn=tcl:
3
a774cd2 @msteveb Some people still only have Tcl 8.4
authored
4 set filename [lindex $argv 0]
cba565f @msteveb Autogenerate the command index in the documentation
authored
5 set f [open $filename]
6
8a0fa55 @msteveb Updates to the manual for hyperlinked commands
authored
7 # Read the file looking for command definitions
cba565f @msteveb Autogenerate the command index in the documentation
authored
8 set lines {}
9 set commands {}
8a0fa55 @msteveb Updates to the manual for hyperlinked commands
authored
10 array set cdict {}
cba565f @msteveb Autogenerate the command index in the documentation
authored
11 set c 0
12
13 while {[gets $f buf] >= 0} {
14 if {[string match "~~*" $buf]} {
278f372 @msteveb Update documentation for recent features
authored
15 if {[string match "*: *" $prev]} {
cba565f @msteveb Autogenerate the command index in the documentation
authored
16 incr c
17 set target cmd_$c
18 set lines [linsert $lines end-1 "\[\[$target\]\]"]
278f372 @msteveb Update documentation for recent features
authored
19 set prevlist [split $prev ":, "]
cba565f @msteveb Autogenerate the command index in the documentation
authored
20 } else {
278f372 @msteveb Update documentation for recent features
authored
21 set target _[string map {:: _} $prev]
22 set prevlist [list $prev]
cba565f @msteveb Autogenerate the command index in the documentation
authored
23 }
278f372 @msteveb Update documentation for recent features
authored
24 foreach cmd $prevlist {
cba565f @msteveb Autogenerate the command index in the documentation
authored
25 set cmd [string trim $cmd]
278f372 @msteveb Update documentation for recent features
authored
26 if {[regexp {^[a-z.:]+$} $cmd]} {
cba565f @msteveb Autogenerate the command index in the documentation
authored
27 lappend commands [list $cmd $target]
8a0fa55 @msteveb Updates to the manual for hyperlinked commands
authored
28 set cdict($cmd) $target
cba565f @msteveb Autogenerate the command index in the documentation
authored
29 }
30 }
31 }
32 lappend lines $buf
33 set prev $buf
34 }
35 close $f
36
8a0fa55 @msteveb Updates to the manual for hyperlinked commands
authored
37 # Build the command index in the list: $index
38 lappend index {[frame="none",grid="none"]}
39 lappend index {|=========================}
cba565f @msteveb Autogenerate the command index in the documentation
authored
40 set i 0
8a0fa55 @msteveb Updates to the manual for hyperlinked commands
authored
41 set row {}
cba565f @msteveb Autogenerate the command index in the documentation
authored
42 foreach command [lsort $commands] {
8a0fa55 @msteveb Updates to the manual for hyperlinked commands
authored
43 lassign $command cmd target
cba565f @msteveb Autogenerate the command index in the documentation
authored
44
8a0fa55 @msteveb Updates to the manual for hyperlinked commands
authored
45 append row "|<<$target,*`$cmd`*>> "
cba565f @msteveb Autogenerate the command index in the documentation
authored
46 incr i
47 if {$i % 8 == 0} {
8a0fa55 @msteveb Updates to the manual for hyperlinked commands
authored
48 lappend index $row
49 set row {}
cba565f @msteveb Autogenerate the command index in the documentation
authored
50 }
51 }
52 while {$i % 8 != 0} {
53 incr i
8a0fa55 @msteveb Updates to the manual for hyperlinked commands
authored
54 append row "| "
cba565f @msteveb Autogenerate the command index in the documentation
authored
55 }
8a0fa55 @msteveb Updates to the manual for hyperlinked commands
authored
56 lappend index $row
57 lappend index {|=========================}
cba565f @msteveb Autogenerate the command index in the documentation
authored
58
8a0fa55 @msteveb Updates to the manual for hyperlinked commands
authored
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`*>> `"
64 }
65
66 # And the command index
67 lappend mapping @INSERTINDEX@ [join $index \n]
68
69 # Output the result
70 foreach line $lines {
b6c95fe @msteveb Fix make-index speed-up
authored
71 if {[string first ` $line] >= 0 || [string first @ $line] >= 0} {
0cbd7a6 @msteveb make-index is *much* slower than it should be
authored
72 puts [string map $mapping $line]
73 } else {
74 puts $line
75 }
8a0fa55 @msteveb Updates to the manual for hyperlinked commands
authored
76 }
Something went wrong with that request. Please try again.