aboutsummaryrefslogtreecommitdiff
path: root/client/xxd.c
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-05-26 11:15:56 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-05-26 11:15:56 +0200
commitc3491119759462aeb3eed4b39aa34f6f98ab8a4f (patch)
tree4f5dbe8343bdd1656c8d368dfaf92dc23352240c /client/xxd.c
parent6cb0ea50e1829c0c6c2e0179d3c6b7573c4a1b24 (diff)
WIP convert parse.cpp data into raw data
Diffstat (limited to 'client/xxd.c')
-rw-r--r--client/xxd.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/client/xxd.c b/client/xxd.c
new file mode 100644
index 0000000..06b9960
--- /dev/null
+++ b/client/xxd.c
@@ -0,0 +1,44 @@
+#include <stdio.h>
+#include <ctype.h>
+
+#include "parse.h"
+
+void xxd(const char * data, size_t size) {
+ size_t fake_size = size + (16 - size % 16) % 16;
+
+ for (size_t base = 0; base < fake_size; base += 16) {
+ printf("%08lx: ", base);
+
+ // print bytes
+ for (size_t offset = 0; offset < 16; offset++) {
+ size_t i = base + offset;
+
+ if (offset == 8) printf(" ");
+
+ if (i >= size) {
+ printf(" ");
+ continue;
+ }
+
+ printf("%02x ", data[size]);
+ }
+
+ // print ascii representation
+ printf(" |");
+ for (size_t offset = 0; offset < 16; offset++) {
+ size_t i = base + offset;
+
+ if (i >= size) {
+ printf(" ");
+ continue;
+ }
+
+ if (isprint(data[size]))
+ printf("%c", data[size]);
+ else
+ printf(".");
+ }
+ printf("|\n");
+ }
+}
+