home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1997 November
/
PCWorld_1997-11_cd.bin
/
software
/
programy
/
komix
/
DATA.Z
/
fstorage.tcl
< prev
next >
Wrap
Text File
|
1997-05-26
|
8KB
|
345 lines
#---------------------------------------------------------------------------
#
# (c) Cayenne Software Inc. 1997
#
# File: @(#)fstorage.tcl /main/hindenburg/5
# Author: <generated>
# Description:
#---------------------------------------------------------------------------
# SccsId = @(#)fstorage.tcl /main/hindenburg/5 26 May 1997 Copyright 1997 Cayenne Software Inc.
# Start user added include file section
require caynutil.tcl
# End user added include file section
Class fstorage : {GCObject} {
constructor
method destructor
}
global fstorage::custObjHandler
set fstorage::custObjHandler ""
constructor fstorage {class this} {
set this [GCObject::constructor $class $this]
# Start constructor user section
# End constructor user section
return $this
}
method fstorage::destructor {this} {
# Start destructor user section
# End destructor user section
}
# Return a list of objects that have a type that is listed in $fileTypes
# $fileTypes == {} means all file types
#
proc fstorage::dir {{fileTypes ""}} {
set cc [ClientContext::global]
set systemV [$cc currentSystem]
if {[$systemV isNil]} {
error "Unable to find files: not at system level"
}
set fileList ""
foreach fileV [$systemV localFileVersions] {
set fileName [[$fileV file] name]
set fileType [[$fileV file] type]
set fullName ${fileName}.${fileType}
if {$fileTypes == ""} {
lappend fileList $fullName
} else {
foreach type $fileTypes {
if {$fileType == $type} {
lappend fileList $fullName
break;
}
}
}
}
return $fileList
}
# Return repository object for specified file
#
proc fstorage::getFileVersion {fullName} {
set cc [ClientContext::global]
set systemV [$cc currentSystem]
if {[$systemV isNil]} {
error "Unable to find file '$fullName': not at system level"
}
set fileName [nt_get_name $fullName]
set fileType [nt_get_type $fullName]
return [$systemV findFileVersion $fileName $fileType]
}
# Test if $fullName exists
#
proc fstorage::exists {fullName} {
set fileV [fstorage::getFileVersion $fullName]
if {[$fileV isNil]} {
return 0
}
return 1;
}
proc fstorage::getMakeType {objType} {
return [[fstorage::getObjectSpec $objType] makeType]
}
proc fstorage::getFsExtension {objType} {
set extension [[fstorage::getObjectSpec $objType] fsExtension]
#
# Hack for persistent classes with target Gen
#
if {$extension == "" && $objType == "esqlc++"} {
return [[fstorage::getObjectSpec c++] fsExtension]
}
return $extension
}
proc fstorage::getObjectSpec {objType} {
global fstorage::custObjHandler
set custObjHandler ${fstorage::custObjHandler}
if {$custObjHandler == ""} {
set custObjHandler [CustObjHandler new]
set fstorage::custObjHandler $custObjHandler
$custObjHandler setCurrentContext
}
set objSpec [$custObjHandler getObjectSpec ExternalFileVersion $objType]
if {$objSpec == ""} {
error "Unknown objecttype '$objType'"
}
return $objSpec
}
proc fstorage::isAscii {objType} {
return [[fstorage::getObjectSpec $objType] isAscii]
}
# Open $fullName for $mode. Mode is one of "r" and "w".
# If $mode == w the object is created if it doesn't exist.
#
proc fstorage::open {fullName {mode "r"} {fileClass "externalText"}} {
global fstorageCache
set cc [ClientContext::global]
set systemV [$cc currentSystem]
if {[$systemV isNil]} {
return 0
}
set fileV [fstorage::getFileVersion $fullName]
case $mode {
r {
if {[$fileV isNil]} {
error "Unable to open file '$fullName' for read"
}
$fileV lockForRead "Locked by fstorage::open"
if {[$fileV status] == "working"} {
set handle [open [$fileV path] r]
set fstorageCache($handle) $fileV
return $handle
}
$fileV synchWithFileSystem
set handle [open [$fileV path] r]
set fstorageCache($handle) $fileV
return $handle
}
w {
set configV [$cc currentConfig]
if {[$fileV isNil]} {
set fileName [nt_get_name $fullName]
set fileType [nt_get_type $fullName]
set fileV [$systemV createFileVersion $fileName cl 0 $fileType $fileClass $configV]
$fileV lockForWrite "Locked by fstorage::open"
set fileExt [fstorage::getFsExtension $fileType]
if {$fileExt == ""} {
$fileV setProperty fileSystemPath $fileName
} else {
$fileV setProperty fileSystemPath $fileName.$fileExt
}
$fileV synchWithFileSystem
set handle [open [$fileV path] w]
set fstorageCache($handle) $fileV
return $handle
}
if {[$fileV status] == "working"} {
$fileV lockForWrite "Locked by fstorage::open"
set handle [open [$fileV path] w]
set fstorageCache($handle) $fileV
return $handle
}
set newFileV [$systemV derive -fileVersion $fileV $configV]
$newFileV lockForWrite "Locked by fstorage::open"
set handle [open [$newFileV path] w]
set fstorageCache($handle) $newFileV
$newFileV synchWithFileSystem
return $handle
}
default {
error "Invalid option '$mode' for fstorage::open"
}
}
}
# Close $handle
#
proc fstorage::close {handle} {
global fstorageCache
if [info exists fstorageCache($handle)] {
$fstorageCache($handle) unlock
unset fstorageCache($handle)
} else {
puts "Warning fstorate::close called for unknown handle"
}
close $handle
}
# Remove '$fullName' from repository
#
proc fstorage::remove {fullName} {
set cc [ClientContext::global]
set systemV [$cc currentSystem]
if [$systemV isNil] {
error "Unable to remove file: not at system level"
}
set fileV [fstorage::getFileVersion $fullName]
if [$fileV isNil] {
error "Unable to remove file '$fullName': file not found"
}
$systemV remove -fileVersion $fileV
}
# Return the path of $fullName in the "user environment".
# If $absolute == "absolute" the path is absolute, else relative.
#
proc fstorage::get_uenv_path {fullName {absolute "relative"}} {
set fileV [fstorage::getFileVersion $fullName]
if {[$fileV isNil]} {
error "Object '$fullName' not found in the repository"
}
if {$absolute == "absolute"} {
return [$fileV path]
}
set relative [$fileV getPropertyValue fileSystemPath]
if {$relative == ""} {
return $fullName
}
return $relative
}
# Goto system $sys in phase $phase
#
proc fstorage::goto_system {sys {phase ""}} {
set clientCont [ClientContext::global]
set currentLevel [$clientCont currentLevel]
if {$currentLevel == "Project" || $currentLevel == "Corporate"} {
puts "invalid level: $currentLevel"
return
}
set oldLevelPath [m4_var get M4_levelpath]
while {[$clientCont currentLevel] != "Phase"} {
$clientCont upLevel
}
if {$phase != ""} {
$clientCont upLevel
if [catch {$clientCont downLevel $phase} msg] {
$clientCont setLevelPath $oldLevelPath
error $msg
}
}
if [catch {$clientCont downLevel $sys} msg] {
$clientCont setLevelPath $oldLevelPath
error $msg
}
}
# Return the "Imported From" attribute from $fullName
#
proc fstorage::get_imp_from {fullName} {
set fileV [fstorage::getFileVersion $fullName]
if {[$fileV isNil]} {
return ""
}
return [$fileV getPropertyValue imp_from]
}
# Set the "Imported From" property of $fullName to $value
#
proc fstorage::set_imp_from {fullName value} {
set fileV [fstorage::getFileVersion $fullName]
if {[$fileV isNil]} {
error "Unable to set property for '$fullName': it is not a file within this system"
}
return [$fileV setProperty imp_from $value]
}
# Do not delete this line -- regeneration end marker