diff options
| author | Ron Yorston <rmy@pobox.com> | 2014-03-19 21:16:23 +0000 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2014-03-19 21:16:23 +0000 |
| commit | ec386adabb3e6b83ecd8e0429eb75dc431b65c40 (patch) | |
| tree | eb8e347ead727537223e6dbf81c4cd12a9627a09 | |
| parent | 114ddd900acf9de27cc9e651d0af26df3948d34f (diff) | |
| download | busybox-w32-ec386adabb3e6b83ecd8e0429eb75dc431b65c40.tar.gz busybox-w32-ec386adabb3e6b83ecd8e0429eb75dc431b65c40.tar.bz2 busybox-w32-ec386adabb3e6b83ecd8e0429eb75dc431b65c40.zip | |
Implement puts replacement to handle OEM codepages
| -rw-r--r-- | include/mingw.h | 2 | ||||
| -rw-r--r-- | win32/winansi.c | 28 |
2 files changed, 26 insertions, 4 deletions
diff --git a/include/mingw.h b/include/mingw.h index a1a9f5f30..23472e1b1 100644 --- a/include/mingw.h +++ b/include/mingw.h | |||
| @@ -141,11 +141,13 @@ int mingw_pclose(FILE *fd); | |||
| 141 | */ | 141 | */ |
| 142 | 142 | ||
| 143 | int winansi_putchar(int c); | 143 | int winansi_putchar(int c); |
| 144 | int winansi_puts(const char *s); | ||
| 144 | size_t winansi_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream); | 145 | size_t winansi_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream); |
| 145 | int winansi_fputs(const char *str, FILE *stream); | 146 | int winansi_fputs(const char *str, FILE *stream); |
| 146 | int winansi_printf(const char *format, ...) __attribute__((format (printf, 1, 2))); | 147 | int winansi_printf(const char *format, ...) __attribute__((format (printf, 1, 2))); |
| 147 | int winansi_fprintf(FILE *stream, const char *format, ...) __attribute__((format (printf, 2, 3))); | 148 | int winansi_fprintf(FILE *stream, const char *format, ...) __attribute__((format (printf, 2, 3))); |
| 148 | #define putchar winansi_putchar | 149 | #define putchar winansi_putchar |
| 150 | #define puts winansi_puts | ||
| 149 | #define fwrite winansi_fwrite | 151 | #define fwrite winansi_fwrite |
| 150 | #define fputs winansi_fputs | 152 | #define fputs winansi_fputs |
| 151 | #define printf(...) winansi_printf(__VA_ARGS__) | 153 | #define printf(...) winansi_printf(__VA_ARGS__) |
diff --git a/win32/winansi.c b/win32/winansi.c index cafad031d..ba3167425 100644 --- a/win32/winansi.c +++ b/win32/winansi.c | |||
| @@ -14,6 +14,7 @@ | |||
| 14 | #undef fputs | 14 | #undef fputs |
| 15 | #undef putchar | 15 | #undef putchar |
| 16 | #undef fwrite | 16 | #undef fwrite |
| 17 | #undef puts | ||
| 17 | /* TODO: write */ | 18 | /* TODO: write */ |
| 18 | 19 | ||
| 19 | /* | 20 | /* |
| @@ -314,19 +315,20 @@ static const char *set_attr(const char *str) | |||
| 314 | static int ansi_emulate(const char *s, FILE *stream) | 315 | static int ansi_emulate(const char *s, FILE *stream) |
| 315 | { | 316 | { |
| 316 | int rv = 0; | 317 | int rv = 0; |
| 318 | const char *t; | ||
| 317 | char *pos, *str; | 319 | char *pos, *str; |
| 318 | size_t out_len, cur_len; | 320 | size_t out_len, cur_len; |
| 319 | static size_t max_len = 0; | 321 | static size_t max_len = 0; |
| 320 | static char *mem = NULL; | 322 | static char *mem = NULL; |
| 321 | 323 | ||
| 322 | /* if no special treatment is required output the string as-is */ | 324 | /* if no special treatment is required output the string as-is */ |
| 323 | for ( pos=s; *pos; ++pos ) { | 325 | for ( t=s; *t; ++t ) { |
| 324 | if ( *pos == '\033' || *pos > 0x7f ) { | 326 | if ( *t == '\033' || *t > 0x7f ) { |
| 325 | break; | 327 | break; |
| 326 | } | 328 | } |
| 327 | } | 329 | } |
| 328 | 330 | ||
| 329 | if ( *pos == '\0' ) { | 331 | if ( *t == '\0' ) { |
| 330 | return fputs(s, stream) == EOF ? EOF : strlen(s); | 332 | return fputs(s, stream) == EOF ? EOF : strlen(s); |
| 331 | } | 333 | } |
| 332 | 334 | ||
| @@ -378,7 +380,7 @@ int winansi_putchar(int c) | |||
| 378 | char t = c; | 380 | char t = c; |
| 379 | char *s = &t; | 381 | char *s = &t; |
| 380 | 382 | ||
| 381 | if (!isatty(0)) | 383 | if (!isatty(STDOUT_FILENO)) |
| 382 | return putchar(c); | 384 | return putchar(c); |
| 383 | 385 | ||
| 384 | init(); | 386 | init(); |
| @@ -390,6 +392,24 @@ int winansi_putchar(int c) | |||
| 390 | return putchar(t) == EOF ? EOF : c; | 392 | return putchar(t) == EOF ? EOF : c; |
| 391 | } | 393 | } |
| 392 | 394 | ||
| 395 | int winansi_puts(const char *s) | ||
| 396 | { | ||
| 397 | int rv; | ||
| 398 | |||
| 399 | if (!isatty(STDOUT_FILENO)) | ||
| 400 | return puts(s); | ||
| 401 | |||
| 402 | init(); | ||
| 403 | |||
| 404 | if (!console) | ||
| 405 | return puts(s); | ||
| 406 | |||
| 407 | rv = ansi_emulate(s, stdout); | ||
| 408 | putchar('\n'); | ||
| 409 | |||
| 410 | return rv; | ||
| 411 | } | ||
| 412 | |||
| 393 | size_t winansi_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) | 413 | size_t winansi_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) |
| 394 | { | 414 | { |
| 395 | size_t lsize, lmemb; | 415 | size_t lsize, lmemb; |
