interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / tool / mkcombo.tcl

106 lines · 2662 bytes Raw Blame History
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
9set 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
16set linemacros 0
17set fname {}
18set src [list]
19
20
21for {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#
45if {![info exists fname]} {
46 set fname sqlite3.c
47 if {$enable_recover} { set fname sqlite3r.c }
48}
49set out [open $fname wb]
50
51# Return a string consisting of N "*" characters.
52#
53proc 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.
60fconfigure $out -translation binary
61puts $out "/[star 78]"
62puts $out {** The following is an amalgamation of these source code files:}
63puts $out {**}
64foreach s $src {
65 regsub {^.*/(src|ext)/} $s {\1/} s2
66 puts $out "** $s2"
67}
68puts $out {**}
69puts $out "[star 78]/"
70
71# Insert a comment into the code
72#
73proc 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#
84proc 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}
95set taillist ""
96foreach file $src {
97 copy_file_verbatim $file
98 append taillist ", [file tail $file]"
99}
100
101set taillist "End of the amalgamation of [string range $taillist 2 end]"
102set n [string length $taillist]
103set ns [expr {(75-$n)/2}]
104if {$ns<3} {set ns 3}
105puts $out "/[star $ns] $taillist [star $ns]/"
106close $out