changeset 115:f1ea981ab225

fc-simtool smsp-dump: support output redirection
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 19 Feb 2021 07:26:15 +0000
parents 2c07684a3980
children 9c16cf1a79af
files simtool/dispatch.c simtool/smsp_dump.c
diffstat 2 files changed, 4 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/simtool/dispatch.c	Fri Feb 19 07:22:56 2021 +0000
+++ b/simtool/dispatch.c	Fri Feb 19 07:26:15 2021 +0000
@@ -159,7 +159,7 @@
 	{"sms-erase-all", 0, 0, 0, cmd_sms_erase_all},
 	{"sms-erase-one", 1, 1, 0, cmd_sms_erase_one},
 	{"sms-erase-range", 2, 2, 0, cmd_sms_erase_range},
-	{"smsp-dump", 0, 1, 0, cmd_smsp_dump},
+	{"smsp-dump", 0, 0, 1, cmd_smsp_dump},
 	{"smsp-erase-all", 0, 0, 0, cmd_smsp_erase_all},
 	{"smsp-erase-one", 1, 1, 0, cmd_smsp_erase_one},
 	{"smsp-erase-range", 2, 2, 0, cmd_smsp_erase_range},
--- a/simtool/smsp_dump.c	Fri Feb 19 07:22:56 2021 +0000
+++ b/simtool/smsp_dump.c	Fri Feb 19 07:26:15 2021 +0000
@@ -110,34 +110,21 @@
 	putc('\n', outf);
 }
 
-cmd_smsp_dump(argc, argv)
+cmd_smsp_dump(argc, argv, outf)
 	char **argv;
+	FILE *outf;
 {
 	int rc;
-	FILE *outf;
 	unsigned recno;
 
 	rc = select_ef_smsp();
 	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);
-		}
 		dump_record(recno, outf);
 	}
-	if (argv[1])
-		fclose(outf);
 	return(0);
 }