# HG changeset patch
# User Mychaela Falconia <falcon@freecalypso.org>
# Date 1739318673 0
# Node ID cf62fe9fac3ae75d98ae43074e69a5f8225d3a22
# Parent  9a9d05a8fc75275dd0e3404746ddd43a7c822e5a
gsmhr-cod2hex: read native endian by default

Let's change gsmhr-* utilities to read *.cod and *.dec files
in the local machine's native byte order by default, and support
both -b and -l override options.  This approach is the only sane
one when we write *.cod and *.dec files in the local endian.

diff -r 9a9d05a8fc75 -r cf62fe9fac3a hrutil/cod2hex.c
--- a/hrutil/cod2hex.c	Tue Feb 11 23:59:21 2025 +0000
+++ b/hrutil/cod2hex.c	Wed Feb 12 00:04:33 2025 +0000
@@ -11,29 +11,34 @@
 #include <strings.h>
 #include <unistd.h>
 #include "../libgsmhr1/tw_gsmhr.h"
+#include "../libtest/local_endian.h"
 
 main(argc, argv)
 	char **argv;
 {
 	char *infname, *outfname;
 	FILE *inf, *outf;
-	int opt, rc, big_endian = 0, emit_5993 = 0;
+	int opt, rc, big_endian, emit_5993 = 0;
 	unsigned frame_no;
 	int16_t params[GSMHR_NUM_PARAMS_ENC];
 	extern int optind;
 
-	while ((opt = getopt(argc, argv, "bx")) != EOF) {
+	big_endian = is_native_big_endian();
+	while ((opt = getopt(argc, argv, "blx")) != EOF) {
 		switch (opt) {
 		case 'b':
 			big_endian = 1;
 			continue;
+		case 'l':
+			big_endian = 0;
+			continue;
 		case 'x':
 			emit_5993 = 1;
 			continue;
 		default:
 		usage:
 			fprintf(stderr,
-				"usage: %s [-b] [-x] input.cod output.hex\n",
+				"usage: %s [-b|-l] [-x] input.cod output.hex\n",
 				argv[0]);
 			exit(1);
 		}