Fossil SCM

Coding style changes to fossil_utf8_to_console().

mistachkin 2015-07-11 22:28 trunk
Commit 484a39a7849a39a4fcc073adcda8f43beb9ec236
1 file changed +14 -9
+14 -9
--- src/utf8.c
+++ src/utf8.c
@@ -77,11 +77,11 @@
7777
** used to store the returned pointer when done.
7878
*/
7979
void *fossil_utf8_to_unicode(const char *zUtf8){
8080
#if defined(_WIN32) || defined(__CYGWIN__)
8181
int nByte = MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, 0, 0);
82
- wchar_t *zUnicode = fossil_malloc( nByte * 2 );
82
+ wchar_t *zUnicode = fossil_malloc( nByte*2 );
8383
MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, zUnicode, nByte);
8484
return zUnicode;
8585
#else
8686
assert( 0 ); /* Never used in unix */
8787
return fossil_strdup(zUtf8); /* TODO: implement for unix */
@@ -304,11 +304,15 @@
304304
** Display UTF-8 on the console. Return the number of
305305
** Characters written. If stdout or stderr is redirected
306306
** to a file, -1 is returned and nothing is written
307307
** to the console.
308308
*/
309
-int fossil_utf8_to_console(const char *zUtf8, int nByte, int toStdErr){
309
+int fossil_utf8_to_console(
310
+ const char *zUtf8,
311
+ int nByte,
312
+ int toStdErr
313
+){
310314
#ifdef _WIN32
311315
int nChar, written = 0;
312316
wchar_t *zUnicode; /* Unicode version of zUtf8 */
313317
DWORD dummy;
314318
Blob blob;
@@ -327,27 +331,28 @@
327331
*/
328332
blob_init(&blob, zUtf8, nByte);
329333
blob_to_utf8_no_bom(&blob, 1);
330334
nChar = MultiByteToWideChar(CP_UTF8, 0, blob_buffer(&blob),
331335
blob_size(&blob), NULL, 0);
332
- zUnicode = malloc( (nChar + 1) *sizeof(zUnicode[0]) );
336
+ zUnicode = fossil_malloc( (nChar+1)*sizeof(zUnicode[0]) );
333337
if( zUnicode==0 ){
334338
return 0;
335339
}
336340
nChar = MultiByteToWideChar(CP_UTF8, 0, blob_buffer(&blob),
337341
blob_size(&blob), zUnicode, nChar);
338342
blob_reset(&blob);
339
- /* Split WriteConsoleW call into multiple chunks, if necessary. See:
343
+ /* Split WriteConsoleW output into multiple chunks, if necessary. See:
340344
* <https://connect.microsoft.com/VisualStudio/feedback/details/635230> */
341
- while( written < nChar ){
345
+ while( written<nChar ){
342346
int size = nChar-written;
343
- if( size > 26000 ) size = 26000;
344
- WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE - toStdErr), zUnicode+written,
345
- size, &dummy, 0);
347
+ if( size>26000 ) size = 26000;
348
+ WriteConsoleW(GetStdHandle(
349
+ toStdErr ? STD_ERROR_HANDLE : STD_OUTPUT_HANDLE),
350
+ zUnicode + written, size, &dummy, 0);
346351
written += size;
347352
}
348
- free(zUnicode);
353
+ fossil_free(zUnicode);
349354
return nChar;
350355
#else
351356
return -1; /* No-op on unix */
352357
#endif
353358
}
354359
--- src/utf8.c
+++ src/utf8.c
@@ -77,11 +77,11 @@
77 ** used to store the returned pointer when done.
78 */
79 void *fossil_utf8_to_unicode(const char *zUtf8){
80 #if defined(_WIN32) || defined(__CYGWIN__)
81 int nByte = MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, 0, 0);
82 wchar_t *zUnicode = fossil_malloc( nByte * 2 );
83 MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, zUnicode, nByte);
84 return zUnicode;
85 #else
86 assert( 0 ); /* Never used in unix */
87 return fossil_strdup(zUtf8); /* TODO: implement for unix */
@@ -304,11 +304,15 @@
304 ** Display UTF-8 on the console. Return the number of
305 ** Characters written. If stdout or stderr is redirected
306 ** to a file, -1 is returned and nothing is written
307 ** to the console.
308 */
309 int fossil_utf8_to_console(const char *zUtf8, int nByte, int toStdErr){
 
 
 
 
310 #ifdef _WIN32
311 int nChar, written = 0;
312 wchar_t *zUnicode; /* Unicode version of zUtf8 */
313 DWORD dummy;
314 Blob blob;
@@ -327,27 +331,28 @@
327 */
328 blob_init(&blob, zUtf8, nByte);
329 blob_to_utf8_no_bom(&blob, 1);
330 nChar = MultiByteToWideChar(CP_UTF8, 0, blob_buffer(&blob),
331 blob_size(&blob), NULL, 0);
332 zUnicode = malloc( (nChar + 1) *sizeof(zUnicode[0]) );
333 if( zUnicode==0 ){
334 return 0;
335 }
336 nChar = MultiByteToWideChar(CP_UTF8, 0, blob_buffer(&blob),
337 blob_size(&blob), zUnicode, nChar);
338 blob_reset(&blob);
339 /* Split WriteConsoleW call into multiple chunks, if necessary. See:
340 * <https://connect.microsoft.com/VisualStudio/feedback/details/635230> */
341 while( written < nChar ){
342 int size = nChar-written;
343 if( size > 26000 ) size = 26000;
344 WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE - toStdErr), zUnicode+written,
345 size, &dummy, 0);
 
