Improved output from ".schema --indent" when a column definition is followed
[sqlite.git] / tool / mkshellc.tcl
blob1a98511ef9d1dcfb54c3ae0aca2f07eaa02d2cbd
1 #!/usr/bin/tclsh
3 # Run this script to generate the "shell.c" source file from
4 # constituent parts.
6 # No arguments are required. This script determines the location
7 # of its input files relative to the location of the script itself.
8 # This script should be tool/mkshellc.tcl. If the directory holding
9 # the script is $DIR, then the component parts are located in $DIR/../src
10 # and $DIR/../ext/misc.
12 set topdir [file dir [file dir [file normal $argv0]]]
13 set out stdout
14 puts $out {/* DO NOT EDIT!
15 ** This file is automatically generated by the script in the canonical
16 ** SQLite source tree at tool/mkshellc.tcl. That script combines source
17 ** code from various constituent source files of SQLite into this single
18 ** "shell.c" file used to implement the SQLite command-line shell.
20 ** Most of the code found below comes from the "src/shell.c.in" file in
21 ** the canonical SQLite source tree. That main file contains "INCLUDE"
22 ** lines that specify other files in the canonical source tree that are
23 ** inserted to getnerate this complete program source file.
25 ** The code from multiple files is combined into this single "shell.c"
26 ** source file to help make the command-line program easier to compile.
28 ** To modify this program, get a copy of the canonical SQLite source tree,
29 ** edit the src/shell.c.in" and/or some of the other files that are included
30 ** by "src/shell.c.in", then rerun the tool/mkshellc.tcl script.
31 */}
32 set in [open $topdir/src/shell.c.in rb]
33 proc omit_redundant_typedefs {line} {
34 global typedef_seen
35 if {[regexp {^typedef .*;} $line]} {
36 if {[info exists typedef_seen($line)]} {
37 return "/* $line */"
39 set typedef_seen($line) 1
41 return $line
43 while {1} {
44 set lx [omit_redundant_typedefs [gets $in]]
45 if {[eof $in]} break;
46 if {[regexp {^INCLUDE } $lx]} {
47 set cfile [lindex $lx 1]
48 puts $out "/************************* Begin $cfile ******************/"
49 set in2 [open $topdir/src/$cfile rb]
50 while {![eof $in2]} {
51 set lx [omit_redundant_typedefs [gets $in2]]
52 if {[regexp {^#include "sqlite} $lx]} continue
53 set lx [string map [list __declspec(dllexport) {}] $lx]
54 puts $out $lx
56 close $in2
57 puts $out "/************************* End $cfile ********************/"
58 continue
60 puts $out $lx
62 close $in
63 close $out