]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
For CLI -utf8, set output codepage too. Adjust PP vars so that the code can be entire...
authorlarrybr <larrybr@noemail.net>
Sat, 15 Apr 2023 16:12:46 +0000 (16:12 +0000)
committerlarrybr <larrybr@noemail.net>
Sat, 15 Apr 2023 16:12:46 +0000 (16:12 +0000)
FossilOrigin-Name: 543594a7277b12d1c58af8e3cba3841667cf924172995536489ce7da704a11d7

manifest
manifest.uuid
src/shell.c.in

index f40d839a7a6be6e0a226c1ebe72c6002e3fa629a..454e8ac7f9ad47d1b928ef3e09fd0b4ae37ce81b 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sstray\sedits\sin\scomments\sin\slast\scheck-in.
-D 2023-04-14T21:34:58.853
+C For\sCLI\s-utf8,\sset\soutput\scodepage\stoo.\sAdjust\sPP\svars\sso\sthat\sthe\scode\scan\sbe\sentirely\somitted\sfor\stargets\spretending\sto\sbe\s"WIN32"\sbut\snot\squite\sdoing\sso.
+D 2023-04-15T16:12:46.806
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -626,7 +626,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c
 F src/resolve.c 3e53e02ce87c9582bd7e7d22f13f4094a271678d9dc72820fa257a2abb5e4032
 F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92
 F src/select.c 93bb02212256b49a90589a4664031896e2b2991198153dff1a33a72f437dad94
-F src/shell.c.in 904c52bc168b5400838461b8c3cad93a47a667670cac537ed2eadc7ac3513a48
+F src/shell.c.in ec8f1e4f87882670885e27037b8c236f569932a823feecbefc25a910c851d4e8
 F src/sqlite.h.in 4fff9c6cc5d4cbba9532a668112efb6dc469c425e1a2196664d7c07d508363ef
 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
 F src/sqlite3ext.h da473ce2b3d0ae407a6300c4a164589b9a6bfdbec9462688a8593ff16f3bb6e4
@@ -2052,8 +2052,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 047344a91583f273a55fe3659bb8020ffc947c05c4274fbda54ee0608e62adb1
-R 871ffb5c7dac7776c2e69fb0be1e0787
+P fa3ce7f013d40147f012e26d0ede75b134174f144d314336310c9ac585e23fb7
+R bf7c6e9f3d2c14f31428bf0dcd17722f
 U larrybr
-Z 211efb5182446fc16d9890afb7d4aec9
+Z e087e76624523fc274ea2606bdd42051
 # Remove this line to create a well-formed Fossil manifest.
index d59bc1bfb80e661afd0fb4d09f0550c1aec507b5..ccd8ec1c4a27dd1d1ce59ad9ba204304d88994ee 100644 (file)
@@ -1 +1 @@
-fa3ce7f013d40147f012e26d0ede75b134174f144d314336310c9ac585e23fb7
\ No newline at end of file
+543594a7277b12d1c58af8e3cba3841667cf924172995536489ce7da704a11d7
\ No newline at end of file
index 79d43ff909495ed907889ad703655d26259280ec..06648f494adbc68080a6097bc1696eb52533090a 100644 (file)
@@ -448,7 +448,8 @@ static int bail_on_error = 0;
 */
 static int stdin_is_interactive = 1;
 
-#if (defined(_WIN32) || defined(WIN32)) && SHELL_USE_LOCAL_GETLINE
+#if (defined(_WIN32) || defined(WIN32)) && SHELL_USE_LOCAL_GETLINE \
+  && !defined(SHELL_OMIT_WIN_UTF8)
 # define SHELL_WIN_UTF8_OPT 1
 #else
 # define SHELL_WIN_UTF8_OPT 0
