]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Enhancements to tool/mkccode.tcl such that it recognizes -D command line
authordrh <>
Tue, 19 Nov 2024 18:26:47 +0000 (18:26 +0000)
committerdrh <>
Tue, 19 Nov 2024 18:26:47 +0000 (18:26 +0000)
arguments and can use them in internal IFDEF and IFNDEF macros.  Update
the tool/sqlite3_analyzer.c.in script such that it omits the SQLite amalgamation
if -DSQLITE_ENABLE_DBSTAT_VTAB is defined.

FossilOrigin-Name: 7fec209290aa1a6dbbca8de154edaac5d8d0ce042bc0617d27fb2095c8d580f1

manifest
manifest.uuid
tool/mkccode.tcl
tool/sqlite3_analyzer.c.in

index 0ed54a2c712f5cdd3b2fed8d7cfc65a87598718d..87bdfbdd5f5b9d38a0f49d9d5c03cdd1a62d2e8e 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sa\sproblem\shandling\sOOM\serrors\sin\sfts3\sthat\scould\soccur\swhen\sparsing\smulti-token\sstrings.
-D 2024-11-19T11:58:32.252
+C Enhancements\sto\stool/mkccode.tcl\ssuch\sthat\sit\srecognizes\s-D\scommand\sline\narguments\sand\scan\suse\sthem\sin\sinternal\sIFDEF\sand\sIFNDEF\smacros.\s\sUpdate\nthe\stool/sqlite3_analyzer.c.in\sscript\ssuch\sthat\sit\somits\sthe\sSQLite\samalgamation\nif\s-DSQLITE_ENABLE_DBSTAT_VTAB\sis\sdefined.
+D 2024-11-19T18:26:47.422
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md e108e1e69ae8e8a59e93c455654b8ac9356a11720d3345df2a4743e9590fb20d
@@ -2135,7 +2135,7 @@ F tool/logest.c c34e5944318415de513d29a6098df247a9618c96d83c38d4abd88641fe46e669
 F tool/max-limits.c cbb635fbb37ae4d05f240bfb5b5270bb63c54439
 F tool/merge-test.tcl de76b62f2de2a92d4c1ca4f976bce0aea6899e0229e250479b229b2a1914b176
 F tool/mkautoconfamal.sh cbdcf993fa83dccbef7fb77b39cdeb31ef9f77d9d88c9e343b58d35ca3898a6a
-F tool/mkccode.tcl 4cb8ad7e7330aaed052b0657a1bfacbc67103c400e41860aff643a482cfc2d3e x
+F tool/mkccode.tcl b0ddad168362ba6225c9372856ba0db90145734e882a9a5bb8951ef0d5bc6331 x
 F tool/mkctimec.tcl ef6a67ec82e5b6fc19152a4c79f237227b18bf67ff16d155bac7adb94355d9cf x
 F tool/mkkeywordhash.c 6b0be901c47f9ad42215fc995eb2f4384ac49213b1fba395102ec3e999acf559
 F tool/mkmsvcmin.tcl d76c45efda1cce2d4005bcea7b8a22bb752e3256009f331120fb4fecb14ebb7a
@@ -2178,7 +2178,7 @@ F tool/speedtest8inst1.c 7ce07da76b5e745783e703a834417d725b7d45fd
 F tool/spellsift.tcl 52b4b04dc4333c7ab024f09d9d66ed6b6f7c6eb00b38497a09f338fa55d40618 x
 F tool/split-sqlite3c.tcl 5aa60643afca558bc732b1444ae81a522326f91e1dc5665b369c54f09e20de60
 F tool/sqldiff.c 2a0987d183027c795ced13d6749061c1d2f38e24eddb428f56fa64c3a8f51e4b
-F tool/sqlite3_analyzer.c.in 348ba349bbdc93c9866439f9f935d7284866a2a4e6898bc906ae1204ade56918
+F tool/sqlite3_analyzer.c.in 39690af454d2866e87e2b475ec5eabee366f211f2307e90b918345f35bb1a643
 F tool/sqlite3_rsync.c 9a1cca2ab1271c59b37a6493c15dc1bcd0ab9149197a9125926bc08dd26b83fb
 F tool/sqltclsh.c.in 1bcc2e9da58fadf17b0bf6a50e68c1159e602ce057210b655d50bad5aaaef898
 F tool/sqltclsh.tcl 862f4cf1418df5e1315b5db3b5ebe88969e2a784525af5fbf9596592f14ed848
@@ -2198,8 +2198,8 @@ F tool/version-info.c 3b36468a90faf1bbd59c65fd0eb66522d9f941eedd364fabccd7227350
 F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7
 F tool/warnings.sh 49a486c5069de041aedcbde4de178293e0463ae9918ecad7539eedf0ec77a139
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P 84d41e9d04c62601e84621e8edb3b81abbacc366a6b5e7059f8b6796fade7ffa
-R 15d5c68f2ffe8e979f466eec5e117ba3
-U dan
-Z 7f81f47d67e456b494dfb3b575661f30
+P 4c4d1db00bd2c522165876dcf1606116a72525d9ffc891b266213704e25cde55
+R cdb63603c9c3a16b29feb4bae93e8b25
+U drh
+Z 2a605008d2464811e071ed45a95c8ad5
 # Remove this line to create a well-formed Fossil manifest.
