changeset 111:869488ef86b6

pb-dump command family reworked for new output redirection
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 19 Feb 2021 07:06:25 +0000
parents 2aa92dfcb4b5
children 440a4582d2a5
files simtool/dispatch.c simtool/pbdump.c
diffstat 2 files changed, 12 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/simtool/dispatch.c	Fri Feb 19 06:59:56 2021 +0000
+++ b/simtool/dispatch.c	Fri Feb 19 07:06:25 2021 +0000
@@ -128,13 +128,13 @@
 	{"grcard2-set-super-hex", 1, 1, 0, cmd_grcard2_set_super_hex},
 	{"iccid", 0, 0, 1, cmd_iccid},
 	{"imsi", 0, 0, 1, cmd_imsi},
-	{"lnd-dump", 0, 1, 0, cmd_lnd_dump},
+	{"lnd-dump", 0, 0, 1, cmd_lnd_dump},
 	{"lnd-erase", 0, 0, 0, cmd_lnd_erase},
 	{"lnd-restore", 1, 1, 0, cmd_lnd_restore},
 	{"lnd-write", 1, 2, 0, cmd_lnd_write},
 	{"opl-dump", 0, 0, 0, cmd_opl_dump},
-	{"pb-dump", 1, 2, 0, cmd_pb_dump},
-	{"pb-dump-rec", 2, 3, 0, cmd_pb_dump_rec},
+	{"pb-dump", 1, 1, 1, cmd_pb_dump},
+	{"pb-dump-rec", 2, 3, 1, cmd_pb_dump_rec},
 	{"pb-erase", 1, 1, 0, cmd_pb_erase},
 	{"pb-erase-one", 2, 2, 0, cmd_pb_erase_one},
 	{"pb-erase-range", 3, 3, 0, cmd_pb_erase_range},
--- a/simtool/pbdump.c	Fri Feb 19 06:59:56 2021 +0000
+++ b/simtool/pbdump.c	Fri Feb 19 07:06:25 2021 +0000
@@ -58,42 +58,30 @@
 	putc('\n', outf);
 }
 
-cmd_pb_dump(argc, argv)
+cmd_pb_dump(argc, argv, outf)
 	char **argv;
+	FILE *outf;
 {
 	int rc;
-	FILE *outf;
 	unsigned recno;
 
 	rc = phonebook_op_common(argv[1]);
 	if (rc < 0)
 		return(rc);
-	if (argv[2]) {
-		outf = fopen(argv[2], "w");
-		if (!outf) {
-			perror(argv[2]);
-			return(-1);
-		}
-	} else
-		outf = stdout;
 	for (recno = 1; recno <= curfile_record_count; recno++) {
 		rc = readrec_op(recno, 0x04, curfile_record_len);
-		if (rc < 0) {
-			if (argv[2])
-				fclose(outf);
+		if (rc < 0)
 			return(rc);
-		}
 		if (check_simresp_all_blank())
 			continue;
 		dump_record(recno, outf);
 	}
-	if (argv[2])
-		fclose(outf);
 	return(0);
 }
 
-cmd_pb_dump_rec(argc, argv)
+cmd_pb_dump_rec(argc, argv, outf)
 	char **argv;
+	FILE *outf;
 {
 	int rc;
 	unsigned recno, startrec, endrec;
@@ -127,41 +115,28 @@
 			return(rc);
 		if (check_simresp_all_blank())
 			continue;
-		dump_record(recno, stdout);
+		dump_record(recno, outf);
 	}
 	return(0);
 }
 
-cmd_lnd_dump(argc, argv)
+cmd_lnd_dump(argc, argv, outf)
 	char **argv;
+	FILE *outf;
 {
 	int rc;
-	FILE *outf;
 	unsigned recno;
 
 	rc = select_ef_lnd();
 	if (rc < 0)
 		return(rc);
-	if (argv[1]) {
-		outf = fopen(argv[1], "w");
-		if (!outf) {
-			perror(argv[1]);
-			return(-1);
-		}
-	} else
-		outf = stdout;
 	for (recno = 1; recno <= curfile_record_count; recno++) {
 		rc = readrec_op(recno, 0x04, curfile_record_len);
-		if (rc < 0) {
-			if (argv[1])
-				fclose(outf);
+		if (rc < 0)
 			return(rc);
-		}
 		if (check_simresp_all_blank())
 			continue;
 		dump_record(recno, outf);
 	}
-	if (argv[1])
-		fclose(outf);
 	return(0);
 }