shithub: mcfs

Download patch

ref: 81632462880f7ab51b5db93785c5fee576dbcd0e
parent: a29584a82088c3b29dec73124283bb8671e5f5db
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Tue Dec 15 03:10:48 EST 2020

ivf2raw: hex dump mode

--- a/extra/ivf2raw.c
+++ b/extra/ivf2raw.c
@@ -51,7 +51,7 @@
 static void
 usage(void)
 {
-	fprint(2, "usage: %s <file.ivf >file.raw\n", argv0);
+	fprint(2, "usage: %s [-h NUM]  <file.ivf >file.raw\n", argv0);
 	exits("usage");
 }
 
@@ -58,16 +58,23 @@
 void
 main(int argc, char **argv)
 {
-	int n, bufsz, framenum;
+	u64int timestamp, framenum;
 	u32int tbnum, tbdenum;
+	int n, bufsz, hxsz;
 	u16int w, h, hlen;
-	u64int timestamp;
 	Biobuf in, out;
 	char tmp[6];
 	u8int *buf;
 	u32int sz;
 
+	hxsz = 0;
 	ARGBEGIN{
+	case 'h':
+		hxsz = atoi(EARGF(usage()));
+		if(hxsz < 0)
+			usage();
+		fmtinstall('H', encodefmt);
+		break;
 	}ARGEND
 
 	if(argc != 0)
@@ -95,11 +102,14 @@
 		if(bufsz < sz){
 			bufsz = sz;
 			if((buf = realloc(buf, bufsz)) == nil)
-				sysfatal("frame %d is too big: %d bytes", framenum, bufsz);
+				sysfatal("frame %llud is too big: %d bytes", framenum, bufsz);
 		}
 		if((n = Bread(&in, buf, sz)) != sz)
 			sysfatal("short read (%d < %d)", n, sz);
-		Bwrite(&out, buf, sz);
+		if(hxsz < 1)
+			Bwrite(&out, buf, sz);
+		else
+			Bprint(&out, "[%6llud %8llud %7ud] %.*H\n", framenum, timestamp, sz, sz > hxsz ? hxsz : sz, buf);
 	}
 
 	Bterm(&in);