3 # This script splits the sqlite3.c amalgamated source code files into
4 # several smaller files such that no single files is more than a fixed
5 # number of lines in length (32k or 64k). Each of the split out files
6 # is #include-ed by the master file.
8 # Splitting files up this way allows them to be used with older compilers
9 # that cannot handle really long source files.
11 set MAX
32768 ;# Maximum number of lines per file.
13 set BEGIN
{^
/\*+ Begin
file ([a-zA-Z0-9_.
]+) \*+/}
14 set END
{^
/\*+ End of
%s
\*+/}
16 set in
[open sqlite3.c
]
17 set out1
[open sqlite3-all.c w
]
18 fconfigure $out1 -translation lf
20 # Copy the header from sqlite3.c into sqlite3-all.c
22 while {[gets $in line
]} {
23 if {[regexp $BEGIN $line]} break
27 # Gather the complete content of a file into memory. Store the
28 # content in $bufout. Store the number of lines is $nout
30 proc gather_one_file
{firstline bufout nout
} {
31 regexp $::BEGIN $firstline all
filename
32 set end
[format $::END $filename]
33 upvar $bufout buf
$nout n
37 while {[gets $in line
]>=0} {
40 if {[regexp $end $line]} break
44 # Write a big chunk of text in to an auxiliary file "sqlite3-NNN.c".
45 # Also add an appropriate #include to sqlite3-all.c
48 proc write_one_file
{content
} {
53 set label [string index ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnop
\
58 set out
[open sqlite3-
$label.c w
]
59 fconfigure $out -translation lf
60 puts -nonewline $out $content
62 puts $::out1 "#include \"sqlite3-$filecnt.c\""
65 # Continue reading input. Store chunks in separate files and add
66 # the #includes to the main sqlite3-all.c file as necessary to reference
71 while {[regexp $BEGIN $line]} {
74 gather_one_file
$line buf n
82 while {[gets $in line
]>=0} {
83 if {[regexp $BEGIN $line]} break