PageRenderTime 47ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/v2/testdata/_sqlite/tool/mksqlite3h.tcl

https://gitlab.com/zchee/ccgo
TCL | 151 lines | 82 code | 18 blank | 51 comment | 18 complexity | cfd352abbe4e41f2e8dc9d58722a06d0 MD5 | raw file
  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.
  28. #
  29. # Example usage:
  30. #
  31. # tclsh mksqlite3h.tcl ../sqlite >sqlite3.h
  32. #
  33. # Get the source tree root directory from the command-line
  34. #
  35. set TOP [lindex $argv 0]
  36. # Enable use of SQLITE_APICALL macros at the right points?
  37. #
  38. set useapicall 0
  39. if {[lsearch -regexp [lrange $argv 1 end] {^-+useapicall}] != -1} {
  40. set useapicall 1
  41. }
  42. # Get the SQLite version number (ex: 3.6.18) from the $TOP/VERSION file.
  43. #
  44. set in [open $TOP/VERSION]
  45. set zVersion [string trim [read $in]]
  46. close $in
  47. set nVersion [eval format "%d%03d%03d" [split $zVersion .]]
  48. # Get the source-id
  49. #
  50. set PWD [pwd]
  51. cd $TOP
  52. set zSourceId [exec $PWD/mksourceid manifest]
  53. cd $PWD
  54. # Set up patterns for recognizing API declarations.
  55. #
  56. set varpattern {^[a-zA-Z][a-zA-Z_0-9 *]+sqlite3_[_a-zA-Z0-9]+(\[|;| =)}
  57. set declpattern1 {^ *([a-zA-Z][a-zA-Z_0-9 ]+ \**)(sqlite3_[_a-zA-Z0-9]+)(\(.*)$}
  58. set declpattern2 \
  59. {^ *([a-zA-Z][a-zA-Z_0-9 ]+ \**)(sqlite3session_[_a-zA-Z0-9]+)(\(.*)$}
  60. set declpattern3 \
  61. {^ *([a-zA-Z][a-zA-Z_0-9 ]+ \**)(sqlite3changeset_[_a-zA-Z0-9]+)(\(.*)$}
  62. set declpattern4 \
  63. {^ *([a-zA-Z][a-zA-Z_0-9 ]+ \**)(sqlite3changegroup_[_a-zA-Z0-9]+)(\(.*)$}
  64. # Force the output to use unix line endings, even on Windows.
  65. fconfigure stdout -translation lf
  66. set filelist [subst {
  67. $TOP/src/sqlite.h.in
  68. $TOP/ext/rtree/sqlite3rtree.h
  69. $TOP/ext/session/sqlite3session.h
  70. $TOP/ext/fts5/fts5.h
  71. }]
  72. # These are the functions that accept a variable number of arguments. They
  73. # always need to use the "cdecl" calling convention even when another calling
  74. # convention (e.g. "stcall") is being used for the rest of the library.
  75. set cdecllist {
  76. sqlite3_config
  77. sqlite3_db_config
  78. sqlite3_log
  79. sqlite3_mprintf
  80. sqlite3_snprintf
  81. sqlite3_test_control
  82. sqlite3_vtab_config
  83. }
  84. # Process the source files.
  85. #
  86. foreach file $filelist {
  87. set in [open $file]
  88. if {![regexp {sqlite\.h\.in} $file]} {
  89. puts "/******** Begin file [file tail $file] *********/"
  90. }
  91. while {![eof $in]} {
  92. set line [gets $in]
  93. # File sqlite3rtree.h contains a line "#include <sqlite3.h>". Omit this
  94. # line when copying sqlite3rtree.h into sqlite3.h.
  95. #
  96. if {[string match {*#include*[<"]sqlite3.h[>"]*} $line]} continue
  97. regsub -- --VERS-- $line $zVersion line
  98. regsub -- --VERSION-NUMBER-- $line $nVersion line
  99. regsub -- --SOURCE-ID-- $line "$zSourceId" line
  100. if {[regexp $varpattern $line] && ![regexp {^ *typedef} $line]} {
  101. set line "SQLITE_API $line"
  102. } else {
  103. if {[regexp $declpattern1 $line all rettype funcname rest] || \
  104. [regexp $declpattern2 $line all rettype funcname rest] || \
  105. [regexp $declpattern3 $line all rettype funcname rest] || \
  106. [regexp $declpattern4 $line all rettype funcname rest]} {
  107. set line SQLITE_API
  108. append line " " [string trim $rettype]
  109. if {[string index $rettype end] ne "*"} {
  110. append line " "
  111. }
  112. if {$useapicall} {
  113. if {[lsearch -exact $cdecllist $funcname] >= 0} {
  114. append line SQLITE_CDECL " "
  115. } else {
  116. append line SQLITE_APICALL " "
  117. }
  118. }
  119. append line $funcname $rest
  120. }
  121. }
  122. if {$useapicall} {
  123. set line [string map [list (*sqlite3_syscall_ptr) \
  124. "(SQLITE_SYSAPI *sqlite3_syscall_ptr)"] $line]
  125. regsub {\(\*} $line {(SQLITE_CALLBACK *} line
  126. }
  127. puts $line
  128. }
  129. close $in
  130. if {![regexp {sqlite\.h\.in} $file]} {
  131. puts "/******** End of [file tail $file] *********/"
  132. }
  133. }