#!/usr/bin/tclsh if {$argc == 2} { if { $argv == "-- -help" || $argv == "-- --help" || $argv == "-- --help" || $argv == "-- -H" || $argv == "-- --H" || $argv == "-- -h" || $argv == "-- --h" } { puts "$argv0 usage: " puts "Where inputFile is a Ccaffeine batch or gui script," puts "and outputFilePrefix will have .cc and .hh appended" puts "to obtain output file names. Also, outputFilePrefix," puts "less any leading directory name elements, will be the" puts "class name used." } } if {$argc != 3} { puts stderr "$argv0 usage: " exit 1 } proc !!! {args} { puts stdout "// $args" } proc !! {args} { puts stdout "// $args" } proc ! {args} { puts stdout "\t\t// $args" } proc !code {x} { global bld_global puts $bld_global(ofile) "\t$x" } proc !header {x} { global bld_global puts $bld_global(hfile) "$x" } global env #parray env ############################################ # generate a block of component constuctor prototypes # that the linker must satisfy somehow from user component # libraries. # @param ofile is an output file such as obtained from tcl open. proc genConstructorExtern {ofile } { global bld_palette puts $ofile "" puts $ofile "/* Generated extern block */" puts $ofile "/*---------------------------------------*/" puts $ofile "extern \"C\" \{" puts $ofile "\t/* We expect the following functions, or equivalent with alternate names," puts $ofile "\t * to exist. Given these component-specific constructor wrappers," puts $ofile "\t * we can do the rest with generic framework facilities and do" puts $ofile "\t * not need to include component or application specific headers." puts $ofile "\t *" puts $ofile "\t * The names generated here depend on the input ccaffeine script," puts $ofile "\t * and may need to be adjusted to match c++ reality." puts $ofile "\t */" foreach i $bld_palette(aliasList) { puts $ofile "\tneo::cca::Component *$bld_palette(ctor,$i)();" } puts $ofile "\}" puts $ofile "" } # end genConstructorExtern ################################################# proc genIncludes {ofile} { puts $ofile "/* Generated file. Includes block */" puts $ofile "/*---------------------------------------*/" puts $ofile "#include \" puts $ofile "#include \" puts $ofile "#include \" } ################################################# ################################################# # this is the dirty ccaffeine specific bit # (other than the input language of course) # of this code. Here we search paths # and scan .cca files. Babel people who # don't use a .cca file can just lump it. this is neo anyway. proc findLoadingData { classAlias } { global bld_palette bld_global scanPath $classAlias if { [lsearch -exact $bld_palette(aliasList) $classAlias] == -1} { puts stderr "Warning: Faking .cca data for $classAlias. check factory output." lappend bld_palette(aliasList) $classAlias set bld_palette(cppname,$classAlias) $classAlias set m [mangle $classAlias] set bld_palette(ctor,$classAlias) create_$classAlias set bld_palette(comment,$classAlias) "// faking create function for $classAlias. fix this code by hand or make sure the component libraries referred to in the input script exist." } } # split the path, find .cca files, and load their data proc scanPath {classAlias} { global bld_palette bld_global if { [lsearch -exact $bld_palette(aliasList) $classAlias] >= 0} { return } set plist [split $bld_palette(path) :] foreach d $plist { set flist "" if {[catch {set flist [glob $d/*.cca] } err ]} { # puts stderr $err continue } set flist [lsort $flist] foreach f $flist { scanFile $f } } } # read a file almost the same ways as ccaffeine does, # with some really ugly hacks to compensate for not # using an xml package. proc scanFile {fname} { if {![file readable $fname]} { return } if {[isOldFormat $fname]} { extractOldFile $fname } if {[isXMLCCAFormat $fname]} { extractXMLCCAFile $fname } } proc extractXMLCCAFile {fname} { global bld_global set names [exec $bld_global(SCAN_CCA_XML) $fname] foreach i [split $names \n] { if {[llength $i] == 4} { set binding [lindex $i 0] set classname [lindex $i 1] set classalias [lindex $i 2] set constructor [lindex $i 3] if { [string compare $binding "neo"]==0 } { policyAdd $classalias $constructor $classname $fname } } } } # read a ccaffeine format file roughly as framework/ComponentFactory does. proc extractOldFile {fname} { global bld_palette set last_buildDate "" set last_builder "" set last_so_file "" set last_buildLocation "" set cmptType "" set last_lib "" set f [open $fname r] set line [gets $f] while { ![eof $f]} { gets $f line if {[string compare -length 1 $line "!"] == 0 || [string compare -length 1 $line "#"]} { # whack commments and metadata gets $f line continue; # could check and cache stuff here, e.g. binding type, lib location. } if { [llength $line] == 1 } { # do nothing. library location the user will deal with } if { [llength $line] == 2 } { set ctor [lindex $line 0] set alias [lindex $line 1] set cppname [stripCreate $ctor] policyAdd $alias $ctor $cppname $fname } gets $f line } } # This is where we control whether # we take last-found or first-found # when searching the file path. # remove the if-check to get last-found behavior. # default is first-found. proc policyAdd {alias ctor cppname filename} { global bld_palette bld_global if {[lsearch $bld_palette(aliasList) $alias] != -1} { if {![info exists bld_palette(warned,$alias,$filename)] } { puts stderr "Warning: ignoring $alias in .cca file $filename" puts stderr "Warning: Found same class first in $bld_palette(filename,$alias)" set bld_palette(warned,$alias,$filename) 1 } return } set bld_palette(ctor,$alias) $ctor set bld_palette(cppname,$alias) $cppname set bld_palette(filename,$alias) $filename set bld_palette(comment,$alias) "// from $filename ." lappend bld_palette(aliasList) $alias } proc stripCreate { ctor } { if { [string compare -length 7 $ctor "create_"] ==0} { return [string range $ctor 7 end] } return $ctor } # if the files does start with < # it's assumed to be xml and therefore must be xml .cca # this could get more complicated later. proc isXMLCCAFormat {fname} { set f [open $fname r] set charOne [read $f 1] if { "$charOne" == "<" } { close $f return 1 } close $f return 0 } # if the files doesn't start with < # it's assumed not to be xml and therefore must be ccaffeine. proc isOldFormat {fname} { set f [open $fname r] set charOne [read $f 1] if { "$charOne" != "<" } { close $f return 1 } close $f return 0 } ################################################# ################################################# # @param ofile is an output file such as obtained from tcl open. # @param ns is the empty string or the name of a namespace(c++) to use # when generating the repository/factory class for the # set of components found in the global array variable bld_palette. # @global bld_palette array with entries: # (aliasList) -- list entry: keys $k to rest of info. # (cppname,$k) -- c++ class for a given alias k # (ctor,$k) -- c constructor for alias k # (dtor,$k) -- c destructor for alias k, or if none use c++ delete. proc genFactory {ofile ns} { global bld_palette global bld_global set hname $bld_global(cBaseName) #parray bld_palette puts $ofile "/* Generated custom factory implementation block */" puts $ofile "/*---------------------------------------*/" # prolog puts $ofile "" puts $ofile "void ${hname}_PrivateRepository::addDescription(std::string name, std::string alias)" puts $ofile "\{" puts $ofile "\tneo::cca::ports::ComponentClassDescription_shared ncpccds =" puts $ofile "\t\tneo::support::ComponentClassDescription::create(name, alias);" puts $ofile "\tdescriptions.push_back(ncpccds);" puts $ofile "\}" puts $ofile "" puts $ofile "${hname}_PrivateRepository::${hname}_PrivateRepository() \{" # init foreach i $bld_palette(aliasList) { puts $ofile "\taddDescription(\"$bld_palette(cppname,$i)\", \"$i\");" } puts $ofile "\}" puts $ofile "" puts $ofile "std::vector\< neo::cca::ports::ComponentClassDescription_shared \> ${hname}_PrivateRepository::getAvailableComponentClasses()" puts $ofile "\{" puts $ofile "\treturn descriptions;" puts $ofile "\}" puts $ofile "" puts $ofile "std::vector\< std::string\> ${hname}_PrivateRepository::getComponentClassAliases()" puts $ofile "\{" puts $ofile "\tstd::vector\< std::string\> result;" puts $ofile "\tfor (size_t i=0, n= descriptions.size(); i < n; i++)" puts $ofile "\t\{" puts $ofile "\t\tresult.push_back( descriptions\[i\]->getDeploymentClassAlias() );" puts $ofile "\t\}" puts $ofile "\treturn result;" puts $ofile "\}" puts $ofile "" puts $ofile "neo::cca::Component * ${hname}_PrivateRepository::createComponentInstance(const std::string & classAlias)" puts $ofile "\{" puts $ofile "\tneo::cca::TypeMap_shared tm;" puts $ofile "\treturn createComponentInstance(classAlias, tm);" puts $ofile "\}" puts $ofile "" puts $ofile "neo::cca::Component * ${hname}_PrivateRepository::createComponentInstance(const std::string & classAlias, neo::cca::TypeMap_shared & properties)" puts $ofile "\{" puts $ofile "\t// note for users. if your components need something other than" puts $ofile "\t// the usual C wrapper (like they want to have properties passed)" puts $ofile "\t// then you will modify the code in this function." # ctor list foreach i $bld_palette(aliasList) { puts $ofile "\tif (classAlias == \"$i\") \{" puts $ofile "\t\t$bld_palette(comment,$i)" puts $ofile "\t\treturn $bld_palette(ctor,$i)();" puts $ofile "\t\}" } puts $ofile "\treturn 0; //throw?" puts $ofile "\}" puts $ofile "" puts $ofile "void ${hname}_PrivateRepository::destroyComponentInstance(const std::string & componentClassAlias, neo::cca::Component * component)" puts $ofile "\{" puts $ofile "\t// note for users: you may need to write a c wrapper" puts $ofile "\t// for your destructor as well if you have used" puts $ofile "\t// advanced c++ techniques for memory management." # dtor list or delete foreach i $bld_palette(aliasList) { puts $ofile "\tif ( componentClassAlias == \"$i\" ) \{" if {![info exists bld_palette(dtor,$i)] || $bld_palette(dtor,$i) == ""} { puts $ofile "\t\tdelete component;" } else { puts $ofile "\t\t$bld_palette(dtor,$i)(component);" } puts $ofile "\t\}" } puts $ofile "\}" } # end genFactory ###################################### proc driverProlog {ofile scriptName} { global bld_global set hname $bld_global(cBaseName) puts $ofile "" puts $ofile "/* Generated custom driver block */" puts $ofile "/*---------------------------------------*/" puts $ofile "#include \"${scriptName}.hh\"" puts $ofile "" puts $ofile "${scriptName}::${scriptName}() \{\}" puts $ofile "" puts $ofile "${scriptName}::~${scriptName}() \{\}" puts $ofile "" puts $ofile "void" puts $ofile "${scriptName}::driverBody( neo::cca::AbstractFramework *af )" puts $ofile "throw(neo::cca::Exception)" puts $ofile "\{" puts $ofile "\tneo::cca::TypeMap_shared dummy;" puts $ofile "\tdummy = af->createTypeMap();" puts $ofile "" puts $ofile "\tneo::cca::ports::BuilderService *bs = 0;" puts $ofile "\t${hname}_PrivateRepository pr;" puts $ofile "" puts $ofile "\tneo::cca::Services *services;" puts $ofile "\t// set the script up as a component in the frame it receives." puts $ofile "\tservices = af->getServices(\"$scriptName\", \"$scriptName\", dummy);" puts $ofile "\t// and find its id tag in the frame." puts $ofile "\tneo::cca::ComponentID_shared myself = services->getComponentID();" puts $ofile "" puts $ofile "\t// tell the framework about the components that come with the driver." puts $ofile "\t// the components from ${hname}_PrivateRepository will now be available from" puts $ofile "\t// the BuilderService port." puts $ofile "\tservices->addProvidesPort(&pr, \"${scriptName}_Factory\", \"neo::cca::ports::ComponentFactory\");" puts $ofile "" puts $ofile "\tservices->registerUsesPort(\"bs\", \"neo::cca::ports::BuilderService\");" puts $ofile "" puts $ofile "" puts $ofile "\tneo::cca::Port *p = 0;" puts $ofile "\tp = services->getPort(\"bs\");" puts $ofile "\tbs = dynamic_cast\< neo::cca::ports::BuilderService *\>(p);" puts $ofile "\tif (bs == 0) \{ throw neo::cca::Exception(neo::cca::BadPortType," puts $ofile "\t\t\t\"Service port bs is not of expected type neo::cca::ports::BuilderService\");" puts $ofile "\t\}" puts $ofile "\tp = 0;" puts $ofile "" } proc driverEpilog {ofile scriptName} { puts $ofile "" puts $ofile "\tbs = 0;" puts $ofile "\tservices->releasePort(\"bs\");" puts $ofile "\tservices->unregisterUsesPort(\"bs\");" puts $ofile "\tservices->removeProvidesPort(\"${scriptName}_Factory\");" puts $ofile "\t// remove ourselves from the frame." puts $ofile "\taf->releaseServices(services);" puts $ofile "\}" puts $ofile "" } # @param ofile is an output file such as obtained from tcl open. # @param ns is the empty string or the name of a namespace(c++) to use # when generating the repository/factory class for the # set of components found in the global array variable bld_palette. proc genFactoryHeader {ofile ns} { global bld_global set hname $bld_global(cBaseName) global bld_palette # prolog puts $ofile "class ${hname}_PrivateRepository :" puts $ofile "public virtual neo::cca::ports::ComponentRepository," puts $ofile "public virtual neo::cca::ports::ComponentFactory" puts $ofile "\{" puts $ofile "private:" puts $ofile "\tstd::vector\< neo::cca::ports::ComponentClassDescription_shared \> descriptions;" puts $ofile "" puts $ofile "\tvoid addDescription(std::string name, std::string alias);" puts $ofile "" puts $ofile "public:" puts $ofile "\t${hname}_PrivateRepository();" puts $ofile "" puts $ofile "\t// ComponentRepository interface" puts $ofile "\tvirtual std::vector\< neo::cca::ports::ComponentClassDescription_shared \> getAvailableComponentClasses();" puts $ofile "" puts $ofile "\t// ComponentFactory interface" puts $ofile "\tvirtual std::vector\< std::string\> getComponentClassAliases();" puts $ofile "" puts $ofile "" puts $ofile "\tvirtual neo::cca::Component * createComponentInstance(const std::string & classAlias);" puts $ofile "" puts $ofile "\tvirtual neo::cca::Component * createComponentInstance(const std::string & classAlias, neo::cca::TypeMap_shared & properties);" puts $ofile "" puts $ofile "\tvirtual void destroyComponentInstance(const std::string & componentClassAlias, neo::cca::Component * component);" #epilog puts $ofile "" puts $ofile "\t//////" puts $ofile "\t// opq component factory interface..." puts $ofile "\t/*" puts $ofile "\t * the rest of the functions are here for type completeness but only" puts $ofile "\t * make sense in the dynamic loading case." puts $ofile "\t */" puts $ofile "" puts $ofile "\t/** dummy stub */" puts $ofile "\tvirtual void setComponentPath(const std::vector< std::string > & paths)" puts $ofile "\t\{" puts $ofile "" puts $ofile "\t\tthrow neo::cca::Exception(\"${hname}_PrivateRepository::setComponentPath: Sorry, static linked\");" puts $ofile "\t\}" puts $ofile "\t/** dummy stub */" puts $ofile "\tvirtual std::vector< std::string > getComponentPath()" puts $ofile "\t\{" puts $ofile "\t\tthrow neo::cca::Exception(\"${hname}_PrivateRepository::getComponentPath: Sorry, static linked\");" puts $ofile "\t\}" puts $ofile "\t/** dummy stub */" puts $ofile "\tvirtual void loadComponentDescription(const std::string & uri)" puts $ofile "\t\{" puts $ofile "\t\tthrow neo::cca::Exception(\"${hname}_PrivateRepository::loadComponentDescription: Sorry, static linked\");" puts $ofile "\t\}" puts $ofile "\t/** dummy stub */" puts $ofile "\tvirtual void indexComponentPath( )" puts $ofile "\t\{" puts $ofile "\t\tthrow neo::cca::Exception(\"${hname}_PrivateRepository::indexComponentPath: Sorry, static linked\");" puts $ofile "\t\}" puts $ofile "\t/** dummy stub */" puts $ofile "\tvirtual void loadClass( const std::string paletteClassAlias , bool global, bool lazy)" puts $ofile "\t\{" puts $ofile "\t\tthrow neo::cca::Exception(\"${hname}_PrivateRepository::loadClass: Sorry, static linked\");" puts $ofile "\t\}" puts $ofile "" puts $ofile "\}; // end class privateRepository" puts $ofile "" puts $ofile "" } # end genFactoryHeader ########################################33 proc genConfigRequests {} { global bld_global bld_param cids set ofile $bld_global(ofile) puts $ofile "\t\{" puts $ofile "\t\tstd::map\< std::string, std::string \> data;" foreach i $bld_param(varlist) { puts $ofile "\t\tdata\[\"$i\"\] = \"$bld_param(val,$i)\";" } puts $ofile "\t\tneo::support::helpers::setParameters(\"$bld_param(compCurr)\"," puts $ofile "\t\t\t\"$bld_param(portCurr)\"," puts $ofile "\t\t\t$cids($bld_param(compCurr)), bs, services, data);" puts $ofile "\t\}" } # end genConfigRequests ########################################33 ########################################33 proc testDriver {} { driverProlog stderr runH2 driverEpilog stderr runH2 } # test routine to create some palette data proc testInitPalette {} { global bld_palette set bld_palette(aliasList) "fred barney joe" set bld_palette(cppname,fred) Fred set bld_palette(cppname,joe) ns1::Joe set bld_palette(cppname,barney) Barney set bld_palette(ctor,fred) create_Fred set bld_palette(ctor,joe) create_ns1_Joe set bld_palette(ctor,barney) create_Barney set bld_palette(dtor,barney) destroy_Barney } ###################################### proc testFactory {} { testInitPalette genFactoryHeader stderr ANON genConstructorExtern stderr genFactory stderr ANON } proc testAll {} { testInitPalette genIncludes stdout genFactoryHeader stdout ANON driverProlog stdout runH2 driverEpilog stdout runH2 genConstructorExtern stdout genFactory stderr ANON } ############################################ # here would be a good place to chekc for ./supp2neo.tcl and load if exists. #################################### # the first set of functions map logged gui commands to # their BS equivalents and output them immediately. # The script input must be well-formed, or # the code may not compile/may not even transform properly. #################################### proc commandCount {args} {} # ignore the global screen size proc setSize {x y} { } proc setMaximum {args} { } # ignore next gui cmponent location proc setDropLocation {x y} { } proc move {c x y} { } # neo draft # component must be the componentid variable name # that goes with the component being called. proc go {component port} { checkEofDone flushConfigRequests global bld_global cids set ofile $bld_global(ofile) puts $ofile "" puts $ofile "\tneo::support::helpers::invokeGo( \"${component}\", \"${port}\", $cids($component) , services, bs);" } # neo done proc connect {u up p pp} { checkEofDone flushConfigRequests global connids cids bld_global set ofile $bld_global(ofile) set key "${u}_${up}_${p}_${pp}" set id [Simp_genConnID $key] set connids($key) $id set uid $cids($u) set pid $cids($p) puts $ofile "\n\tneo::cca::ConnectionID_shared" puts $ofile "\t$id =" puts $ofile "\t\tbs-\>connect(${uid}, \"${up}\", ${pid}, \"${pp}\");" lappend bld_global(connstack) $id } # neo done proc disconnect {u up p pp} { flushConfigRequests global connids cids bld_global set ofile $bld_global(ofile) set key "${u}_${up}_${p}_${pp}" set id $connids($key) puts $ofile "\tbs-\>disconnect($id, 0);" unset connids($key) } # neo done proc disconnectSlop {} { flushConfigRequests global bld_global connids set ofile $bld_global(ofile) puts $ofile "\t// Section to clean up connections the user didn't. reverse order." # collect the open connections in reverse order of making. set stack {} foreach i $bld_global(connstack) { if {[info exists connids($i)]} { set newstack [linsert $stack 0 $i] set stack $newstack } } foreach i $stack { puts $ofile "\tbs-\>disconnect(${i}, 0);" unset connids($i) } } # neo done proc parameters {newcomp newport var args} { configure $newcomp $newport $var $args } # logic: # foreach param port seen, accumulate data # until any other keyword or param port is processed. # bld_param(active) 0/1 already accumulated something # bld_param(portCurr) port most recent # bld_param(compCurr) component most recent # bld_param(varlist) keys set so far # for i in varlist: # bld_param(val,$i) value for each key # bld_param(type,$i) type for each key (not yet supported) # neo done proc configure {newcomp newport var args} { checkEofDone # first handle special case of value request if {! [string length $args]} { return } global bld_global bld_param # handle already got a param if { $bld_param(active) } { if { $newcomp == $bld_param(compCurr) && $newport == $bld_param(portCurr) } { addParam $var $args } else { genConfigRequests startParamSet $newcomp $newport $var $args } } else { set bld_param(active) 1 startParamSet $newcomp $newport $var $args } } # neo done proc flushConfigRequests {} { global bld_global bld_param if {$bld_param(active)} { genConfigRequests set bld_param(active) 0 } } # neo done proc startParamSet {newcomp newport var val} { global bld_global bld_param set bld_param(compCurr) $newcomp set bld_param(portCurr) $newport set bld_param(varlist) $var set bld_param(val,$var) $val } # neo done proc addParam { var val} { global bld_global bld_param lappend bld_param(varlist) $var set bld_param(val,$var) $val } # neo done proc quit {args} { checkEofDone flushConfigRequests puts stdout "\n\t// quit $args \n" user_eof } # neo done proc repository {verb args} { checkEofDone flushConfigRequests switch -- $verb { list { } get-ports { # do nothing. this will be taken care of # at link time by user. } get - get-global - get-lazy - get-lazy-global { # handle classes from .cca files findLoadingData "[lindex $args 0]" } } } # just internally accumulate the path with : separators # path init/append/prepend/set arg proc path {args} { checkEofDone global bld_palette env if { [llength $args] == 0} { # print path request; ignore it return } switch -- "[lindex $args 0]" { init { set bld_palette(path) $env(CCA_COMPONENT_PATH) set bld_palette(aliasList) {} } set { if { [llength $args] > 1} { set bld_palette(path) [lindex $args 1] set bld_palette(aliasList) {} } } append { if { [llength $args] > 1} { append bld_palette(path) ":[lindex $args 1]" } } prepend { if { [llength $args] > 1} { set val "[lindex $args 1]:" append val $bld_palette(path) set bld_palette(path) $val } } default {} } } # neo done proc pulldown {type c} { checkEofDone flushConfigRequests global bld_global cids set ofile $bld_global(ofile) set id [Simp_genCID $c] set cids($c) $id puts $bld_global(ofile) "\n\tneo::cca::ComponentID_shared $id =" puts $bld_global(ofile) "\t\tbs-\>createInstance(\"$id\", \"$type\", dummy);" lappend bld_global(compstack) $id } # neo done proc create {type c} { checkEofDone pulldown $type $c } # neo done proc destroySlop {} { flushConfigRequests global bld_global cids set ofile $bld_global(ofile) puts $ofile "\n\t// Section to clean up components the user didn't. reverse order." set stack {} foreach i $bld_global(compstack) { if {[info exists cids($i)]} { set newstack [linsert $stack 0 $i] set stack $newstack } } foreach i $stack { puts $ofile "\tbs-\>destroyInstance(${i}, 0.0);" unset cids($i) } } # neo done proc genMainHeader {} { global jname bld_global set hname $bld_global(cBaseName) set hfile $bld_global(hfile) puts $hfile "#ifndef ${hname}_hh_seen" puts $hfile "#define ${hname}_hh_seen" genIncludes $hfile puts $hfile "" puts $hfile "class $hname : public virtual NeoMain \{" puts $hfile "" puts $hfile "public:" puts $hfile "" puts $hfile "\t${hname}();" puts $hfile "" puts $hfile "\tvirtual ~${hname}();" puts $hfile "" puts $hfile "\tvirtual void driverBody( neo::cca::AbstractFramework *af)" puts $hfile "\t\tthrow(neo::cca::Exception);" puts $hfile "" puts $hfile "\};" puts $hfile "" genFactoryHeader $hfile "" puts $hfile "#endif // ${hname}_hh_seen" } # neo done proc checkEofDone {} { global bld_global if {$bld_global(eof_done) == 1} { puts stderr "eof command found in middle of input. output maybe wrong." exit 1 } } # neo done proc user_eof {} { global jname global bld_global if {$bld_global(eof_done) == 1} { return } set bld_global(eof_done) 1 set ofile $bld_global(ofile) # whack connections user missed, in reverse order. disconnectSlop # whack components user missed, in reverse order. destroySlop driverEpilog $ofile $jname genConstructorExtern $ofile genFactory $ofile "" genMainHeader } #################################### # the second set of functions manages identifier mappings #################################### # come up with unique in the existing list name from iname proc Simp_genCID {iname} { global cids set testid $iname if { [llength [array get cids $testid]] == 0 } { return $testid } set n 2 set testid "${iname}_$n" while {[llength [array get cids $testid]] != 0 } { incr n set testid "${iname}_$n" } return $testid } proc Simp_genConnID {iname} { global connids set testid $iname if { [llength [array get connids $testid]] == 0 } { return $testid } set n 2 set testid "${iname}_$n" while {[llength [array get connids $testid]] != 0 } { incr n set testid "${iname}_$n" } return $testid } proc Simp_genCCD {iname} { global ccds set testid $iname if { [llength [array get ccds $testid]] == 0 } { return $testid } set n 2 set testid "${iname}_$n" while {[llength [array get ccds $testid]] != 0 } { incr n set testid "${iname}_$n" } return $testid } proc Simp_Init {} { # arrays of c++ var name from string name global cids connids ccds bld_palette bld_param bld_global env set bld_palette(aliasList) "" set bld_global(eof_done) 0 set bld_param(active) 0 set bld_param(varList) "" set ccds(-) 0 set connids(-) 0 set cids(-) 0 if {[info exists env(SCAN_CCA_XML)]} { set bld_global(SCAN_CCA_XML) $env(SCAN_CCA_XML) } else { set bld_global(SCAN_CCA_XML) ./scanCCAxml.x } } proc mangle {fname} { regsub -all -- {\.} $fname {_} fname1 regsub -all -- {-} $fname1 {_} fname2 regsub -all -- {:} $fname2 {_} jname return "$jname" } # neo done proc Neo_Header { ofile fname jname hfile } { genIncludes $ofile driverProlog $ofile $jname } #################################### # main #################################### Simp_Init set fname [lindex $argv 1] set baseName [lindex $argv 2] set cBaseName [file tail $baseName] set jname $cBaseName global jname fname set cfile [open $baseName.cc w+] set hfile [open $baseName.hh w+] set bld_global(ofile) $cfile set bld_global(hfile) $hfile set bld_global(cBaseName) $cBaseName Neo_Header $cfile $fname $jname $hfile #exec cat $fname | egrep -v {^\!} | sed -e {s/^eof/user_eof/g} > $fname.tmp1 exec cat $fname | sed -e {s/^eof/user_eof/g} > $fname.tmp1 # force the finish if not found. exec echo user_eof >> $fname.tmp1 #exec cat $fname | egrep -v {^\!} > $fname.tmp1 source $fname.tmp1 exec /bin/rm $fname.tmp1 close $cfile close $hfile exit 0