From: Timo Kokkonen Date: Tue, 27 Mar 2012 19:07:51 +0000 (+0300) Subject: Replace existing printf functions with trace(...) X-Git-Url: http://git.itanic.dy.fi/?p=glucose;a=commitdiff_plain;h=52390b05dd33de3aa3787d0228caf2635e5176ef Replace existing printf functions with trace(...) This unifies the way printing is done. Everything goes to stderr by default. Using genering tracing functions also removes the custom trace_level handling. Signed-off-by: Timo Kokkonen --- diff --git a/contour-protocol.c b/contour-protocol.c index c9c0aa7..99fda48 100644 --- a/contour-protocol.c +++ b/contour-protocol.c @@ -40,11 +40,10 @@ static int send_msg(const struct msg *msg, int fd, int usage_code) } usleep(30 * 1000); + trace(1, "Sending: "); - if (trace_level >= 3) - print_hex(msg->data + 1, datalen(msg->data) - 1); - if (trace_level >= 2) - print_ascii(msg->data + 1, datalen(msg->data) - 1); + print_hex(3, msg->data + 1, datalen(msg->data) - 1); + print_ascii(2, msg->data + 1, datalen(msg->data) - 1); ret = hiddev_write(msg->data, fd, usage_code); if (ret) @@ -84,11 +83,10 @@ static int read_and_verify(struct msg *msg, int fd) memcpy(msg->data, buf, sizeof(buf)); memset(&msg->data[sizeof(buf)], 0, sizeof(msg->data)-sizeof(buf)); + trace(2, "Got data %d: ", datalen(buf)); - if (trace_level >= 3) - print_hex(buf, datalen(buf)); - if (trace_level >= 2) - print_ascii(buf, datalen(buf)); + print_hex(3, buf, datalen(buf)); + print_ascii(2, buf, datalen(buf)); err: return 0; } diff --git a/hiddev.c b/hiddev.c index 8cf4e5a..889ae60 100644 --- a/hiddev.c +++ b/hiddev.c @@ -82,9 +82,9 @@ int hiddev_write(const unsigned char data[64], int fd , int usage_code) return 0; err2: - printf("HIDIOCSREPORT\n"); + trace(0, "HIDIOCSREPORT\n"); err: - printf("Error in IOCTL: %m\n"); + trace(0, "Error in IOCTL: %m\n"); return rc; } @@ -101,7 +101,7 @@ static int get_usagecode(int fd) rc = ioctl(fd, HIDIOCGUCODE, &uref); if (rc < 0) { - printf("Error gettin usage code: %m\n"); + trace(0, "Error gettin usage code: %m\n"); return rc; } diff --git a/utils.c b/utils.c index 8ae2b46..6b2f651 100644 --- a/utils.c +++ b/utils.c @@ -34,24 +34,24 @@ int datalen(const unsigned char *data) return len + 1; } -void print_hex(const unsigned char *data, int len) +void print_hex(int level, const unsigned char *data, int len) { int i; for (i = 0; i < len; i++) - printf("0x%02x ", data[i]); + trace(level, "0x%02x ", data[i]); - printf("\n"); + trace(level, "\n"); } -void print_ascii(const unsigned char *data, int len) +void print_ascii(int level, const unsigned char *data, int len) { int i; for (i = 0; i < len; i++) - printf("%c", is_printable(data[i]) ? data[i] : '.'); + trace(level, "%c", is_printable(data[i]) ? data[i] : '.'); - printf("\n"); + trace(level, "\n"); } void sanitize_ascii(unsigned char *data, int len) diff --git a/utils.h b/utils.h index 370cca4..cbc0601 100644 --- a/utils.h +++ b/utils.h @@ -38,8 +38,8 @@ extern int trace_level; } while (0) int datalen(const unsigned char *data); -void print_hex(const unsigned char *data, int len); -void print_ascii(const unsigned char *data, int len); +void print_hex(int level, const unsigned char *data, int len); +void print_ascii(int level, const unsigned char *data, int len); void sanitize_ascii(unsigned char *data, int len); #endif