modernc.org/cc@v1.0.1/v2/testdata/_sqlite/ext/fts5/tool/mkfts5c.tcl (about) 1 #!/bin/sh 2 # restart with tclsh \ 3 exec tclsh "$0" "$@" 4 5 set srcdir [file dirname [file dirname [info script]]] 6 set G(src) [string map [list %dir% $srcdir] { 7 %dir%/fts5.h 8 %dir%/fts5Int.h 9 fts5parse.h 10 fts5parse.c 11 %dir%/fts5_aux.c 12 %dir%/fts5_buffer.c 13 %dir%/fts5_config.c 14 %dir%/fts5_expr.c 15 %dir%/fts5_hash.c 16 %dir%/fts5_index.c 17 %dir%/fts5_main.c 18 %dir%/fts5_storage.c 19 %dir%/fts5_tokenize.c 20 %dir%/fts5_unicode2.c 21 %dir%/fts5_varint.c 22 %dir%/fts5_vocab.c 23 }] 24 25 set G(hdr) { 26 27 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS5) 28 29 #if !defined(NDEBUG) && !defined(SQLITE_DEBUG) 30 # define NDEBUG 1 31 #endif 32 #if defined(NDEBUG) && defined(SQLITE_DEBUG) 33 # undef NDEBUG 34 #endif 35 36 } 37 38 set G(footer) { 39 40 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS5) */ 41 } 42 43 #------------------------------------------------------------------------- 44 # Read and return the entire contents of text file $zFile from disk. 45 # 46 proc readfile {zFile} { 47 set fd [open $zFile] 48 set data [read $fd] 49 close $fd 50 return $data 51 } 52 53 #------------------------------------------------------------------------- 54 # This command returns a string identifying the current sqlite version - 55 # the equivalent of the SQLITE_SOURCE_ID string. 56 # 57 proc fts5_source_id {zDir} { 58 set top [file dirname [file dirname $zDir]] 59 set uuid [string trim [readfile [file join $top manifest.uuid]]] 60 61 set L [split [readfile [file join $top manifest]]] 62 set date [lindex $L [expr [lsearch -exact $L D]+1]] 63 set date [string range $date 0 [string last . $date]-1] 64 set date [string map {T { }} $date] 65 66 return "fts5: $date $uuid" 67 } 68 69 proc fts5c_init {zOut} { 70 global G 71 set G(fd) stdout 72 set G(fd) [open $zOut w] 73 74 puts -nonewline $G(fd) $G(hdr) 75 } 76 77 proc fts5c_printfile {zIn} { 78 global G 79 set data [readfile $zIn] 80 set zTail [file tail $zIn] 81 puts $G(fd) "#line 1 \"$zTail\"" 82 83 set sub_map [list --FTS5-SOURCE-ID-- [fts5_source_id $::srcdir]] 84 if {$zTail=="fts5parse.c"} { 85 lappend sub_map yy fts5yy YY fts5YY TOKEN FTS5TOKEN 86 } 87 88 foreach line [split $data "\n"] { 89 if {[regexp {^#include.*fts5} $line]} { 90 set line "/* $line */" 91 } elseif { 92 ![regexp { sqlite3Fts5Init\(} $line] 93 && [regexp {^(const )?[a-zA-Z][a-zA-Z0-9]* [*]?sqlite3Fts5} $line] 94 } { 95 set line "static $line" 96 } 97 set line [string map $sub_map $line] 98 puts $G(fd) $line 99 } 100 } 101 102 proc fts5c_close {} { 103 global G 104 puts -nonewline $G(fd) $G(footer) 105 if {$G(fd)!="stdout"} { 106 close $G(fd) 107 } 108 } 109 110 111 fts5c_init fts5.c 112 foreach f $G(src) { fts5c_printfile $f } 113 fts5c_close