diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2015-02-24 13:02:28 -0500 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2015-02-24 13:02:55 -0500 |
commit | 0fdf858fa62cdd419dd31dacdb122f9d7b04b29b (patch) | |
tree | 2bbf62b723d5de0783a35336c8baf764dacd6ce7 /gpsmon.c | |
parent | ce98082321cedfd9c033d6bcaa6ac1b7bf0876d7 (diff) | |
download | gpsd-0fdf858fa62cdd419dd31dacdb122f9d7b04b29b.tar.gz |
In gpsmon, repair PPSBAR emission.
Diffstat (limited to 'gpsmon.c')
-rw-r--r-- | gpsmon.c | 22 |
1 files changed, 19 insertions, 3 deletions
@@ -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(); |