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
|
# -*- tcl -*-
# sak::doc - Documentation facilities
package require sak::util
package require sak::doc::auto
namespace eval ::sak::doc {}
# ###
# API commands
## ### ### ### ######### ######### #########
proc ::sak::doc::index {modules {excluded {}}} {
# The argument (= set of modules) is irrelevant to this command.
global base
# First locate all manpages in the CVS workspace.
set manpages [auto::findManpages $base $excluded]
auto::saveManpages $manpages
# Then scan the found pages and extract the information needed for
# keyword index and table of contents.
array set meta [auto::scanManpages $manpages]
# Sort through the extracted data.
array set kwic {} ; # map: keyword -> list (file...)
array set title {} ; # map: file -> description
array set cat {} ; # map: category -> list (file...)
array set name {} ; # map: file -> label
set apps {} ; # list (file...)
array set mods {} ; # map: module -> list(file...)
foreach page [array names meta] {
unset -nocomplain m
array set m $meta($page)
# Collect keywords and file mapping for index.
foreach kw $m(keywords) {
lappend kwic($kw) $page
}
# Get page title, relevant for display order
if {$m(desc) eq ""} {
set m(desc) $m(shortdesc)
}
set title($page) $m(desc)
# Get page name/title, relevant for display order.
set name($page) $m(title)
# Get page category, for sectioning and display order in the
# table of contents
if {$m(category) ne ""} {
set c $m(category)
} else {
set c Unfiled
}
lappend cat($c) $page
# Type of documented entity
set type [lindex [file split $page] 0]
if {$type eq "apps"} {
lappend apps $page
} else {
lappend mods([lindex [file split $page] 1]) $page
}
}
#parray meta
#parray kwic
#parray title
#parray name
#parray cat
#puts "apps = $apps"
#parray mods
auto::saveKeywordIndex kwic name
auto::saveTableOfContents title name cat apps mods
auto::saveSimpleTableOfContents1 title name apps toc_apps.txt
auto::saveSimpleTableOfContents2 title name mods toc_mods.txt
auto::saveSimpleTableOfContents3 title name cat toc_cats.txt
return
}
proc ::sak::doc::imake {modules {excluded {}}} {
global base
# The argument (= set of modules) is irrelevant to this command.
auto::saveManpages [auto::findManpages $base $excluded]
return
}
proc ::sak::doc::ishow {modules} {
if {[catch {
set manpages [auto::loadManpages]
} msg]} {
puts stderr "Unable to use manpage listing '[auto::manpages]'\n$msg"
} else {
puts [join $manpages \n]
}
return
}
## ### ### ### ######### ######### #########
proc ::sak::doc::validate {modules} {Gen null null $modules}
proc ::sak::doc::html {modules} {Gen html html $modules}
proc ::sak::doc::nroff {modules} {Gen nroff n $modules}
proc ::sak::doc::tmml {modules} {Gen tmml tmml $modules}
proc ::sak::doc::text {modules} {Gen text txt $modules}
proc ::sak::doc::wiki {modules} {Gen wiki wiki $modules}
proc ::sak::doc::latex {modules} {Gen latex tex $modules}
proc ::sak::doc::dvi {modules} {
latex $modules
file mkdir [file join doc dvi]
cd [file join doc dvi]
foreach f [lsort -dict [glob -nocomplain ../latex/*.tex]] {
set target [file rootname [file tail $f]].dvi
if {[file exists $target]
&& [file mtime $target] > [file mtime $f]} {
continue
}
puts "Gen (dvi): $f"
exec latex $f 1>@ stdout 2>@ stderr
}
cd ../..
return
}
proc ::sak::doc::ps {modules} {
dvi $modules
file mkdir [file join doc ps]
cd [file join doc ps]
foreach f [lsort -dict [glob -nocomplain ../dvi/*.dvi]] {
set target [file rootname [file tail $f]].ps
if {[file exists $target]
&& [file mtime $target] > [file mtime $f]} {
continue
}
puts "Gen (ps): $f"
exec dvips -o $target $f >@ stdout 2>@ stderr
}
cd ../..
return
}
proc ::sak::doc::pdf {modules} {
dvi $modules
file mkdir [file join doc pdf]
cd [file join doc pdf]
foreach f [lsort -dict [glob -nocomplain ../ps/*.ps]] {
set target [file rootname [file tail $f]].pdf
if {[file exists $target]
&& [file mtime $target] > [file mtime $f]} {
continue
}
puts "Gen (pdf): $f"
exec ps2pdf $f $target >@ stdout 2>@ stderr
}
cd ../..
return
}
proc ::sak::doc::list {modules} {
Gen list l $modules
set FILES [glob -nocomplain doc/list/*.l]
set LIST [open [file join doc list manpages.tcl] w]
foreach file $FILES {
set f [open $file r]
puts $LIST [read $f]
close $f
}
close $LIST
eval file delete -force $FILES
return
}
# ### ### ### ######### ######### #########
## Implementation
proc ::sak::doc::Gen {fmt ext modules} {
global distribution
global tcl_platform
getpackage doctools doctools/doctools.tcl
set null 0 ; if {![string compare $fmt null]} {set null 1}
set hidden 0 ; if {![string compare $fmt desc]} {set hidden 1}
if {!$null} {
file mkdir [file join doc $fmt]
set prefix "Gen ($fmt)"
} else {
set prefix "Validate "
}
foreach m $modules {
set mpath [sak::util::module2path $m]
::doctools::new dt \
-format $fmt \
-module $m
set fl [glob -nocomplain [file join $mpath *.man]]
if {[llength $fl] == 0} {
dt destroy
continue
}
foreach f $fl {
if {!$null} {
set target [file join doc $fmt \
[file rootname [file tail $f]].$ext]
if {[file exists $target]
&& [file mtime $target] > [file mtime $f]} {
continue
}
}
if {!$hidden} {puts "$prefix: $f"}
dt configure -file $f
if {$null} {
dt configure -deprecated 1
}
set fail [catch {
set data [dt format [get_input $f]]
} msg]
set warnings [dt warnings]
if {[llength $warnings] > 0} {
puts stderr [join $warnings \n]
}
if {$fail} {
puts stderr $msg
continue
}
if {!$null} {
write_out $target $data
}
}
dt destroy
}
}
# ### ### ### ######### ######### #########
package provide sak::doc 1.0
##
# ###
|