]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix CLI Windows build, refine its help, re-org ShellState
authorlarrybr <larrybr@noemail.net>
Sat, 5 Feb 2022 15:26:39 +0000 (15:26 +0000)
committerlarrybr <larrybr@noemail.net>
Sat, 5 Feb 2022 15:26:39 +0000 (15:26 +0000)
FossilOrigin-Name: 991a06a4801270fddea7375d141863dc29fa87b737c728af60c81eea8445a0ea

manifest
manifest.uuid
src/shell.c.in
tool/mkshellc.tcl

index 396ccba98e644b66e2743a879d720525f5f3c01b..413eccbebeffe3e61a38981e42461b748c244d91 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C CLI\s.param\ssave/load\sdone;\smany\sother\ssmall\srefinements
-D 2022-02-04T21:49:47.692
+C Fix\sCLI\sWindows\sbuild,\srefine\sits\shelp,\sre-org\sShellState
+D 2022-02-05T15:26:39.028
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -553,7 +553,7 @@ F src/random.c 097dc8b31b8fba5a9aca1697aeb9fd82078ec91be734c16bffda620ced7ab83c
 F src/resolve.c 0dd8e23fda88411d63b2e6650f2380fdb08e88112e9a095fc23d5a08de4b2641
 F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92
 F src/select.c a6d2d4bed279d7fe4fcedaf297eaf6441e8e17c6e3947a32d24d23be52ac02f2
-F src/shell.c.in 0f82e96ec4b2c5701c581114a6cb9987983cb5fbc5b60d3fe34123ccaa453c9f x
+F src/shell.c.in 7c1978cfec3647870d7b2fe45178ec323a44e5549041be7db0ed190c4701579b x
 F src/sqlite.h.in d4daed3b2deb2e43df7f12be119b1b17a2954feadc33d521565bacbd072bfcb6
 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
 F src/sqlite3ext.h a95cb9ed106e3d39e2118e4dcc15a14faec3fa50d0093425083d340d9dfd96e6
@@ -1877,7 +1877,7 @@ F tool/mkopcodec.tcl 33d20791e191df43209b77d37f0ff0904620b28465cca6990cf8d60da61
 F tool/mkopcodeh.tcl 130b88697da6ec5b89b41844d955d08fb62c2552e889dec8c7bcecb28d8f50bd
 F tool/mkopts.tcl 680f785fdb09729fd9ac50632413da4eadbdf9071535e3f26d03795828ab07fa
 F tool/mkpragmatab.tcl de206c64b6e9ac8cd5e3cbd0ffe456f07d5710605ef8385d677e60ce3335ea12
-F tool/mkshellc.tcl df5d249617f9cc94d5c48eb0401673eb3f31f383ecbc54e8a13ca3dd97e89450
+F tool/mkshellc.tcl 5a9e27449694b179d2facde3fa10ff5a2d689be25822526addc20a1f1d9a12ec
 F tool/mksourceid.c 36aa8020014aed0836fd13c51d6dc9219b0df1761d6b5f58ff5b616211b079b9
 F tool/mkspeedsql.tcl a1a334d288f7adfe6e996f2e712becf076745c97
 F tool/mksqlite3c-noext.tcl 4f7cfef5152b0c91920355cbfc1d608a4ad242cb819f1aea07f6d0274f584a7f
@@ -1943,8 +1943,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 62d212d0da93102dd3b7dc4368a0c8acf2469a7f8ef8fcf60e57e69fe028600e
-R b76f1d9304bd6e797f5b019c4f944ad0
+P 6d415ac2c10da26e97164cb0846683a57e6a7f3717519c5fe889e077321a2cbd
+R caf017840a4e87c78151d22dc2043bdc
 U larrybr
-Z 4329007f8b9bbf62cbca025566949b18
+Z 304046c8b2c6fad5a59c02f068067d82
 # Remove this line to create a well-formed Fossil manifest.
index 78736b0c4de29f4ca8426ac73fe5f3e99586211f..6ec5f92c17db91b03181125cd38ed03fd17a5a74 100644 (file)
@@ -1 +1 @@
-6d415ac2c10da26e97164cb0846683a57e6a7f3717519c5fe889e077321a2cbd
\ No newline at end of file
+991a06a4801270fddea7375d141863dc29fa87b737c728af60c81eea8445a0ea
\ No newline at end of file
index 371d2026aaad96b2a3d52d3465a8fd4991da10f3..19f828370c6f92ca574dba8a83ff5e26c2501cc1 100755 (executable)
@@ -86,6 +86,7 @@
 typedef sqlite3_int64 i64;
 typedef sqlite3_uint64 u64;
 typedef unsigned char u8;
