sqlite
[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.
Brought by drakestapleton
| 1 | #!/usr/bin/tclsh |
| 2 | # |
| 3 | # Use this script to combine multiple source code files into a single |
| 4 | # file. Example: |
| 5 | # |
| 6 | # tclsh mkcombo.tcl file1.c file2.c file3.c -o file123.c |
| 7 | # |
| 8 | |
| 9 | set help {Usage: tclsh mkcombo.tcl [OPTIONS] [FILELIST] |
| 10 | where OPTIONS is zero or more of the following with these effects: |
| 11 | --linemacros=? => Emit #line directives into output or not. (? = 1 or 0) |
| 12 | --o FILE => write to alternative output file named FILE |
| 13 | --help => See this. |
| 14 | } |
| 15 | |
| 16 | set linemacros 0 |
| 17 | set fname {} |
| 18 | set src [list] |
| 19 | |
| 20 | |
| 21 | for {set i 0} {$i<[llength $argv]} {incr i} { |
| 22 | set x [lindex $argv $i] |
| 23 | if {[regexp {^-?-linemacros(?:=([01]))?$} $x ma ulm]} { |
| 24 | if {$ulm == ""} {set ulm 1} |
| 25 | set linemacros $ulm |
| 26 | } elseif {[regexp {^-o$} $x]} { |
| 27 | incr i |
| 28 | if {$i==[llength $argv]} { |
| 29 | error "No argument following $x" |
| 30 | } |
| 31 | set fname [lindex $argv $i] |
| 32 | } elseif {[regexp {^-?-((help)|\?)$} $x]} { |
| 33 | puts $help |
| 34 | exit 0 |
| 35 | } elseif {[regexp {^-?-} $x]} { |
| 36 | error "unknown command-line option: $x" |
| 37 | } else { |
| 38 | lappend src $x |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | # Open the output file and write a header comment at the beginning |
| 43 | # of the file. |
| 44 | # |
| 45 | if {![info exists fname]} { |
| 46 | set fname sqlite3.c |
| 47 | if {$enable_recover} { set fname sqlite3r.c } |
| 48 | } |
| 49 | set out [open $fname wb] |
| 50 | |
| 51 | # Return a string consisting of N "*" characters. |
| 52 | # |
| 53 | proc star N { |
| 54 | set r {} |
| 55 | for {set i 0} {$i<$N} {incr i} {append r *} |
| 56 | return $r |
| 57 | } |
| 58 | |
| 59 | # Force the output to use unix line endings, even on Windows. |
| 60 | fconfigure $out -translation binary |
| 61 | puts $out "/[star 78]" |
| 62 | puts $out {** The following is an amalgamation of these source code files:} |
| 63 | puts $out {**} |
| 64 | foreach s $src { |
| 65 | regsub {^.*/(src|ext)/} $s {\1/} s2 |
| 66 | puts $out "** $s2" |
| 67 | } |
| 68 | puts $out {**} |
| 69 | puts $out "[star 78]/" |
| 70 | |
| 71 | # Insert a comment into the code |
| 72 | # |
| 73 | proc section_comment {text} { |
| 74 | global out s78 |
| 75 | set n [string length $text] |
| 76 | set nstar [expr {60 - $n}] |
| 77 | puts $out "/************** $text [star $nstar]/" |
| 78 | } |
| 79 | |
| 80 | # Read the source file named $filename and write it into the |
| 81 | # sqlite3.c output file. The only transformation is the trimming |
| 82 | # of EOL whitespace. |
| 83 | # |
| 84 | proc copy_file_verbatim {filename} { |
| 85 | global out |
| 86 | set in [open $filename rb] |
| 87 | set tail [file tail $filename] |
| 88 | section_comment "Begin file $tail" |
| 89 | while {![eof $in]} { |
| 90 | set line [string trimright [gets $in]] |
| 91 | puts $out $line |
| 92 | } |
| 93 | section_comment "End of $tail" |
| 94 | } |
| 95 | set taillist "" |
| 96 | foreach file $src { |
| 97 | copy_file_verbatim $file |
| 98 | append taillist ", [file tail $file]" |
| 99 | } |
| 100 | |
| 101 | set taillist "End of the amalgamation of [string range $taillist 2 end]" |
| 102 | set n [string length $taillist] |
| 103 | set ns [expr {(75-$n)/2}] |
| 104 | if {$ns<3} {set ns 3} |
| 105 | puts $out "/[star $ns] $taillist [star $ns]/" |
| 106 | close $out |