From ddc9ded3f065d8da59a843390814b1c19061c566 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 28 Jun 2011 06:29:04 +0000 Subject: chprintf() implemented, improved the shell. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3093 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/various/chprintf.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'os/various/chprintf.c') diff --git a/os/various/chprintf.c b/os/various/chprintf.c index 383a2121a..1645cd678 100644 --- a/os/various/chprintf.c +++ b/os/various/chprintf.c @@ -45,6 +45,29 @@ static char *ltoa(char *p, long num, unsigned radix) { return p; } +/** + * @brief System formatted output function. + * @details This function implements a minimal @p printf() like functionality + * with output on a @p BaseChannel. + * The general parameters format is: %[.][width|*][l|L]p. + * The following parameter types (p) are supported: + * - x hexadecimal integer. + * - X hexadecimal long. + * - o octal integer. + * - O octal long. + * - d decimal signed integer. + * - D decimal signed long. + * - u decimal unsigned integer. + * - U decimal unsigned long. + * - c character. + * - s string. + * . + * @note Floating point types are not implemented, this function is meant + * as a system utility and not a full implementation. + * + * @param[in] chp pointer to a @p BaseChannel implementing object + * @param[in] fmt formatting string + */ void chprintf(BaseChannel *chp, const char *fmt, ...) { va_list ap; char buf[MAX_FILLER + 1]; @@ -84,8 +107,7 @@ void chprintf(BaseChannel *chp, const char *fmt, ...) { c = va_arg(ap, int); else break; - width *= 10; - width += c; + width = width * 10 + c; } n = 0; if (c == '.') { @@ -122,7 +144,8 @@ void chprintf(BaseChannel *chp, const char *fmt, ...) { lflag = TRUE; case 'o': c = 8; - oxu: if (lflag) +oxu: + if (lflag) l = va_arg(ap, long); else l = va_arg(ap, int); -- cgit v1.2.3