home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1997 November
/
PCWorld_1997-11_cd.bin
/
software
/
programy
/
komix
/
DATA.Z
/
methodextr.tcl
< prev
next >
Wrap
Text File
|
1997-03-18
|
4KB
|
149 lines
#---------------------------------------------------------------------------
#
# (c) Cayenne Software Inc. 1997
#
# File: @(#)methodextr.tcl /main/hindenburg/3
# Author: <generated>
# Description: VCM integration file
#---------------------------------------------------------------------------
# SccsId = @(#)methodextr.tcl /main/hindenburg/3 18 Mar 1997 Copyright 1997 Cayenne Software Inc.
# Start user added include file section
# End user added include file section
# This class can parse a OO Tcl input file,
# and extract specified methods to an output file.
Class MethodExtracter : {GCObject} {
constructor
method destructor
method parseArgs
method usage
method openFiles
method closeFiles
method parse
method isSpecifiedMethodHeader
method extract
# File descriptor for the input file.
#
attribute inputFileDesc
# File descriptor for the output file.
#
attribute outputFileDesc
# List of methods that must be extracted
# (specified without class name.
#
attribute methods
}
constructor MethodExtracter {class this} {
set this [GCObject::constructor $class $this]
# Start constructor user section
# End constructor user section
return $this
}
method MethodExtracter::destructor {this} {
# Start destructor user section
# End destructor user section
}
method MethodExtracter::parseArgs {this arguments} {
set inputFile [lindex $arguments 0]
set outputFile [lindex $arguments 1]
$this openFiles $inputFile $outputFile
foreach method [lrange $arguments 2 end] {
$this methods "[$this methods] $method"
}
}
method MethodExtracter::usage {this} {
puts "Usage: extract <infile> <outfile> <method> \[<method>\] \[<method>\]..."
}
# Open inputFile for reading,
# outputFile for writing and store in
# instance variables.
#
method MethodExtracter::openFiles {this inputFile outputFile} {
$this inputFileDesc [open $inputFile r]
if { [$this inputFileDesc] == "" } {
error "Could not open $inputFile for reading"
}
$this outputFileDesc [open $outputFile w]
if { [$this outputFileDesc] == "" } {
error "Could not open $outputFile for writing"
}
}
# Close file descriptors.
#
method MethodExtracter::closeFiles {this} {
close [$this inputFileDesc]
close [$this outputFileDesc]
}
# Do the actual parsing.
#
method MethodExtracter::parse {this} {
# read input file, toggling inSpecifiedMethod state.
# if it is on, write output file, if it is not, don't.
# Assume that a not indented brace marks the end of a method
set inSpecifiedMethod 0
while { [gets [$this inputFileDesc] line] >= 0 } {
if [$this isSpecifiedMethodHeader $line] {
set inSpecifiedMethod 1
}
if $inSpecifiedMethod {
puts [$this outputFileDesc] $line
if [regexp {^\}} $line] {
set inSpecifiedMethod 0
puts [$this outputFileDesc] ""
}
}
}
}
# Returns whether line contains the header of one
# of the methods in 'methods'.
#
method MethodExtracter::isSpecifiedMethodHeader {this line} {
if [regexp {^method[ ]*[^:]*::([^ ]*)} $line dummy method] {
if [regexp $method [$this methods]] {
return 1
}
}
if [regexp {^proc[ ]*[^:]*::([^ ]*)} $line dummy method] {
if [regexp $method [$this methods]] {
return 1
}
}
return 0
}
# Entry point: do the extraction.
#
method MethodExtracter::extract {this arguments} {
if { [llength $arguments] < 3 } {
$this usage
return
}
$this parseArgs $arguments
$this parse
$this closeFiles
}
# Do not delete this line -- regeneration end marker