OLD | NEW |
1 #!/usr/bin/tclsh | 1 #!/usr/bin/tclsh |
2 # | 2 # |
3 # This script constructs the "sqlite3.h" header file from the following | 3 # This script constructs the "sqlite3.h" header file from the following |
4 # sources: | 4 # sources: |
5 # | 5 # |
6 # 1) The src/sqlite.h.in source file. This is the template for sqlite3.h. | 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. | 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. | 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. | 9 # 4) The manifest.uuid file from the fossil SCM. This gives the SHA1 hash. |
10 # | 10 # |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 if {[regexp {^D (2[-0-9T:]+)} $line all date]} { | 56 if {[regexp {^D (2[-0-9T:]+)} $line all date]} { |
57 set zDate [string map {T { }} $date] | 57 set zDate [string map {T { }} $date] |
58 break | 58 break |
59 } | 59 } |
60 } | 60 } |
61 close $in | 61 close $in |
62 | 62 |
63 # Set up patterns for recognizing API declarations. | 63 # Set up patterns for recognizing API declarations. |
64 # | 64 # |
65 set varpattern {^[a-zA-Z][a-zA-Z_0-9 *]+sqlite3_[_a-zA-Z0-9]+(\[|;| =)} | 65 set varpattern {^[a-zA-Z][a-zA-Z_0-9 *]+sqlite3_[_a-zA-Z0-9]+(\[|;| =)} |
66 set declpattern {^ *[a-zA-Z][a-zA-Z_0-9 ]+ \**sqlite3_[_a-zA-Z0-9]+\(} | 66 set declpattern {^ *([a-zA-Z][a-zA-Z_0-9 ]+ \**)(sqlite3_[_a-zA-Z0-9]+)(\(.*)$} |
67 | 67 |
68 # Force the output to use unix line endings, even on Windows. | 68 # Force the output to use unix line endings, even on Windows. |
69 fconfigure stdout -translation lf | 69 fconfigure stdout -translation lf |
70 | 70 |
71 set filelist [subst { | 71 set filelist [subst { |
72 $TOP/src/sqlite.h.in | 72 $TOP/src/sqlite.h.in |
73 $TOP/ext/rtree/sqlite3rtree.h | 73 $TOP/ext/rtree/sqlite3rtree.h |
| 74 $TOP/ext/fts5/fts5.h |
74 }] | 75 }] |
75 | 76 |
| 77 # These are the functions that accept a variable number of arguments. They |
| 78 # always need to use the "cdecl" calling convention even when another calling |
| 79 # convention (e.g. "stcall") is being used for the rest of the library. |
| 80 set cdecllist { |
| 81 sqlite3_config |
| 82 sqlite3_db_config |
| 83 sqlite3_log |
| 84 sqlite3_mprintf |
| 85 sqlite3_snprintf |
| 86 sqlite3_test_control |
| 87 sqlite3_vtab_config |
| 88 } |
| 89 |
76 # Process the source files. | 90 # Process the source files. |
77 # | 91 # |
78 foreach file $filelist { | 92 foreach file $filelist { |
79 set in [open $file] | 93 set in [open $file] |
80 while {![eof $in]} { | 94 while {![eof $in]} { |
81 | 95 |
82 set line [gets $in] | 96 set line [gets $in] |
83 | 97 |
84 # File sqlite3rtree.h contains a line "#include <sqlite3.h>". Omit this | 98 # File sqlite3rtree.h contains a line "#include <sqlite3.h>". Omit this |
85 # line when copying sqlite3rtree.h into sqlite3.h. | 99 # line when copying sqlite3rtree.h into sqlite3.h. |
86 # | 100 # |
87 if {[string match {*#include*<sqlite3.h>*} $line]} continue | 101 if {[string match {*#include*[<"]sqlite3.h[>"]*} $line]} continue |
88 | 102 |
89 regsub -- --VERS-- $line $zVersion line | 103 regsub -- --VERS-- $line $zVersion line |
90 regsub -- --VERSION-NUMBER-- $line $nVersion line | 104 regsub -- --VERSION-NUMBER-- $line $nVersion line |
91 regsub -- --SOURCE-ID-- $line "$zDate $zUuid" line | 105 regsub -- --SOURCE-ID-- $line "$zDate $zUuid" line |
92 | 106 |
93 if {[regexp {define SQLITE_EXTERN extern} $line]} { | 107 if {[regexp $varpattern $line] && ![regexp {^ *typedef} $line]} { |
94 puts $line | |
95 puts [gets $in] | |
96 puts "" | |
97 puts "#ifndef SQLITE_API" | |
98 puts "# define SQLITE_API" | |
99 puts "#endif" | |
100 set line "" | |
101 } | |
102 | |
103 if {([regexp $varpattern $line] && ![regexp {^ *typedef} $line]) | |
104 || ([regexp $declpattern $line]) | |
105 } { | |
106 set line "SQLITE_API $line" | 108 set line "SQLITE_API $line" |
| 109 } else { |
| 110 if {[regexp $declpattern $line all rettype funcname rest]} { |
| 111 set line SQLITE_API |
| 112 append line " " [string trim $rettype] |
| 113 if {[string index $rettype end] ne "*"} { |
| 114 append line " " |
| 115 } |
| 116 if {[lsearch -exact $cdecllist $funcname] >= 0} { |
| 117 append line SQLITE_CDECL |
| 118 } else { |
| 119 append line SQLITE_STDCALL |
| 120 } |
| 121 append line " " $funcname $rest |
| 122 } |
107 } | 123 } |
108 puts $line | 124 puts $line |
109 } | 125 } |
110 close $in | 126 close $in |
111 } | 127 } |
OLD | NEW |