@@ -594,32 +595,38 @@ static char *dynamicContinuePrompt(void){
 #endif /* !defined(SQLITE_OMIT_DYNAPROMPT) */
 
 #if SHELL_WIN_UTF8_OPT
-/* Following variables are used for -utf8 operation. */
-static int stdinEof = 0;  /* EOF seen on console input */
-static int infsMode;      /* Input file stream mode upon shell start */
-static UINT codePage = 0; /* Input code page upon shell start */
-static HANDLE hConsoleIn = INVALID_HANDLE_VALUE; /* Console input handle */
-static DWORD consoleMode; /* Console mode upon shell start */
-
-/*
-** Prepare input stream, (if known to be a WIN32 console), for UTF-8
+/* Following struct is used for -utf8 operation. */
+static struct ConsoleState {
+  int stdinEof;      /* EOF has been seen on console input */
+  int infsMode;      /* Input file stream mode upon shell start */
+  UINT inCodePage;   /* Input code page upon shell start */
+  UINT outCodePage;  /* Output code page upon shell start */
+  HANDLE hConsoleIn; /* Console input handle */
+  DWORD consoleMode; /* Console mode upon shell start */
+} conState = { 0, 0, 0, 0, INVALID_HANDLE_VALUE, 0 };
+
+/*
+** Prepare console, (if known to be a WIN32 console), for UTF-8
 ** input (from either typing or suitable paste operations) and for
 ** UTF-8 rendering. This may "fail" with a message to stderr, where
 ** the preparation is not done and common "code page" issues occur.
 */
-static void instream_prepare(void){
-  hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
-  if( isatty(0) && GetFileType(hConsoleIn)==FILE_TYPE_CHAR ){
+static void console_prepare(void){
+  conState.hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
+  if( isatty(0) && GetFileType(conState.hConsoleIn)==FILE_TYPE_CHAR ){
     if( !IsValidCodePage(CP_UTF8) ){
       fprintf(stderr, "Cannot use UTF-8 code page.\n");
       console_utf8 = 0;
       return;
     }
-    codePage = GetConsoleCP();
+    conState.inCodePage = GetConsoleCP();
+    conState.outCodePage = GetConsoleOutputCP();
     SetConsoleCP(CP_UTF8);
-    GetConsoleMode( hConsoleIn, &consoleMode);
-    SetConsoleMode( hConsoleIn, consoleMode | ENABLE_LINE_INPUT );
-    infsMode = _setmode(_fileno(stdin), _O_U16TEXT);
+    SetConsoleOutputCP(CP_UTF8);
+    GetConsoleMode( conState.hConsoleIn, &conState.consoleMode);
+    SetConsoleMode( conState.hConsoleIn,
+                    conState.consoleMode | ENABLE_LINE_INPUT );
+    conState.infsMode = _setmode(_fileno(stdin), _O_U16TEXT);
     console_utf8 = 1;
   }else{
     console_utf8 = 0;
@@ -627,13 +634,15 @@ static void instream_prepare(void){
 }
 
 /*
-** Undo the effects of instream_prepare(), if any.
+** Undo the effects of console_prepare(), if any.
 */
-static void SQLITE_CDECL instream_restore(void){
-  if( console_utf8 && codePage!=0 &&hConsoleIn != INVALID_HANDLE_VALUE ){
-    _setmode(_fileno(stdin), infsMode);
-    SetConsoleCP(codePage);
-    SetConsoleMode( hConsoleIn, consoleMode );
+static void SQLITE_CDECL console_restore(void){
+  if( console_utf8 && conState.inCodePage!=0
+      && conState.hConsoleIn != INVALID_HANDLE_VALUE ){
+    _setmode(_fileno(stdin), conState.infsMode);
+    SetConsoleCP(conState.inCodePage);
+    SetConsoleOutputCP(conState.outCodePage);
+    SetConsoleMode( conState.hConsoleIn, conState.consoleMode );
     console_utf8 = 0; /* Avoid multiple calls. */
   }
 }
@@ -651,7 +660,7 @@ static char* utf8_fgets(char *buf, int ncmax, FILE *fin){
     wchar_t wbuf[SQLITE_IALIM];
     int lend = 0;
     int noc = 0;
-    if( ncmax == 0 || stdinEof ) return 0;
+    if( ncmax == 0 || conState.stdinEof ) return 0;
     buf[0] = 0;
     while( noc < ncmax-7-1 && !lend ){
       /* There is room for at least 2 more characters and a 0-terminator. */
@@ -659,7 +668,7 @@ static char* utf8_fgets(char *buf, int ncmax, FILE *fin){
         ? SQLITE_IALIM : (ncmax-1 - noc)/4;
 # undef SQLITE_IALIM
       DWORD nbr = 0;
-      BOOL bRC = ReadConsoleW(hConsoleIn, wbuf, na, &nbr, 0);
+      BOOL bRC = ReadConsoleW(conState.hConsoleIn, wbuf, na, &nbr, 0);
       if( !bRC || (noc==0 && nbr==0) ) return 0;
       if( nbr > 0 ){
         int nmb = WideCharToMultiByte(CP_UTF8, WC_COMPOSITECHECK|WC_DEFAULTCHAR,
@@ -682,7 +691,7 @@ static char* utf8_fgets(char *buf, int ncmax, FILE *fin){
           /* Check for ^Z (anywhere in line) too. */
           while( iseg < noc ){
             if( buf[iseg]==0x1a ){
-              stdinEof = 1;
+              conState.stdinEof = 1;
               noc = iseg; /* Chop ^Z and anything following. */
               break;
             }
@@ -11861,7 +11870,7 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
   stdout_is_console = isatty(1);
 #endif
 #if SHELL_WIN_UTF8_OPT
-  atexit(instream_restore); /* Needs revision for CLI as library call */
+  atexit(console_restore); /* Needs revision for CLI as library call */
 #endif
 #ifdef SQLITE_DEBUG
   mem_main_enter = sqlite3_memory_used();
@@ -12335,7 +12344,7 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
   }
 #if SHELL_WIN_UTF8_OPT
   if( console_utf8 && stdin_is_interactive ){
-    instream_prepare();
+    console_prepare();
   }else{
     setBinaryMode(stdin, 0);
     console_utf8 = 0;