summary refs log tree commit diff
path: root/mico-dump.c
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2023-10-15 19:17:27 +0200
committerLeah Neukirchen <leah@vuxu.org>2023-10-15 19:17:27 +0200
commitf9ad993a1586436a539721f84058bf63055c8ac5 (patch)
tree18dd0d72901e83d70c12bb43a3b5c22a53935945 /mico-dump.c
parent9ed51426baac47f3fe4b45cc7a018b9f6eeff2dd (diff)
downloadmico-f9ad993a1586436a539721f84058bf63055c8ac5.tar.gz
mico-f9ad993a1586436a539721f84058bf63055c8ac5.tar.xz
mico-f9ad993a1586436a539721f84058bf63055c8ac5.zip
wip
Diffstat (limited to 'mico-dump.c')
-rw-r--r--mico-dump.c52
1 files changed, 46 insertions, 6 deletions
diff --git a/mico-dump.c b/mico-dump.c
index cd80609..467db45 100644
--- a/mico-dump.c
+++ b/mico-dump.c
@@ -1,3 +1,4 @@
+#include <arpa/inet.h>
 #include <assert.h>
 #include <stdint.h>
 #include <stdio.h>
@@ -6,6 +7,8 @@
 
 #include <zip.h>
 
+#define MICO_HEADER "\211MiC\r\n\032\n"
+
 zip_t *zip;
 
 struct bitreader {
@@ -81,6 +84,8 @@ get1(struct bitreader *input)
 	return v;
 }
 
+#define ntohll(x) ((1==ntohl(1)) ? (x) : ((uint64_t)ntohl((x) & 0xFFFFFFFF) << 32) | ntohl((x) >> 32))
+
 int
 main(int argc, char *argv[])
 {
@@ -108,18 +113,53 @@ main(int argc, char *argv[])
 		*s++ = '}';
 		*s = 0;
 
-		int64_t t = 0, td = 0;
-		double v = 0.0;
+		char header[8];
+		uint64_t len, lenv;
+		int ret = zip_fread(ts.input, &header, sizeof header);
+		if (ret < 0) {
+			printf("err: %s", zip_strerror(zip));
+		}
+
+		if (memcmp(header, MICO_HEADER, 8) != 0) {
+			printf("wrong header\n");
+			continue;
+		}
+
+		ret = zip_fread(ts.input, &len, sizeof len);
+		if (ret < 0) {
+			printf("err: %s", zip_strerror(zip));
+		}
+
+		len = ntohll(len);
 
-		int64_t len = get1(&ts);
-		int64_t lenv = get1(&vs);
+		ret = zip_fread(vs.input, &header, sizeof header);
+		if (ret < 0) {
+			printf("err: %s", zip_strerror(zip));
+		}
+
+		if (memcmp(header, MICO_HEADER, 8) != 0) {
+			printf("wrong header\n");
+			continue;
+		}
+
+		ret = zip_fread(vs.input, &lenv, sizeof lenv);
+		if (ret < 0) {
+			printf("err: %s", zip_strerror(zip));
+		}
+
+		lenv = ntohll(lenv);
+
+		printf("len=%ld lenv=%d\n", len, lenv);
 
 		if (len != lenv) {
-			fprintf(stderr, "time and value length don't agree");
+			fprintf(stderr, "time and value length don't agree\n");
 			exit(-1);
 		}
 
-		for (int64_t j = 0; j < len; j++) {
+		int64_t t = 0, td = 0;
+		double v = 0.0;
+
+		for (uint64_t j = 0; j < len; j++) {
 			int64_t tdd = get1(&ts);
 			int64_t vd = get1(&vs);