]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Always use fputws() for output to a Windows command-line prompt.
authordrh <>
Tue, 24 Sep 2024 09:51:53 +0000 (09:51 +0000)
committerdrh <>
Tue, 24 Sep 2024 09:51:53 +0000 (09:51 +0000)
FossilOrigin-Name: 33950a8c3f3e48e5107fe56647da05147aa84f9c3eccbe7c8671f5b502ebb70b

manifest
manifest.uuid
src/shell.c.in

index 8b26ee78437be36bac1b4927febff75862d25c38..f90dfa8f2553eec77b240282100b2039161a754e 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C CLI\suses\sonly\slib-c\sfor\sI/O\son\sWindows.\s\sNo\scalls\sto\sWin32.\s\sWorks\son\sWin11,\nat\sleast.\s\sReads\sand\swrites\sunicode\sto/from\sthe\sconsole\sand\sUTF-8\sto/from\sfiles.\nPrototype\scode\sonly\s-\smust\stesting\sand\sadditional\swork\srequired.
-D 2024-09-23T20:23:43.341
+C Always\suse\sfputws()\sfor\soutput\sto\sa\sWindows\scommand-line\sprompt.
+D 2024-09-24T09:51:53.618
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -768,7 +768,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c
 F src/resolve.c b2cd748488012312824508639b6af908461e45403037d5c4e19d9b0e8195507f
 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97
 F src/select.c 4b14337a2742f0c0beeba490e9a05507e9b4b12184b9cd12773501d08d48e3fe
-F src/shell.c.in 265c877932142ee8ef05a6aa5a0a5bff92905ffef97dc6f566062a27814274a1
+F src/shell.c.in 6054892954e926a30a5b3d2994805477d38154692b5bb571d81db86791d0e58b
 F src/sqlite.h.in 77f55bd1978a04a14db211732f0a609077cf60ba4ccf9baf39988f508945419c
 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54
@@ -2213,11 +2213,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 2e5194407a1b34dd0659c350ea8098bfef7b3f11aa5b2a07ecd2bce5582655a2
-R 7c20c2fd1880ef1b062b32c88da2e8e4
-T *branch * cli-stdlib
-T *sym-cli-stdlib *
-T -sym-trunk *
+P 5c54530d5a0a4125a1ba44f22537c4f63d5e5708f347c43cbac3e1832c4335da
+R 39e94947c12065fc6ead20518785128b
 U drh
-Z cdf0bc25a30881c9fe4f62b1ff96af22
+Z 9f7cd507ccaf6f6343bd8b5a2d5f1672
 # Remove this line to create a well-formed Fossil manifest.
index 7417271d4ae0ad780e6b490eb80672dcc2bbe657..d6a1143c6788d44453fcac76b0b8154613bc38ee 100644 (file)
@@ -1 +1 @@
-5c54530d5a0a4125a1ba44f22537c4f63d5e5708f347c43cbac3e1832c4335da
+33950a8c3f3e48e5107fe56647da05147aa84f9c3eccbe7c8671f5b502ebb70b
index a2b22845d6a2d63554fba0a96adbd825f3d8d0e8..c400073872c865ff48167c6f7df0221fca847086 100644 (file)
@@ -288,6 +288,62 @@ static char *cli_fgets(char *buf, int sz, FILE *in){
 # define cli_fgets fgets
 #endif
 
+#ifdef _WIN32
+/* fputs() for windows */
+static int cli_fputs(const char *z, FILE *out){
+  if( isatty(_fileno(out)) ){
+    /* When writing to the command-prompt in Windows, it is necessary
+    ** to use _O_WTEXT input mode and write UTF-16 characters.
+    */
+    int sz = (int)strlen(z);
+    wchar_t *b1 = malloc( (sz+1)*sizeof(wchar_t) );
+    if( b1==0 ) return 0;
+    sz = MultiByteToWideChar(CP_UTF8, 0, z, sz, b1, sz);
+    b1[sz] = 0;
+    _setmode(_fileno(out), _O_WTEXT);
+    fputws(b1, out);
+    sqlite3_free(b1);
+    return 0;
+  }else{
+    /* Writing to a file or other destination, just write bytes without
+    ** any translation. */
+    return fputs(z, out);
+  }
+}
+#else
+/* library version works for everybody else */
+# define cli_fputs fputs
+#endif
+
+#ifdef _WIN32
+/* fprintf() for windows */
+static void cli_fprintf(FILE *out, const char *zFormat, ...){
+  if( isatty(fileno(out)) ){
+    /* When writing to the command-prompt in Windows, it is necessary
+    ** to use _O_WTEXT input mode and write UTF-16 characters.
+    */
+    char *z;
+    va_list ap;
+
+    va_start(ap, zFormat);
+    z = sqlite3_vmprintf(zFormat, ap);
+    va_end(ap);
+    cli_fputs(z, out);
+    sqlite3_free(z);
+  }else{
+    /* Writing to a file or other destination, just write bytes without
+    ** any translation. */
+    va_list ap;
+    va_start(ap, zFormat);
+    vfprintf(out, zFormat, ap);
+    va_end(ap);
+  }
+}
+#else
+/* library version works for everybody else */
+# define cli_fprintf fprintf
+#endif
+
 /* Use console I/O package as a direct INCLUDE. */
 #define SQLITE_INTERNAL_LINKAGE static
 
@@ -300,13 +356,13 @@ static char *cli_fgets(char *buf, int sz, FILE *in){
 # define SQLITE_CIO_NO_FLUSH
 #endif
 
-#define oputf(fmt, ...) printf(fmt,__VA_ARGS__)
-#define eputf(fmt, ...) fprintf(stderr,fmt,__VA_ARGS__)
-#define sputf(fp,fmt, ...) fprintf(fp,fmt,__VA_ARGS__)
+#define oputf(fmt, ...) cli_fprintf(stdout,fmt,__VA_ARGS__)
+#define eputf(fmt, ...) cli_fprintf(stderr,fmt,__VA_ARGS__)
+#define sputf(fp,fmt, ...) cli_fprintf(fp,fmt,__VA_ARGS__)
 /* These next 3 macros are for emitting simple string literals. */
-#define oputz(z) fputs(z,stdout)
-#define eputz(z) fputs(z,stderr)
-#define sputz(fp,z) fputs(z,fp)
+#define oputz(z) cli_fputs(z,stdout)
+#define eputz(z) cli_fputs(z,stderr)
+#define sputz(fp,z) cli_fputs(z,fp)
 #define oputb(buf,na) fwrite(buf,1,na,stdout)
 
 /* True if the timer is enabled */