home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
komix
/
DATA.Z
/
docgenerat.tcl
< prev
next >
Wrap
Text File
|
1997-10-14
|
13KB
|
530 lines
#---------------------------------------------------------------------------
#
# (c) Cayenne Software Inc. 1997
#
# File: @(#)docgenerat.tcl /main/titanic/12
# Author: <generated>
# Description:
#---------------------------------------------------------------------------
# SccsId = @(#)docgenerat.tcl /main/titanic/12 14 Oct 1997 Copyright 1997 Cayenne Software Inc.
# Start user added include file section
# End user added include file section
Class DocGenerator : {Object} {
method destructor
constructor
method generateDocument
method generateSection
method generateStructure
method createComponent
method delta2Indentation
attribute indentation
attribute editing
}
global DocGenerator::double
set DocGenerator::double "_no"
global DocGenerator::msg
set DocGenerator::msg ""
method DocGenerator::destructor {this} {
# Start destructor user section
# End destructor user section
}
constructor DocGenerator {class this name} {
set this [Object::constructor $class $this $name]
$this editing 0
$this indentation 0
return $this
}
method DocGenerator::generateDocument {this specFile} {
wmtkmessage "Generating document"
wmtkmessage ""
if {! [docTool editDsm]} {
return 0
}
# Clear the dsm
set components ""
set struct [docTool structure]
for {set component [$struct firstComponent]} \
{"$component" != ""} \
{set component [$component next]} {
lappend components $component
}
foreach component $components {
$component delete
}
set result 1
$this editing 1
# read the structure file
if ![file exists $specFile] {
wmtkerror "File '$specFile' does not exist"
}
set specList [readConfigurationFile $specFile]
$this indentation 0
$this generateStructure $specList "" 1
if [catch {$struct save}] {
wmtkerror "Save of document structure failed"
set result 0
}
set diagram [$struct diagram]
$struct quit
if [catch {$struct load $diagram}] {
wmtkerror "Load of document structure failed"
}
$this editing 0
wmtkmessage ""
wmtkmessage "Generating document finished"
return $result
}
method DocGenerator::generateSection {this section specFile withContents} {
set quit 0
# check if the document structure is locked for edit
# save it when it is being edited
if {! [$this editing]} {
if {! [docTool editDsm]} {
return 0
}
$this editing 1
set quit 1
}
# read the structure file
if ![file exists $specFile] {
wmtkerror "file $specFile does not exists"
return 0
}
set specList [readConfigurationFile $specFile]
# can not just take '$this indentation [$section indentation]'
# because section is not updated yet
$this indentation 0
# find the corresponding component in the DSM
set struct [docTool structure]
set comp [$struct findComponent [$section uiName]]
if { $comp != ""} {
$this indentation [$comp indentation]
}
$this generateStructure $specList $comp $withContents
set result 1
if $quit {
if [catch {$struct save}] {
set result 0
wmtkerror "Save of document structure failed"
}
set diagram [$struct diagram]
$struct quit
if [catch {$struct load $diagram}] {
wmtkerror "Load of document structure failed"
}
$this editing 0
}
return $result
}
method DocGenerator::generateStructure {this specList startComp withContents} {
require_module_file "docstructp.tcl" docwriter
# lock the dsm
# ...
set prevComp $startComp
set sectionSet {}
foreach structLine $specList {
set docStructPart [DocStructPart new $structLine]
# skip the ones with double names and the same parent (error)
# ...
set comp [$this createComponent $docStructPart $prevComp]
set indent ""
for { set j [$comp indentation] } { $j > 0} { incr j -1} {
set indent " $indent"
}
global DocGenerator::msg
set DocGenerator::msg "$indent"
set section [DocGenerator::createSection $docStructPart 0]
if {"$section" == ""} {
$comp delete
continue
}
if [$section isA LocalSection] {
set orgIndent [$this indentation]
$section generateStructure $withContents
# set the prevComp to the last component
set prevComp [documentStructure lastComponent]
$this indentation $orgIndent
lappend sectionSet $section
} else {
set prevComp $comp
}
}
# Be sure the structure-info in the section is up-to-date
# before generating the contents
docTool updateSections
# now generate the contents of the created sections
if { $withContents == 1} {
foreach section $sectionSet {
$section generateContents
}
}
}
method DocGenerator::createComponent {this docStructPart prevComp} {
set struct [docTool structure]
set component [$struct findComponent [$docStructPart sectionName]]
set compChildren {}
if {$component == ""} {
global classCount
set component [DocComponent new DocComponent$classCount $struct]
incr classCount
$component uiName [$docStructPart sectionName]
} else {
set section [docTool findSection [$docStructPart sectionName]]
if {$section != ""} {
set tree [$section getTree]
foreach leaf $tree {
set comp [$struct findComponent [$leaf uiName]]
if {$comp != ""} {
lappend compChildren $comp
}
}
}
}
$this indentation [expr {
[$this indentation] +
[$this delta2Indentation [$docStructPart levelDelta]]
}]
$component indentation [$this indentation]
if {$prevComp != ""} {
$component moveBehind $prevComp
}
foreach comp $compChildren {
$comp delete
}
return $component
}
proc DocGenerator::createSection {docStructPart {uniqueName 1}} {
set itemType section
set sv [$docStructPart documentVersion]
if {![isCommand $sv]} {
set sv [docTool document]
}
set cv [$sv configVersion]
set editor [[$sv editor] name]
set version [[$sv editor] version]
set name [$docStructPart sectionName]
set type [$docStructPart sectionType]
set class [$docStructPart sectionClass]
if {$class == ""} {
set class $type
}
set class [Document::getClass $editor $version $class]
if {$class == ""} {
set fileV [$docStructPart fileVersion]
if {[isCommand $fileV]} {
if {![$fileV isNil]} {
if {[$fileV isA ExternalFileVersion]} {
# for text file references without
# a section class
set class TextRefSection
}
}
}
if {$class == ""} {
return ""
}
}
if {[lsearch [Document::getSuperClasses $class] \
"SystemFileReference"] != -1} {
set fv [$docStructPart fileVersion]
set section [DocGenerator::updateSection \
$docStructPart \
[$sv findFileReference $name $type] \
$uniqueName]
if [$section isNil] {
set section [$sv createFixedFileReference \
$name $type $fv $cv]
DocGenerator::setLongName $section $name
} elseif $uniqueName {
return $section
}
} elseif {[lsearch [Document::getSuperClasses $class] \
"ExternalFileVersion"] != -1} {
# it's a ExternalFileVersion
set section [DocGenerator::updateSection \
$docStructPart \
[$sv findFileVersion $name $type] \
$uniqueName]
if [$section isNil] {
set fileClass [Document::getFileClass \
$editor $version $type]
set section [$sv createFileVersion \
$name $itemType 0 $type $fileClass $cv]
DocGenerator::setLongName $section $name
} elseif {"[$section getInfo Status]" == "frozen"} {
set section [$sv derive -fileVersion $section $cv]
} elseif $uniqueName {
return $section
}
} elseif {[lsearch [Document::getSuperClasses $class] \
"ItemPropertyReference"] != -1} {
set section [DocGenerator::updateSection \
$docStructPart \
[$sv findPropertyReference $name $type] \
$uniqueName]
if [$section isNil] {
set workItem [$docStructPart workItem]
set itemKeeper [$workItem owner]
if [$itemKeeper isA SystemVersion] {
set object [$itemKeeper system]
} else {
set object [$itemKeeper file]
}
set item [$workItem item]
if [catch {set section [$sv createItemPropRef \
$name $type $object $item]} msg] {
wmtkerror $msg
return ""
}
DocGenerator::setLongName $section $name
} elseif $uniqueName {
return $section
}
} elseif {[lsearch [Document::getSuperClasses $class] \
"FilePropertyReference"] != -1} {
set section [DocGenerator::updateSection \
$docStructPart \
[$sv findPropertyReference $name $type] \
$uniqueName]
if [$section isNil] {
set file [[$docStructPart fileVersion] file]
if [catch {set section [$sv createFilePropRef \
$name $type $file]} msg] {
wmtkerror $msg
return ""
}
DocGenerator::setLongName $section $name
} elseif $uniqueName {
return $section
}
} else { # no match
wmtkerror "Invalid class '$class' for section '$name'."
return ""
}
if [isCommand docTool] {
docTool setSection [rmWhiteSpace $name] $section
}
if {[$section isA FilepropSection]} {
# set the item of the property and the property name
$section setProperty refProperties \
"[$docStructPart propertyNames]"
# the default status is selected, make is fixed
$section status fixed $cv
# update the document directory
$section updateDocDir
} elseif {[$section isA ItempropSection]} {
# set the diagram of the property and the property name
$section setProperty refProperties \
"[$docStructPart propertyNames]"
# the default status is current, make is snapshot
$section status snapshot $cv
# update the document directory
$section updateDocDir
} elseif {![$section isA LocalSection]} {
# update the document directory
$section updateDocDir
} else {
set structGen [$docStructPart structureGenerator]
if {$structGen != ""} {
$section setProperty structureGen $structGen
}
set contGen [$docStructPart contentsGenerator]
if {$contGen != ""} {
$section setProperty contentsGen $contGen
}
# create the local section
#section synchWithFileSystem
# fill the LocalSection with the initial contents
set fr ""
if { [$docStructPart initContents] != "" } {
set fr [$docStructPart initContents]
} elseif { [$section initContents] != "" } {
set fr [$section initContents]
}
if {$fr != ""} {
set to [$section docLocation]
# is it an absolute path, don't look in M4_dir
if {![file exists $fr]} {
set mfr [DocGenerator::getCustPath $fr]
if {$mfr != ""} {
file copy -force $mfr $to
BasicFS::removeFile $mfr
} else {
set msg "Initial contents '$fr' not found"
wmtkmessage $msg
if [isCommand docTool] {
wmtkmessage "$msg
} else {
wmtkerror $msg
}
}
} else {
file copy -force $fr $to
}
} else {
set file [$section docLocation]
# touch this one
if {![catch {set fid [open $file w]} reason]} {
puts $fid " "
close $fid
}
}
}
return $section
}
proc DocGenerator::updateSection {docStructPart section uniqueName} {
global DocGenerator::msg
if {[$section isNil] || "[$section getInfo Status]" == "frozen"} {
append DocGenerator::msg \
"Create section '[$docStructPart sectionName]'"
wmtkmessage ${DocGenerator::msg}
set DocGenerator::msg ""
return $section
}
if $uniqueName {
$docStructPart sectionName [DocGenerator::uniqueName \
[$docStructPart sectionName]]
return [DocGenerator::createSection $docStructPart]
}
append DocGenerator::msg \
"Update section '[$docStructPart sectionName]'"
wmtkmessage ${DocGenerator::msg}
set DocGenerator::msg ""
return $section
}
method DocGenerator::delta2Indentation {this levelDelta} {
if [lempty $levelDelta] {
return 0
}
set delta [string index $levelDelta 0]
if { $delta == "=" } {
return 0
} elseif { $delta == "+" } {
return 1
} elseif { $delta == "-" } {
set offset [string range $levelDelta 1 end]
if {$offset == ""} {
return -1
} else {
return $levelDelta
}
}
return 0
}
proc DocGenerator::uniqueName {name} {
set id [string last ${DocGenerator::double} $name]
if {$id < 0} {
return "${name}${DocGenerator::double}2"
}
incr id [string length ${DocGenerator::double}]
set nr [string range $name $id end]
incr nr
incr id -1
return "[string range $name 0 $id]$nr"
}
proc DocGenerator::getCustPath {custFile} {
set name [path_name base $custFile]
set type [path_name type $custFile]
set tmpFile [args_file {}]
# user
require custfileut.tcl
set path [CustFileUtilities::find "" $name $type]
if {$path != ""} {
file copy -force $path $tmpFile
return $tmpFile
}
# levels, modules, corporate
set cc [ClientContext::global]
if {[$cc downLoadCustomFile $name $type etc $tmpFile] == 0} {
return $tmpFile
}
unlink $tmpFile
return ""
}
proc DocGenerator::setLongName {section longName} {
$section setProperty longName "$longName"
}
# Do not delete this line -- regeneration end marker