~aleteoryx/tclircc

ref: 5602edaaf2ca3282ade006b64ec1fadbfad25016 tclircc/bin/docgen.tcl -rwxr-xr-x 1.1 KiB
5602edaaaleteoryx disable sr.ht toc a month ago
                                                                                
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
#!/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 $ofd {---
toc: false
---}
    puts -nonewline $ofd [.doc format [read $ifd]]
    close $ifd
    close $ofd

    puts $ofile
  }

  lappend to_check {*}[glob -directory $cur -types d -nocomplain *]
}