1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
|
set dir [file dirname [info script]]
# do we use the svn version
set libdir [file join $dir .. .. GUI Guib lib]
#
if { [file isdirectory $libdir] } {
lappend auto_path $dir $libdir
} else {
# do we use the tarball version
set libdir [glob -nocomplain -directory [file join $dir .. ..] \
[file join PWgui-* lib Guib-* lib]]
#
if { $libdir != {} && [file isdirectory $libdir] } {
lappend auto_path $dir $libdir
} else {
puts stderr "no usable directory containing the tclu library found; you need to download the PWgui package"
exit 1
}
}
package require tclu 0.9
package require struct::tree 2.1
package require struct::stack 1.3
package require textutil
namespace eval ::helpdoc {
variable dir [file dirname [info script]]
# schema-related variables
variable attrArr; # stores all about attributes
variable elemArr; # stores all about elements
variable defineArr; # stores all about define's
variable elemList ""
variable itemList ""
variable state
array set state {
depth 0
rootVisited 0
rootElem ""
}
variable stackArr
array set stackArr [subst {
repetition [::struct::stack]
optional [::struct::stack]
interleave [::struct::stack]
currentElem [::struct::stack]
}]
$stackArr(repetition) push 1; # decimal-digit | + | * | ? (meaning integer-number of times, one-or-more, zero-or-more, zero-or-one)
$stackArr(optional) push 0
$stackArr(interleave) push 0
$stackArr(currentElem) push ""
# stack & tree for parsing input definitions
variable tree ""
variable stack [::struct::stack]
# output-related
variable indentNum 3
variable txtDepth 0
variable fid
variable head
variable rbd_var
variable rbd_stack
variable rbd_info
variable robodoc [auto_execok robodoc]
variable xsltproc [auto_execok xsltproc]
# TXT variables
variable vargroup 0
variable dimensiongroup 0
variable colgroup 0
variable rowgroup 0
variable options 0
variable options_first 0
}
namespace eval ::helpdoc::tag {}
namespace eval ::helpdoc::schema {}
source [file join $::helpdoc::dir readSchema.tcl]
proc ::helpdoc::openOutputs {file} {
variable fid
variable head
set head [file rootname $file]
set fid(xml) [open $head.xml w]
set fid(txt) [open $head.txt w]
# currently disabled
#set fid(rbd) [open $head.rbd w]
puts $fid(xml) {<?xml version="1.0" encoding="ISO-8859-1"?>}
puts $fid(xml) {<?xml-stylesheet type="text/xsl" href="input_xx.xsl"?>}
puts $fid(xml) {<!-- FILE AUTOMATICALLY CREATED: DO NOT EDIT, CHANGES WILL BE LOST -->
}
puts $fid(txt) "*** FILE AUTOMATICALLY CREATED: DO NOT EDIT, CHANGES WILL BE LOST ***\n"
#puts $fid(rbd) "# *** FILE AUTOMATICALLY CREATED: DO NOT EDIT, CHANGES WILL BE LOST ***\n"
}
proc ::helpdoc::writeOutputs {} {
variable tree
variable head
variable fid
variable robodoc
variable xsltproc
variable rbd_info
#$tree destroy
# TXT
puts $fid(txt) "This file has been created by helpdoc utility on [clock format [clock seconds]]"
puts ""
foreach fmt [array names fid] {
puts "File $head.$fmt has been written."
close $fid($fmt)
}
flush stdout
# run XSLTPROC
if { $xsltproc != "" } {
puts -nonewline " Executing: $xsltproc --stringparam version \"$::opt(version)\" --stringparam current-date \"[clock format [clock seconds]]\" $head.xml > $head.html ..."
if { [catch [list exec $xsltproc --stringparam version "$::opt(version)" --stringparam current-date [clock format [clock seconds]] $head.xml > $head.html] errorMsg] } {
puts stderr " \[Error\]"
puts stderr "Execution of xsltproc failed with error message:\n\n$errorMsg"
} else {
puts " \[OK\]"
puts "File $head.html has been written."
}
} else {
puts "***"
puts "*** \[WARNING\] xsltproc not found, XML --> HTML conversion skipped"
puts "***"
puts "*** please install the xsltproc program to convert INPUT_*.xml to INPUT_*.html"
puts "***"
}
# run ROBODOC
if { 0 } {
# currently disbabled
if { $robodoc != "" } {
if { ! [file isdirectory $head.d] } {
file mkdir $head.d
} else {
foreach file [glob -nocomplain $head.d/*.html] {
file delete $file
}
}
if { ! [file isdirectory $head.robodoc] } {
file mkdir $head.robodoc
}
file copy -force $head.rbd $head.robodoc/
catch {exec $robodoc --doc $head.d/ --src $head.robodoc/ --documenttitle "Description of $rbd_info(program) input file"}
if { [file exists $head.d/toc_index.html] } {
file copy -force $head.d/toc_index.html $head.d/index.html
puts "File $head.d/index.html has been written."
}
}
}
}
proc ::helpdoc::readSchema {} {
puts "\n***\n*** Parsing the helpdoc.schema\n***\n"
namespace eval schema { ::source [file join $basedir helpdoc.schema] }
puts "\n\n***\n*** Assigning ref's\n***\n"
assignRefs_
puts "\n\n***\n*** Creating tags commands\n***\n"
createTagCmds_
#puts "\n\n***\n*** Creating regexps for @-tags\n***\n"
createAtcmdRegexp_
}
proc ::helpdoc::print_xml {tree node action} {
variable fid
set depth [$tree depth $node]
set tag [$tree get $node tag]
set attributes [getFromTree $tree $node attributes]
set content [getFromTree $tree $node text]
xml_tag_${action} $tag $attributes $content $depth
}
proc ::helpdoc::print_txt {tree node action} {
variable fid
set depth [$tree depth $node]
set tag [$tree get $node tag]
set attributes [getFromTree $tree $node attributes]
set content [getFromTree $tree $node text]
txt_tag_${action} $tree $node $tag $attributes $content [expr $depth - 1]
# currently disabled:
# robodoc
#rbd_tag_${action} $tag $attributes $content $depth
}
proc ::helpdoc::process {fileList} {
variable tree
variable vargroup
variable dimensiongroup
variable mode
# first read the schema (and load tag's commands)
readSchema
#puts "tag commands: [info procs ::helpdoc::tag::*]"
foreach file $fileList {
set vargroup 0
set dimensiongroup 0
if { [file exists $file] } {
openOutputs $file
puts "\n\n***\n*** Parsing definition file: $file\n***\n"
namespace eval tag [list source $file]
set mode default
$tree walkproc root -order both print_xml
$tree walkproc root -order both print_txt
writeOutputs
$tree destroy
unset mode
} else {
puts stderr "file [file join [pwd] $file] does not exists : aborting ..."
exit 1
}
}
}
|