From: drh <> Date: Sat, 11 Apr 2026 12:35:53 +0000 (+0000) Subject: Remove arbitrary limits on the length of CLI prompts. Use environment X-Git-Url: http://git.ipfire.org/index.cgi?a=commitdiff_plain;h=cd2879711736b2a89af712271ba764fee99abb69;p=thirdparty%2Fsqlite.git Remove arbitrary limits on the length of CLI prompts. Use environment variables SQLITE_PS1 and SQLITE_PS2 (if they exist) as the default CLI prompts. FossilOrigin-Name: a46ceaeab968d8f376c5a225c23c0be8619fed4511b7e567baf3a8d7736c19d1 --- diff --git a/manifest b/manifest index d19732cd62..5e3013e532 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\s\B\sescape\sfor\sprompts\sso\sthat\sit\suses\swcwidth()\sinstead\sof\nstrlen()\sto\scompute\sspacing. -D 2026-04-11T11:24:09.462 +C Remove\sarbitrary\slimits\son\sthe\slength\sof\sCLI\sprompts.\s\sUse\senvironment\nvariables\sSQLITE_PS1\sand\sSQLITE_PS2\s(if\sthey\sexist)\sas\sthe\sdefault\nCLI\sprompts. +D 2026-04-11T12:35:53.197 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea @@ -735,7 +735,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c 928ff887f2a7c64275182060d94d06fdddbe32226c569781cf7e7edc6f58d7fd F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c ffe199f025a0dd74670d2a77232bdea364a4d7b36f32c64a6572d39ba6a11576 -F src/shell.c.in 50505cdfdae8163b7c7476c7ad94c79c3b851274301e680dbb7b91c6d6bdc13b +F src/shell.c.in 7ad3effc35e738c90d87b6b5336a0ddd7cc1bcb32cfc7c73cab4666e8c0afb22 F src/sqlite.h.in a5605faa9479bbaac16c4ab43eb09ff50632004a8e05084d3fde56063ef73766 F src/sqlite3.rc 015537e6ac1eec6c7050e17b616c2ffe6f70fca241835a84a4f0d5937383c479 F src/sqlite3ext.h 1b7a0ee438bb5c2896d0609c537e917d8057b3340f6ad004d2de44f03e3d3cca @@ -2197,8 +2197,8 @@ F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee F tool/warnings.sh a554d13f6e5cf3760f041b87939e3d616ec6961859c3245e8ef701d1eafc2ca2 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f F tool/winmain.c 00c8fb88e365c9017db14c73d3c78af62194d9644feaf60e220ab0f411f3604c -P 7c9998de1b839cfbe12c4328ac5176f5fae981e139c5f8888b100752f5e4756b -R effaffd5b612cee5e2c7467276ff636f +P c6ff4f701d9cf963cf2472ed72ad4e201227560dde2ba8d48602af2e49170e89 +R 5b11b0f858f42d7a9b800b9821aa8115 U drh -Z 38f50b0294cde0ae9e16e79e3a672fcb +Z c8ef1c46f1e4fc036ec422f313143d28 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 723703ae42..734582b578 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c6ff4f701d9cf963cf2472ed72ad4e201227560dde2ba8d48602af2e49170e89 +a46ceaeab968d8f376c5a225c23c0be8619fed4511b7e567baf3a8d7736c19d1 diff --git a/src/shell.c.in b/src/shell.c.in index 4e5f913c6c..9db31bcf37 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -355,11 +355,6 @@ typedef struct Mode { #define MFLG_CRLF 0x02 /* Use CR/LF output line endings */ #define MFLG_HDR 0x04 /* .header used to change headers on/off */ -/* -** Size of the prompt strings -*/ -#define PROMPT_MAX 128 - /* ** State information about the database connection is contained in an ** instance of the following structure. @@ -403,6 +398,7 @@ struct ShellState { char *zErrPrefix; /* Alternative error message prefix */ sqlite3_stmt *pStmt; /* Current statement if any. */ FILE *pLog; /* Write log output here */ + char *azPrompt[2]; /* Main and continuation prompt strings */ Mode mode; /* Current display mode */ Mode modePrior; /* Backup */ struct SavedMode { /* Ability to define custom mode configurations */ @@ -442,8 +438,6 @@ struct ShellState { #endif char zTestcase[30]; /* Name of current test case */ char outfile[FILENAME_MAX]; /* Filename for *out */ - char mainPrompt[PROMPT_MAX]; /* Main prompt */ - char contPrompt[PROMPT_MAX]; /* Continuation prompt */ }; #ifdef SQLITE_SHELL_FIDDLE @@ -793,20 +787,6 @@ static sqlite3_int64 timeOfDay(void){ #endif } - - -/* This is variant of the standard-library strncpy() routine with the -** one change that the destination string is always zero-terminated, even -** if there is no zero-terminator in the first n-1 characters of the source -** string. -*/ -static char *shell_strncpy(char *dest, const char *src, size_t n){ - size_t i; - for(i=0; iazPrompt[bContinue] ){ + return p->azPrompt[bContinue]; + } +#ifndef SQLITE_SHELL_FIDDLE + zPS = getenv(bContinue ? "SQLITE_PS2" : "SQLITE_PS1"); + if( zPS ) return zPS; +#endif + if( bContinue ){ + return "\\B...\\H> "; + }else{ + return "SQLite \\f> "; + } +} + /* ** Expand escapes in the given input prompt string. Return the ** expanded prompt in memory obtained from sqlite3_malloc(). The @@ -1079,7 +1087,7 @@ static char *expand_prompt( } if( c=='B' ){ - /* \B is a no-op for the main prmopt. For the continuation prompt, + /* \B is a no-op for the main prompt. For the continuation prompt, ** \B expands to zero or more spaces to make the continuation prompt ** at least as wide as the main prompt. */ if( onoff ) idxSpace = sqlite3_str_length(pOut); @@ -1099,7 +1107,7 @@ static char *expand_prompt( /* Expand the \B, if there is one and if this is a continuation prompt */ if( idxSpace>=0 && zPrior!=0 && zPrior[0]!=0 ){ - char *zOther = expand_prompt(p, 0, p->mainPrompt); + char *zOther = expand_prompt(p, 0, prompt_string(p,0)); size_t wOther = sqlite3_qrf_wcswidth(zOther); size_t wThis = sqlite3_qrf_wcswidth(sqlite3_str_value(pOut)); sqlite3_free(zOther); @@ -1146,7 +1154,7 @@ static char *one_input_line( if( in!=0 ){ zResult = local_getline(zPrior, in); }else{ - const char *zBase = bContinue ? p->contPrompt : p->mainPrompt; + const char *zBase = prompt_string(p, bContinue!=0); char *zPrompt = expand_prompt(p, zAll, zBase); shell_check_oom(zPrompt); #if SHELL_USE_LOCAL_GETLINE @@ -10562,10 +10570,12 @@ static int do_meta_command(const char *zLine, ShellState *p){ if( c=='p' && cli_strncmp(azArg[0], "prompt", n)==0 ){ if( nArg >= 2) { - shell_strncpy(p->mainPrompt,azArg[1],sizeof(p->mainPrompt)-1); + free(p->azPrompt[0]); + p->azPrompt[0] = strdup(azArg[1]); } if( nArg >= 3) { - shell_strncpy(p->contPrompt,azArg[2],sizeof(p->contPrompt)-1); + free(p->azPrompt[1]); + p->azPrompt[1] = strdup(azArg[2]); } }else @@ -12864,8 +12874,6 @@ static void main_init(ShellState *p) { #endif sqlite3_config(SQLITE_CONFIG_URI, 1); sqlite3_config(SQLITE_CONFIG_MULTITHREAD); - sqlite3_snprintf(sizeof(p->mainPrompt), p->mainPrompt,"SQLite \\f> "); - sqlite3_snprintf(sizeof(p->contPrompt), p->contPrompt,"\\B...\\H> "); } /* @@ -13702,6 +13710,8 @@ int SQLITE_CDECL main(int argc, char **argv){ free(data.dot.azArg); free(data.dot.aiOfst); free(data.dot.abQuot); + free(data.azPrompt[0]); + free(data.azPrompt[1]); if( data.nTestRun ){ sqlite3_fprintf(stdout, "%d test%s run with %d error%s\n", data.nTestRun, data.nTestRun==1 ? "" : "s", @@ -13863,6 +13873,6 @@ void fiddle_exec(const char * zSql){ } char *fiddle_get_prompt(void){ - return expand_prompt(&shellState, 0, &shellState.mainPrompt[0]); + return expand_prompt(&shellState, 0, prompt_string(&shellState,0)); } #endif /* SQLITE_SHELL_FIDDLE */