CLI to cease dumping back to OS shel on ^C.

FossilOrigin-Name: 7b1f635268bd5b093b22f832c3ac9e5d642d1aac5ebc620619be5a24930feb83
This commit is contained in:
larrybr 2023-04-18 22:28:48 +00:00
parent 359c5ac1fb
commit 7b1a49c993
3 changed files with 37 additions and 23 deletions

View File

@ -1,5 +1,5 @@
C Ensure\sthat\sthe\sVACUUM\scommand\sis\snot\sconfused\sby\salternative\sencodings\swhen\nit\sis\sthe\sfirst\scommand\srun\son\snew\sdatabase\sconnection.\n[forum:/forumpost/09503b4d33|Forum\spost\s09503b4d33].
D 2023-04-18T15:21:55.208
C CLI\sto\scease\sdumping\sback\sto\sOS\sshel\son\s^C.
D 2023-04-18T22:28:48.172
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -632,7 +632,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c
F src/resolve.c 3e53e02ce87c9582bd7e7d22f13f4094a271678d9dc72820fa257a2abb5e4032
F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92
F src/select.c 4054886848b2aaf3d92d28bda9fabff3b5c5c1ffe8511b0dbafcea008d58a66b
F src/shell.c.in 2a11419d77d8e4f7b4e3aea6922a9560630889423e3728205d77b4be2511cc89
F src/shell.c.in eb273024a60f6d9f56865eeacd83247fd20919d8248ea0127ee54d6f0d6abe91
F src/sqlite.h.in 4fff9c6cc5d4cbba9532a668112efb6dc469c425e1a2196664d7c07d508363ef
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
F src/sqlite3ext.h da473ce2b3d0ae407a6300c4a164589b9a6bfdbec9462688a8593ff16f3bb6e4
@ -2058,8 +2058,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 5acc3ef83e16a9f2803981a6e61eca62fe177cac4eed1befe2ade3a5977a1eab
R 1c9639553f364b83ea46a14ee324415d
U drh
Z 1f598f7bd83b32193e1562d0ae423411
P 8b0fe63f873661037351fc1eba6071b98b5c97a0fc8bd8a504a90d047f78bc0d
R 734cf00e9ab5f48eb416aa4234b55f52
T *branch * cli-no-dump
T *sym-cli-no-dump *
T -sym-trunk *
U larrybr
Z 0e6d888acccf444ddfa65e448f5f1581
# Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
8b0fe63f873661037351fc1eba6071b98b5c97a0fc8bd8a504a90d047f78bc0d
7b1f635268bd5b093b22f832c3ac9e5d642d1aac5ebc620619be5a24930feb83

View File

@ -627,8 +627,8 @@ static void console_prepare(void){
conState.outCodePage = GetConsoleOutputCP();
SetConsoleCP(CP_UTF8);
SetConsoleOutputCP(CP_UTF8);
SetConsoleMode(conState.hConsoleIn,
conState.consoleMode | ENABLE_LINE_INPUT);
consoleMode |= ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT;
SetConsoleMode(conState.hConsoleIn, consoleMode);
conState.infsMode = _setmode(_fileno(stdin), _O_U16TEXT);
console_utf8 = 1;
}else{
@ -992,10 +992,18 @@ static char *one_input_line(FILE *in, char *zPrior, int isContinuation){
#if SHELL_USE_LOCAL_GETLINE
printf("%s", zPrompt);
fflush(stdout);
do{
zResult = local_getline(zPrior, stdin);
if( zResult==0 ) sqlite3_sleep(50);
}while( zResult==0 && seenInterrupt>0 );
#else
free(zPrior);
zResult = shell_readline(zPrompt);
while( zResult==0 ){
sqlite3_sleep(50);
if( seenInterrupt==0 ) break;
zResult = shell_readline("");
}
if( zResult && *zResult ) shell_add_history(zResult);
#endif
}
@ -2102,8 +2110,7 @@ static void output_csv(ShellState *p, const char *z, int bSep){
*/
static void interrupt_handler(int NotUsed){
UNUSED_PARAMETER(NotUsed);
seenInterrupt++;
if( seenInterrupt>2 ) exit(1);
if( ++seenInterrupt>1 ) exit(1);
if( globalDb ) sqlite3_interrupt(globalDb);
}
@ -11830,6 +11837,10 @@ static char *cmdline_option_value(int argc, char **argv, int i){
return argv[i];
}
static void sayAbnormalExit(void){
if( seenInterrupt ) fprintf(stderr, "Program interrupted.\n");
}
#ifndef SQLITE_SHELL_IS_UTF8
# if (defined(_WIN32) || defined(WIN32)) \
&& (defined(_MSC_VER) || (defined(UNICODE) && defined(__GNUC__)))
@ -11871,8 +11882,8 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
char **argvToFree = 0;
int argcToFree = 0;
#endif
setvbuf(stderr, 0, _IONBF, 0); /* Make sure stderr is unbuffered */
#ifdef SQLITE_SHELL_FIDDLE
stdin_is_interactive = 0;
stdout_is_console = 1;
@ -11884,6 +11895,7 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
#if SHELL_WIN_UTF8_OPT
atexit(console_restore); /* Needs revision for CLI as library call */
#endif
atexit(sayAbnormalExit);
#ifdef SQLITE_DEBUG
mem_main_enter = sqlite3_memory_used();
#endif
@ -11907,6 +11919,14 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
}
}
#endif
/* Register a valid signal handler early, before much else is done. */
#ifdef SIGINT
signal(SIGINT, interrupt_handler);
#elif (defined(_WIN32) || defined(WIN32)) && !defined(_WIN32_WCE)
if( !SetConsoleCtrlHandler(ConsoleCtrlHandler, TRUE) ){
fprintf(stderr, "No ^C handler.\n");
}
#endif
#if USE_SYSTEM_SQLITE+0!=1
if( cli_strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,60)!=0 ){
@ -11946,15 +11966,6 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
assert( argc>=1 && argv && argv[0] );
Argv0 = argv[0];
/* Make sure we have a valid signal handler early, before anything
** else is done.
*/
#ifdef SIGINT
signal(SIGINT, interrupt_handler);
#elif (defined(_WIN32) || defined(WIN32)) && !defined(_WIN32_WCE)
SetConsoleCtrlHandler(ConsoleCtrlHandler, TRUE);
#endif
#ifdef SQLITE_SHELL_DBNAME_PROC
{
/* If the SQLITE_SHELL_DBNAME_PROC macro is defined, then it is the name