diff libutil/alpha_decode.c @ 157:f064dbcc5f41

libutil split from libcommon
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 26 Feb 2021 20:19:58 +0000
parents libcommon/alpha_decode.c@d4dc86195382
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libutil/alpha_decode.c	Fri Feb 26 20:19:58 2021 +0000
@@ -0,0 +1,38 @@
+/*
+ * This module contains functions for decoding and displaying alpha fields
+ * that exist in various SIM files.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+
+static void
+print_alpha_field_hex(data, nbytes, outf)
+	u_char *data;
+	unsigned nbytes;
+	FILE *outf;
+{
+	u_char *dp, *endp;
+
+	fputs("HEX ", outf);
+	dp = data;
+	endp = data + nbytes;
+	while (dp < endp)
+		fprintf(outf, "%02X", *dp++);
+}
+
+void
+print_alpha_field(data, nbytes, outf)
+	u_char *data;
+	unsigned nbytes;
+	FILE *outf;
+{
+	if (!nbytes) {
+		fputs("\"\"", outf);
+		return;
+	}
+	if (data[0] & 0x80)
+		print_alpha_field_hex(data, nbytes, outf);
+	else
+		print_gsm7_string_to_file(data, nbytes, outf);
+}