summaryrefslogtreecommitdiff
path: root/gpsmon.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2015-02-24 13:02:28 -0500
committerEric S. Raymond <esr@thyrsus.com>2015-02-24 13:02:55 -0500
commit0fdf858fa62cdd419dd31dacdb122f9d7b04b29b (patch)
tree2bbf62b723d5de0783a35336c8baf764dacd6ce7 /gpsmon.c
parentce98082321cedfd9c033d6bcaa6ac1b7bf0876d7 (diff)
downloadgpsd-0fdf858fa62cdd419dd31dacdb122f9d7b04b29b.tar.gz
In gpsmon, repair PPSBAR emission.
Diffstat (limited to 'gpsmon.c')
-rw-r--r--gpsmon.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/gpsmon.c b/gpsmon.c
index 1b3a6ae3..2e6f7298 100644
--- a/gpsmon.c
+++ b/gpsmon.c
@@ -168,6 +168,21 @@ static inline void report_unlock(void) { }
*
******************************************************************************/
+static void visibilize(/*@out@*/char *buf2, size_t len2, const char *buf)
+/* string is mostly printable, dress up the nonprintables a bit */
+{
+ const char *sp;
+
+ buf2[0] = '\0';
+ for (sp = buf; *sp != '\0' && strlen(buf2)+4 < len2; sp++)
+ if (isprint((unsigned char) *sp) || (sp[0] == '\n' && sp[1] == '\0')
+ || (sp[0] == '\r' && sp[2] == '\0'))
+ (void)snprintf(buf2 + strlen(buf2), 2, "%c", *sp);
+ else
+ (void)snprintf(buf2 + strlen(buf2), 6, "\\x%02x",
+ (unsigned)(*sp & 0xff));
+}
+
/*@-compdef -mustdefine@*/
static void cond_hexdump(/*@out@*/char *buf2, size_t len2,
const char *buf, size_t len)
@@ -243,7 +258,6 @@ static void gpsmon_report(const char *buf)
/* log to the packet window if curses is up, otherwise stdout */
{
/* report locking is left to caller */
- assert(buf[0] != '\0' && buf[0] != '\n');
if (!curses_active)
(void)fputs(buf, stdout);
else if (packetwin != NULL)
@@ -257,9 +271,11 @@ static void gpsmon_report(const char *buf)
/*@-compdef@*/
static void packet_vlog(/*@out@*/char *buf, size_t len, const char *fmt, va_list ap)
{
- char buf2[len * 2];
+ char buf2[BUFSIZ];
+
+ visibilize(buf2, sizeof(buf2), buf);
+
report_lock();
- cond_hexdump(buf2, len * 2, buf, len);
(void)vsnprintf(buf2 + strlen(buf2), len, fmt, ap);
gpsmon_report(buf2);
report_unlock();