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 /win32 | |
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
Diffstat (limited to 'win32')
-rw-r--r-- | win32/winansi.c | 28 |
1 files changed, 24 insertions, 4 deletions
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; |