home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1997 November
/
PCWorld_1997-11_cd.bin
/
software
/
programy
/
komix
/
DATA.Z
/
oldimport.tcl
< prev
next >
Wrap
Text File
|
1997-02-05
|
7KB
|
278 lines
#---------------------------------------------------------------------------
#
# Copyright (c) 1992-1995 by Cadre Technologies Inc.
#
# This software is furnished under a license and may be used only in
# accordance with the terms of such license and with the inclusion of
# the above copyright notice. This software or any other copies thereof
# may not be provided or otherwise made available to any other person.
# No title to and ownership of the software is hereby transferred.
#
# The information in this software is subject to change without notice
# and should not be construed as a commitment by Cadre Technologies Inc.
#
#---------------------------------------------------------------------------
#
# File : @(#)oldimport.tcl /main/hindenburg/9 (1.10)
# Original date : 7-8-1992
# Description : Import front end for old style targets
#
#---------------------------------------------------------------------------
#
require wmt_util.tcl
require cgen_msg.tcl
require legacy.tcl
require machdep.tcl
require fstorage.tcl
require subimport.tcl
global import_new; set import_new 0
global import_sel; set import_sel 0
global ooplClassFilter; set ooplClassFilter ""
global ooplExclClassFilter; set ooplExclClassFilter ""
#
# Boolean options understood by import.tcl.
#
# The first element of each sublist will cause the second element to be
# made "global" and set to either 0 or 1, depending on whether the first
# element was specified as an argument to 'otsh' after the "--".
#
# The third element in each sublist gives the default value for the option,
# i.e. the value it will get if the option was not specified.
#
global boolean_options
set boolean_options { {-trace tracing 0} \
{-debug debug 0} \
{-time timing 0} }
#
# See if any boolean options were specified, set the appropriate
# variables, and remove any options from argv.
#
proc parse_options {} {
global boolean_options argv
foreach opt $boolean_options {
set i [lsearch $argv [lindex $opt 0]]
set optvar [lindex $opt 1]
eval "global $optvar"
if {$i == -1} {
set optdef [lindex $opt 2]
eval "set $optvar $optdef"
} else {
set argv [lreplace $argv $i $i]
eval "set $optvar 1"
}
}
}
# Import files: handles both import-new and import-selected by
# loading the model and by "sourcing" gensql.tcl and/or gen${t_lang}.tcl
#
proc import {} {
global oomodel do_struct_file
set t_lang [m4_var get M4_target_lang]
set do_struct_file 0
# remove sql as src_object for languages without persistent code
# generation
if ![supportPersistentCodeGen] {
regsub -all "sql" $src_objects "" new_src_objects
set src_objects $new_src_objects
}
if {![loadomt $t_lang]} {
return
}
if [lempty $tgt_objects] {
global import_new
set import_new 1
if [lempty $src_objects] {
if [supportPersistentCodeGen] {
require_with_reload gensql.tcl
}
require_with_reload gen${t_lang}.tcl
return
}
# Always generate struct file if Import New + OOPL + SQL
# generation, because struct file may have changed if new
# persistent classes are imported.
#
set do_struct_file [expr {$t_lang == "cpp" &&
[lsearch $src_objects "oopl"] != -1 &&
[lsearch $src_objects "sql"] != -1}]
set post_require_files {}
foreach imp_model $src_objects {
case $imp_model in {
{oopl} {lappend post_require_files gen${t_lang}.tcl}
{sql} {require_with_reload gensql.tcl}
}
}
foreach prf $post_require_files {
require_with_reload $prf
}
return
}
#
# Import selected: Generate the selected target files
#
global import_sel
set import_sel 1
set oopl_files ""
set sql_files ""
foreach file $tgt_objects {
set type [nt_get_type $file]
if {[lsearch [getOoplTypesToGenerateFor] $type] != -1} {
lappend oopl_files $file
continue
}
if [supportPersistentCodeGen] {
if {"$type" == "$sql_type"} {
lappend sql_files $file
continue
}
}
m4_warning $W_UNKNOWN_FILE $file
}
global tool_tgt_objs
if {![lempty $sql_files]} {
set tool_tgt_objs $sql_files
require_with_reload gensql.tcl
}
if {![lempty $oopl_files]} {
set tool_tgt_objs $oopl_files
require_with_reload gen${t_lang}.tcl
}
$oomodel delete
}
proc loadomt {t_lang} {
global oomodel
if [lempty $tgt_objects] {
set types_list [getOoplTypesToGenerateFor]
set cl_files [fstorage::dir $types_list]
global ooplExclClassFilter
set ooplExclClassFilter [get_class_list $cl_files]
} else {
global ooplClassFilter
set ooplClassFilter [get_class_list $tgt_objects]
}
set cc [ClientContext::global]
set systemNameType [$cc levelNameAt System]
set phaseNameType [$cc levelNameAt Phase]
set prevPhaseV [[$cc currentPhase] previous [$cc currentConfig]]
if [$prevPhaseV isNil] {
m4_error $E_NO_PREV_PHASE $phaseNameType
return 0
}
set prevPhase [$prevPhaseV phase]
set prevPhaseNameType [$prevPhase name].[$prevPhase name]
if {[$prevPhase type] != "ObjectDesign"} {
m4_error $E_WRONG_PREV_PHASE $prevPhaseNameType
return 0
}
if {[catch {fstorage::goto_system $systemNameType $prevPhaseNameType} reason]} {
puts stderr $reason
return 0
}
set oomodel [OOModel::createModel]
fstorage::goto_system $systemNameType $phaseNameType
if {[$oomodel error] > 0} {
##m4_error $E_LOAD_MODEL
puts stdout "Loading OOPL model failed due to previous errors"
$oomodel delete
return 0
}
return 1
}
#
# Make a list of classes out of a list of files
#
proc get_class_list {file_list} {
set result ""
foreach file $file_list {
set type [nt_get_type $file]
if {[lsearch [getOoplTypesToGenerateFor] $type] != -1} {
if [catch {set names [fstorage::get_imp_from $file]} reason] {
puts stderr $reason
set names ""
}
if {"$names" == ""} {
set nm [nt_get_name $file]
if {[lsearch [getNamesNotToGenerateFor] $nm] != -1} {
continue
}
m4_warning $W_IMPFROM_NOT_SET $file $nm
}
foreach nm $names {
if {[lsearch $result $nm] == -1} {
lappend result $nm
}
}
}
}
return $result
}
#
# Parse options and make sure argv does not contain them anymore.
#
parse_options
#
# Save src/tgt objects
#
global src_objects; set src_objects [CommandLineInterface::getSourceObjects]
global tgt_objects; set tgt_objects [CommandLineInterface::getTargetObjects]
#
# Now reimplement them
#
proc get_tgt_objs {} {
global tool_tgt_objs
return [get tool_tgt_objs]
}
#
# Just call import
#
if [catch {import} msg] {
switch $errorCode {
ERR_CPP_CONFIG {puts stderr "ERROR: $msg"}
ERR_UNIQUE_FILENAME {puts stderr "ERROR: $msg"}
default {puts stderr $errorInfo}
}
}