1 Star 0 Fork 0

liangkangnan/jimtcl

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
make-index 1.55 KB
一键复制 编辑 原始数据 按行查看 历史
#!/usr/bin/env tclsh
# vim:se syn=tcl:
set filename [lindex $argv 0]
set f [open $filename]
# Read the file looking for command definitions
set lines {}
set commands {}
array set cdict {}
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\]\]"]
set prevlist [split $prev ", "]
} else {
set target _[string map {:: _} $prev]
set prevlist [list $prev]
}
foreach cmd $prevlist {
set cmd [string trim $cmd :]
if {[regexp {^[a-z.:]+$} $cmd]} {
lappend commands [list $cmd $target]
set cdict($cmd) $target
}
}
}
lappend lines $buf
set prev $buf
}
close $f
# Build the command index in the list: $index
lappend index {[frame="none",grid="none"]}
lappend index {|=========================}
set i 0
set row {}
foreach command [lsort $commands] {
lassign $command cmd target
append row "|<<$target,*`$cmd`*>> "
incr i
if {$i % 8 == 0} {
lappend index $row
set row {}
}
}
while {$i % 8 != 0} {
incr i
append row "| "
}
lappend index $row
lappend index {|=========================}
# Map all `cmd` to <<$target,`cmd`>>
set mapping {}
foreach c [array names cdict] {
lappend mapping `$c` <<$cdict($c),*`$c`*>>
lappend mapping "`$c " "<<$cdict($c),*`$c`*>> `"
}
# And the command index
lappend mapping @INSERTINDEX@ [join $index \n]
# Output the result
foreach line $lines {
if {[string first ` $line] >= 0 || [string first @ $line] >= 0} {
puts [string map $mapping $line]
} else {
puts $line
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/liangkangnan/jimtcl.git
git@gitee.com:liangkangnan/jimtcl.git
liangkangnan
jimtcl
jimtcl
master

搜索帮助