346 written += size;
347 }
348 free(zUnicode);
349 return nChar;
350 #else
351 return -1; /* No-op on unix */
352 #endif
353 }
354
--- src/utf8.c
+++ src/utf8.c
@@ -77,11 +77,11 @@
77 ** used to store the returned pointer when done.
78 */
79 void *fossil_utf8_to_unicode(const char *zUtf8){
80 #if defined(_WIN32) || defined(__CYGWIN__)
81 int nByte = MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, 0, 0);
82 wchar_t *zUnicode = fossil_malloc( nByte*2 );
83 MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, zUnicode, nByte);
84 return zUnicode;
85 #else
86 assert( 0 ); /* Never used in unix */
87 return fossil_strdup(zUtf8); /* TODO: implement for unix */
@@ -304,11 +304,15 @@
304 ** Display UTF-8 on the console. Return the number of
305 ** Characters written. If stdout or stderr is redirected
306 ** to a file, -1 is returned and nothing is written
307 ** to the console.
308 */
309 int fossil_utf8_to_console(
310 const char *zUtf8,
311 int nByte,
312 int toStdErr
313 ){
314 #ifdef _WIN32
315 int nChar, written = 0;
316 wchar_t *zUnicode; /* Unicode version of zUtf8 */
317 DWORD dummy;
318 Blob blob;
@@ -327,27 +331,28 @@
331 */
332 blob_init(&blob, zUtf8, nByte);
333 blob_to_utf8_no_bom(&blob, 1);
334 nChar = MultiByteToWideChar(CP_UTF8, 0, blob_buffer(&blob),
335 blob_size(&blob), NULL, 0);
336 zUnicode = fossil_malloc( (nChar+1)*sizeof(zUnicode[0]) );
337 if( zUnicode==0 ){
338 return 0;
339 }
340 nChar = MultiByteToWideChar(CP_UTF8, 0, blob_buffer(&blob),
341 blob_size(&blob), zUnicode, nChar);
342 blob_reset(&blob);
343 /* Split WriteConsoleW output into multiple chunks, if necessary. See:
344 * <https://connect.microsoft.com/VisualStudio/feedback/details/635230> */
345 while( written<nChar ){
346 int size = nChar-written;
347 if( size>26000 ) size = 26000;
348 WriteConsoleW(GetStdHandle(
349 toStdErr ? STD_ERROR_HANDLE : STD_OUTPUT_HANDLE),
350 zUnicode + written, size, &dummy, 0);
351 written += size;
352 }
353 fossil_free(zUnicode);
354 return nChar;
355 #else
356 return -1; /* No-op on unix */
357 #endif
358 }
359

Keyboard Shortcuts

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