home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1997 November
/
PCWorld_1997-11_cd.bin
/
software
/
programy
/
komix
/
DATA.Z
/
docgenerat.tcl
< prev
next >
Wrap
Text File
|
1996-10-29
|
12KB
|
486 lines
#---------------------------------------------------------------------------
#
# (c) Cadre Technologies Inc. 1996
#
# File: @(#)docgenerat.tcl /main/hindenburg/5
# Author: <generated>
# Description:
#---------------------------------------------------------------------------
# SccsId = @(#)docgenerat.tcl /main/hindenburg/5 29 Oct 1996 Copyright 1996 Cadre Technologies 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
attribute curConfigV
attribute curPhaseV
attribute curSystemV
}
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
set cc [ClientContext::global]
$this curConfigV [$cc currentConfig]
$this curPhaseV [$cc currentPhase]
$this curSystemV [$cc currentSystem]
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
#set specFile [m4_path_name etc $specFile]
if ![file exists $specFile] {
wmtkerror "File '$specFile' does not exist"
}
set specList [readConfigurationFile $specFile]
$this indentation 0
$this generateStructure $specList "" 1
if {[$struct save] == -1} {
wmtkerror "Save of document structure failed"
set result 0
}
set diagram [$struct diagram]
$struct quit
if {[$struct load $diagram] == -1} {
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 {[$struct save] == -1} {
set result 0
wmtkerror "Save of document structure failed"
}
set diagram [$struct diagram]
$struct quit
if {[$struct load $diagram] == -1} {
wmtkerror "Load of document structure failed"
}
$this editing 0
}
return $result
}
method DocGenerator::generateStructure {this specList startComp withContents} {
require "docstructp.tcl"
# 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 prevComp [$this createComponent $docStructPart $prevComp]
set indent ""
for { set j [$prevComp indentation] } { $j > 0} { incr j -1} {
set indent " $indent"
}
global DocGenerator::msg
set DocGenerator::msg "$indent"
set section [DocGenerator::createSection $docStructPart 0]
if {$section != "" && [$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
}
}
# 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]
} 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]
} 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]
set section [$sv createItemPropRef \
$name $type $object $item]
} 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]
set section [$sv createFilePropRef $name $type $file]
} 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 != ""} {
# is it an absolute path, don't look in M4_dir
if {![file exists $fr]} {
if {[catch {set fr [m4_path_name etc $fr]} err]} {
puts $err
} else {
set to [$section docLocation]
BasicFS::copyFile $fr $to
}
} else {
set to [$section docLocation]
BasicFS::copyFile $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"
}
# Do not delete this line -- regeneration end marker