You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ad...@apache.org on 2017/04/20 01:07:29 UTC

[1/3] incubator-mynewt-core git commit: MYNEWT-734 console_printf() return # printed chrs.

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/master 31d00cb0a -> fd7bf2bf5


MYNEWT-734 console_printf() return # printed chrs.

The *printf family of functions do this. It is useful for aligning text.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/80fb08ca
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/80fb08ca
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/80fb08ca

Branch: refs/heads/master
Commit: 80fb08cac5ce1d56c7662b3e549acea6264b47f1
Parents: 31d00cb
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Apr 19 16:20:33 2017 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Wed Apr 19 16:34:01 2017 -0700

----------------------------------------------------------------------
 sys/console/full/include/console/console.h    |  2 +-
 sys/console/full/src/cons_fmt.c               | 40 +++++++++++++++++++---
 sys/console/minimal/include/console/console.h |  5 +--
 sys/console/stub/include/console/console.h    |  5 +--
 4 files changed, 42 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/80fb08ca/sys/console/full/include/console/console.h
----------------------------------------------------------------------
diff --git a/sys/console/full/include/console/console.h b/sys/console/full/include/console/console.h
index 054b997..c7ae04c 100644
--- a/sys/console/full/include/console/console.h
+++ b/sys/console/full/include/console/console.h
@@ -34,7 +34,7 @@ int console_read(char *str, int cnt, int *newline);
 void console_blocking_mode(void);
 void console_echo(int on);
 
-void console_printf(const char *fmt, ...)
+int console_printf(const char *fmt, ...)
     __attribute__ ((format (printf, 1, 2)));;
 
 extern int console_is_midline;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/80fb08ca/sys/console/full/src/cons_fmt.c
----------------------------------------------------------------------
diff --git a/sys/console/full/src/cons_fmt.c b/sys/console/full/src/cons_fmt.c
index 83c9ca0..1a3c72e 100644
--- a/sys/console/full/src/cons_fmt.c
+++ b/sys/console/full/src/cons_fmt.c
@@ -38,43 +38,73 @@ static const FILE console_file = {
     .vmt = &console_file_ops
 };
 
-void
+/**
+ * Prints the specified format string to the console.
+ *
+ * @return                      The number of characters that would have been
+ *                                  printed if the console buffer were
+ *                                  unlimited.  This return value is analogous
+ *                                  to that of snprintf.
+ */
+int
 console_printf(const char *fmt, ...)
 {
     va_list args;
+    int num_chars;
+
+    num_chars = 0;
+
     if (console_get_ticks()) {
         /* Prefix each line with a timestamp. */
         if (!console_is_midline) {
-            fprintf((FILE *)&console_file, "%lu:", (unsigned long)os_time_get());
+            num_chars += fprintf((FILE *)&console_file, "%lu:",
+                                 (unsigned long)os_time_get());
         }
     }
     va_start(args, fmt);
-    vfprintf((FILE *)&console_file, fmt, args);
+    num_chars += vfprintf((FILE *)&console_file, fmt, args);
     va_end(args);
+
+    return num_chars;
 }
 
 #else
 
-void
+/**
+ * Prints the specified format string to the console.
+ *
+ * @return                      The number of characters that would have been
+ *                                  printed if the console buffer were
+ *                                  unlimited.  This return value is analogous
+ *                                  to that of snprintf.
+ */
+int
 console_printf(const char *fmt, ...)
 {
     va_list args;
     char buf[CONS_OUTPUT_MAX_LINE];
+    int num_chars;
     int len;
+
     if (console_get_ticks()) {
         /* Prefix each line with a timestamp. */
         if (!console_is_midline) {
-            len = snprintf(buf, sizeof(buf), "%lu:", (unsigned long)os_time_get());
+            len = snprintf(buf, sizeof(buf), "%lu:",
+                           (unsigned long)os_time_get());
+            num_chars += len;
             console_write(buf, len);
         }
     }
 
     va_start(args, fmt);
     len = vsnprintf(buf, sizeof(buf), fmt, args);
+    num_chars += len;
     if (len >= sizeof(buf)) {
         len = sizeof(buf) - 1;
     }
     console_write(buf, len);
     va_end(args);
+
+    return num_chars;
 }
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/80fb08ca/sys/console/minimal/include/console/console.h
----------------------------------------------------------------------
diff --git a/sys/console/minimal/include/console/console.h b/sys/console/minimal/include/console/console.h
index 384b6a9..61f6534 100644
--- a/sys/console/minimal/include/console/console.h
+++ b/sys/console/minimal/include/console/console.h
@@ -46,11 +46,12 @@ console_echo(int on)
 {
 }
 
-static void console_printf(const char *fmt, ...)
+static int console_printf(const char *fmt, ...)
     __attribute__ ((format (printf, 1, 2)));;
