Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/sqlite/blob/master/ext/fts5/extract_api_docs.tcl # sqlite [Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `sqlite / ext / fts5 / extract_api_docs.tcl` 257 lines ยท 6330 bytes Raw Blame History 1 # 2 # 2014 August 24 3 # 4 # The author disclaims copyright to this source code. In place of 5 # a legal notice, here is a blessing: 6 # 7 # May you do good and not evil. 8 # May you find forgiveness for yourself and forgive others. 9 # May you share freely, never taking more than you give. 10 # 11 #-------------------------------------------------------------------------- 12 # 13 # This script extracts the documentation for the API used by fts5 auxiliary 14 # functions from header file fts5.h. It outputs html text on stdout that 15 # is included in the documentation on the web. 16 # 17 18 set ::fts5_docs_output "" 19 if {[info commands hd_putsnl]==""} { 20 if {[llength $argv]>0} { set ::extract_api_docs_mode [lindex $argv 0] } 21 proc output {text} { 22 puts $text 23 } 24 } else { 25 proc output {text} { 26 append ::fts5_docs_output "$text\n" 27 } 28 } 29 if {[info exists ::extract_api_docs_mode]==0} {set ::extract_api_docs_mode api} 30 31 32 set input_file [file join [file dir [info script]] fts5.h] 33 set fd [open $input_file] 34 set data [read $fd] 35 close $fd 36 37 38 # Argument $data is the entire text of the fts5.h file. This function 39 # extracts the definition of the Fts5ExtensionApi structure from it and 40 # returns a key/value list of structure member names and definitions. i.e. 41 # 42 # iVersion {int iVersion} xUserData {void *(*xUserData)(Fts5Context*)} ... 43 # 44 proc get_struct_members {data} { 45 46 # Extract the structure definition from the fts5.h file. 47 regexp "struct Fts5ExtensionApi {(.*?)};" $data -> defn 48 49 # Remove all comments from the structure definition 50 regsub -all {/[*].*?[*]/} $defn {} defn2 51 52 set res [list] 53 foreach member [split $defn2 {;}] { 54 55 set member [string trim $member] 56 if {$member!=""} { 57 catch { set name [lindex $member end] } 58 regexp {.*?[(][*]([^)]*)[)]} $member -> name 59 lappend res $name $member 60 } 61 } 62 63 set res 64 } 65 66 proc get_struct_docs {data names} { 67 # Extract the structure definition from the fts5.h file. 68 regexp {EXTENSION API FUNCTIONS(.*?)[*]/} $data -> docs 69 70 set current_doc "" 71 set current_header "" 72 73 foreach line [split $docs "\n"] { 74 regsub {[*]*} $line {} line 75 if {[regexp {^ } $line]} { 76 append current_doc "$line\n" 77 } elseif {[string trim $line]==""} { 78 if {$current_header!=""} { append current_doc "\n" } 79 } else { 80 if {$current_doc != ""} { 81 lappend res $current_header $current_doc 82 set current_doc "" 83 } 84 set subject n/a 85 regexp {^ *([[:alnum:]_]*)} $line -> subject 86 if {[lsearch $names $subject]>=0} { 87 set current_header $subject 88 } else { 89 set current_header [string trim $line] 90 } 91 } 92 } 93 94 if {$current_doc != ""} { 95 lappend res $current_header $current_doc 96 } 97 98 set res 99 } 100 101 proc get_tokenizer_docs {data} { 102 regexp {(xCreate:.*?)[*]/} $data -> docs 103 104 set res "
\n" 109 continue 110 } 111 if {[regexp {FTS5_TOKENIZER} $line]} { 112 set line
113 } 114 if {[regexp {SYNONYM SUPPORT} $line]} { 115 set line "
\n" 119 } else { 120 append res "$line\n" 121 } 122 } 123 124 set res 125 } 126 127 proc get_api_docs {data} { 128 # Initialize global array M as a map from Fts5StructureApi member name 129 # to member definition. i.e. 130 # 131 # iVersion -> {int iVersion} 132 # xUserData -> {void *(*xUserData)(Fts5Context*)} 133 # ... 134 # 135 array set M [get_struct_members $data] 136 137 # Initialize global list D as a map from section name to documentation 138 # text. Most (all?) section names are structure member names. 139 # 140 set D [get_struct_docs $data [array names M]] 141 142 output "
$hdr