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/tool/mksqlite3h.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 / tool / mksqlite3h.tcl` 226 lines ยท 7425 bytes Raw Blame History 1 #!/usr/bin/tclsh 2 # 3 # This script constructs the "sqlite3.h" header file from the following 4 # sources: 5 # 6 # 1) The src/sqlite.h.in source file. This is the template for sqlite3.h. 7 # 2) The VERSION file containing the current SQLite version number. 8 # 3) The manifest file from the fossil SCM. This gives use the date. 9 # 4) The manifest.uuid file from the fossil SCM. This gives the SHA1 hash. 10 # 11 # Run this script by specifying the root directory of the source tree 12 # on the command-line. 13 # 14 # This script performs processing on src/sqlite.h.in. It: 15 # 16 # 1) Adds SQLITE_EXTERN in front of the declaration of global variables, 17 # 2) Adds SQLITE_API in front of the declaration of API functions, 18 # 3) Replaces the string --VERS-- with the current library version, 19 # formatted as a string (e.g. "3.6.17"), and 20 # 4) Replaces the string --VERSION-NUMBER-- with current library version, 21 # formatted as an integer (e.g. "`3006017`"). 22 # 5) Replaces the string --SOURCE-ID-- with the date and time and sha1 23 # hash of the fossil-scm manifest for the source tree. 24 # 6) Adds the SQLITE_CALLBACK calling convention macro in front of all 25 # callback declarations. 26 # 27 # This script outputs to stdout unless the -o FILENAME option is used. 28 # 29 # Example usage: 30 # 31 # tclsh mksqlite3h.tcl ../sqlite [OPTIONS] 32 # ^^^^^^^^^ 33 # Root of source tree 34 # 35 # Where options are: 36 # 37 # --enable-recover Include the sqlite3recover extension 38 # -o FILENAME Write results to FILENAME instead of stdout 39 # --useapicall SQLITE_APICALL instead of SQLITE_CDECL 40 # 41 42 # Default output stream 43 set out stdout 44 45 # Get the source tree root directory from the command-line 46 # 47 set TOP [lindex $argv 0] 48 49 # If the -o FILENAME option is present, use FILENAME for output. 50 # 51 set x [lsearch $argv -o] 52 if {$x>0} { 53 incr x 54 set out [open [lindex $argv $x] wb] 55 } 56 57 # Enable use of SQLITE_APICALL macros at the right points? 58 # 59 set useapicall 0 60 61 # Include sqlite3recover.h? 62 # 63 set enable_recover 0 64 65 # Process command-line arguments 66 if {[lsearch -regexp [lrange $argv 1 end] {^-+useapicall}] != -1} { 67 set useapicall 1 68 } 69 if {[lsearch -regexp [lrange $argv 1 end] {^-+enable-recover}] != -1} { 70 set enable_recover 1 71 } 72 73 # Get the SQLite version number (ex: 3.6.18) from the $TOP/VERSION file. 74 # 75 set in [open [file normalize $TOP/VERSION] rb] 76 set zVersion [string trim [read $in]] 77 close $in 78 set nVersion [eval format "%d%03d%03d" [split $zVersion .]] 79 80 # Get the source-id 81 # 82 proc file-content {fn} { 83 set fd [open $fn rb] 84 set rv [string trim [read $fd]] 85 close $fd 86 return $rv 87 } 88 89 set PWD [pwd] 90 cd $TOP 91 set tmpfile $PWD/tmp-[clock millisec]-[expr {int(rand()*`100000000000`)}].txt 92 set mksourceid $PWD/mksourceid 93 if {![file exists $mksourceid] && [file exists ${mksourceid}.exe]} { 94 # Workaround for Windows-based Unix-like environments 95 # https://sqlite.org/forum/forumpost/`41ba710dd9943453` 96 set mksourceid ${mksourceid}.exe 97 } 98 exec $mksourceid manifest > $tmpfile 99 set zSourceId [file-content $tmpfile] 100 file delete -force $tmpfile 101 cd $PWD 102 103 # Collect SQLITE_SCM_BRANCH, SQLITE_SCM_TAGS, and SQLITE_SCM_DATETIME 104 set zVerTime [lindex [lindex [split [file-content $TOP/manifest] "\n"] 1] 1]Z; # D-card 105 if {![file exists $TOP/manifest.tags]} { 106 puts stderr "WARNING: building sqlite3.h without manifest.tags, which is generated by the SCM." 107 puts stderr "This means that we cannot record the tag/branch info. We will continue with " 108 puts stderr "a placeholder value. To remedy this, run the following command from a " 109 puts stderr "check-out:\n" 110 puts stderr " fossil set manifest urt\n" 111 set zSourceId [string range $zSourceId 0 end-13]-experimental; # Keep SHA3 hash length 112 set zBranch "unknown" 113 set zTags "unknown" 114 } else { 115 # Read the list of branch/tags from manifest.tags 116 set content [file-content $TOP/manifest.tags]; 117 set zTags {} 118 foreach {x tag} [lassign $content - zBranch] { 119 if {$tag eq $zBranch} continue 120 lappend zTags $tag 121 } 122 } 123 124 # Set up patterns for recognizing API declarations. 125 # 126 set varpattern {^[a-zA-Z][a-zA-Z_0-9 *]+sqlite3_[_a-zA-Z0-9]+(\[|;| =)} 127 set declpattern1 {^ *([a-zA-Z][a-zA-Z_0-9 ]+ \**)(sqlite3_[_a-zA-Z0-9]+)(\(.*)$} 128 129 set declpattern2 \ 130 {^ *([a-zA-Z][a-zA-Z_0-9 ]+ \**)(sqlite3session_[_a-zA-Z0-9]+)(\(.*)$} 131 132 set declpattern3 \ 133 {^ *([a-zA-Z][a-zA-Z_0-9 ]+ \**)(sqlite3changeset_[_a-zA-Z0-9]+)(\(.*)$} 134 135 set declpattern4 \ 136 {^ *([a-zA-Z][a-zA-Z_0-9 ]+ \**)(sqlite3changegroup_[_a-zA-Z0-9]+)(\(.*)$} 137 138 set declpattern5 \ 139 {^ *([a-zA-Z][a-zA-Z_0-9 ]+ \**)(sqlite3rebaser_[_a-zA-Z0-9]+)(\(.*)$} 140 141 # Force the output to use unix line endings, even on Windows. 142 fconfigure stdout -translation binary 143 144 set filelist [subst { 145 $TOP/src/sqlite.h.in 146 $TOP/ext/rtree/sqlite3rtree.h 147 $TOP/ext/session/sqlite3session.h 148 $TOP/ext/fts5/fts5.h 149 }] 150 if {$enable_recover} { 151 lappend filelist "$TOP/ext/recover/sqlite3recover.h" 152 } 153 154 # These are the functions that accept a variable number of arguments. They 155 # always need to use the "cdecl" calling convention even when another calling 156 # convention (e.g. "stcall") is being used for the rest of the library. 157 set cdecllist { 158 sqlite3_config 159 sqlite3_db_config 160 sqlite3_log 161 sqlite3_mprintf 162 sqlite3_snprintf 163 sqlite3_str_appendf 164 sqlite3_test_control 165 sqlite3_vtab_config 166 } 167 168 # Process the source files. 169 # 170 foreach file $filelist { 171 set in [open $file rb] 172 if {![regexp {sqlite\.h\.in} $file]} { 173 puts $out "/******** Begin file [file tail $file] *********/" 174 } 175 while {![eof $in]} { 176 177 set line [string trimright [gets $in]] 178 179 # File sqlite3rtree.h contains a line "#include ". Omit this 180 # line when copying sqlite3rtree.h into sqlite3.h. 181 # 182 if {[string match {*#include*[<"]sqlite3.h[>"]*} $line]} continue 183 184 regsub -- --VERS-- $line $zVersion line 185 regsub -- --VERSION-NUMBER-- $line $nVersion line 186 regsub -- --SOURCE-ID-- $line "$zSourceId" line 187 regsub -- --SCM-BRANCH-- $line "$zBranch" line 188 regsub -- --SCM-TAGS-- $line "$zTags" line 189 regsub -- --SCM-DATETIME-- $line "$zVerTime" line 190 191 if {[regexp $varpattern $line] && ![regexp {^ *typedef} $line]} { 192 set line "SQLITE_API $line" 193 } else { 194 if {[regexp $declpattern1 $line all rettype funcname rest] || \ 195 [regexp $declpattern2 $line all rettype funcname rest] || \ 196 [regexp $declpattern3 $line all rettype funcname rest] || \ 197 [regexp $declpattern4 $line all rettype funcname rest] || \ 198 [regexp $declpattern5 $line all rettype funcname rest]} { 199 set line SQLITE_API 200 append line " " [string trim $rettype] 201 if {[string index $rettype end] ne "*"} { 202 append line " " 203 } 204 if {$useapicall} { 205 if {[lsearch -exact $cdecllist $funcname] >= 0} { 206 append line SQLITE_CDECL " " 207 } else { 208 append line SQLITE_APICALL " " 209 } 210 } 211 append line $funcname $rest 212 } 213 } 214 if {$useapicall && ![regexp {^\*\*} $line]} { 215 set line [string map [list (*sqlite3_syscall_ptr) \ 216 "(SQLITE_SYSAPI *sqlite3_syscall_ptr)"] $line] 217 regsub -all {\(\*} $line {(SQLITE_CALLBACK*} line 218 } 219 puts $out $line 220 } 221 close $in 222 if {![regexp {sqlite\.h\.in} $file]} { 223 puts $out "/******** End of [file tail $file] *********/" 224 } 225 } 226 puts $out "#endif /* SQLITE3_H */"