blob: 46c2a528fef7c9da552d8d75b25513ccbcb9f560 [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*/}
33set in [open $topdir/src/shell.c.in rb]
drhf5c75622018-01-05 20:30:54 +000034proc omit_redundant_typedefs {line} {
35 global typedef_seen
36 if {[regexp {^typedef .*;} $line]} {
37 if {[info exists typedef_seen($line)]} {
38 return "/* $line */"
39 }
40 set typedef_seen($line) 1
41 }
42 return $line
43}
dan68cb86e2019-04-20 20:57:28 +000044set iLine 0
drhb3c45232017-08-28 14:33:27 +000045while {1} {
drhf5c75622018-01-05 20:30:54 +000046 set lx [omit_redundant_typedefs [gets $in]]
drhb3c45232017-08-28 14:33:27 +000047 if {[eof $in]} break;
dan68cb86e2019-04-20 20:57:28 +000048 incr iLine
drh2ce15c32017-07-11 13:34:40 +000049 if {[regexp {^INCLUDE } $lx]} {
50 set cfile [lindex $lx 1]
51 puts $out "/************************* Begin $cfile ******************/"
dan73c0d272019-04-27 20:30:19 +000052# puts $out "#line 1 \"$cfile\""
drh2ce15c32017-07-11 13:34:40 +000053 set in2 [open $topdir/src/$cfile rb]
54 while {![eof $in2]} {
drhf5c75622018-01-05 20:30:54 +000055 set lx [omit_redundant_typedefs [gets $in2]]
dan68cb86e2019-04-20 20:57:28 +000056 if {[regexp {^#include "sqlite} $lx]} {
57 set lx "/* $lx */"
58 }
drh03491a12018-01-07 21:58:17 +000059 if {[regexp {^# *include "test_windirent.h"} $lx]} {
60 set lx "/* $lx */"
61 }
dan9c1cf322017-08-30 13:21:17 +000062 set lx [string map [list __declspec(dllexport) {}] $lx]
drh2ce15c32017-07-11 13:34:40 +000063 puts $out $lx
64 }
65 close $in2
66 puts $out "/************************* End $cfile ********************/"
dan73c0d272019-04-27 20:30:19 +000067# puts $out "#line [expr $iLine+1] \"shell.c.in\""
drh2ce15c32017-07-11 13:34:40 +000068 continue
69 }
70 puts $out $lx
71}
72close $in
73close $out