Simplify code slightly. Improve comments on added code and its use.

FossilOrigin-Name: 046c84296627382ee416f64b02b77a937b368e30b32e6b800de5a854810766f6
This commit is contained in:
larrybr
2023-10-29 19:55:22 +00:00
parent 060c097e0d
commit 84eab13df9
3 changed files with 45 additions and 20 deletions
+6 -6
View File
@@ -1,5 +1,5 @@
C Properly\sclose\sa\shandle.\sUse\sa\sputatively\seffective\sruntime\stest\sfor\sUTF-8\sconsole\sI/O\scapability.\s(This\smakes\sthe\sversion\stest\suseful\smainly\sfor\savoiding\sa\swarning\sthat\sUTF-8\sconsole\sI/O\scould\snot\sbe\ssetup.)
D 2023-10-29T16:26:12.664
C Simplify\scode\sslightly.\sImprove\scomments\son\sadded\scode\sand\sits\suse.
D 2023-10-29T19:55:22.809
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -722,7 +722,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c
F src/resolve.c 31229276a8eb5b5de1428cd2d80f6f1cf8ffc5248be25e47cf575df12f1b8f23
F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97
F src/select.c 64c9bc7494f3d220a27498137551762c25458282388ea9ac0a710dd6d5dc1510
F src/shell.c.in 6c7a4481b776a2d568816344597d0481359b4a20f465ce1c3033004fa9fa4a72
F src/shell.c.in 9e234ec61ce462b63ce37b29d875d0a716878f049ad50f13f55b859d01c919ad
F src/sqlite.h.in ef0e41e83ad1ac0dcc9ec9939bf541a44b1c5de821bee2d6c61754c3252f3276
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
F src/sqlite3ext.h 2f30b2671f4c03cd27a43f039e11251391066c97d11385f5f963bb40b03038ac
@@ -2139,8 +2139,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 6b9b2a886fd4d239c2e87c3f3809c011f77c0f60e0c279bbe4e1d1b53c609e2d
R bab24205be6731c553860e9beeba6fcf
P dc91eb91725f3db65c73725f1fbcf18a711cafb65b4fea3277aa0905a24df353
R 21d5e98541aed894e5aa957e7e737a78
U larrybr
Z a3328aae66d1d54e0b613e1b32590aa3
Z 84338a34602261108f59c503d896ebcf
# Remove this line to create a well-formed Fossil manifest.
+1 -1
View File
@@ -1 +1 @@
dc91eb91725f3db65c73725f1fbcf18a711cafb65b4fea3277aa0905a24df353
046c84296627382ee416f64b02b77a937b368e30b32e6b800de5a854810766f6
+38 -13
View File
@@ -615,7 +615,24 @@ static struct ConsoleState {
#if !SQLITE_OS_WINRT
static int CheckAtLeastWin10(void){
/*
** Check Windows major version against given value, returning
** 1 if the OS major version is no less than the argument.
** This check uses very late binding to the registry access
** API so that it can operate gracefully on OS versions that
** do not have that API. The Windows NT registry, for versions
** through Windows 11 (at least, as of October 2023), keeps
** the actual major version number at registry key/value
** HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentMajorVersionNumber
** where it can be read more reliably than allowed by various
** version info APIs which "process" the result in a manner
** incompatible with the purpose of the CLI's version check.
**
** If the registry API is unavailable, or the location of
** the above registry value changes, or the OS major version
** is less than the argument, this function returns 0.
*/
static int CheckAtLeastWinX(DWORD major_version){
typedef LONG (WINAPI *REG_OPEN)(HKEY,LPCSTR,DWORD,REGSAM,PHKEY);
typedef LSTATUS (WINAPI *REG_READ)(HKEY,LPCSTR,LPCSTR,DWORD,
LPDWORD,PVOID,LPDWORD);
@@ -633,7 +650,7 @@ static int CheckAtLeastWin10(void){
DWORD kv = 0, kvsize = sizeof(kv);
if( ERROR_SUCCESS == rkRead(hk, 0, "CurrentMajorVersionNumber",
RRF_RT_REG_DWORD, 0, &kv, &kvsize) ){
rv = (kv >= 10);
rv = (kv >= major_version);
}
rkFree(hk);
}
@@ -642,16 +659,22 @@ static int CheckAtLeastWin10(void){
}
return rv;
}
# define IS_WIN10_OR_LATER() CheckAtLeastWin10()
# define IS_WIN10_OR_LATER() CheckAtLeastWinX(10)
#else /* defined(SQLITE_OS_WINRT) */
# define IS_WIN10_OR_LATER() 0
#endif
/*
** Prepare console, (if known to be a WIN32 console), for UTF-8
** input (from either typing or suitable paste operations) and/or for
** UTF-8 rendering. This may "fail" with a message to stderr, where
** Prepare console, (if known to be a WIN32 console), for UTF-8 input
** (from either typing or suitable paste operations) and/or for UTF-8
** output rendering. This may "fail" with a message to stderr, where
** the preparation is not done and common "code page" issues occur.
**
** The console state upon entry is preserved, in conState, so that
** console_restore() can later restore the same console state.
**
** The globals console_utf8_in and console_utf8_out are set, for
** later use in selecting UTF-8 or MBCS console I/O translations.
*/
static void console_prepare_utf8(void){
HANDLE hCI = GetStdHandle(STD_INPUT_HANDLE);
@@ -678,17 +701,17 @@ static void console_prepare_utf8(void){
csWork.outCodePage = GetConsoleOutputCP();
if( conI ){
if( !SetConsoleCP(CP_UTF8) ) goto bail;
console_utf8_in = 1;
consoleMode |= ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT;
SetConsoleMode(conState.hConsole, consoleMode);
csWork.infsMode = _setmode(_fileno(stdin), _O_U16TEXT);
}
if( conO ){
/* Here, it is assumed that if conI is true, this call will
** also succeed, so there is no need to undo above setup. */
/* Here, it is assumed that if conI is true, this call will also
** succeed, so there is no need to undo above setup upon failure. */
if( !SetConsoleOutputCP(CP_UTF8) ) goto bail;
console_utf8_out = 1;
}
console_utf8_in = conI;
console_utf8_out = conO;
conState = csWork;
}
@@ -12250,9 +12273,11 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
#endif
#if SHELL_WIN_UTF8_OPT
/* If Windows build and not RT, set default MBCS/UTF-8 translation
** for console according to detected Windows version. This default
** may be overridden by the -utf8 or -no-utf8 invocation options.
/* If Windows build and not RT, set default MBCS/UTF-8 translation for
** console according to detected Windows version. This default may be
** overridden by a -no-utf8 or (undocumented) -utf8 invocation option.
** If a runtime check for UTF-8 console I/O capability is devised,
** that should be preferred over this version check.
*/
mbcs_opted = (IS_WIN10_OR_LATER())? 0 : 1;
#endif