#!/bin/env tclsh
set files {
*.tcl
spdx/lib.tcl
ui/*.tcl
db/*.tcl
irc/*.tcl
}
set basedir \
[file normalize \
[file join \
[file dirname \
[dict get [info frame [info frame]] file]] ..]]
cd [file join $basedir src]
set files [glob -nocomplain {*}$files]
file mkdir [file join $basedir doc doctools gen]
exec -- [file join $basedir bin docextract.tcl] -o [file join $basedir doc doctools gen] -all {*}$files
package require doctools
doctools::new .doc
.doc configure -format markdown -ibase [file join $basedir doc doctools]
cd [file join $basedir doc doctools gen]
set to_check .
while {[llength $to_check]} {
set to_check [lassign $to_check cur]
foreach file [glob -directory $cur -types f -nocomplain *.man] {
set ofile [file rootname $file].md
set opath [file join $basedir doc md $ofile]
file mkdir [file dirname $opath]
.doc configure -file $ofile
set ifd [open $file r]
set ofd [open $opath w]
puts -nonewline $ofd [.doc format [read $ifd]]
close $ifd
close $ofd
# TODO: postprocess to remove toc
puts $ofile
}
lappend to_check {*}[glob -directory $cur -types d -nocomplain *]
}