index dea58b2d927750d779b01b879b46f259245c8523..643a526325bc09777cafc1cb268d2511b93680d6 100644 (file)
@@ -1 +1 @@
-4c4d1db00bd2c522165876dcf1606116a72525d9ffc891b266213704e25cde55
+7fec209290aa1a6dbbca8de154edaac5d8d0ce042bc0617d27fb2095c8d580f1
index e847c8d3b8c9540e1c6b1802ea04b8d51a355a1f..457865b66fcd3c862045dc2cd3bf5334d35a7764 100755 (executable)
@@ -6,7 +6,7 @@
 #
 # Usage example:
 #
-#     tclsh mkccode.tcl demoapp.c.in >demoapp.c
+#     tclsh mkccode.tcl -DENABLE_FEATURE_XYZ demoapp.c.in >demoapp.c
 #
 # The demoapp.c.in file contains a mixture of C code, TCL script, and
 # processing directives used by mktclsqliteprog.tcl to build the final C-code
 #      then all of the text in the input file is converted into C-language
 #      string literals.
 #
+# IFDEF macro
+# IFNDEF macro
+# ELSE
+# ENDIF
+#
+#      The text from "IFDEF macro" down to the next ELSE or ENDIF is
+#      included only if -Dmacro appears as a command-line argument.
+#      The "IFNDEF macro" simply inverts the initial test.
+#
 # None of the control directives described above will nest.  Only the
 # top-level input file ("demoapp.c.in" in the example) is interpreted.
 # referenced files are copied verbatim.
 #
-if {[llength $argv]!=1} {
-  puts stderr "Usage: $argv0 TEMPLATE >OUTPUT"
+proc usage {} {
+  puts stderr "Usage: $::argv0 \[OPTIONS\] TEMPLATE >OUTPUT"
   exit 1
 }
-set infile [lindex $argv 0]
+set infile {}
+foreach ax $argv {
+  if {[string match -D* $ax]} {
+    if {[string match *=* $ax]} {
+      regexp {-D([^=]+)=(.*)} ax all name value
+      set DEF($name) $value
+    } else {
+      set DEF([string range $ax 2 end]) 1
+    }
+    continue
+  }
+  if {[string match -* $ax]} {
+    puts stderr "$::argv0:  Unknown option \"$ax\""
+    usage
+  }
+  if {$infile!=""} {
+    puts stderr "$::argv0:  Surplus argument: \"$ax\""
+    usage
+  }
+  set infile $ax
+}
 set ROOT [file normalize [file dir $argv0]/..]
 set HOME [file normalize [file dir $infile]]
 set in [open $infile rb]
 puts [subst {/* DO NOT EDIT
 **
-** This file was generated by \"$argv0 $infile\".
+** This file was generated by \"$argv0 $argv\".
 ** To make changes, edit $infile then rerun the generator
 ** command.
 */}]
 set instr 0
+set omit {}
+set nomit 0
+set ln 0
 while {1} {
   set line [gets $in]
+  incr ln
   if {[eof $in]} break
   if {[regexp {^INCLUDE (.*)} $line all path]} {
+    if {$nomit>0 && [string match *1* $omit]} continue
     if {0} {
       # https://github.com/msteveb/jimtcl/issues/320
       regsub {^\$ROOT\y} $path $ROOT path
@@ -91,10 +125,43 @@ while {1} {
     puts "/* END_STRING */"
     continue
   }
-  if {$instr} {
+  if {[regexp {^IFNDEF +([A-Za-z_]+)} $line all name]} {
+    set omit $omit[info exists DEF($name)]
+    incr nomit
+    continue
+  }
+  if {[regexp {^IFDEF +([A-Za-z_]+)} $line all name]} {
+    set omit $omit[expr {![info exists DEF($name)]}]
+    incr nomit
+    continue
+  }
+  if {[regexp {^ELSE} $line]} {
+    if {!$nomit} {
+      puts stderr "$infile:$ln: ELSE without a prior IFDEF"
+      exit 1
+    }
+    set omit [string range $omit 0 end-1][expr {![string index $omit end]}]
+    continue
+  }
+  if {[regexp {^ENDIF} $line]} {
+    if {!$nomit} {
+      puts stderr "$infile:$ln: ENDIF without a prior IFDEF"
+      exit 1
+    }
+    incr nomit -1
+    set omit [string range $omit 0 [expr {$nomit-1}]]
+    continue
+  }
+  if {$nomit>0 && [string match *1* $omit]} {
+    # noop
+  } elseif {$instr} {
     set x [string map "\\\\ \\\\\\\\ \\\" \\\\\"" $line]
     puts "\"$x\\n\""
   } else {
     puts $line
   }
 }
+if {$nomit} {
+  puts stderr "$infile:$ln: One or more unterminated IFDEFs"
+  exit 1
+}
index 1c9fc836a11c50751e89d9cc6646891f84e00a6e..a934f05700b4f4f9c1acaf1bafaded94d263cad4 100644 (file)
@@ -3,6 +3,7 @@
 ** text on standard output.
 */
 #define TCLSH_INIT_PROC sqlite3_analyzer_init_proc
+IFNDEF SQLITE_ENABLE_DBSTAT_VTAB
 #define SQLITE_ENABLE_DBSTAT_VTAB 1
 #undef SQLITE_THREADSAFE
 #define SQLITE_THREADSAFE 0
 #define SQLITE_DEFAULT_MEMSTATUS 0
 #define SQLITE_MAX_EXPR_DEPTH 0
 #define SQLITE_OMIT_LOAD_EXTENSION 1
-#if !defined(SQLITE_AMALGAMATION) && !defined(USE_EXTERNAL_SQLITE)
 INCLUDE sqlite3.c
-#endif
+ELSE
+#include "sqlite3.h"
+ENDIF
 INCLUDE $ROOT/src/tclsqlite.c
 
 #if defined(_WIN32)