3
# Run this script redirecting the sqlite3.h file as standard
4
# inputs and this script will generate API documentation.
6
set rcsid {$Id: mkapidoc.tcl,v 1.2 2007/06/20 09:09:48 danielk1977 Exp $}
8
header {C/C++ Interface For SQLite Version 3}
10
<h2 class=pdf_section>C/C++ Interface For SQLite Version 3</h2>
13
# Scan standard input to extract the information we need
14
# to build the documentation.
22
while {![eof stdin]} {
25
# Looking for the CAPI3REF: keyword
26
if {[regexp {^\*\* CAPI3REF: +(.*)} $line all tx]} {
30
} elseif {$phase==1} {
31
if {[string range $line 0 1]=="**"} {
32
set lx [string trim [string range $line 3 end]]
33
if {[regexp {^CATEGORY: +([a-z]*)} $lx all cx]} {
35
} elseif {[regexp {^KEYWORDS: +(.*)} $lx all kx]} {
42
} elseif {[string range $line 0 1]=="*/"} {
45
} elseif {$phase==2} {
47
set kwlist [lsort [array names keyword]]
48
unset -nocomplain keyword
50
lappend content [list $key $title $type $kwlist $body $code]
58
if {[regexp {^#define (SQLITE_[A-Z0-9_]+)} $line all kx]} {
61
} elseif {[regexp {^typedef .* (sqlite[0-9a-z_]+);} $line all kx]} {
64
} elseif {[regexp {^[a-z].*[ *](sqlite3_[a-z0-9_]+)\(} $line all kx]} {
73
# Output HTML that displays the given list in N columns
75
proc output_list {N lx} {
76
puts {<table width="100%" cellpadding="5"><tr>}
78
set n [expr {($len + $N - 1)/$N}]
79
for {set i 0} {$i<$N} {incr i} {
80
set start [expr {$i*$n}]
81
set end [expr {($i+1)*$n}]
82
puts {<td valign="top"><ul>}
83
for {set j $start} {$j<$end} {incr j} {
84
set entry [lindex $lx $j]
86
foreach {link label} $entry break
87
puts "<li><a href=\"#$link\">$label</a></li>"
95
# Do a table of contents for objects
99
foreach {key title type keywords body code} $c break
100
if {$type!="datatype"} continue
101
set keywords [lsort $keywords]
102
set k [lindex $keywords 0]
103
foreach kw $keywords {
104
lappend objlist [list $k $kw]
107
puts {<h2>Datatypes:</h2>}
108
output_list 3 $objlist
111
# Do a table of contents for constants
115
foreach {key title type keywords body code} $c break
116
if {$type!="constant"} continue
117
set keywords [lsort $keywords]
118
set k [lindex $keywords 0]
119
foreach kw $keywords {
120
lappend clist [list $k $kw]
123
puts {<h2>Constants:</h2>}
124
set clist [lsort -index 1 $clist]
129
# Do a table of contents for functions
133
foreach {key title type keywords body code} $c break
134
if {$type!="function"} continue
135
set keywords [lsort $keywords]
136
set k [lindex $keywords 0]
137
foreach kw $keywords {
138
lappend funclist [list $k $kw]
141
puts {<h2>Functions:</h2>}
142
set funclist [lsort -index 1 $funclist]
143
output_list 3 $funclist
148
proc resolve_links {args} {
149
set tag [lindex $args 0]
150
regsub -all {[^a-zA-Z0-9_]} $tag {} tag
151
set x "<a href=\"#$tag\">"
152
if {[llength $args]>2} {
153
append x [lrange $args 2 end]</a>
155
append x [lindex $args 0]</a>
160
# Output all the records
162
foreach c [lsort $content] {
163
foreach {key title type keywords body code} $c break
164
foreach k $keywords {
165
puts "<a name=\"$k\"></a>"
167
puts "<h2>$title</h2>"
168
puts "<blockquote><pre>"
170
puts "</pre></blockquote>"
171
regsub -all "\n\n+" $body {</p>\1<p>} body
172
regsub -all {\[} <p>$body</p> {[resolve_links } body
173
set body [subst -novar -noback $body]