changeset 9:dc565e91069d

pb-dump meaty function factored out into libcommon
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 12 Feb 2021 00:28:06 +0000
parents 4a9bf783491d
children a76ec3e7da09
files libcommon/Makefile libcommon/pbdumpfunc.c simtool/pbdump.c
diffstat 3 files changed, 61 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- a/libcommon/Makefile	Fri Feb 12 00:07:24 2021 +0000
+++ b/libcommon/Makefile	Fri Feb 12 00:28:06 2021 +0000
@@ -2,7 +2,7 @@
 CFLAGS=	-O2 -I/usr/include/PCSC
 OBJS=	alpha_decode.o alpha_valid.o apdu.o atr.o cardconnect.o chkblank.o \
 	dumpdirfunc.o exit.o hexdump.o hexread.o hexstr.o names.o \
-	number_decode.o pinentry.o revnibbles.o
+	number_decode.o pbdumpfunc.o pinentry.o revnibbles.o
 LIB=	libcommon.a
 
 all:	${LIB}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libcommon/pbdumpfunc.c	Fri Feb 12 00:28:06 2021 +0000
@@ -0,0 +1,57 @@
+/*
+ * This module implements the meaty function for pb-dump commands.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include "simresp.h"
+
+static
+check_blank_area(dp, endp)
+	u_char *dp, *endp;
+{
+	while (dp < endp)
+		if (*dp++ != 0xFF)
+			return(-1);
+	return(0);
+}
+
+void
+dump_phonebook_record(recno, outf)
+	unsigned recno;
+	FILE *outf;
+{
+	int rc;
+	unsigned textlen;
+	u_char *fixp;
+	char digits[21];
+
+	fprintf(outf, "#%u: ", recno);
+	if (sim_resp_data_len > 14) {
+		rc = validate_alpha_field(sim_resp_data,
+					  sim_resp_data_len - 14,
+					  &textlen);
+		if (rc < 0) {
+malformed:		fprintf(outf, "malformed record\n");
+			return;
+		}
+	} else
+		textlen = 0;
+	fixp = sim_resp_data + sim_resp_data_len - 14;
+	if (fixp[0] < 2 || fixp[0] > 11)
+		goto malformed;
+	rc = decode_phone_number(fixp + 2, fixp[0] - 1, digits);
+	if (rc < 0)
+		goto malformed;
+	rc = check_blank_area(fixp + 1 + fixp[0], fixp + 12);
+	if (rc < 0)
+		goto malformed;
+	/* all checks passed */
+	fprintf(outf, "%s,0x%02X ", digits, fixp[1]);
+	if (fixp[12] != 0xFF)
+		fprintf(outf, "CCP=%u ", fixp[12]);
+	if (fixp[13] != 0xFF)
+		fprintf(outf, "EXT=%u ", fixp[13]);
+	print_alpha_field(sim_resp_data, textlen, outf);
+	putc('\n', outf);
+}
--- a/simtool/pbdump.c	Fri Feb 12 00:07:24 2021 +0000
+++ b/simtool/pbdump.c	Fri Feb 12 00:28:06 2021 +0000
@@ -1,65 +1,12 @@
 /*
- * This module implements the pb-dump command.
+ * This module implements pb-dump and pb-dump-rec commands.
  */
 
 #include <sys/types.h>
-#include <string.h>
-#include <strings.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include "simresp.h"
 #include "curfile.h"
 
-static
-check_blank_area(dp, endp)
-	u_char *dp, *endp;
-{
-	while (dp < endp)
-		if (*dp++ != 0xFF)
-			return(-1);
-	return(0);
-}
-
-static void
-dump_record(recno, outf)
-	unsigned recno;
-	FILE *outf;
-{
-	int rc;
-	unsigned textlen;
-	u_char *fixp;
-	char digits[21];
-
-	fprintf(outf, "#%u: ", recno);
-	if (curfile_record_len > 14) {
-		rc = validate_alpha_field(sim_resp_data,
-					  curfile_record_len - 14,
-					  &textlen);
-		if (rc < 0) {
-malformed:		fprintf(outf, "malformed record\n");
-			return;
-		}
-	} else
-		textlen = 0;
-	fixp = sim_resp_data + sim_resp_data_len - 14;
-	if (fixp[0] < 2 || fixp[0] > 11)
-		goto malformed;
-	rc = decode_phone_number(fixp + 2, fixp[0] - 1, digits);
-	if (rc < 0)
-		goto malformed;
-	rc = check_blank_area(fixp + 1 + fixp[0], fixp + 12);
-	if (rc < 0)
-		goto malformed;
-	/* all checks passed */
-	fprintf(outf, "%s,0x%02X ", digits, fixp[1]);
-	if (fixp[12] != 0xFF)
-		fprintf(outf, "CCP=%u ", fixp[12]);
-	if (fixp[13] != 0xFF)
-		fprintf(outf, "EXT=%u ", fixp[13]);
-	print_alpha_field(sim_resp_data, textlen, outf);
-	putc('\n', outf);
-}
-
 cmd_pb_dump(argc, argv)
 	char **argv;
 {
@@ -87,7 +34,7 @@
 		}
 		if (check_simresp_all_blank())
 			continue;
-		dump_record(recno, outf);
+		dump_phonebook_record(recno, outf);
 	}
 	if (argv[2])
 		fclose(outf);
@@ -129,7 +76,7 @@
 			return(rc);
 		if (check_simresp_all_blank())
 			continue;
-		dump_record(recno, stdout);
+		dump_phonebook_record(recno, stdout);
 	}
 	return(0);
 }