]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
DEBUG: extra func in hexdump.
authorAdam Sutton <dev@adamsutton.me.uk>
Mon, 10 Sep 2012 15:33:53 +0000 (16:33 +0100)
committerAdam Sutton <dev@adamsutton.me.uk>
Mon, 10 Sep 2012 19:54:53 +0000 (20:54 +0100)
src/utils.c

index ca88294f7aca4126c105ff3b44f8c31ca5c1db56..89ae56d44317d02d181e83088877741d27dfa1f8 100644 (file)
@@ -117,18 +117,34 @@ rate_to_sri(int rate)
 /**
  *
  */
+#define HEXDUMP_WIDTH 16
 void
 hexdump(const char *pfx, const uint8_t *data, int len)
 {
-  int i;
-  printf("%s: ", pfx);
-  for(i = 0; i < len; i++)
-    printf("%02x.", data[i]);
-  printf("\n");
+  int i, j=0, l;
+  char str[HEXDUMP_WIDTH+1];
+  l = ((len+(HEXDUMP_WIDTH-1))/HEXDUMP_WIDTH)*HEXDUMP_WIDTH;
+  str[0] = 0;
+  for (i = 0; i < l; i++) {
+    if (!j) printf("%s: ", pfx);
+    if (i < len) {
+      printf("%02X ", data[i]);
+      str[j] = data[i];
+      if (str[j] < ' ' || str[j] > '~') str[j] = '.';
+    } else {
+      printf("   ");
+      str[j] = ' ';
+    }
+    j++;
+    if (j == HEXDUMP_WIDTH) {
+      str[j] = 0;
+      printf("%s\n", str);
+      str[0] = 0;
+      j = 0;
+    }
+  }
 }
 
-
-
 /**
  * @file
  * @brief Base64 encode/decode