mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-27 20:41:58 +03:00
Merge trunk into this branch. Fix a small jimtcl/tclsh regex incompatibility in mkccode.tcl.
FossilOrigin-Name: 7fb3ebfec634e0508267049fddb2b513201dbefce4d378ca3ec261c5d8336d7f
This commit is contained in:
@ -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
|
||||
@ -33,29 +33,63 @@
|
||||
# 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
|
||||
}
|
||||
|
Reference in New Issue
Block a user