+typedef unsigned short u16;
 #if SQLITE_USER_AUTHENTICATION
 # include "sqlite3userauth.h"
 #endif
@@ -726,7 +727,7 @@ static char *local_getline(char *zLine, InSource *pInSrc){
 #if defined(_WIN32) || defined(WIN32)
   /* For interactive input on Windows systems, translate the
   ** multi-byte characterset characters into UTF-8. */
-  if( stdin_is_interactive && pInSrc==&stdInSource) ){
+  if( stdin_is_interactive && pInSrc==&stdInSource ){
     char *zTrans = sqlite3_win32_mbcs_to_utf8_v2(zLine, 0);
     if( zTrans ){
       int nTrans = strlen30(zTrans)+1;
@@ -1168,14 +1169,14 @@ struct EQPGraph {
 
 /* Runtime test for shell extended parsing, given ShellState pointer */
 #if SHELL_EXTENDED_PARSING
-# define SHEXT_PARSING(pSS) (pSS->bExtendedDotCmds & (1<<SHEXT_PARSING_BIT) !=0)
+# define SHEXT_PARSING(pSS) ((pSS->bExtendedDotCmds&(1<<SHEXT_PARSING_BIT))!=0)
 #else
 # define SHEXT_PARSING(pSS) 0
 #endif
 
 /* Runtime test for shell variable expansion, given ShellState pointer */
 #if SHELL_EXTENDED_PARSING
-# define SHEXT_VAREXP(pSS) (pSS->bExtendedDotCmds & (1<<SHEXT_VAREXP_BIT) !=0)
+# define SHEXT_VAREXP(pSS) ((pSS->bExtendedDotCmds&(1<<SHEXT_VAREXP_BIT))!=0)
 #else
 # define SHEXT_VAREXP(pSS) 0
 #endif
@@ -1189,6 +1190,15 @@ typedef struct ColModeOpts {
 #define ColModeOpts_default { 60, 0, 0 }
 #define ColModeOpts_default_qbox { 60, 1, 0 }
 
+typedef struct OutModeState {
+  u8 showHeader;         /* True to show column names in List or Column mode */
+  u8 mode;               /* An output mode setting */
+  u16 shellFlgs;         /* Various flags */
+  ColModeOpts cmOpts;    /* Option values affecting columnar mode output */
+  char colSeparator[20]; /* Column separator character for several modes */
+  char rowSeparator[20]; /* Row separator character for MODE_Ascii */
+} OutModeState;
+
 /*
 ** State information about the database connection is contained in an
 ** instance of the following structure.
@@ -1202,6 +1212,7 @@ struct ShellState {
   u8 autoEQPtrace;       /* autoEQP is in trace mode */
   u8 scanstatsOn;        /* True to display scan stats before each finalize */
   u8 openMode;           /* SHELL_OPEN_NORMAL, _APPENDVFS, or _ZIPFILE */
+  int openFlags;         /* Additional flags to open.  (SQLITE_OPEN_NOFOLLOW) */
   u8 doXdgOpen;          /* Invoke start/open/xdg-open in output_reset() */
   u8 nEqpLevel;          /* Depth of the EQP output graph */
   u8 eTraceType;         /* SHELL_TRACE_* value for type of trace */
@@ -1209,44 +1220,44 @@ struct ShellState {
   u8 bSafeModePersist;   /* The long-term value of bSafeMode */
   u8 bAllowSysDump;      /* Allow .dump use for sqlite_* tables. */
   u8 bExtendedDotCmds;   /* Bits set to enable various shell extensions */
+
+  u8 showHeader;         /* True to show column names in List or Column mode */
+  u16 shellFlgs;         /* Various flags */
+  u16 priorShFlgs;       /* Saved copy of flags */
+  u8 mode;               /* An output mode setting */
+  u8 modePrior;          /* Saved mode */
+  u8 cMode;              /* temporary output mode for the current query */
+  u8 normalMode;         /* Output mode before ".explain on" */
   ColModeOpts cmOpts;    /* Option values affecting columnar mode output */
+  char colSeparator[20]; /* Column separator character for several modes */
+  char colSepPrior[20];  /* Saved column separator */
+  char rowSeparator[20]; /* Row separator character for MODE_Ascii */
+  char rowSepPrior[20];  /* Saved row separator */
+
+  int *colWidth;         /* Requested width of each column in columnar modes */
+  int *actualWidth;      /* Actual width of each column */
+  int nWidth;            /* Number of slots in colWidth[] and actualWidth[] */
+  char nullValue[20];    /* Text to print for NULL retrieved from database */
+
   unsigned statsOn;      /* True to display memory stats before each finalize */
-  u8 bQuote;             /* Quote results for .mode box and table */
-  int iWrap;             /* In columnar modes, wrap lines reaching this limit */
   unsigned mEqpLines;    /* Mask of veritical lines in the EQP output graph */
   int inputNesting;      /* Track nesting level of .read and other redirects */
   int outCount;          /* Revert to stdout when reaching zero */
   int cnt;               /* Number of records displayed so far */
-  int openFlags;         /* Additional flags to open.  (SQLITE_OPEN_NOFOLLOW) */
   InSource *pInSource;   /* Read commands and SQL from this stream source */
   FILE *out;             /* Write results here */
   FILE *traceOut;        /* Output for sqlite3_trace() */
   int nErr;              /* Number of errors seen */
-  int mode;              /* An output mode setting */
-  int modePrior;         /* Saved mode */
-  int cMode;             /* temporary output mode for the current query */
-  int normalMode;        /* Output mode before ".explain on" */
   int writableSchema;    /* True if PRAGMA writable_schema=ON */
-  int showHeader;        /* True to show column names in List or Column mode */
   int nCheck;            /* Number of ".check" commands run */
   unsigned nProgress;    /* Number of progress callbacks encountered */
   unsigned mxProgress;   /* Maximum progress callbacks before failing */
   unsigned flgProgress;  /* Flags for the progress callback */
-  unsigned shellFlgs;    /* Various flags */
-  unsigned priorShFlgs;  /* Saved copy of flags */
   sqlite3_int64 szMax;   /* --maxsize argument to .open */
   char *zDestTable;      /* Name of destination table when MODE_Insert */
   char *zTempFile;       /* Temporary file that might need deleting */
   char *zEditor;         /* Name of editor if non-zero, then deletable */
   char zTestcase[30];    /* Name of current test case */
-  char colSeparator[20]; /* Column separator character for several modes */
-  char rowSeparator[20]; /* Row separator character for MODE_Ascii */
-  char colSepPrior[20];  /* Saved column separator */
-  char rowSepPrior[20];  /* Saved row separator */
-  int *colWidth;         /* Requested width of each column in columnar modes */
-  int *actualWidth;      /* Actual width of each column */
-  int nWidth;            /* Number of slots in colWidth[] and actualWidth[] */
-  char nullValue[20];    /* Text to print for NULL retrieved from database */
   char outfile[FILENAME_MAX]; /* Filename for *out */
   sqlite3_stmt *pStmt;   /* Current statement if any. */
   FILE *pLog;            /* Write log output here */
@@ -4534,21 +4545,23 @@ static const char *(azHelp[]) = {
   "     --bom                 Prefix output with a UTF8 byte-order mark",
   "     -e                    Send output to the system text editor",
   "     -x                    Send output as CSV to a spreadsheet",
-  ".parameter CMD ...       Manage SQL parameter bindings",
-  "   clear ?NAMES?           Erase some or all parameter bindings",
+  ".parameter CMD ...       Manage SQL parameter bindings and scripts table",
+  "   clear ?NAMES?           Erase some or all named parameters",
 #ifndef SQLITE_NOHAVE_SYSTEM
   "   edit NAME               Use edit() to create or alter parameter NAME",
 #endif
-  "   init                    Initialize the TEMP table that holds bindings",
-  "   list                    List the current parameter bindings",
-  "   load FILE ?NAMES?       Load some or all parameter bindings from FILE",
-  "   save FILE ?NAMES?       Save some or all parameter bindings into FILE",
+  "   init                    Initialize TEMP table for bindings and scripts",
+  "   list                    List parameters table binding and script values",
+  "   load ?FILE? ?NAMES?     Load some or all named parameters from FILE",
+  "      If FILE missing, empty or '~', it defaults to ~/sqlite_params.sdb",
+  "   save ?FILE? ?NAMES?     Save some or all named parameters into FILE",
+  "      If FILE missing, empty or '~', it defaults to ~/sqlite_params.sdb",
   "   set ?TOPT? NAME VALUE   Give SQL parameter NAME a value of VALUE",
-  "      NAME must begin with $,:,@, or ? for bindings, or a letter to be",
-  "      executable; the value is following argument list, space-joined.",
+  "      NAME must begin with one of $,:,@,? for bindings, or with a letter",
+  "      to be executable; the value is following argument list, space-joined.",
   "      Option TOPT may be one of {-b -i -n -r -t} to cast effective value",
   "      to BLOB, INT, NUMERIC, REAL or TEXT respectively.",
-  "   unset ?NAMES?           Remove named parameter(s) from the binding table",
+  "   unset ?NAMES?           Remove named parameter(s) from parameters table",
   ".print STRING...         Print literal STRING, then a newline",
 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
   ".progress N              Invoke progress handler after every N opcodes",
@@ -4861,10 +4874,10 @@ static int session_filter(void *pCtx, const char *zTab){
 ** Otherwise, assume an ordinary database regardless of the filename if
 ** the type cannot be determined from content.
 */
-int deduceDatabaseType(const char *zName, int dfltZip){
+u8 deduceDatabaseType(const char *zName, int dfltZip){
   FILE *f = fopen(zName, "rb");
   size_t n;
-  int rc = SHELL_OPEN_UNSPEC;
+  u8 rc = SHELL_OPEN_UNSPEC;
   char zBuf[100];
   if( f==0 ){
     if( dfltZip && sqlite3_strlike("%.zip",zName,0)==0 ){
@@ -5163,8 +5176,8 @@ static void open_db(ShellState *p, int openFlags){
       if( zDbFilename==0 || zDbFilename[0]==0 ){
         p->openMode = SHELL_OPEN_NORMAL;
       }else{
-        p->openMode = (u8)deduceDatabaseType(zDbFilename, 
-                             (openFlags & OPEN_DB_ZIPFILE)!=0);
+        p->openMode = deduceDatabaseType(zDbFilename,
+                                         (openFlags & OPEN_DB_ZIPFILE)!=0);
       }
     }
     switch( p->openMode ){
@@ -10016,7 +10029,7 @@ static int do_meta_command(char *zLine, ShellState *p){
     char *zNewFilename = 0;  /* Name of the database file to open */
     int iName = 1;           /* Index in azArg[] of the filename */
     int newFlag = 0;         /* True to delete file before opening */
-    int openMode = SHELL_OPEN_UNSPEC;
+    u8 openMode = SHELL_OPEN_UNSPEC;
 
     /* Check for command-line arguments */
     for(iName=1; iName<nArg; iName++){
@@ -12072,9 +12085,9 @@ static int runOneSqlLine(ShellState *p, char *zSql, int bAltIn, int startline){
 ** Returns are: 0 => not open (aka complete), 1 => is open (incomplete)
 ** The following macros may be applied to the scan state:
 */
-#define DCSS_InDarkArg(dcss) ((dcss)&argPosMask==inDqArg)
+#define DCSS_InDarkArg(dcss) (((dcss)&argPosMask)==inDqArg)
 #define DCSS_EndEscaped(dcss) (((dcss)&endEscaped)!=0)
-#define DCSS_IsOpen(dcss) (((dcss) & isOpenMask)!=0)
+#define DCSS_IsOpen(dcss) (((dcss)&isOpenMask)!=0)
 typedef enum {
   DCSS_Start = 0,
   twixtArgs = 0, inSqArg = 1, inDarkArg = 2, inDqArg = 3, /* ordered */
@@ -12088,7 +12101,6 @@ static void dot_command_scan(char *zCmd, DCmd_ScanState *pScanState){
   char c = (ss&isOpenMask)? 1 : *zCmd++;
   while( c!=0 ){
     switch( ss ){
-    twixt:
     case twixtArgs:
       while( IsSpace(c) ){
         if( (c=*zCmd++)==0 ) goto atEnd; 
index 82ecd2f61a6cf7adfef07217287074fbbdab0580..f1e2bd2eb6de12486d3a2e49831f3e8e9a26e440 100644 (file)
@@ -38,7 +38,14 @@ proc omit_redundant_typedefs {line} {
     if {[info exists typedef_seen($line)]} {
       return "/* $line */"
     }
-    set typedef_seen($line) 1
+    if {[regexp {\s(\w+)\s*;} $line _ tdname]} {
+      if {[info exists typedef_seen($tdname)]} {
+        return "/* [regsub {;} $line {; **/}]"
+      }
+      set typedef_seen($tdname) 1
+    } else {
+      set typedef_seen($line) 1
+    }
   }
   return $line
 }