How to find the location of TCL procedure?

放肆的年华 提交于 2020-01-03 08:14:28

问题


How can be find the location of procedure (function) in TCL. Under location I mean the source file in which it is declared.

I'm trying to read foreign source-code and can not find the declaration of a single procedure, example:

set MSISDNElement [regexp -all -inline {ISDN +[0-9]+} $Command]

if { $MSISDNElement != "" } {
    foreach elm $MSISDNElement {
        set MSISDNValue [list ISDN [getInternationalFormat [lindex $elm 1]]]
    }
}

set EptData [list [lindex $Command 1]]

InitEptData 3
foreach Element $EptData {
    SetEptData [lindex $Element 0] [lindex $Element 1]
}

For the functions InitEptData & SetEptData I can't find any declaration. Could someone familiar much more in deep with TCL, to explain how to solve that issue which I'm facing? Thanks in advance!


回答1:


There is no generic answer to this, as Tcl allows you to declare procedures on the fly, so they could have no actual file reference.

There are some attempts to improve the situation for procs that have a defining file, for example TIP280, which is actually available as info framein recent 8.5 versions, and TIP 86, which is only in discussion.

But if a simple grepdoes not work, you could track the moment a procedure or command gets created.

This happens in various places (Tcl OO might add a few more, not sure):

  • During a load command when a binary extension registers its command handler functions with Tcl_CreateCommand or the more modern Tcl_CreateObjCommand.
  • During a source command when a file with proc definitions is loaded
  • While running the proc command itself to define a new procedure

Using the commands info commands and namespace children you can walk the whole namespace tree to get a list of defined commands before and after the executed command. So you can create a wrapper that tracks any new commands. See http://wiki.tcl.tk/1489 for some hints how to do it.

Or, simply use a debugger like RamDebugger http://www.compassis.com/ramdebugger/Intro, or ActiveStates commercial debugger.




回答2:


From the bash shell, I use:

 find . -name "*.tcl" -exec grep -H proc_name_to_find {} \; | grep proc

This finds all tcl files, then executes grep on each file to search for the proc_name_to_find, and then the output is greped once more for those lines that contain 'proc'

Since grep -H outputs filenames with the output string, this shows you the output you need to find the definition in your editor.

Example:

$ find . -name "*.tcl" -exec grep -H set_prime {} \; | grep proc
./my_lib.tcl:proc prime_test::set_prime {{quiet 0} {no_compare 0}} {

There are other solutions with xargs...



来源:https://stackoverflow.com/questions/12651549/how-to-find-the-location-of-tcl-procedure

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!