Team Ai
Modelpublic

AryaWu/sqlite

sourceHugging Faceupdated 10mo agoView on Hugging Face
0likes
split-sqlite3c.tcl97 linesDownload Raw Back to tool
1#!/usr/bin/tclsh2#3# This script splits the sqlite3.c amalgamated source code files into4# several smaller files such that no single files is more than a fixed5# number of lines in length (32k or 64k).  Each of the split out files6# is #include-ed by the master file.7#8# Splitting files up this way allows them to be used with older compilers9# that cannot handle really long source files.10#11set MAX 32768    ;# Maximum number of lines per file.12 13set BEGIN {^/\*+ Begin file ([a-zA-Z0-9_.]+) \*+/}14set END   {^/\*+ End of %s \*+/}15 16set in [open sqlite3.c]17set out1 [open sqlite3-all.c w]18fconfigure $out1 -translation binary19 20# Copy the header from sqlite3.c into sqlite3-all.c21#22while {[gets $in line]} {23  if {[regexp $BEGIN $line]} break24  puts $out1 $line25}26 27# Gather the complete content of a file into memory.  Store the28# content in $bufout.  Store the number of lines is $nout29#30proc gather_one_file {firstline bufout nout} {31  regexp $::BEGIN $firstline all filename32  set end [format $::END $filename]33  upvar $bufout buf $nout n34  set buf $firstline\n35  global in36  set n 037  while {[gets $in line]>=0} {38    incr n39    append buf $line\n40    if {[regexp $end $line]} break41  }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.c46#47set filecnt 048proc write_one_file {content} {49  global filecnt50  incr filecnt51  set label $filecnt52  if {$filecnt>9} {53    set label [string index ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnop \54                [expr {$filecnt-10}]]55  } else {56    set label $filecnt57  }58  set out [open sqlite3-$label.c w]59  fconfigure $out -translation text60  puts -nonewline $out $content61  close $out62  puts $::out1 "#include \"sqlite3-$filecnt.c\""63}64 65# Continue reading input.  Store chunks in separate files and add66# the #includes to the main sqlite3-all.c file as necessary to reference67# the extra chunks.68#69set all {}70set N 071while {[regexp $BEGIN $line]} {72  set buf {}73  set n 074  gather_one_file $line buf n75  if {$n+$N>=$MAX} {76    write_one_file $all77    set all {}78    set N 079  }80  append all $buf81  incr N $n82  while {[gets $in line]>=0} {83    if {[regexp $BEGIN $line]} break84    if {$N>0} {85      write_one_file $all86      set N 087      set all {}88    }89    puts $out1 $line90  }91}92if {$N>0} {93  write_one_file $all94}95close $out196close $in97