interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / ext / fts5 / tool / mkfts5c.tcl

140 lines · 3266 bytes Raw Blame History
1#!/bin/sh
2# restart with tclsh \
3exec tclsh "$0" "$@"
4
5set srcdir [file dirname [file dirname [file normalize [info script]]]]
6set 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
25set G(hdr) {
26/*
27** This, the "fts5.c" source file, is a composite file that is itself
28** assembled from the following files:
29**
30** fts5.h
31** fts5Int.h
32** fts5parse.h <--- Generated from fts5parse.y by Lemon
33** fts5parse.c <--- Generated from fts5parse.y by Lemon
34** fts5_aux.c
35** fts5_buffer.c
36** fts5_config.c
37** fts5_expr.c
38** fts5_hash.c
39** fts5_index.c
40** fts5_main.c
41** fts5_storage.c
42** fts5_tokenize.c
43** fts5_unicode2.c
44** fts5_varint.c
45** fts5_vocab.c
46*/
47#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS5)
48
49#if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
50# define NDEBUG 1
51#endif
52#if defined(NDEBUG) && defined(SQLITE_DEBUG)
53# undef NDEBUG
54#endif
55
56#ifdef HAVE_STDINT_H
57#include <stdint.h>
58#endif
59#ifdef HAVE_INTTYPES_H
60#include <inttypes.h>
61#endif
62}
63
64set G(footer) {
65/* Here ends the fts5.c composite file. */
66#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS5) */
67}
68
69#-------------------------------------------------------------------------
70# Read and return the entire contents of text file $zFile from disk.
71#
72proc readfile {zFile} {
73 set fd [open $zFile]
74 set data [read $fd]
75 close $fd
76 return $data
77}
78
79#-------------------------------------------------------------------------
80# This command returns a string identifying the current sqlite version -
81# the equivalent of the SQLITE_SOURCE_ID string.
82#
83proc fts5_source_id {zDir} {
84 set top [file dirname [file dirname $zDir]]
85 set uuid [string trim [readfile [file join $top manifest.uuid]]]
86
87 set L [split [readfile [file join $top manifest]]]
88 set date [lindex $L [expr [lsearch -exact $L D]+1]]
89 set idx [expr {[string last . $date]-1}]
90 set date [string range $date 0 $idx]
91 set date [string map {T { }} $date]
92
93 return "fts5: $date $uuid"
94}
95
96proc fts5c_init {zOut} {
97 global G
98 set G(fd) stdout
99 set G(fd) [open $zOut w]
100
101 puts -nonewline $G(fd) $G(hdr)
102}
103
104proc fts5c_printfile {zIn} {
105 global G
106 set data [readfile $zIn]
107 set zTail [file tail $zIn]
108 puts $G(fd) "#line 1 \"$zTail\""
109
110 set sub_map [list --FTS5-SOURCE-ID-- [fts5_source_id $::srcdir]]
111 if {$zTail=="fts5parse.c"} {
112 lappend sub_map yy fts5yy YY fts5YY TOKEN FTS5TOKEN
113 }
114
115 foreach line [split $data "\n"] {
116 if {[regexp {^#include.*fts5} $line]} {
117 set line "/* $line */"
118 } elseif {
119 ![regexp { sqlite3Fts5Init\(} $line]
120 && [regexp {^(const )?[a-zA-Z][a-zA-Z0-9]* [*]?sqlite3Fts5} $line]
121 } {
122 set line "static $line"
123 }
124 set line [string map $sub_map $line]
125 puts $G(fd) $line
126 }
127}
128
129proc fts5c_close {} {
130 global G
131 puts -nonewline $G(fd) $G(footer)
132 if {$G(fd)!="stdout"} {
133 close $G(fd)
134 }
135}
136
137
138fts5c_init fts5.c
139foreach f $G(src) { fts5c_printfile $f }
140fts5c_close