From 867c7c95aa67ea1f19286c3593500214101bacd9 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 5 Sep 2013 09:01:21 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6262 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/various/chprintf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/various/chprintf.c') diff --git a/os/various/chprintf.c b/os/various/chprintf.c index d712b98ab..787b6c7ab 100644 --- a/os/various/chprintf.c +++ b/os/various/chprintf.c @@ -109,7 +109,7 @@ void chprintf(BaseSequentialStream *chp, const char *fmt, ...) { va_list ap; char *p, *s, c, filler; int i, precision, width; - bool_t is_long, left_align; + bool is_long, left_align; long l; #if CHPRINTF_USE_FLOAT float f; -- cgit v1.2.3 From b6146e1fe402c875d6c4469ab6fec58715317b8a Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 12 Nov 2013 13:44:26 +0000 Subject: Added chvprintf() function to the chprintf module. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6471 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/various/chprintf.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'os/various/chprintf.c') diff --git a/os/various/chprintf.c b/os/various/chprintf.c index 787b6c7ab..ffb6650f8 100644 --- a/os/various/chprintf.c +++ b/os/various/chprintf.c @@ -13,8 +13,10 @@ See the License for the specific language governing permissions and limitations under the License. */ + /* - Concepts and parts of this file have been contributed by Fabio Utzig. + Concepts and parts of this file have been contributed by Fabio Utzig, + chvprintf() added by Brent Roman. */ /** @@ -25,8 +27,6 @@ * @{ */ -#include - #include "ch.h" #include "chprintf.h" @@ -86,7 +86,7 @@ static char *ftoa(char *p, double num) { /** * @brief System formatted output function. - * @details This function implements a minimal @p printf() like functionality + * @details This function implements a minimal @p vprintf()-like functionality * with output on a @p BaseSequentialStream. * The general parameters format is: %[-][width|*][.precision|*][l|L]p. * The following parameter types (p) are supported: @@ -104,9 +104,11 @@ static char *ftoa(char *p, double num) { * * @param[in] chp pointer to a @p BaseSequentialStream implementing object * @param[in] fmt formatting string + * @param[in] ap list of parameters + * + * @api */ -void chprintf(BaseSequentialStream *chp, const char *fmt, ...) { - va_list ap; +void chvprintf(BaseSequentialStream *chp, const char *fmt, va_list ap) { char *p, *s, c, filler; int i, precision, width; bool is_long, left_align; @@ -118,13 +120,10 @@ void chprintf(BaseSequentialStream *chp, const char *fmt, ...) { char tmpbuf[MAX_FILLER + 1]; #endif - va_start(ap, fmt); while (TRUE) { c = *fmt++; - if (c == 0) { - va_end(ap); + if (c == 0) return; - } if (c != '%') { chSequentialStreamPut(chp, (uint8_t)c); continue; -- cgit v1.2.3 From 130e3be57409f06dd395ef8626bf848097ea1b79 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 3 Dec 2013 09:36:46 +0000 Subject: chsnprintf() implementation added. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6528 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/various/chprintf.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'os/various/chprintf.c') diff --git a/os/various/chprintf.c b/os/various/chprintf.c index ffb6650f8..190a7defa 100644 --- a/os/various/chprintf.c +++ b/os/various/chprintf.c @@ -29,6 +29,7 @@ #include "ch.h" #include "chprintf.h" +#include "memstreams.h" #define MAX_FILLER 11 #define FLOAT_PRECISION 100000 @@ -259,4 +260,48 @@ unsigned_common: } } +/** + * @brief System formatted output function. + * @details This function implements a minimal @p vprintf()-like functionality + * with output on a @p BaseSequentialStream. + * The general parameters format is: %[-][width|*][.precision|*][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. + * . + * + * @param[in] str pointer to a buffer + * @param[in] size maximum size of the buffer + * @param[in] fmt formatting string + * @param[in] ap list of parameters + * + * @api + */ +int chsnprintf(char *str, size_t size, const char *fmt, ...) { + va_list ap; + MemoryStream ms; + BaseSequentialStream *chp; + + /* Memory stream object to be used as a string writer.*/ + msObjectInit(&ms, (uint8_t *)str, size, 0); + + /* Performing the print operation using the common code.*/ + chp = (BaseSequentialStream *)&ms; + va_start(ap, fmt); + chvprintf(chp, fmt, ap); + va_end(ap); + + /* Final zero and size return.*/ + chSequentialStreamPut(chp, 0); + return ms.eos - 1; +} + /** @} */ -- cgit v1.2.3 From fa017d8b3f8a01076e70c957e7fb1681ea36abf8 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 9 Feb 2014 08:44:55 +0000 Subject: Fixed a warning in chprintf() using the IAR compiler. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6679 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/various/chprintf.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'os/various/chprintf.c') diff --git a/os/various/chprintf.c b/os/various/chprintf.c index 190a7defa..0feee72c3 100644 --- a/os/various/chprintf.c +++ b/os/various/chprintf.c @@ -77,10 +77,10 @@ static char *ftoa(char *p, double num) { long l; unsigned long precision = FLOAT_PRECISION; - l = num; + l = (long)num; p = long_to_string_with_divisor(p, l, 10, 0); *p++ = '.'; - l = (num - l) * precision; + l = (long)((num - l) * precision); return long_to_string_with_divisor(p, l, 10, precision / 10); } #endif @@ -250,8 +250,8 @@ unsigned_common: chSequentialStreamPut(chp, (uint8_t)filler); while (++width != 0); } - while (--i >= 0) - chSequentialStreamPut(chp, (uint8_t)*s++); + chSequentialStreamWrite(chp, (uint8_t*)s, i); + s += i; while (width) { chSequentialStreamPut(chp, (uint8_t)filler); @@ -281,7 +281,7 @@ unsigned_common: * @param[in] str pointer to a buffer * @param[in] size maximum size of the buffer * @param[in] fmt formatting string - * @param[in] ap list of parameters + * @return The size of the generated string. * * @api */ -- cgit v1.2.3 From 5ba4cc9696ec19eb91db95df83b206ba05337c70 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 22 Apr 2014 11:22:06 +0000 Subject: Fixed bug #472. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6879 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/various/chprintf.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'os/various/chprintf.c') diff --git a/os/various/chprintf.c b/os/various/chprintf.c index 0feee72c3..78453f52b 100644 --- a/os/various/chprintf.c +++ b/os/various/chprintf.c @@ -246,12 +246,12 @@ unsigned_common: chSequentialStreamPut(chp, (uint8_t)*s++); i--; } - do + do { chSequentialStreamPut(chp, (uint8_t)filler); - while (++width != 0); + } while (++width != 0); } - chSequentialStreamWrite(chp, (uint8_t*)s, i); - s += i; + while (--i >= 0) + chSequentialStreamPut(chp, (uint8_t)*s++); while (width) { chSequentialStreamPut(chp, (uint8_t)filler); -- cgit v1.2.3