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