使用大型 TCL 项目打印源层次结构 [英] Printing out source hierarchy with large TCL project
问题描述
所以我正在处理一个大型 TCL 项目,并认为构建一个关于文件如何在项目中作为源的树视图会很酷.我修改了源命令以执行以下操作:
So I am working with a large TCL project and thought it would be cool to build a treeview of how files were being source in the project. I modified the source command to do the following:
rename ::source ::real_source
proc ::source args {
set file_handle [open "file_source.tcl" a]
puts $file_handle $args
puts $file_handle $argv0
close $file_handle
uplevel 1 ::real_source $args
}
哪个有效并保存所有正在获取的文件,但我想知道是否有人对如何确定哪些文件正在调用 source 命令有任何想法?
Which works and saves all of the files being sourced but I was wondering if anyone had any ideas on how I could determine which files are calling the source command?
我遇到的另一个有趣的问题是我的新源程序似乎只能在某些文件中运行.文件 A 源文件 B 和文件 B 中的所有源文件似乎都可以正常工作,但在该文件下的任何内容似乎都可以返回使用旧的源程序.关于为什么会发生这种情况的任何想法?
Another interesting issue I am running into is that my new source procedure seems to only work in some files. File A sources File B and all of the sources in File B seem to work correctly but anything under that seems to go back to using the old source procedure. Any ideas on why this is happening?
推荐答案
[info script]
会给你调用 source
示例:
a.tcl
rename ::source ::real_source
proc ::source args {
puts "[info script] sources $args"
uplevel 1 ::real_source $args
}
source b.tcl
b.tcl
puts "in file b"
source c.tcl
c.tcl
puts "in file c"
输出
a.tcl sources b.tcl
in file b
b.tcl sources c.tcl
in file c
这篇关于使用大型 TCL 项目打印源层次结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!