blob: 534ac6156a4e607c3c0bb77b2f5468b9ebe92ef3 [file] [log] [blame]
drh2ce15c32017-07-11 13:34:40 +00001#!/usr/bin/tclsh
2#
drhaa62d2e2017-10-12 13:47:48 +00003# Run this script to generate the "shell.c" source file from
drh2ce15c32017-07-11 13:34:40 +00004# constituent parts.
5#
drhaa62d2e2017-10-12 13:47:48 +00006# 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.
11#
drh2ce15c32017-07-11 13:34:40 +000012set topdir [file dir [file dir [file normal $argv0]]]
drhaa62d2e2017-10-12 13:47:48 +000013set out stdout
drh2ce15c32017-07-11 13:34:40 +000014puts $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.
19**
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.
24**
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.
27**
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*/}
32set in [open $topdir/src/shell.c.in rb]
drhf5c75622018-01-05 20:30:54 +000033proc omit_redundant_typedefs {line} {
34 global typedef_seen
35 if {[regexp {^typedef .*;} $line]} {
36 if {[info exists typedef_seen($line)]} {
37 return "/* $line */"
38 }
39 set typedef_seen($line) 1
40 }
41 return $line
42}
drhb3c45232017-08-28 14:33:27 +000043while {1} {
drhf5c75622018-01-05 20:30:54 +000044 set lx [omit_redundant_typedefs [gets $in]]
drhb3c45232017-08-28 14:33:27 +000045 if {[eof $in]} break;
drh2ce15c32017-07-11 13:34:40 +000046 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]} {
drhf5c75622018-01-05 20:30:54 +000051 set lx [omit_redundant_typedefs [gets $in2]]
drh2ce15c32017-07-11 13:34:40 +000052 if {[regexp {^#include "sqlite} $lx]} continue
drh03491a12018-01-07 21:58:17 +000053 if {[regexp {^# *include "test_windirent.h"} $lx]} {
54 set lx "/* $lx */"
55 }
dan9c1cf322017-08-30 13:21:17 +000056 set lx [string map [list __declspec(dllexport) {}] $lx]
drh2ce15c32017-07-11 13:34:40 +000057 puts $out $lx
58 }
59 close $in2
60 puts $out "/************************* End $cfile ********************/"
61 continue
62 }
63 puts $out $lx
64}
65close $in
66close $out