You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ja...@apache.org on 2017/04/26 22:41:09 UTC
[21/50] [abbrv] incubator-mynewt-core git commit: MYNEWT-734
console_printf() return # printed chrs.
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/bluetooth5
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