From f9bc2c5cb1dd5fc1f287b034812c5bccb909e7df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=90=E4=BD=90=E6=9E=97?= Date: Thu, 7 Oct 2021 14:04:12 +0000 Subject: [PATCH] update lite-python/lib/utils/stdout.c. --- lite-python/lib/utils/stdout.c | 45 ++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/lite-python/lib/utils/stdout.c b/lite-python/lib/utils/stdout.c index e3b202c..87e730c 100755 --- a/lite-python/lib/utils/stdout.c +++ b/lite-python/lib/utils/stdout.c @@ -26,37 +26,44 @@ SOFTWARE. *****************************************************************************/ +#include #include #include #include "py/mpconfig.h" #include "py/mphal.h" -// Send string of given length -void mp_hal_stdout_tx_strn(const char* str, size_t len) -{ - extern int putchar(int ch); +static void mp_hal_stdout_print_native(const char* str, size_t len) +{ + int i = 0; - while( len-- ) - { - putchar(*str++); - } -} - -void mp_hal_stdout_tx_strn_cooked(const char* str, size_t len) -{ - while( len-- ) + while( i < len ) { - if( *str == '\n' ) + if( str[i] == '\r' ) { - mp_hal_stdout_tx_strn("\r", 1); + putchar('\r'); + putchar('\n'); + + if( (str[i+1] == '\n') || (str[i+1] == '\0') ) + { + i++; + } + } + else if( str[i] == '\n' ) + { + putchar('\r'); + putchar('\n'); + } + else + { + putchar(str[i]); } - mp_hal_stdout_tx_strn(str++, 1); + i++; } } -// Send zero-terminated string -void mp_hal_stdout_tx_str(const char *str) +void mp_hal_stdout_tx_strn_cooked(const char* str, size_t len) { - mp_hal_stdout_tx_strn(str, strlen(str)); + mp_hal_stdout_print_native(str, len); } + -- Gitee