aboutsummaryrefslogtreecommitdiff
path: root/make-index
blob: 37eda49420496784d840a31f6930412c880a8246 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env tclsh
# vim:se syn=tcl:

set filename [lindex $argv 0]
set f [open $filename]

while {[gets $f buf] >= 0} {
	if {$buf eq "@INSERTINDEX@"} {
		break
	}
	puts $buf
}

# Collect lines and commands
set lines {}
set commands {}
set c 0

while {[gets $f buf] >= 0} {
	if {[string match "~~*" $buf]} {
		if {[string match "*:*" $prev]} {
			incr c
			set target cmd_$c
			set lines [linsert $lines end-1 "\[\[$target\]\]"]
		} else {
			set target _$prev
		}
		foreach cmd [split $prev ":,"] {
			set cmd [string trim $cmd]
			if {$cmd ne ""} {
				lappend commands [list $cmd $target]
			}
		}
	}
	lappend lines $buf
	set prev $buf
}
close $f

# Output the index
puts {[frame="none",grid="none"]}
puts {|=========================}
set i 0
foreach command [lsort $commands] {
	foreach {cmd target} $command break

	puts -nonewline "|<<$target,$cmd>> "
	incr i
	if {$i % 8 == 0} {
		puts ""
	}
}
while {$i % 8 != 0} {
	incr i
	puts -nonewline "| "
}
puts ""
puts {|=========================}

puts [join $lines \n]