diff options
Diffstat (limited to 'libraries/sqlite/unix/sqlite-3.5.1/www/mkapidoc.tcl')
-rw-r--r-- | libraries/sqlite/unix/sqlite-3.5.1/www/mkapidoc.tcl | 176 |
1 files changed, 176 insertions, 0 deletions
diff --git a/libraries/sqlite/unix/sqlite-3.5.1/www/mkapidoc.tcl b/libraries/sqlite/unix/sqlite-3.5.1/www/mkapidoc.tcl new file mode 100644 index 0000000..723f84a --- /dev/null +++ b/libraries/sqlite/unix/sqlite-3.5.1/www/mkapidoc.tcl | |||
@@ -0,0 +1,176 @@ | |||
1 | #!/usr/bin/tclsh | ||
2 | # | ||
3 | # Run this script redirecting the sqlite3.h file as standard | ||
4 | # inputs and this script will generate API documentation. | ||
5 | # | ||
6 | set rcsid {$Id: mkapidoc.tcl,v 1.2 2007/06/20 09:09:48 danielk1977 Exp $} | ||
7 | source common.tcl | ||
8 | header {C/C++ Interface For SQLite Version 3} | ||
9 | puts { | ||
10 | <h2 class=pdf_section>C/C++ Interface For SQLite Version 3</h2> | ||
11 | } | ||
12 | |||
13 | # Scan standard input to extract the information we need | ||
14 | # to build the documentation. | ||
15 | # | ||
16 | set title {} | ||
17 | set type {} | ||
18 | set body {} | ||
19 | set code {} | ||
20 | set phase 0 | ||
21 | set content {} | ||
22 | while {![eof stdin]} { | ||
23 | set line [gets stdin] | ||
24 | if {$phase==0} { | ||
25 | # Looking for the CAPI3REF: keyword | ||
26 | if {[regexp {^\*\* CAPI3REF: +(.*)} $line all tx]} { | ||
27 | set title $tx | ||
28 | set phase 1 | ||
29 | } | ||
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]} { | ||
34 | set type $cx | ||
35 | } elseif {[regexp {^KEYWORDS: +(.*)} $lx all kx]} { | ||
36 | foreach k $kx { | ||
37 | set keyword($k) 1 | ||
38 | } | ||
39 | } else { | ||
40 | append body $lx\n | ||
41 | } | ||
42 | } elseif {[string range $line 0 1]=="*/"} { | ||
43 | set phase 2 | ||
44 | } | ||
45 | } elseif {$phase==2} { | ||
46 | if {$line==""} { | ||
47 | set kwlist [lsort [array names keyword]] | ||
48 | unset -nocomplain keyword | ||
49 | set key $type:$kwlist | ||
50 | lappend content [list $key $title $type $kwlist $body $code] | ||
51 | set title {} | ||
52 | set keywords {} | ||
53 | set type {} | ||
54 | set body {} | ||
55 | set code {} | ||
56 | set phase 0 | ||
57 | } else { | ||
58 | if {[regexp {^#define (SQLITE_[A-Z0-9_]+)} $line all kx]} { | ||
59 | set type constant | ||
60 | set keyword($kx) 1 | ||
61 | } elseif {[regexp {^typedef .* (sqlite[0-9a-z_]+);} $line all kx]} { | ||
62 | set type datatype | ||
63 | set keyword($kx) 1 | ||
64 | } elseif {[regexp {^[a-z].*[ *](sqlite3_[a-z0-9_]+)\(} $line all kx]} { | ||
65 | set type function | ||
66 | set keyword($kx) 1 | ||
67 | } | ||
68 | append code $line\n | ||
69 | } | ||
70 | } | ||
71 | } | ||
72 | |||
73 | # Output HTML that displays the given list in N columns | ||
74 | # | ||
75 | proc output_list {N lx} { | ||
76 | puts {<table width="100%" cellpadding="5"><tr>} | ||
77 | set len [llength $lx] | ||
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] | ||
85 | if {$entry!=""} { | ||
86 | foreach {link label} $entry break | ||
87 | puts "<li><a href=\"#$link\">$label</a></li>" | ||
88 | } | ||
89 | } | ||
90 | puts {</ul></td>} | ||
91 | } | ||
92 | puts {</tr></table>} | ||
93 | } | ||
94 | |||
95 | # Do a table of contents for objects | ||
96 | # | ||
97 | set objlist {} | ||
98 | foreach c $content { | ||
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] | ||
105 | } | ||
106 | } | ||
107 | puts {<h2>Datatypes:</h2>} | ||
108 | output_list 3 $objlist | ||
109 | puts {<hr>} | ||
110 | |||
111 | # Do a table of contents for constants | ||
112 | # | ||
113 | set clist {} | ||
114 | foreach c $content { | ||
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] | ||
121 | } | ||
122 | } | ||
123 | puts {<h2>Constants:</h2>} | ||
124 | set clist [lsort -index 1 $clist] | ||
125 | output_list 3 $clist | ||
126 | puts {<hr>} | ||
127 | |||
128 | |||
129 | # Do a table of contents for functions | ||
130 | # | ||
131 | set funclist {} | ||
132 | foreach c $content { | ||
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] | ||
139 | } | ||
140 | } | ||
141 | puts {<h2>Functions:</h2>} | ||
142 | set funclist [lsort -index 1 $funclist] | ||
143 | output_list 3 $funclist | ||
144 | puts {<hr>} | ||
145 | |||
146 | # Resolve links | ||
147 | # | ||
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> | ||
154 | } else { | ||
155 | append x [lindex $args 0]</a> | ||
156 | } | ||
157 | return $x | ||
158 | } | ||
159 | |||
160 | # Output all the records | ||
161 | # | ||
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>" | ||
166 | } | ||
167 | puts "<h2>$title</h2>" | ||
168 | puts "<blockquote><pre>" | ||
169 | puts "$code" | ||
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] | ||
174 | puts "$body" | ||
175 | puts "<hr>" | ||
176 | } | ||