How to find the location of the TCL procedure?

How to find the location of a procedure (function) in TCL. By location, I mean the source file in which it is declared.

I am trying to read external source code and cannot find the declaration of one procedure, for 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 strong> and SetEptData strong> I cannot find any declaration. Could someone get a deeper understanding of TCL to explain how to solve this problem I am facing? Thanks in advance!

+6
source share
2 answers

There is no general answer to this question, since Tcl allows you to declare procedures on the fly, so they cannot have an actual file link.

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

But if simple grep does not work, you can keep track of when the procedure or command was created.

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

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

Using the commands info commands and namespace children , you can go through the entire tree of namespaces to get a list of specific commands before and after the command. This way you can create a shell that tracks any new commands. See http://wiki.tcl.tk/1489 for some tips on how to do this.

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

+9
source

From the bash shell, I use:

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

This finds all tcl files, and then grep each file to search for proc_name_to_find, and then output again for lines containing "proc"

Since grep -H prints filenames with an output string, this shows you the result you need to define the definition in your editor.

An 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 ...

0
source

Source: https://habr.com/ru/post/926575/


All Articles