From 52e55e8db7b0428ee78fab1475f9d92b257a29f6 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Fri, 30 Jan 2009 09:56:13 +0000 Subject: Make hex_escapes() generally available. --- Makefile.am | 2 +- gpsctl.c | 71 ------------------------------------------------------------- gpsd.h-tail | 1 + hex.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 72 deletions(-) diff --git a/Makefile.am b/Makefile.am index 196d6d66..31393bb9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -81,7 +81,7 @@ gpsd_LDADD = $(DBUS_LIBS) $(LIBM) libgps.la -lm $(LIBPTHREAD) # Build gpsctl # gpsctl_SOURCES = gpsctl.c -gpsctl_LDADD = $(LIBM) libgps.la -lm $(LIBPTHREAD) +gpsctl_LDADD = $(LIBM) libgps.la -lm $(LIBPTHREAD) $(NCURSES_LIBS) # # Build gpspipe diff --git a/gpsctl.c b/gpsctl.c index 2064f21a..6069492d 100644 --- a/gpsctl.c +++ b/gpsctl.c @@ -51,77 +51,6 @@ static gps_mask_t get_packet(struct gps_device_t *session) } /*@ +noret @*/ -static ssize_t hex_escapes(/*@out@*/char *cooked, const char *raw) -/* interpret C-style hex escapes */ -{ - char c, *cookend; - - /*@ +charint -mustdefine -compdef @*/ - for (cookend = cooked; *raw != '\0'; raw++) - if (*raw != '\\') - *cookend++ = *raw; - else { - switch(*++raw) { - case 'b': *cookend++ = '\b'; break; - case 'e': *cookend++ = '\x1b'; break; - case 'f': *cookend++ = '\f'; break; - case 'n': *cookend++ = '\n'; break; - case 'r': *cookend++ = '\r'; break; - case 't': *cookend++ = '\r'; break; - case 'v': *cookend++ = '\v'; break; - case 'x': - switch(*++raw) { - case '0': c = 0x00; break; - case '1': c = 0x10; break; - case '2': c = 0x20; break; - case '3': c = 0x30; break; - case '4': c = 0x40; break; - case '5': c = 0x50; break; - case '6': c = 0x60; break; - case '7': c = 0x70; break; - case '8': c = 0x80; break; - case '9': c = 0x90; break; - case 'A': case 'a': c = 0xa0; break; - case 'B': case 'b': c = 0xb0; break; - case 'C': case 'c': c = 0xc0; break; - case 'D': case 'd': c = 0xd0; break; - case 'E': case 'e': c = 0xe0; break; - case 'F': case 'f': c = 0xf0; break; - default: - return -1; - } - switch(*++raw) { - case '0': c += 0x00; break; - case '1': c += 0x01; break; - case '2': c += 0x02; break; - case '3': c += 0x03; break; - case '4': c += 0x04; break; - case '5': c += 0x05; break; - case '6': c += 0x06; break; - case '7': c += 0x07; break; - case '8': c += 0x08; break; - case '9': c += 0x09; break; - case 'A': case 'a': c += 0x0a; break; - case 'B': case 'b': c += 0x0b; break; - case 'C': case 'c': c += 0x0c; break; - case 'D': case 'd': c += 0x0d; break; - case 'E': case 'e': c += 0x0e; break; - case 'F': case 'f': c += 0x0f; break; - default: - return -2; - } - *cookend++ = c; - break; - case '\\': *cookend++ = '\\'; break; - default: - return -3; - } - } - return (ssize_t)(cookend - cooked); - /*@ +charint +mustdefine +compdef @*/ -} - - int main(int argc, char **argv) { int option, status; diff --git a/gpsd.h-tail b/gpsd.h-tail index 69f2e44e..6e11db2b 100644 --- a/gpsd.h-tail +++ b/gpsd.h-tail @@ -404,6 +404,7 @@ extern /*@ observer @*/ char *gpsd_hexdump(/*@null@*/const void *, size_t); extern /*@ observer @*/ char *gpsd_hexdump_wrapper(/*@null@*/const void *, size_t, int); extern int gpsd_hexpack(char *, char *, size_t); extern int hex2bin(char *); +extern ssize_t hex_escapes(/*@out@*/char *cooked, const char *raw); extern void ntpd_link_activate(struct gps_device_t *session); extern char /*@observer@*/ *gpsd_id(/*@in@*/struct gps_device_t *); extern void gpsd_position_fix_dump(struct gps_device_t *, /*@out@*/char[], size_t); diff --git a/hex.c b/hex.c index 270e346a..2c7170a0 100644 --- a/hex.c +++ b/hex.c @@ -98,3 +98,73 @@ int hex2bin(char *s) return ((a<<4) + b); } /*@ -charint +shiftimplementation @*/ + +ssize_t hex_escapes(/*@out@*/char *cooked, const char *raw) +/* interpret C-style hex escapes */ +{ + char c, *cookend; + + /*@ +charint -mustdefine -compdef @*/ + for (cookend = cooked; *raw != '\0'; raw++) + if (*raw != '\\') + *cookend++ = *raw; + else { + switch(*++raw) { + case 'b': *cookend++ = '\b'; break; + case 'e': *cookend++ = '\x1b'; break; + case 'f': *cookend++ = '\f'; break; + case 'n': *cookend++ = '\n'; break; + case 'r': *cookend++ = '\r'; break; + case 't': *cookend++ = '\r'; break; + case 'v': *cookend++ = '\v'; break; + case 'x': + switch(*++raw) { + case '0': c = 0x00; break; + case '1': c = 0x10; break; + case '2': c = 0x20; break; + case '3': c = 0x30; break; + case '4': c = 0x40; break; + case '5': c = 0x50; break; + case '6': c = 0x60; break; + case '7': c = 0x70; break; + case '8': c = 0x80; break; + case '9': c = 0x90; break; + case 'A': case 'a': c = 0xa0; break; + case 'B': case 'b': c = 0xb0; break; + case 'C': case 'c': c = 0xc0; break; + case 'D': case 'd': c = 0xd0; break; + case 'E': case 'e': c = 0xe0; break; + case 'F': case 'f': c = 0xf0; break; + default: + return -1; + } + switch(*++raw) { + case '0': c += 0x00; break; + case '1': c += 0x01; break; + case '2': c += 0x02; break; + case '3': c += 0x03; break; + case '4': c += 0x04; break; + case '5': c += 0x05; break; + case '6': c += 0x06; break; + case '7': c += 0x07; break; + case '8': c += 0x08; break; + case '9': c += 0x09; break; + case 'A': case 'a': c += 0x0a; break; + case 'B': case 'b': c += 0x0b; break; + case 'C': case 'c': c += 0x0c; break; + case 'D': case 'd': c += 0x0d; break; + case 'E': case 'e': c += 0x0e; break; + case 'F': case 'f': c += 0x0f; break; + default: + return -2; + } + *cookend++ = c; + break; + case '\\': *cookend++ = '\\'; break; + default: + return -3; + } + } + return (ssize_t)(cookend - cooked); + /*@ +charint +mustdefine +compdef @*/ +} -- cgit v1.2.1