Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/sqlite/blob/master/tool/split-sqlite3c.tcl # sqlite [Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `sqlite / tool / split-sqlite3c.tcl` 96 lines ยท 2354 bytes Raw Blame History 1 #!/usr/bin/tclsh 2 # 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. 7 # 8 # Splitting files up this way allows them to be used with older compilers 9 # that cannot handle really long source files. 10 # 11 set MAX 32768 ;# Maximum number of lines per file. 12 13 set BEGIN {^/\*+ Begin file ([a-zA-Z0-9_.]+) \*+/} 14 set END {^/\*+ End of %s \*+/} 15 16 set in [open sqlite3.c] 17 set out1 [open sqlite3-all.c w] 18 fconfigure $out1 -translation binary 19 20 # Copy the header from sqlite3.c into sqlite3-all.c 21 # 22 while {[gets $in line]} { 23 if {[regexp $BEGIN $line]} break 24 puts $out1 $line 25 } 26 27 # Gather the complete content of a file into memory. Store the 28 # content in $bufout. Store the number of lines is $nout 29 # 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 34 set buf $firstline\n 35 global in 36 set n 0 37 while {[gets $in line]>=0} { 38 incr n 39 append buf $line\n 40 if {[regexp $end $line]} break 41 } 42 } 43 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 46 # 47 set filecnt 0 48 proc write_one_file {content} { 49 global filecnt 50 incr filecnt 51 set label $filecnt 52 if {$filecnt>9} { 53 set label [string index ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnop \ 54 [expr {$filecnt-10}]] 55 } else { 56 set label $filecnt 57 } 58 set out [open sqlite3-$label.c w] 59 fconfigure $out -translation text 60 puts -nonewline $out $content 61 close $out 62 puts $::out1 "#include \"sqlite3-$label.c\"" 63 } 64 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 67 # the extra chunks. 68 # 69 set all {} 70 set N 0 71 while {[regexp $BEGIN $line]} { 72 set buf {} 73 set n 0 74 gather_one_file $line buf n 75 if {$n+$N>=$MAX} { 76 write_one_file $all 77 set all {} 78 set N 0 79 } 80 append all $buf 81 incr N $n 82 while {[gets $in line]>=0} { 83 if {[regexp $BEGIN $line]} break 84 if {$N>0} { 85 write_one_file $all 86 set N 0 87 set all {} 88 } 89 puts $out1 $line 90 } 91 } 92 if {$N>0} { 93 write_one_file $all 94 } 95 close $out1 96 close $in