tcl - How to find a procedure by using the code inside the proc? -


is possible find procedure name using content of procedure?

for example,

proc test {args} {     set vara "exam"     puts "test program" } 

using statement set vara, possible find procedure name test?

because, need find procedure know output [it's printing something, need find procedure using that].

i tried many ways info frame, command. but, nothing helps.

with info proc, can content of procedure may helps in expect.

the following procedure search given word in namespaces. can change search in particular namespace well. also, search word can case insensitive if altered in terms of regexp -nocase. return list of procedure names contains search word.

proc getprocnamebycontent {searchword} {     set resultproclist {}     set nslist [namespace children ::]; # getting namespaces list     lappend nslist ::; # adding 'global scope namespace       foreach ns $nslist {         if {$ns eq "::"} {             set currentscopeprocs [info proc $ns*]         } else {             set currentscopeprocs [info proc ${ns}::*]         }          foreach myproc $currentscopeprocs  {             if {[regexp $searchword [info body $myproc]]} {                 puts "found in $myproc"                 lappend resultproclist $myproc             }         }     }     return $resultproclist } 

example

% proc x {} {         puts hai } % proc y {} {         puts hello } % proc z {} {         puts world } % namespace eval dinesh {         proc test {} {                 puts "world amazing"         } } % % getprocnamebycontent world found in ::dinesh::test found in ::z ::dinesh::test ::z % 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -