drh | 2ce15c3 | 2017-07-11 13:34:40 +0000 | [diff] [blame] | 1 | #!/usr/bin/tclsh |
| 2 | # |
drh | aa62d2e | 2017-10-12 13:47:48 +0000 | [diff] [blame] | 3 | # Run this script to generate the "shell.c" source file from |
drh | 2ce15c3 | 2017-07-11 13:34:40 +0000 | [diff] [blame] | 4 | # constituent parts. |
| 5 | # |
drh | aa62d2e | 2017-10-12 13:47:48 +0000 | [diff] [blame] | 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. |
| 11 | # |
drh | 2ce15c3 | 2017-07-11 13:34:40 +0000 | [diff] [blame] | 12 | set topdir [file dir [file dir [file normal $argv0]]] |
drh | aa62d2e | 2017-10-12 13:47:48 +0000 | [diff] [blame] | 13 | set out stdout |
drh | a4df1bd | 2021-06-16 15:56:09 +0000 | [diff] [blame] | 14 | fconfigure stdout -translation binary |
drh | 2ce15c3 | 2017-07-11 13:34:40 +0000 | [diff] [blame] | 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. |
| 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 | */} |
drh | 20de9f6 | 2021-07-29 16:49:28 +0000 | [diff] [blame] | 33 | set in [open $topdir/src/shell.c.in] |
| 34 | fconfigure $in -translation binary |
drh | f5c7562 | 2018-01-05 20:30:54 +0000 | [diff] [blame] | 35 | proc 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 | } |
dan | 68cb86e | 2019-04-20 20:57:28 +0000 | [diff] [blame] | 45 | set iLine 0 |
drh | b3c4523 | 2017-08-28 14:33:27 +0000 | [diff] [blame] | 46 | while {1} { |
drh | f5c7562 | 2018-01-05 20:30:54 +0000 | [diff] [blame] | 47 | set lx [omit_redundant_typedefs [gets $in]] |
drh | b3c4523 | 2017-08-28 14:33:27 +0000 | [diff] [blame] | 48 | if {[eof $in]} break; |
dan | 68cb86e | 2019-04-20 20:57:28 +0000 | [diff] [blame] | 49 | incr iLine |
drh | 2ce15c3 | 2017-07-11 13:34:40 +0000 | [diff] [blame] | 50 | if {[regexp {^INCLUDE } $lx]} { |
| 51 | set cfile [lindex $lx 1] |
| 52 | puts $out "/************************* Begin $cfile ******************/" |
dan | 73c0d27 | 2019-04-27 20:30:19 +0000 | [diff] [blame] | 53 | # puts $out "#line 1 \"$cfile\"" |
drh | 20de9f6 | 2021-07-29 16:49:28 +0000 | [diff] [blame] | 54 | set in2 [open $topdir/src/$cfile] |
| 55 | fconfigure $in2 -translation binary |
drh | 2ce15c3 | 2017-07-11 13:34:40 +0000 | [diff] [blame] | 56 | while {![eof $in2]} { |
drh | f5c7562 | 2018-01-05 20:30:54 +0000 | [diff] [blame] | 57 | set lx [omit_redundant_typedefs [gets $in2]] |
dan | 68cb86e | 2019-04-20 20:57:28 +0000 | [diff] [blame] | 58 | if {[regexp {^#include "sqlite} $lx]} { |
| 59 | set lx "/* $lx */" |
| 60 | } |
drh | 03491a1 | 2018-01-07 21:58:17 +0000 | [diff] [blame] | 61 | if {[regexp {^# *include "test_windirent.h"} $lx]} { |
| 62 | set lx "/* $lx */" |
| 63 | } |
dan | 9c1cf32 | 2017-08-30 13:21:17 +0000 | [diff] [blame] | 64 | set lx [string map [list __declspec(dllexport) {}] $lx] |
drh | 2ce15c3 | 2017-07-11 13:34:40 +0000 | [diff] [blame] | 65 | puts $out $lx |
| 66 | } |
| 67 | close $in2 |
| 68 | puts $out "/************************* End $cfile ********************/" |
dan | 73c0d27 | 2019-04-27 20:30:19 +0000 | [diff] [blame] | 69 | # puts $out "#line [expr $iLine+1] \"shell.c.in\"" |
drh | 2ce15c3 | 2017-07-11 13:34:40 +0000 | [diff] [blame] | 70 | continue |
| 71 | } |
| 72 | puts $out $lx |
| 73 | } |
| 74 | close $in |
| 75 | close $out |