diff options
author | drh <drh@noemail.net> | 2011-04-01 18:12:58 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2011-04-01 18:12:58 +0000 |
commit | 1d21021f59ce16c4e4d10fc314c9fa3300fc04b2 (patch) | |
tree | bd67640768a18f535ee87ac6e45592f7134e6e09 /tool/split-sqlite3c.tcl | |
parent | e433235ec237ecfc8e3d9b96114a9e8ad980408d (diff) | |
download | sqlite-1d21021f59ce16c4e4d10fc314c9fa3300fc04b2.tar.gz sqlite-1d21021f59ce16c4e4d10fc314c9fa3300fc04b2.zip |
Add a script that will break the amalgamation source file up into 4 or 5
smaller source files, each 32K lines or fewer, and a single "sqlite3-all.c"
source file that #includes the others.
FossilOrigin-Name: 5d34e64d4d2398aa9a54fd0a4f1de37ced7ea5dd
Diffstat (limited to 'tool/split-sqlite3c.tcl')
-rw-r--r-- | tool/split-sqlite3c.tcl | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/tool/split-sqlite3c.tcl b/tool/split-sqlite3c.tcl new file mode 100644 index 000000000..287b75282 --- /dev/null +++ b/tool/split-sqlite3c.tcl @@ -0,0 +1,82 @@ +#!/usr/bin/tclsh +# +# This script splits the sqlite3.c amalgamated source code files into +# several smaller files such that no single files is more than a fixed +# number of lines in length (32k or 64k). Each of the split out files +# is #include-ed by the master file. +# +# Splitting files up this way allows them to be used with older compilers +# that cannot handle really long source files. +# +set MAX 32768 ;# Maximum number of lines per file. + +set BEGIN {^/\*+ Begin file ([a-zA-Z0-9_.]+) \*+/} +set END {^/\*+ End of %s \*+/} + +set in [open sqlite3.c] +set out1 [open sqlite3-all.c w] + +# Copy the header from sqlite3.c into sqlite3-all.c +# +while {[gets $in line]} { + if {[regexp $BEGIN $line]} break + puts $out1 $line +} + +# Gather the complete content of a file into memory. Store the +# content in $bufout. Store the number of lines is $nout +# +proc gather_one_file {firstline bufout nout} { + regexp $::BEGIN $firstline all filename + set end [format $::END $filename] + upvar $bufout buf $nout n + set buf $firstline\n + global in + set n 0 + while {[gets $in line]>=0} { + incr n + append buf $line\n + if {[regexp $end $line]} break + } +} + +# Write a big chunk of text in to an auxiliary file "sqlite3-NNN.c". +# Also add an appropriate #include to sqlite3-all.c +# +set filecnt 0 +proc write_one_file {content} { + global filecnt + incr filecnt + set out [open sqlite3-$filecnt.c w] + puts -nonewline $out $content + close $out + puts $::out1 "#include \"sqlite3-$filecnt.c\"" +} + +# Continue reading input. Store chunks in separate files and add +# the #includes to the main sqlite3-all.c file as necessary to reference +# the extra chunks. +# +set all {} +set N 0 +while {[regexp $BEGIN $line]} { + set buf {} + set n 0 + gather_one_file $line buf n + if {$n+$N>=$MAX} { + write_one_file $all + set all {} + set N 0 + } + append all $buf + incr N $n + while {[gets $in line]>=0} { + if {[regexp $BEGIN $line]} break + puts $out1 $line + } +} +if {$N>0} { + write_one_file $all +} +close $out1 +close $in |