blob: 82ecd2f61a6cf7adfef07217287074fbbdab0580 [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
drha4df1bd2021-06-16 15:56:09 +000014fconfigure stdout -translation binary
drh2ce15c32017-07-11 13:34:40 +000015puts $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.
20**
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.
25**
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.
28**
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*/}
drh20de9f62021-07-29 16:49:28 +000033set in [open $topdir/src/shell.c.in]
34fconfigure $in -translation binary
drhf5c75622018-01-05 20:30:54 +000035proc omit_redundant_typedefs {line} {
36 global typedef_seen
37 if {[regexp {^typedef .*;} $line]} {
38 if {[info exists typedef_seen($line)]} {
39 return "/* $line */"
40 }
41 set typedef_seen($line) 1
42 }
43 return $line
44}
dan68cb86e2019-04-20 20:57:28 +000045set iLine 0
drhb3c45232017-08-28 14:33:27 +000046while {1} {
drhf5c75622018-01-05 20:30:54 +000047 set lx [omit_redundant_typedefs [gets $in]]
drhb3c45232017-08-28 14:33:27 +000048 if {[eof $in]} break;
dan68cb86e2019-04-20 20:57:28 +000049 incr iLine
drh2ce15c32017-07-11 13:34:40 +000050 if {[regexp {^INCLUDE } $lx]} {
51 set cfile [lindex $lx 1]
52 puts $out "/************************* Begin $cfile ******************/"
dan73c0d272019-04-27 20:30:19 +000053# puts $out "#line 1 \"$cfile\""
drh20de9f62021-07-29 16:49:28 +000054 set in2 [open $topdir/src/$cfile]
55 fconfigure $in2 -translation binary
drh2ce15c32017-07-11 13:34:40 +000056 while {![eof $in2]} {
drhf5c75622018-01-05 20:30:54 +000057 set lx [omit_redundant_typedefs [gets $in2]]
dan68cb86e2019-04-20 20:57:28 +000058 if {[regexp {^#include "sqlite} $lx]} {
59 set lx "/* $lx */"
60 }
drh03491a12018-01-07 21:58:17 +000061 if {[regexp {^# *include "test_windirent.h"} $lx]} {
62 set lx "/* $lx */"
63 }
dan9c1cf322017-08-30 13:21:17 +000064 set lx [string map [list __declspec(dllexport) {}] $lx]
drh2ce15c32017-07-11 13:34:40 +000065 puts $out $lx
66 }
67 close $in2
68 puts $out "/************************* End $cfile ********************/"
dan73c0d272019-04-27 20:30:19 +000069# puts $out "#line [expr $iLine+1] \"shell.c.in\""
drh2ce15c32017-07-11 13:34:40 +000070 continue
71 }
72 puts $out $lx
73}
74close $in
75close $out