home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1997 November
/
PCWorld_1997-11_cd.bin
/
software
/
programy
/
komix
/
DATA.Z
/
upgrade_labels.tcl
< prev
next >
Wrap
Text File
|
1996-06-03
|
6KB
|
246 lines
#---------------------------------------------------------------------------
#
# (c) Cadre Technologies Inc. 1996
#
# File: %W%
# Author: Harm Leijendeckers
# Description: Upgrade labels.
#
#---------------------------------------------------------------------------
# SccsId = %W% %G% Copyright 1996 Cadre Technologies Inc.
proc update_component { tableId c_component c_diagram contents new_label_name } {
set labels_to_be_removed {}
set new_label_value ""
foreach field $contents {
db select -s c_id
db select -l c_value
db select -s c_type
db from label$tableId
db where -s "c_component =" $c_component
db where -s "and c_type =" $field
set result [db run]
if [lempty $result] {
continue
}
set c_id [lvarpop result]
set c_value [lvarpop result]
set c_type [lvarpop result]
lappend labels_to_be_removed [list $c_id $c_type \
[string length $new_label_value] $c_value]
set new_label_value "$new_label_value$c_value"
}
# create new label in the database
set newobid [gen_obid CompLabel $tableId]
db insert -s c_id $newobid
db insert -s c_diagram $c_diagram
db insert -s c_component $c_component
db insert -s c_type $new_label_name
db insert -l c_value $new_label_value
db into label$tableId
db run
# update compitr table and remove old labels
foreach label_info $labels_to_be_removed {
set c_id [lvarpop label_info]
set c_labeltype [lvarpop label_info]
set c_namebegin [lvarpop label_info]
set value [lvarpop label_info]
set blank_length [expr [string length $value] - \
[string length [string trimleft $value]]]
set c_value [string trim $value]
set c_namebegin [expr $c_namebegin + $blank_length]
set c_namelen [string length $c_value]
# update compitr
if { $c_labeltype == "name" || $c_labeltype == "type" } {
db update compitr$tableId
db set -s c_label $newobid
db set -i c_namebegin $c_namebegin
db set -i c_namelen $c_namelen
db set -s c_labeltype $new_label_name
db where -s "c_label =" $c_id
db run
}
# remove old label
remove_label $tableId $c_id
}
}
proc update_attributes { tableId } {
db select -s c_id
db select -s c_diagram
db from row$tableId
db where -s "c_type =" attribute
foreach r [db runLoop] {
set c_id [lvarpop r]
set c_diagram [lvarpop r]
update_component $tableId $c_id $c_diagram \
"modifiers name colon type init_value" name_type
}
}
proc update_methods { tableId } {
db select -s c_id
db select -s c_diagram
db from row$tableId
db where -s "c_type =" method
foreach r [db runLoop] {
set c_id [lvarpop r]
set c_diagram [lvarpop r]
update_component $tableId $c_id $c_diagram \
"modifiers name left_parenth right_parenth colon type constraint" \
name_type
}
}
proc update_parameters { tableId } {
db select -s c_id
db select -s c_diagram
db from cell$tableId
db where -s "c_type =" parameter
foreach c [db runLoop] {
set c_id [lvarpop c]
set c_diagram [lvarpop c]
update_component $tableId $c_id $c_diagram "name colon type comma" \
name_type
}
}
proc update_etds { tableId } {
db select -s c_id
db select -s c_diagram
db from node$tableId
db where -s "c_type =" etd_initiator
db where -s "or c_type =" etd_object
foreach n [db runLoop] {
set c_id [lvarpop n]
set c_diagram [lvarpop n]
update_component $tableId $c_id $c_diagram "name colon type" name_type
}
}
proc update_stds { tableId } {
db select -s c_id
db select -s c_diagram
db from cono$tableId
db where -s "c_type =" activity
foreach c [db runLoop] {
set c_id [lvarpop c]
set c_diagram [lvarpop c]
update_component $tableId $c_id $c_diagram "do name" name
}
}
# Remove CompLabels with no value except the ones at segments of a
# transition in a std.
#
proc remove_labels { tableId } {
# Labels die value "" worden niet meer opgeslagen met uitzondering van
# labels bij de segmenten van transitions in een std die altijd een
# spatie als waarde krijgen.
# First retrieve all c_id's of segments of transitions in a std
db select -s c_id
db from segment$tableId
db where "c_connector in ( select c_id \
from conn$tableId \
where c_type = 'transition' )"
set allStdTransitionSegments [db runLoop]
# Iterate over all labels to find the ones with no value.
# If the label is empty and belongs to a std transition segment, update
# it's value with a space.
db select -s c_id
db select -l c_value
db select -s c_type
db select -s c_component
db from label$tableId
foreach label [db runLoop] {
set c_id [lvarpop label]
set c_value [lvarpop label]
set c_type [lvarpop label]
set c_component [lvarpop label]
# if necessary, update std transition segment label
if { [lsearch $allStdTransitionSegments $c_component] != -1 &&
$c_value == "" } {
db update label$tableId
db set -l c_value " "
db where -s "c_id =" $c_id
db run
continue
}
# check if c_value is not empty
if { $c_value != "" } {
continue
}
# check if c_id not in allStdTransitionSegments
if { [lsearch $allStdTransitionSegments $c_id] != -1 } {
continue
}
# remove label and all compitr to it
remove_label $tableId $c_id
remove_compitrs_to $tableId $c_id
}
}
# Remove a label
#
proc remove_label { tableId c_id } {
db remove label$tableId
db where -s "c_id =" $c_id
db run
}
# Remove all CompItemRefs of a CompLabel.
#
proc remove_compitrs_to { tableId c_label } {
db remove compitr$tableId
db where -s "c_label =" $c_label
db run
}
# Remove all non-item referring CompItemRefs.
#
proc remove_compitrs { tableId } {
db remove compitr$tableId
db where -s "c_item =" ""
db runLoop
}
# Main procedure to update labels
#
proc update_labels { tableId } {
remove_labels $tableId
remove_compitrs $tableId
update_attributes $tableId
update_methods $tableId
update_parameters $tableId
update_etds $tableId
update_stds $tableId
}