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 | */} |
| 33 | set in [open $topdir/src/shell.c.in rb] |
drh | f5c7562 | 2018-01-05 20:30:54 +0000 | [diff] [blame] | 34 | proc 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 | } |
dan | 68cb86e | 2019-04-20 20:57:28 +0000 | [diff] [blame] | 44 | set iLine 0 |
drh | b3c4523 | 2017-08-28 14:33:27 +0000 | [diff] [blame] | 45 | while {1} { |
drh | f5c7562 | 2018-01-05 20:30:54 +0000 | [diff] [blame] | 46 | set lx [omit_redundant_typedefs [gets $in]] |
drh | b3c4523 | 2017-08-28 14:33:27 +0000 | [diff] [blame] | 47 | if {[eof $in]} break; |
dan | 68cb86e | 2019-04-20 20:57:28 +0000 | [diff] [blame] | 48 | incr iLine |
drh | 2ce15c3 | 2017-07-11 13:34:40 +0000 | [diff] [blame] | 49 | if {[regexp {^INCLUDE } $lx]} { |
| 50 | set cfile [lindex $lx 1] |
| 51 | puts $out "/************************* Begin $cfile ******************/" |
dan | 73c0d27 | 2019-04-27 20:30:19 +0000 | [diff] [blame] | 52 | # puts $out "#line 1 \"$cfile\"" |
drh | 2ce15c3 | 2017-07-11 13:34:40 +0000 | [diff] [blame] | 53 | set in2 [open $topdir/src/$cfile rb] |
| 54 | while {![eof $in2]} { |
drh | f5c7562 | 2018-01-05 20:30:54 +0000 | [diff] [blame] | 55 | set lx [omit_redundant_typedefs [gets $in2]] |
dan | 68cb86e | 2019-04-20 20:57:28 +0000 | [diff] [blame] | 56 | if {[regexp {^#include "sqlite} $lx]} { |
| 57 | set lx "/* $lx */" |
| 58 | } |
drh | 03491a1 | 2018-01-07 21:58:17 +0000 | [diff] [blame] | 59 | if {[regexp {^# *include "test_windirent.h"} $lx]} { |
| 60 | set lx "/* $lx */" |
| 61 | } |
dan | 9c1cf32 | 2017-08-30 13:21:17 +0000 | [diff] [blame] | 62 | set lx [string map [list __declspec(dllexport) {}] $lx] |
drh | 2ce15c3 | 2017-07-11 13:34:40 +0000 | [diff] [blame] | 63 | puts $out $lx |
| 64 | } |
| 65 | close $in2 |
| 66 | puts $out "/************************* End $cfile ********************/" |
dan | 73c0d27 | 2019-04-27 20:30:19 +0000 | [diff] [blame] | 67 | # puts $out "#line [expr $iLine+1] \"shell.c.in\"" |
drh | 2ce15c3 | 2017-07-11 13:34:40 +0000 | [diff] [blame] | 68 | continue |
| 69 | } |
| 70 | puts $out $lx |
| 71 | } |
| 72 | close $in |
| 73 | close $out |