about summary refs log tree commit diff homepage
path: root/merge.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2021-12-22 21:54:31 -0500
committerJune McEnroe <june@causal.agency>2021-12-22 21:57:04 -0500
commit92187f2a12bcc9b108773e080074b4cfc47f6db9 (patch)
treedf466941ed713b0ed7d38ef656f1647a3e730ad4 /merge.c
parentDecay (diff)
downloadtorus-master.tar.gz
torus-master.zip
Support reading gzipped data in merge HEAD master
Diffstat (limited to 'merge.c')
-rw-r--r--merge.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/merge.c b/merge.c
index 66a7a5e..42ef2c1 100644
--- a/merge.c
+++ b/merge.c
@@ -23,6 +23,7 @@
 #include <stdio.h>
 #include <sysexits.h>
 #include <wchar.h>
+#include <zlib.h>
 
 #include "torus.h"
 
@@ -83,10 +84,10 @@ static void drawTile(int offsetY, const struct Tile *tile) {
 int main(int argc, char *argv[]) {
 	if (argc != 4) return EX_USAGE;
 
-	FILE *fileA = fopen(argv[1], "r");
+	gzFile fileA = gzopen(argv[1], "r");
 	if (!fileA) err(EX_NOINPUT, "%s", argv[1]);
 
-	FILE *fileB = fopen(argv[2], "r");
+	gzFile fileB = gzopen(argv[2], "r");
 	if (!fileB) err(EX_NOINPUT, "%s", argv[2]);
 
 	FILE *fileC = fopen(argv[3], "w");
@@ -94,13 +95,18 @@ int main(int argc, char *argv[]) {
 
 	curse();
 
+	int error;
 	struct Tile tileA, tileB;
 	for (;;) {
-		size_t countA = fread(&tileA, sizeof(tileA), 1, fileA);
-		if (ferror(fileA)) err(EX_IOERR, "%s", argv[1]);
+		size_t countA = gzfread(&tileA, sizeof(tileA), 1, fileA);
+		if (!countA && gzerror(fileA, &error)) {
+			errx(EX_IOERR, "%s: %s", argv[1], gzerror(fileA, &error));
+		}
 
-		size_t countB = fread(&tileB, sizeof(tileB), 1, fileB);
-		if (ferror(fileB)) err(EX_IOERR, "%s", argv[2]);
+		size_t countB = gzfread(&tileB, sizeof(tileB), 1, fileB);
+		if (!countB && gzerror(fileB, &error)) {
+			errx(EX_IOERR, "%s: %s", argv[2], gzerror(fileB, &error));
+		}
 
 		if (!countA && !countB) break;
 		if (!countA || !countB) errx(EX_DATAERR, "different size inputs");