home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
komix
/
DATA.Z
/
caynutil.tcl
< prev
next >
Wrap
Text File
|
1997-11-27
|
10KB
|
449 lines
#---------------------------------------------------------------------------
#
# Copyright (c) 1992-1997 by Cayenne Software, 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 : @(#)caynutil.tcl /main/titanic/13
# Original date : Wed Aug 5 12:04:46 MET DST 1992
# Description : Cayenne TCL utilities
# Basic utilities, should not use TCL procs defined
# in other files !!!
#
#---------------------------------------------------------------------------
#
# @(#)caynutil.tcl /main/titanic/13 27 Nov 1997 Copyright 1992-1997 Cayenne Software, Inc.
#
#---------------------------------------------------------------------------
require cayn_msg.tcl
#
# Procedure to reset the result to ""
#
proc null {} {}
#
# The Unix date command implemented in Tcl
#
proc date {} {
return [clock format [clock seconds]]
}
#
# Return the name part of name.type
#
proc nt_get_name {name} {
regsub {\.[^.]*$} $name "" name
return $name
}
#
# Return the type part of name.type
#
proc nt_get_type {fullname} {
if {[regsub {.*\.} $fullname "" type]} {
return [get type]
}
return ""
}
#
# Print the contents of variable s on the standard output stream
#
proc echo {s} {
puts stdout $s
}
#
# Print the contents of errorInfo on the standard output stream
#
proc perror {} {
echo $errorInfo
}
#
# Read the contents from a file into a Tcl string
#
proc read_file_into_text {path text} {
upvar $text txt
if {![file exists $path]} {
m4_error $E_EXIST_FILE $path
return 0
}
set fd [open $path "r"]
set txt [read $fd]
close $fd
return 1
}
#
# capitalize the first letter of a string
#
proc cap {str} {
set ch [string toupper [string index $str 0]]
return "$ch[string range $str 1 end]"
}
#
# uncapitalize the first letter of a string
#
proc uncap {str} {
set ch [string tolower [string index $str 0]]
return "$ch[string range $str 1 end]"
}
#
# For all words separated by underscores in s, create a string
# where all these words are capitalized and separated by spaces.
#
proc cap_underscores {s} {
set new ""
foreach word [split $s _] {
if ![lempty $new] {
append new " "
}
append new [cap $word]
}
return $new
}
#
# Copy a file
#
proc copy_text_file {from to} {
set max 8092
set in [open $from r]
set out [open $to w]
while {[set result [read $in $max]] != ""} {
puts $out $result nonewline
}
close $in
close $out
}
#
# Function to show proc invocations, activated using option "-trace"
#
proc trace_call {call obj args} {
global tracing
if {$tracing == 1} {
puts -nonewline " >>> [$obj get_obj_type]::$call '"
if [catch {puts -nonewline "[$obj getName]"}] {
puts -nonewline "<unnamed>"
}
puts "' $args"
}
}
#
# Append one or more strings to the given list only if it was not
# already present. Has exactly the same calling interface as the builtin
# 'lappend'.
#
# Returns the new list
#
proc lappend_unique {l args} {
upvar $l list
foreach s $args {
if {[lsearch -exact $list $s] == -1} {
lappend list $s
}
}
return $list
}
#
# Reverse the given list and return it.
#
proc listReverse {list} {
set rev {}
foreach e $list {
set rev [linsert $rev 0 $e]
}
return $rev
}
#
# Subtract two lists: all elements that are in the
# first list but not in the second list are returned.
#
proc listSubtract {first second} {
set diff {}
foreach e $first {
if {[lsearch $second $e] == -1} {
lappend diff $e
}
}
return $diff
}
#
# Expand customization file 'typeName'.hdr into TextSection 'sect';
# 'fileName' is used to expand the variable $filename in the header.
#
proc expandHeaderIntoSection {fileName typeName sect} {
set clientContext [ClientContext::global]
set proj [$clientContext currentProject]
set configV [$clientContext currentConfig]
set phaseV [$clientContext currentPhase]
set systemV [$clientContext currentSystem]
if {![$proj isNil] } {
set projName [$proj name]
} else {
set projName unknown
}
if {![$configV isNil] } {
set configName [[$configV config] name]
set configVersion [$configV versionNumber]
} else {
set configName unknown
set configVersion "?"
}
if {![$phaseV isNil] } {
set phaseName [[$phaseV phase] name]
set phaseVersion [$phaseV versionNumber]
} else {
set phaseName unknown
set phaseVersion "?"
}
if {![$systemV isNil] } {
set systemName [[$systemV system] name]
set systemVersion [$systemV versionNumber]
} else {
set systemName unknown
set systemVersion "?"
}
set headerFile [BasicFS::tmpFile]
$clientContext downLoadCustomFile $typeName hdr etc $headerFile
expand_file $sect $headerFile \
filename $fileName \
proj $proj \
configV $configVersion \
phaseV $phaseVersion \
systemV $systemVersion \
projName $projName \
configName $configName \
phaseName $phaseName \
systemName $systemName
unlink $headerFile
}
#
# Find the name of the first (selected) module with a certain type
#
proc getModuleNameByType {typeName} {
set modh [ModuleHandler new]
$modh setCurrentContext
foreach mod [$modh moduleSpecSet] {
if [$mod selectState] {
if {[$mod type] == $typeName} {
return [$mod name]
}
}
}
return ""
}
#
# Check whether the type is a legal diagram type
#
proc isLegalDiagType {type} {
switch -exact -- $type {
cad -
ccd -
cdm -
cod -
dfd -
etd -
mgd -
std -
ucd {return 1}
}
return 0
}
proc otglob { args } {
set argErr "wrong # args: should be \"otglob ?-esc <char>? ?switches? name ?name ...?\""
if { [lempty $args] } {
error $argErr
return
}
set command ""
set parsing 1
for { set i 0 } { $i < [llength $args] } { incr i } {
set parm [lindex $args $i]
if { $parm == "--" } { set parsing 0 }
if { $parsing && [string first "-esc" $parm] != -1 } {
incr i
set escape [string index [lindex $args $i] 0]
if { ![info exists escape] || [lempty $escape] } {
error "bad switch \"$parm\": must be -nocomplain, -esc <char> or --"
return
}
continue
}
if { [string first " " $parm] != -1 } {
# Excessive quoting needed to allow 'otglob "i:\\my dir\\*"'
set parm "{{$parm}}"
}
if { [lempty $command] } {
set command $parm
} else {
set command "$command $parm"
}
}
if { ![info exists escape] || [lempty $escape] } { set escape # }
if { [lempty $command] } {
error $argErr
return
}
if { $tcl_platform(platform) == "windows" } {
regsub -all {\\} $command {/} command
}
regsub -all "$escape" $command {\\\\} command
set catchResult [catch "eval glob $command" result]
if { $tcl_platform(platform) == "windows" } {
set tmpResult ""
foreach file $result {
regsub -all {/} $file {\\} file
lappend tmpResult $file
}
set result $tmpResult
}
if { $catchResult == 1 } {
error "$result"
}
return $result
}
#
# Evaluate a script at the current procedure level.
#
# During evaluation, any backslashes in the variables named by
# the stringRefs list are replaced by strings of the form @@@
# to be able to do Tcl string manipulations safely.
#
# Both existing variables that contain backslashes and new variables
# set by the script must be specified in the variable list.
#
# Example:
#
# set cmd "d:\\bin\\command.exe d:\\dir\\file z:\\dir.z"
# protect_backslashes {cmd arg1} {set arg1 [lindex $cmd 1]}
# puts "$arg1"
#
# This will correctly print "d:\dir\file", which would not be
# the case if this is done:
#
# set cmd "d:\\bin\\command.exe d:\\dir\\file z:\\dir.z"
# set arg1 [lindex $cmd 1]
# puts "$arg1"
#
proc protect_backslashes {stringRefs script} {
foreach stringRefN $stringRefs {
upvar $stringRefN stringN
catch {regsub -all {\\} $stringN {@@@} stringN}
}
set result [uplevel $script]
foreach stringRefN $stringRefs {
upvar $stringRefN stringN
catch {regsub -all {@@@} $stringN {\\} stringN}
}
return $result
}
# try to find out if we have an object id
# call example: isObjectId Corporate:Uj0DiRzQBN50W8wAAAGUAAQAAAAAA Corporate:
#
proc isObjectId {str {prefix ""}} {
set colon [string first : $str]
if {$colon == -1} {
# must contain a colon
return 0
}
if {$prefix != ""} {
set strL [string length $str]
set prefixL [string length $prefix]
incr strL -$prefixL
incr prefixL -1
if [string compare $prefix [string range $str 0 $prefixL]] {
return 0
}
} else {
incr colon
set strL [string length [string range $str $colon end]]
}
# id part must be 29 long
if {$strL != 29} {
return 0
}
if [catch {set decodeId [ORB::decodeObjectId $str]}] {
return 0
}
# second number must be between 100 and 1000
set secNum [lindex $decodeId 1]
if [expr (100<$secNum) && ($secNum<1000)] {
return 1
}
return 0
}