From ec1d598148bd2e277a5d706ed4ed8658336a734b Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Wed, 16 May 2012 11:23:03 +0200 Subject: [PATCH] Precision (printf("%.Ns", text1)) not supported by all compilers, for example some versions of avrgcc and mspgcc. --- apps/serial-shell/serial-shell.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/apps/serial-shell/serial-shell.c b/apps/serial-shell/serial-shell.c index c605de4ec..024f2405a 100644 --- a/apps/serial-shell/serial-shell.c +++ b/apps/serial-shell/serial-shell.c @@ -32,8 +32,6 @@ * SUCH DAMAGE. * * This file is part of the Contiki operating system. - * - * $Id: serial-shell.c,v 1.5 2009/03/17 15:56:32 adamdunkels Exp $ */ /** @@ -59,6 +57,7 @@ PROCESS(serial_shell_process, "Contiki serial shell"); void shell_default_output(const char *text1, int len1, const char *text2, int len2) { + int i; if(text1 == NULL) { text1 = ""; len1 = 0; @@ -68,13 +67,15 @@ shell_default_output(const char *text1, int len1, const char *text2, int len2) len2 = 0; } - /* Workaround for absence of "%.*s" format in avr-libc */ -#if defined (__AVR__) - printf("%s %s\r\n", text1, text2); -#else - printf("%.*s%.*s\r\n", len1, text1, len2, text2); -#endif - + /* Precision (printf("%.Ns", text1)) not supported on all platforms. + putchar(c) not be supported on all platforms. */ + for(i = 0; i < len1; i++) { + printf("%c", text1[i]); + } + for(i = 0; i < len2; i++) { + printf("%c", text2[i]); + } + printf("\r\n"); } /*---------------------------------------------------------------------------*/ void @@ -94,12 +95,12 @@ PROCESS_THREAD(serial_shell_process, ev, data) PROCESS_BEGIN(); shell_init(); - + while(1) { PROCESS_WAIT_EVENT_UNTIL(ev == serial_line_event_message && data != NULL); shell_input(data, strlen(data)); } - + PROCESS_END(); } /*---------------------------------------------------------------------------*/