开发者

Printing out source hierarchy with large TCL project

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
}

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?

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] will give you the name of the file invoking source

Example:

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"

outputs

a.tcl sources b.tcl
in file b
b.tcl sources c.tcl
in file c
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