Here's Version 2 of vtkfind

Tom G. Smith smitty at kcc.com
Wed Oct 20 14:51:11 EDT 1999


As it's written, vtkfind should work on any unix host (AIX, HP-UX, IRIX,
Linux, etc.), but it uses the unix find command, so I doubt it would
work on NT.  It could be changed, I think, to use Perl's own directory
search functions, thereby making it os-independent.  I don't have the
need to change it right now, since I have ready access to Linux.  If
anyone decides to change it to work on NT please, send me a copy.  On
Linux, it's been a great help to me so far in learning vtk.

> Did anybody try vtkfind with activePerl on NT
> 
> thnx
> 
> cheers
> ~sathya
> 
> On Wed, 20 Oct 1999, Tom G. Smith wrote:
> 
> > #!/usr/bin/perl
> > # ---------------------------------------------------------------------
> > # Description:  See help routine below.
> > # Created by Tom Smith (smitty at kcc.com).  You're free to copy, modify,
> > # and redistribute this script, and use it for any purpose you like,
> > # so long as you clearly document changes as yours and not mine.
> > # 
> > # IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR
> > # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
> > # OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF,
> > # EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
> > # 
> > # THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
> > # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
> > # PARTICULAR PURPOSE, AND NON-INFRINGEMENT.  THIS SOFTWARE IS PROVIDED ON AN
> > # "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
> > # MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
> > # ---------------------------------------------------------------------
> > # Changelog:
> > # 991014 Smitty created.
> > # 991019 Smitty changed Version to 2.
> > # 991019 Smitty changed to find methods defined with all the macros in
> > #	VtkSetGet.h, e.g. the SetObjectMacro.
> > # ---------------------------------------------------------------------
> > 
> > sub help {
> > # ---------------------------------------------------------------------
> > # Prints help text.
> > # ---------------------------------------------------------------------
> > 	print<<END;
> > Description:
> > 	vtkfind, Version 2.
> > 	Scans files in the vtk source directory to report information
> > 	about vtk object classes, e.g. all the children with
> > 	inheritance from a base class, or all the parents from
> > 	which a class has inherited, or to which classes a given
> > 	method name is native to.
> > 
> > Usage: vtkfind [-a] [-c] [-d dir] [-e <edit command>] \\
> > 		[-h] [-m] [-p] [-s] <name>
> > 
> > -a indicates <name> is to remain as is.  When using -h or -s, without
> > 	-a you can leave off the vtk prefix and vtkfind will add it
> > 	for you.  Also, you don't need to worry about capitalization.
> > 	For example, "vtkfind -a SetDebug" would report -
> > 		/opt/vtk/common/vtkObject.h     vtkObject/void SetDebug(...
> > 	and "vtkfind -h object" would report -
> > 		/opt/vtk/common/vtkObject.h
> > 	When using -m without -a, vtkfind does the search case-insensitive,
> > 	but it doesn't automatically prefix "vtk" to <name> for you, since
> > 	few, if any, methods have that prefix.
> > 
> > -c indicates find all the children of the class <name>, i.e. all the
> > 	classes for which <name> is an inherited class.  This option
> > 	is relatively expensive, since all *.h files must be scanned.
> > 
> > -d dir
> > 	Dir is the directory for the vtk source.  The default is /opt/vtk.
> > 
> > -e <edit command>
> > 	Indicates if a filename is found it is to be appended to
> > 	<edit command> and executed.  For example
> > 	"vtkfind -e 'vi -R' -h object" would cause the command
> > 	"vi -R /opt/vtk/common/vtkObject.h" to be executed.
> > 	Use -e in conjunction with -m cautiously.  The command
> > 	"vtkfind -e 'vi -R' insertnextcell" will put in edit on
> > 	four files.
> > 
> > -h indicates the full path to <name>.h is to be found,
> > 	e.g. "vtkfind -h vtkunstructuredgrid" might list
> > 	/opt/vtk/common/vtkUnstructuredGrid.h.  Can be used in
> > 	conjunction with -e (see above).
> > 
> > -m indicates all the *.h files in the vtk source directory (see -d)
> > 	are to be searched to find the classes to which the specified
> > 	method is native.  Can be used in conjunction with -e (see
> > 	above).
> > 
> > -p indicates find all the parents of the class <name>, i.e. all the
> > 	classes from which <name> has inherited.
> > 
> > -s indicates the full path to <name>.cxx is to be found,
> > 	e.g. "vtkfind -s vtkunstructuredgrid" might list
> > 	/opt/vtk/common/vtkUnstructuredGrid.cxx.  Can be used in
> > 	conjunction with -e (see above).
> > END
> > exit;
> > } # End help.
> > 
> > sub listhit {
> > # ---------------------------------------------------------------------
> > # Called by both searchfile and namelist to take the proper action
> > # when a filename matching the search criteria is found.
> > # ---------------------------------------------------------------------
> > 	local($file,$trailer)=@_;
> > 
> > 	if ($edit) {
> > 		system("$edit $file") unless($hits{$file});
> > 		$hits{$file}=1; # Indicate file found.
> > 	} else {
> > 		print("$file$trailer\n");
> > 	}
> > 	return(1);
> > } # End listhit.
> > 
> > sub namelist {
> > # ---------------------------------------------------------------------
> > # Returns 1 or 0 after listing the full path to the specified filename.
> > # ---------------------------------------------------------------------
> > 	local($file,$name,$suffix)=@_;
> > 	local(@q,$basename,$ret);
> > 
> > 	$ret=0;
> >         @q=split("/",$file);
> >         $basename=pop(@q);
> > 	$basename=lc($basename) unless($a_switch);
> > 	$ret=&listhit($file) if ($basename =~ /^$name$suffix$/);
> > 	return($ret);
> > } # End namelist.
> > 
> > sub search {
> > # ---------------------------------------------------------------------
> > # Called from mainline to initiate a search.
> > # ---------------------------------------------------------------------
> > 	local($name,$suffix,$action)=@_;
> > 	local($ret);
> > 
> > 	if($action eq "p") {
> > 		$ret=&searchparent($name,$suffix,$action);
> > 	} else {
> > 		$ret=&searchfiles($name,$suffix,$action);
> > 	}
> > 	return($ret);
> > } # End search.
> > 
> > sub searchfile {
> > # ---------------------------------------------------------------------
> > # Called to search the specified file for the specified object.
> > # action may be either -
> > #	"c" for class definition, searching for inheritance from
> > #		$name in a class defined in this file.
> > #	"m" for $name being a method of a class defined in this file.
> > #	"p" for class $name being defined in this file.  If found,
> > #		the class' parent name will be returned, or a 1 if
> > #		no parent is defined.  Otherwise 0 is returned.
> > # ---------------------------------------------------------------------
> > 	local($file,$name,$action)=@_;
> > 	local($class,$line, at lines,$macroform,$parent,$prefix,$rest,
> > 		$ret,$save,$suffix);
> > 
> > 	$ret=0;
> > 	die("ERROR: Unable to read $file\n") unless (open(IN,$file));
> > 	chop(@lines=<IN>);
> > 	close(IN);
> > 	$class="";
> > 	if ($action eq "m" && $name =~ /^([gs]et)(.*)/) {
> > 		$macroform=1;
> > 		$prefix=$1;
> > 		$suffix=$2;
> > 	}
> > 	foreach $line (@lines) {
> > 		next if ($line =~ m#^\s*//#); # Skip comments.
> > 		if ($line =~ /^\s*class\s+VTK_EXPORT\s+(\w+)\s+(.*)/) {
> > 			$class=$1;
> > 			$rest=$2;
> > 			if ($action =~ /[cp]/) { 
> > 				$parent = ($rest =~ /:\s+public\s+(\w+)/)
> > 					? $1 : "";
> > 				if ($action eq "c") { 
> > 					$ret=&listhit($file,"\t$class")
> > 						if ($name eq lc($parent));
> > 					last if($ret); # All done.
> > 				}
> > 				if ($action eq "p") { 
> > 					if ($name eq lc($class)) {
> > 						$ret=($parent) ? $parent : 1;
> > 						&listhit($file,
> > 							"\t$class/$parent");
> > 						last; # All done.
> > 					}
> > 				}
> > 			}
> > 		}
> > 		if ($action eq "m") { 
> > 			$line=~s/^\s*(.*)/$1/;
> > 			$save=$line;
> > 			$line=lc($line) unless($a_switch);
> > 			$ret=&listhit($file,"\t$class/$save")
> > 				if ($line =~ /^.*$name\s*\(.*/ ||
> > 				($macroform &&
> > 				&searchmacro($line,$prefix,$suffix)));
> > 		}
> > 	}
> > 	return($ret);
> > } # End searchfile.
> > 
> > sub searchfiles {
> > # ---------------------------------------------------------------------
> > # Called to search directory $dir for the specified name.
> > # ---------------------------------------------------------------------
> > 	local($name,$suffix,$action)=@_;
> > 	local($cmd,$file, at files,$ret);
> > 
> > 	$cmd="find $dir/* -type f -name '*$suffix'";
> > 	chop(@files=`$cmd`);
> > 	$ret=0;
> > 	foreach $file (@files) {
> > 		if ($action eq "c") {
> > 			$ret=1 if(&searchfile($file,$name,$action));
> > 			next;
> > 		}
> > 		if ($action eq "h" || $action eq "s") {
> > 			$ret=&namelist($file,$name,$suffix);
> > 			last if($ret);
> > 			next;
> > 		}
> > 		if ($action eq "m") {
> > 			$ret+=&searchfile($file,$name,$action);
> > 			next;
> > 		}
> > 		if ($action eq "p") {
> > 			last if($ret=&searchfile($file,$name,$action));
> > 			next;
> > 		}
> > 	}
> > 	return($ret);
> > } # End searchfiles.
> > 
> > sub searchmacro {
> > # ---------------------------------------------------------------------
> > # Returns 1 if $line is a macro to define a Set/Get method.
> > # $line will've been translated to all lowercase.
> > # ---------------------------------------------------------------------
> > 	local($line,$prefix,$suffix)=@_;
> > 	local($macro);
> > 
> > 	foreach $macro (
> > 		"",
> > 		"clamp",
> > 		"object",
> > 		"referencecountedobject",
> > 		"string",
> > 		"vector",
> > 		"vector2",
> > 		"vector3",
> > 		"vector4",
> > 		"vector6",
> > 		"viewportcoordinate",
> > 		"worldcoordinate"
> > 	) {
> > 		return(1) if ($line =~
> > 			/^vtk${prefix}${macro}macro\($suffix,.*/);
> > 	}
> > 	return(0);
> > } # End searchmacro.
> > 
> > sub searchparent {
> > # ---------------------------------------------------------------------
> > # Called to initiate a parent search.
> > # ---------------------------------------------------------------------
> > 	local($name,$suffix,$action)=@_;
> > 	local($ret);
> > 
> > 	$ret=0;
> > 	while(1) {
> > 		last unless($name=lc(&searchfiles($name,$suffix,$action)));
> > 		$ret=1; # We found at least one file.
> > 	}
> > 	return($ret);
> > } # End searchparent.
> > 
> > # Mainline ---------------------------------------------------------------
> > &help if (0==scalar(@ARGV));
> > $dir="/opt/vtk"; # Default.
> > $prefix="vtk"; # Default.
> > $suffix=".h"; # Default.
> > $action="m"; # Default.
> > while($arg=shift) {
> > 	if (substr($arg,0,1) eq "-") {
> > 		if (length($arg) > 2) {
> > 			unshift(@ARGV,"-".substr($arg,2));
> > 			$arg=substr($arg,0,2);
> > 		}
> > 		if ($arg eq "-a") {
> > 			$a_switch=1;
> > 			$prefix="";
> > 			next;
> > 		}
> > 		if ($arg eq "-c") { $action="c"; next; }
> > 		if ($arg eq "-d") {
> > 			die("ERROR: -d not followed by path\n")
> > 				unless($dir=shift);
> > 			next;
> > 		}
> > 		if ($arg eq "-e") {
> > 			die("ERROR: -e not followed by edit command\n")
> > 				unless($edit=shift);
> > 			next;
> > 		}
> > 		if ($arg eq "-h") { $action="h"; next; }
> > 		if ($arg eq "-m") { $action="m"; next; }
> > 		if ($arg eq "-p") { $action="p"; next; }
> > 		if ($arg eq "-s") {
> > 			$action="s";
> > 			$suffix=".cxx";
> > 			next;
> > 		}
> > 	}
> > 	unshift(@ARGV,$arg);
> > 	last;
> > }
> > die("ERROR: No name to search for specified.\n") unless($name=shift);
> > unless($a_switch) {
> > 	$name="$prefix$name" if ($action ne "m" && 0 != index($name,$prefix));
> > 	$name=lc($name); # Make it all lowercase.
> > }
> > unless(&search($name,$suffix,$action)) {
> > 	print("Not Found: $name\n");
> > 	exit 1;
> > }
> > 
> > 
> > -----------------------------------------------------------------------------
> > This is the private VTK discussion list.  Please keep messages on-topic.
> > Check the FAQ at: <http://www.automatrix.com/cgi-bin/vtkfaq>
> > To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
> > <majordomo at gsao.med.ge.com>.  For help, send message body containing
> > "info vtkusers" to the same address.     Live long and prosper.
> > -----------------------------------------------------------------------------
> > 
> > 
> 
> 


-- 


-----------------------------------------------------------------------------
This is the private VTK discussion list.  Please keep messages on-topic.
Check the FAQ at: <http://www.automatrix.com/cgi-bin/vtkfaq>
To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
<majordomo at gsao.med.ge.com>.  For help, send message body containing
"info vtkusers" to the same address.     Live long and prosper.
-----------------------------------------------------------------------------




More information about the vtkusers mailing list