summaryrefslogtreecommitdiff
path: root/hex.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2011-06-17 11:37:39 -0400
committerEric S. Raymond <esr@thyrsus.com>2011-06-17 11:37:39 -0400
commit0e0f7f0b7c6c658259f09152ff8326f05b81b271 (patch)
treeb2587f05a9a1ab49eb9a6a299e8844dc741e32df /hex.c
parent607cdcca3ec69f74245b06cbb147e2435360d190 (diff)
downloadgpsd-0e0f7f0b7c6c658259f09152ff8326f05b81b271.tar.gz
Improve the code for making sensor data and command strings visible...
...and remove some const declarations that could have spelled trouble in the future.
Diffstat (limited to 'hex.c')
-rw-r--r--hex.c43
1 files changed, 24 insertions, 19 deletions
diff --git a/hex.c b/hex.c
index 5c6d9a38..04eae847 100644
--- a/hex.c
+++ b/hex.c
@@ -3,34 +3,39 @@
* BSD terms apply: see the file COPYING in the distribution root for details.
*/
#include <string.h>
+#include <ctype.h>
#include "gpsd.h"
-char /*@ observer @*/ *gpsd_hexdump(const void *binbuf, size_t binbuflen)
+char /*@ observer @*/ *gpsd_hexdump(char *binbuf, size_t binbuflen)
{
- static char hexbuf[MAX_PACKET_LENGTH * 2 + 1];
+ if (isprint(binbuf[binbuflen-1]))
+ return binbuf;
+ else {
+ static char hexbuf[MAX_PACKET_LENGTH * 2 + 1];
#ifndef SQUELCH_ENABLE
- size_t i, j = 0;
- size_t len =
- (size_t) ((binbuflen >
- MAX_PACKET_LENGTH) ? MAX_PACKET_LENGTH : binbuflen);
- const char *ibuf = (const char *)binbuf;
- const char *hexchar = "0123456789abcdef";
+ size_t i, j = 0;
+ size_t len =
+ (size_t) ((binbuflen >
+ MAX_PACKET_LENGTH) ? MAX_PACKET_LENGTH : binbuflen);
+ const char *ibuf = (const char *)binbuf;
+ const char *hexchar = "0123456789abcdef";
- if (NULL == binbuf || 0 == binbuflen)
- return "";
+ if (NULL == binbuf || 0 == binbuflen)
+ return "";
- /*@ -shiftimplementation @*/
- for (i = 0; i < len; i++) {
- hexbuf[j++] = hexchar[(ibuf[i] & 0xf0) >> 4];
- hexbuf[j++] = hexchar[ibuf[i] & 0x0f];
- }
- /*@ +shiftimplementation @*/
- hexbuf[j] = '\0';
+ /*@ -shiftimplementation @*/
+ for (i = 0; i < len; i++) {
+ hexbuf[j++] = hexchar[(ibuf[i] & 0xf0) >> 4];
+ hexbuf[j++] = hexchar[ibuf[i] & 0x0f];
+ }
+ /*@ +shiftimplementation @*/
+ hexbuf[j] = '\0';
#else /* SQUELCH defined */
- hexbuf[0] = '\0';
+ hexbuf[0] = '\0';
#endif /* SQUELCH_ENABLE */
- return hexbuf;
+ return hexbuf;
+ }
}
int gpsd_hexpack( /*@in@*/ const char *src, /*@out@ */ char *dst, size_t len)