]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Improvements to the #define mechanism in the CLI that allows other programs
authordrh <>
Thu, 23 Apr 2026 16:40:34 +0000 (16:40 +0000)
committerdrh <>
Thu, 23 Apr 2026 16:40:34 +0000 (16:40 +0000)
that incorporate the shell.c source file to customize some of the
prompt expansions.

FossilOrigin-Name: e5f8840d11c1863cfc5c0b4a3d16c9ec9ab6ca6ecb7ff1a3a9a237715eed5d30

manifest
manifest.uuid
src/shell.c.in

index ee79d07a54139ef321f51c816caead6dd42098be..fc6cf468affdd72e63cabaa73be2a9c4e86befd6 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Have\stestrunner.tcl\sreturn\sa\snon-zero\sexit\sstatus\sif\sone\sor\smore\stests\shave\sfailed.
-D 2026-04-23T15:54:00.129
+C Improvements\sto\sthe\s#define\smechanism\sin\sthe\sCLI\sthat\sallows\sother\sprograms\nthat\sincorporate\sthe\sshell.c\ssource\sfile\sto\scustomize\ssome\sof\sthe\nprompt\sexpansions.
+D 2026-04-23T16:40:34.462
 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
@@ -736,7 +736,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c
 F src/resolve.c 928ff887f2a7c64275182060d94d06fdddbe32226c569781cf7e7edc6f58d7fd
 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97
 F src/select.c 4c05cde130f26991b7411d8c6809e0630625e18078742c963a047b4b9cc01d49
-F src/shell.c.in ae78db9539da5f8ada1ac2761b77b865e56ec2ba9145461e56de6eb762aeef18
+F src/shell.c.in 20b15f46e927aa2e485519bea8eb080f793409aef78dcea743214e3036ab3649
 F src/sqlite.h.in 39d2e09114d2bdb7afd998f4a469c8f8cd065f8093835a7d0422f260fc78fb4f
 F src/sqlite3.rc 015537e6ac1eec6c7050e17b616c2ffe6f70fca241835a84a4f0d5937383c479
 F src/sqlite3ext.h 9788c301f95370fa30e808861f1d2e6f022a816ddbe2a4f67486784c1b31db2e
@@ -2203,8 +2203,8 @@ F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee
 F tool/warnings.sh a554d13f6e5cf3760f041b87939e3d616ec6961859c3245e8ef701d1eafc2ca2
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
 F tool/winmain.c 00c8fb88e365c9017db14c73d3c78af62194d9644feaf60e220ab0f411f3604c
-P e7c7acd1a4e5cb0f8e68f119352480c1aa9dd3c2b289c92f88e9e697a2e440e0
-R ce5ff5cb6237d0749d0d59bd9ff7f7b8
-U dan
-Z 0037f23c5e61abb774fba5ce36636000
+P 50ddc36d32540b6d98990b5c9a465beb5b68cc31ae3f0ed162f6fe07e7c74e2d
+R ede7f0f979d13fe3709ae4285b970a9c
+U drh
+Z e87aec3e23905d0d97d6755d895e148d
 # Remove this line to create a well-formed Fossil manifest.
index 2f9f4942169a62573fc1600f7e2f1914503752aa..3cba8fe09141679cd985dc0b32533c515b668c6d 100644 (file)
@@ -1 +1 @@
-50ddc36d32540b6d98990b5c9a465beb5b68cc31ae3f0ed162f6fe07e7c74e2d
+e5f8840d11c1863cfc5c0b4a3d16c9ec9ab6ca6ecb7ff1a3a9a237715eed5d30
index 52233de2959faea685d886bc98c4084e3afef6f6..8880824c7ab5498cbcc977b0ce4f41fcfa0e7b36 100644 (file)
@@ -928,18 +928,37 @@ static char *local_getline(char *zLine, FILE *in){
 #endif
 
 /*
-** Redefinable escape value for the prompt string.
+** Redefinable name of a function that is used to find the text for
+** some prompt expansions:  /A  /V  /v
 */
-#ifndef SQLITE_PS_APP
-# define SQLITE_PS_APP "SQLite"                      /* Expansion for /A */
-#endif
-#ifndef SQLITE_PS_RELEASE
-# define SQLITE_PS_VERSION_RELEASE shellRelease()    /* Expansion for /v */
-#endif
-#ifndef SQLITE_PS_PATCH
-# define SQLITE_PS_VERSION_PATCH   shellPatch()      /* Expansion for /V */
+#ifndef SQLITE_PS_APPDEF
+# define SQLITE_PS_APPDEF shellPromptAppDef
+#else
+extern const char *SQLITE_PS_APPDEF(int);
 #endif
 
+/*
+** Return a string appropriate for various prompt expansion characters.
+** Return an empty string at least.  Always return a valid string pointer.
+*/
+static const char *shellPromptAppDef(int c){
+  if( c=='A' ) return "SQLite";
+  if( c=='V' ) return sqlite3_libversion();
+  if( c=='v' ){
+    static char zRel[16];
+    const char *zF = sqlite3_libversion();
+    const char *zD = strrchr(zF,'.');
+    if( zD && (size_t)(zD-zF)<sizeof(zRel)-1 ){
+      memcpy(zRel,zF,(size_t)(zD-zF));
+      zRel[(size_t)(zD-zF)] = 0;
+      return zRel;
+    }else{
+      return zF;
+    }
+  }
+  return "";
+}
+
 /*
 ** Return the raw (unexpanded) prompt string.  This will be the
 ** first of the following that exist:
@@ -989,20 +1008,6 @@ static const char *prompt_filename(ShellState *p){
   return zFN;
 }
 
-/*
-** Return strings appropriate to substitute for /V and /v
-*/
-static const char *shellPatch(void){ return sqlite3_libversion(); }
-static const char *shellRelease(void){
-  static char zRel[16];
-  const char *zF = shellPatch();
-  const char *zD = strrchr(zF,'.');
-  int i = (int)(zD - zF);
-  memcpy(zRel,zF,i);
-  zRel[i] = 0;
-  return zRel;
-}
-
 /*
 ** Expand escapes in the given input prompt string.  Return the
 ** expanded prompt in memory obtained from sqlite3_malloc().  The
@@ -1065,24 +1070,11 @@ static char *expand_prompt(
       i = -1;
       continue;
     }
-    if( c=='A' ){
+    if( c=='A' || c=='V' || c=='v' ){
       /* /A expands to the application name */
-      if( !mOff ) sqlite3_str_appendall(pOut, SQLITE_PS_APP);
-      zPrompt += 2;
-      i = -1;
-      continue;
-    }
-    if( c=='V' ){
       /* /V expands to the version number with patch level */
-      if( !mOff ) sqlite3_str_appendall(pOut, SQLITE_PS_VERSION_PATCH);
-      zPrompt += 2;
-      i = -1;
-      continue;
-    }
-    if( c=='v' ){
       /* /v expands to the version number without the patch level */
-      /* /V expands to the version number with patch level */
-      if( !mOff ) sqlite3_str_appendall(pOut, SQLITE_PS_VERSION_RELEASE);
+      if( !mOff ) sqlite3_str_appendall(pOut, SQLITE_PS_APPDEF(c));
       zPrompt += 2;
       i = -1;
       continue;