-static void inline
+static int inline
 console_printf(const char *fmt, ...)
 {
+    return 0;
 }
 
 #define console_is_midline  0

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/80fb08ca/sys/console/stub/include/console/console.h
----------------------------------------------------------------------
diff --git a/sys/console/stub/include/console/console.h b/sys/console/stub/include/console/console.h
index ca7a1b9..3c83b9d 100644
--- a/sys/console/stub/include/console/console.h
+++ b/sys/console/stub/include/console/console.h
@@ -56,12 +56,13 @@ console_write(const char *str, int cnt)
 {
 }
 
-static void inline console_printf(const char *fmt, ...)
+static int inline console_printf(const char *fmt, ...)
     __attribute__ ((format (printf, 1, 2)));
 
-static void inline
+static int inline
 console_printf(const char *fmt, ...)
 {
+    return 0;
 }
 
 static void inline


[3/3] incubator-mynewt-core git commit: Merge branch 'console-num-chars' of https://github.com/ccollins476ad/incubator-mynewt-core

Posted by ad...@apache.org.
Merge branch 'console-num-chars' of https://github.com/ccollins476ad/incubator-mynewt-core

This closes #240. This closes #239.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/fd7bf2bf
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/fd7bf2bf
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/fd7bf2bf

Branch: refs/heads/master
Commit: fd7bf2bf59e0dba634b12acf6fde576cbb26c9d0
Parents: b83face 80fb08c
Author: aditihilbert <ad...@runtime.io>
Authored: Wed Apr 19 18:06:04 2017 -0700
Committer: aditihilbert <ad...@runtime.io>
Committed: Wed Apr 19 18:06:04 2017 -0700

----------------------------------------------------------------------
 sys/console/full/include/console/console.h    |  2 +-
 sys/console/full/src/cons_fmt.c               | 40 +++++++++++++++++++---
 sys/console/minimal/include/console/console.h |  5 +--
 sys/console/stub/include/console/console.h    |  5 +--
 4 files changed, 42 insertions(+), 10 deletions(-)
----------------------------------------------------------------------



[2/3] incubator-mynewt-core git commit: MYNEWT-735 tinyprintf: negative field width spec.

Posted by ad...@apache.org.
MYNEWT-735 tinyprintf: negative field width spec.

>From the printf(3) man page on my OS X:

 `-'          A negative field width flag; the converted value is to
              be left adjusted on the field boundary.  Except for n
              conversions, the converted value is padded on the right
              with blanks, rather than on the left with blanks or
              zeros.  A - overrides a 0 if both are given.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/b83face5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/b83face5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/b83face5

Branch: refs/heads/master
Commit: b83face5dfb740328c79081424fd2abdd9ca8d1d
Parents: 31d00cb
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Apr 19 16:30:27 2017 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Wed Apr 19 16:39:14 2017 -0700

----------------------------------------------------------------------
 libc/baselibc/src/tinyprintf.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b83face5/libc/baselibc/src/tinyprintf.c
----------------------------------------------------------------------
diff --git a/libc/baselibc/src/tinyprintf.c b/libc/baselibc/src/tinyprintf.c
index 7719d80..11bcf63 100644
--- a/libc/baselibc/src/tinyprintf.c
+++ b/libc/baselibc/src/tinyprintf.c
@@ -70,6 +70,7 @@ struct param {
     char sign:1;        /**<  The sign to display (if any) */
     char alt:1;         /**< alternate form */
     char uc:1;          /**<  Upper case (for base16 only) */
+    char left:1;        /**<  Force text to left (padding on right) */
     char base;  /**<  number base (e.g.: 8, 10, 16) */
     char *bf;           /**<  Buffer to output */
 };
@@ -155,8 +156,8 @@ static unsigned putchw(FILE *putp, struct param *p)
     else if (p->alt && p->base == 8)
         n--;
 
-    /* Fill with space, before alternate or sign */
-    if (!p->lz) {
+    /* Unless left-aligned, fill with space, before alternate or sign */
+    if (!p->lz && !p->left) {
         while (n-- > 0)
             written += putf(putp, ' ');
     }
@@ -183,6 +184,12 @@ static unsigned putchw(FILE *putp, struct param *p)
     bf = p->bf;
     while ((ch = *bf++))
         written += putf(putp, ch);
+
+    /* If left-aligned, pad the end with spaces. */
+    if (p->left) {
+        while (n-- > 0)
+            written += putf(putp, ' ');
+    }
     
     return written;
 }
@@ -246,17 +253,24 @@ size_t tfp_format(FILE *putp, const char *fmt, va_list va)
             p.alt = 0;
             p.width = 0;
             p.sign = 0;
+            p.left = 0;
             lng = 0;
 
             /* Flags */
             while ((ch = *(fmt++))) {
                 switch (ch) {
                 case '0':
-                    p.lz = 1;
+                    if (!p.left) {
+                        p.lz = 1;
+                    }
                     continue;
                 case '#':
                     p.alt = 1;
                     continue;
+                case '-':
+                    p.left = 1;
+                    p.lz = 0;
+                    continue;
                 default:
                     break;
                 }