Fossil SCM
Coding style changes to fossil_utf8_to_console().
Commit
484a39a7849a39a4fcc073adcda8f43beb9ec236
Parent
e7f7f79ce8e0933…
1 file changed
+14
-9
+14
-9
| --- src/utf8.c | ||
| +++ src/utf8.c | ||
| @@ -77,11 +77,11 @@ | ||
| 77 | 77 | ** used to store the returned pointer when done. |
| 78 | 78 | */ |
| 79 | 79 | void *fossil_utf8_to_unicode(const char *zUtf8){ |
| 80 | 80 | #if defined(_WIN32) || defined(__CYGWIN__) |
| 81 | 81 | 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 ); | |
| 83 | 83 | MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, zUnicode, nByte); |
| 84 | 84 | return zUnicode; |
| 85 | 85 | #else |
| 86 | 86 | assert( 0 ); /* Never used in unix */ |
| 87 | 87 | return fossil_strdup(zUtf8); /* TODO: implement for unix */ |
| @@ -304,11 +304,15 @@ | ||
| 304 | 304 | ** Display UTF-8 on the console. Return the number of |
| 305 | 305 | ** Characters written. If stdout or stderr is redirected |
| 306 | 306 | ** to a file, -1 is returned and nothing is written |
| 307 | 307 | ** to the console. |
| 308 | 308 | */ |
| 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 | +){ | |
| 310 | 314 | #ifdef _WIN32 |
| 311 | 315 | int nChar, written = 0; |
| 312 | 316 | wchar_t *zUnicode; /* Unicode version of zUtf8 */ |
| 313 | 317 | DWORD dummy; |
| 314 | 318 | Blob blob; |
| @@ -327,27 +331,28 @@ | ||
| 327 | 331 | */ |
| 328 | 332 | blob_init(&blob, zUtf8, nByte); |
| 329 | 333 | blob_to_utf8_no_bom(&blob, 1); |
| 330 | 334 | nChar = MultiByteToWideChar(CP_UTF8, 0, blob_buffer(&blob), |
| 331 | 335 | blob_size(&blob), NULL, 0); |
| 332 | - zUnicode = malloc( (nChar + 1) *sizeof(zUnicode[0]) ); | |
| 336 | + zUnicode = fossil_malloc( (nChar+1)*sizeof(zUnicode[0]) ); | |
| 333 | 337 | if( zUnicode==0 ){ |
| 334 | 338 | return 0; |
| 335 | 339 | } |
| 336 | 340 | nChar = MultiByteToWideChar(CP_UTF8, 0, blob_buffer(&blob), |
| 337 | 341 | blob_size(&blob), zUnicode, nChar); |
| 338 | 342 | blob_reset(&blob); |
| 339 | - /* Split WriteConsoleW call into multiple chunks, if necessary. See: | |
| 343 | + /* Split WriteConsoleW output into multiple chunks, if necessary. See: | |
| 340 | 344 | * <https://connect.microsoft.com/VisualStudio/feedback/details/635230> */ |
| 341 | - while( written < nChar ){ | |
| 345 | + while( written<nChar ){ | |
| 342 | 346 | 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); | |
| 346 | 351 | written += size; |
| 347 | 352 | } |
| 348 | - free(zUnicode); | |
| 353 | + fossil_free(zUnicode); | |
| 349 | 354 | return nChar; |
| 350 | 355 | #else |
| 351 | 356 | return -1; /* No-op on unix */ |
| 352 | 357 | #endif |
| 353 | 358 | } |
| 354 | 359 |
| --- 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 |