# HG changeset patch
# User Mychaela Falconia <falcon@freecalypso.org>
# Date 1739319476 0
# Node ID 901753f59f8830f1ca8bfc5c0fa9af7dad692f7d
# Parent  cf62fe9fac3ae75d98ae43074e69a5f8225d3a22
gsmhr-cod-parse: read native endian by default

diff -r cf62fe9fac3a -r 901753f59f88 hrutil/Makefile
--- a/hrutil/Makefile	Wed Feb 12 00:04:33 2025 +0000
+++ b/hrutil/Makefile	Wed Feb 12 00:17:56 2025 +0000
@@ -1,15 +1,16 @@
 PROGS=	gsmhr-cod-parse gsmhr-cod2hex gsmhr-dec-craft gsmhr-dec-parse tw5b-dump
 LIBHR1=	../libgsmhr1/libgsmhr1.a
 LIBTEST=../libtest/libtest.a
+LIBS=	${LIBHR1} ${LIBTEST}
 
 include ../config.defs
 
 all:	${PROGS}
 
-gsmhr-cod-parse:	cod-parse.o print-frame.o read-cod.o ${LIBHR1}
+gsmhr-cod-parse:	cod-parse.o print-frame.o read-cod.o ${LIBS}
 	${CC} ${CFLAGS} -o $@ $^
 
-gsmhr-cod2hex:	cod2hex.o read-cod.o tw5b-out-cod.o ${LIBHR1} ${LIBTEST}
+gsmhr-cod2hex:	cod2hex.o read-cod.o tw5b-out-cod.o ${LIBS}
 	${CC} ${CFLAGS} -o $@ $^
 
 gsmhr-dec-craft:	dec-craft.o ${LIBHR1}
@@ -18,7 +19,7 @@
 gsmhr-dec-parse:	dec-parse.o print-frame.o read-dec.o ${LIBHR1}
 	${CC} ${CFLAGS} -o $@ $^
 
-tw5b-dump:	print-frame.o tw5b-dump.o ${LIBHR1} ${LIBTEST}
+tw5b-dump:	print-frame.o tw5b-dump.o ${LIBS}
 	${CC} ${CFLAGS} -o $@ $^
 
 install:
diff -r cf62fe9fac3a -r 901753f59f88 hrutil/cod-parse.c
--- a/hrutil/cod-parse.c	Wed Feb 12 00:04:33 2025 +0000
+++ b/hrutil/cod-parse.c	Wed Feb 12 00:17:56 2025 +0000
@@ -8,7 +8,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <strings.h>
+#include <unistd.h>
 #include "../libgsmhr1/tw_gsmhr.h"
+#include "../libtest/local_endian.h"
 
 main(argc, argv)
 	char **argv;
@@ -18,18 +20,27 @@
 	int big_endian;
 	unsigned frame_no;
 	int16_t params[GSMHR_NUM_PARAMS_ENC];
-	int rc;
+	int opt, rc;
 
-	if (argc == 2 && argv[1][0] != '-') {
-		big_endian = 0;
-		infname = argv[1];
-	} else if (argc == 3 && !strcmp(argv[1], "-b")) {
-		big_endian = 1;
-		infname = argv[2];
-	} else {
-		fprintf(stderr, "usage: %s [-b] file.cod\n", argv[0]);
-		exit(1);
+	big_endian = is_native_big_endian();
+	while ((opt = getopt(argc, argv, "bl")) != EOF) {
+		switch (opt) {
+		case 'b':
+			big_endian = 1;
+			continue;
+		case 'l':
+			big_endian = 0;
+			continue;
+		default:
+		usage:
+			fprintf(stderr, "usage: %s [-b|-l] file.cod\n",
+				argv[0]);
+			exit(1);
+		}
 	}
+	if (argc != optind + 1)
+		goto usage;
+	infname = argv[optind];
 	inf = fopen(infname, "r");
 	if (!inf) {
 		perror(infname);