Fossil SCM

write unicode to console, when possible.

jan.nijtmans 2012-09-05 08:15 eclipse-project
Commit 7fd74e72f8ab8a0799b7b90aa758c894e6138bb2
2 files changed +6 -23 +1 -1
+6 -23
--- src/file.c
+++ src/file.c
@@ -1118,19 +1118,18 @@
11181118
}
11191119
11201120
/*
11211121
** Display UTF8 on the console. Return the number of
11221122
** Characters written. If stdout or stderr is redirected
1123
-** to a file, so it is not a console, -1 is returned and
1124
-** nothing is written.
1123
+** to a file, -1 is returned and ** nothing is written
1124
+** to the console.
11251125
*/
11261126
int fossil_utf8_to_console(const char *zUtf8, int nByte, int toStdErr){
11271127
#ifdef _WIN32
11281128
int nChar;
1129
- WCHAR *zUnicode; /* Unicode version of zUtf8 */
1130
- char *zConsole; /* Console version of zUtf8 */
1131
- int codepage; /* Console code page */
1129
+ wchar_t *zUnicode; /* Unicode version of zUtf8 */
1130
+ DWORD dummy;
11321131
11331132
static int once = 1;
11341133
static int istty[2];
11351134
if( once ){
11361135
istty[0] = _isatty(fileno(stdout));
@@ -1150,28 +1149,12 @@
11501149
nChar = MultiByteToWideChar(CP_UTF8, 0, zUtf8, nByte, zUnicode, nChar);
11511150
if( nChar==0 ){
11521151
free(zUnicode);
11531152
return 0;
11541153
}
1155
- zUnicode[nChar] = '\0';
1156
- codepage = GetConsoleCP();
1157
- nByte = WideCharToMultiByte(codepage, 0, zUnicode, nChar, 0, 0, 0, 0);
1158
- zConsole = malloc( nByte + 1);
1159
- if( zConsole==0 ){
1160
- free(zUnicode);
1161
- return 0;
1162
- }
1163
- nByte = WideCharToMultiByte(codepage, 0, zUnicode, nChar, zConsole, nByte, 0, 0);
1164
- zConsole[nByte] = '\0';
1165
- free(zUnicode);
1166
- if( nByte == 0 ){
1167
- free(zConsole);
1168
- zConsole = 0;
1169
- return 0;
1170
- }
1171
- fwrite(zConsole, 1, nByte, toStdErr ? stderr : stdout);
1172
- fflush(toStdErr ? stderr : stdout);
1154
+ zUnicode[nChar] = '\0';;
1155
+ WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE + toStdErr), zUnicode, nChar, &dummy, 0);
11731156
return nChar;
11741157
#else
11751158
return -1; /* No-op on unix */
11761159
#endif
11771160
}
11781161
--- src/file.c
+++ src/file.c
@@ -1118,19 +1118,18 @@
1118 }
1119
1120 /*
1121 ** Display UTF8 on the console. Return the number of
1122 ** Characters written. If stdout or stderr is redirected
1123 ** to a file, so it is not a console, -1 is returned and
1124 ** nothing is written.
1125 */
1126 int fossil_utf8_to_console(const char *zUtf8, int nByte, int toStdErr){
1127 #ifdef _WIN32
1128 int nChar;
1129 WCHAR *zUnicode; /* Unicode version of zUtf8 */
1130 char *zConsole; /* Console version of zUtf8 */
1131 int codepage; /* Console code page */
1132
1133 static int once = 1;
1134 static int istty[2];
1135 if( once ){
1136 istty[0] = _isatty(fileno(stdout));
@@ -1150,28 +1149,12 @@
1150 nChar = MultiByteToWideChar(CP_UTF8, 0, zUtf8, nByte, zUnicode, nChar);
1151 if( nChar==0 ){
1152 free(zUnicode);
1153 return 0;
1154 }
1155 zUnicode[nChar] = '\0';
1156 codepage = GetConsoleCP();
1157 nByte = WideCharToMultiByte(codepage, 0, zUnicode, nChar, 0, 0, 0, 0);
1158 zConsole = malloc( nByte + 1);
1159 if( zConsole==0 ){
1160 free(zUnicode);
1161 return 0;
1162 }
1163 nByte = WideCharToMultiByte(codepage, 0, zUnicode, nChar, zConsole, nByte, 0, 0);
1164 zConsole[nByte] = '\0';
1165 free(zUnicode);
1166 if( nByte == 0 ){
1167 free(zConsole);
1168 zConsole = 0;
1169 return 0;
1170 }
1171 fwrite(zConsole, 1, nByte, toStdErr ? stderr : stdout);
1172 fflush(toStdErr ? stderr : stdout);
1173 return nChar;
1174 #else
1175 return -1; /* No-op on unix */
1176 #endif
1177 }
1178
--- src/file.c
+++ src/file.c
@@ -1118,19 +1118,18 @@
1118 }
1119
1120 /*
1121 ** Display UTF8 on the console. Return the number of
1122 ** Characters written. If stdout or stderr is redirected
1123 ** to a file, -1 is returned and ** nothing is written
1124 ** to the console.
1125 */
1126 int fossil_utf8_to_console(const char *zUtf8, int nByte, int toStdErr){
1127 #ifdef _WIN32
1128 int nChar;
1129 wchar_t *zUnicode; /* Unicode version of zUtf8 */
1130 DWORD dummy;
 
1131
1132 static int once = 1;
1133 static int istty[2];
1134 if( once ){
1135 istty[0] = _isatty(fileno(stdout));
@@ -1150,28 +1149,12 @@
1149 nChar = MultiByteToWideChar(CP_UTF8, 0, zUtf8, nByte, zUnicode, nChar);
1150 if( nChar==0 ){
1151 free(zUnicode);
1152 return 0;
1153 }
1154 zUnicode[nChar] = '\0';;
1155 WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE + toStdErr), zUnicode, nChar, &dummy, 0);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1156 return nChar;
1157 #else
1158 return -1; /* No-op on unix */
1159 #endif
1160 }
1161
+1 -1
--- src/printf.c
+++ src/printf.c
@@ -815,11 +815,11 @@
815815
** a file, no translation occurs. No translation ever occurs on unix.
816816
*/
817817
void fossil_puts(const char *z, int toStdErr){
818818
#if defined(_WIN32)
819819
if( fossil_utf8_to_console(z, strlen(z), toStdErr) >= 0 ){
820
- return;
820
+ return;
821821
}
822822
#endif
823823
assert( toStdErr==0 || toStdErr==1 );
824824
fwrite(z, 1, strlen(z), toStdErr ? stderr : stdout);
825825
fflush(toStdErr ? stderr : stdout);
826826
--- src/printf.c
+++ src/printf.c
@@ -815,11 +815,11 @@
815 ** a file, no translation occurs. No translation ever occurs on unix.
816 */
817 void fossil_puts(const char *z, int toStdErr){
818 #if defined(_WIN32)
819 if( fossil_utf8_to_console(z, strlen(z), toStdErr) >= 0 ){
820 return;
821 }
822 #endif
823 assert( toStdErr==0 || toStdErr==1 );
824 fwrite(z, 1, strlen(z), toStdErr ? stderr : stdout);
825 fflush(toStdErr ? stderr : stdout);
826
--- src/printf.c
+++ src/printf.c
@@ -815,11 +815,11 @@
815 ** a file, no translation occurs. No translation ever occurs on unix.
816 */
817 void fossil_puts(const char *z, int toStdErr){
818 #if defined(_WIN32)
819 if( fossil_utf8_to_console(z, strlen(z), toStdErr) >= 0 ){
820 return;
821 }
822 #endif
823 assert( toStdErr==0 || toStdErr==1 );
824 fwrite(z, 1, strlen(z), toStdErr ? stderr : stdout);
825 fflush(toStdErr ? stderr : stdout);
826

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button