mkfts5c.tcl 3.2 KB

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