Minor doc tweaks.
[sqlite.git] / tool / mkshellc.tcl
blobaf9804e4faac594def10e2a9816f5886e154fc1f
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 fconfigure stdout -translation binary
15 puts $out {/* DO NOT EDIT!
16 ** This file is automatically generated by the script in the canonical
17 ** SQLite source tree at tool/mkshellc.tcl. That script combines source
18 ** code from various constituent source files of SQLite into this single
19 ** "shell.c" file used to implement the SQLite command-line shell.
21 ** Most of the code found below comes from the "src/shell.c.in" file in
22 ** the canonical SQLite source tree. That main file contains "INCLUDE"
23 ** lines that specify other files in the canonical source tree that are
24 ** inserted to getnerate this complete program source file.
26 ** The code from multiple files is combined into this single "shell.c"
27 ** source file to help make the command-line program easier to compile.
29 ** To modify this program, get a copy of the canonical SQLite source tree,
30 ** edit the src/shell.c.in" and/or some of the other files that are included
31 ** by "src/shell.c.in", then rerun the tool/mkshellc.tcl script.
32 */}
33 set in [open $topdir/src/shell.c.in]
34 fconfigure $in -translation binary
35 proc omit_redundant_typedefs {line} {
36 global typedef_seen
37 if {[regexp {^typedef .* ([a-zA-Z0-9_]+);} $line all typename]} {
38 # --------------------\y jimtcl does not support \y
39 if {[info exists typedef_seen($typename)]} {
40 return "/* [string map {/* // */ //} $line] */"
42 set typedef_seen($typename) 1
44 return $line
46 set iLine 0
47 while {1} {
48 set lx [omit_redundant_typedefs [gets $in]]
49 if {[eof $in]} break;
50 incr iLine
51 if {[regexp {^INCLUDE } $lx]} {
52 set cfile [lindex $lx 1]
53 puts $out "/************************* Begin $cfile ******************/"
54 # puts $out "#line 1 \"$cfile\""
55 set in2 [open $topdir/src/$cfile]
56 fconfigure $in2 -translation binary
57 while {![eof $in2]} {
58 set lx [omit_redundant_typedefs [gets $in2]]
59 if {[regexp {^# *include "sqlite} $lx]} {
60 set lx "/* $lx */"
62 if {[regexp {^# *include "test_windirent.h"} $lx]} {
63 set lx "/* $lx */"
65 set lx [string map [list __declspec(dllexport) {}] $lx]
66 puts $out $lx
68 close $in2
69 puts $out "/************************* End $cfile ********************/"
70 # puts $out "#line [expr $iLine+1] \"shell.c.in\""
71 continue
73 puts $out $lx
75 close $in
76 close $out