diff simtool/opldump.c @ 10:ddd767f6e15b

fc-simtool ported over
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 14 Mar 2021 07:11:25 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/simtool/opldump.c	Sun Mar 14 07:11:25 2021 +0000
@@ -0,0 +1,69 @@
+/*
+ * This module implements the opl-dump command,
+ * a companion command to pnn-dump.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include "simresp.h"
+#include "curfile.h"
+#include "file_id.h"
+
+select_ef_opl()
+{
+	int rc;
+
+	rc = select_op(DF_GSM);
+	if (rc < 0)
+		return(rc);
+	rc = select_op(EF_OPL);
+	if (rc < 0)
+		return(rc);
+	rc = parse_ef_select_response();
+	if (rc < 0)
+		return(rc);
+	if (curfile_structure != 0x01) {
+		fprintf(stderr, "error: EF_OPL is not linear fixed\n");
+		return(-1);
+	}
+	if (curfile_record_len < 8) {
+		fprintf(stderr,
+"error: EF_OPL record length is less than the spec minimum of 8 bytes\n");
+		return(-1);
+	}
+	return(0);
+}
+
+static void
+dump_record(recno, outf)
+	unsigned recno;
+	FILE *outf;
+{
+	char ascbuf[8];
+
+	decode_plmn_3bytes(sim_resp_data, ascbuf, 0);
+	fprintf(outf, "#%u: %s %02X%02X-%02X%02X %u\n", recno, ascbuf,
+		sim_resp_data[3], sim_resp_data[4], sim_resp_data[5],
+		sim_resp_data[6], sim_resp_data[7]);
+}
+
+cmd_opl_dump(argc, argv, outf)
+	char **argv;
+	FILE *outf;
+{
+	int rc;
+	unsigned recno;
+
+	rc = select_ef_opl();
+	if (rc < 0)
+		return(rc);
+	for (recno = 1; recno <= curfile_record_count; recno++) {
+		rc = readrec_op(recno, 0x04, curfile_record_len);
+		if (rc < 0)
+			return(rc);
+		if (check_simresp_all_blank())
+			continue;
+		dump_record(recno, outf);
+	}
+	return(0);
+}