changeset 100:a75c0aafb367

plmnsel-erase command implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 17 Feb 2021 22:54:35 +0000
parents d2e800abd257
children 63c76f9d678a
files simtool/dispatch.c simtool/plmnsel.c
diffstat 2 files changed, 47 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/simtool/dispatch.c	Wed Feb 17 22:43:18 2021 +0000
+++ b/simtool/dispatch.c	Wed Feb 17 22:54:35 2021 +0000
@@ -40,6 +40,7 @@
 extern int cmd_pb_update_imm();
 extern int cmd_pb_update_imm_hex();
 extern int cmd_plmnsel_dump();
+extern int cmd_plmnsel_erase();
 extern int cmd_plmnsel_write();
 extern int cmd_pnn_dump();
 extern int cmd_readbin();
@@ -132,6 +133,7 @@
 	{"pb-update-imm", 3, 4, cmd_pb_update_imm},
 	{"pb-update-imm-hex", 4, 4, cmd_pb_update_imm_hex},
 	{"plmnsel-dump", 0, 0, cmd_plmnsel_dump},
+	{"plmnsel-erase", 1, 2, cmd_plmnsel_erase},
 	{"plmnsel-write", 2, 2, cmd_plmnsel_write},
 	{"pnn-dump", 0, 0, cmd_pnn_dump},
 	{"quit", 0, 0, good_exit},
--- a/simtool/plmnsel.c	Wed Feb 17 22:43:18 2021 +0000
+++ b/simtool/plmnsel.c	Wed Feb 17 22:54:35 2021 +0000
@@ -5,6 +5,8 @@
 #include <sys/types.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
+#include <strings.h>
 #include "simresp.h"
 #include "curfile.h"
 #include "file_id.h"
@@ -110,3 +112,46 @@
 		return(rc);
 	return update_bin_op(idx * 3, rec, 3);
 }
+
+cmd_plmnsel_erase(argc, argv)
+	char **argv;
+{
+	int rc;
+	unsigned idx, start, end, nrec;
+	u_char rec[3];
+
+	rc = select_ef_plmnsel();
+	if (rc < 0)
+		return(rc);
+	nrec = curfile_total_size / 3;
+	start = strtoul(argv[1], 0, 0);
+	if (start >= nrec) {
+		fprintf(stderr,
+			"error: specified starting index is out of range\n");
+		return(-1);
+	}
+	if (!argv[2])
+		end = start;
+	else if (!strcmp(argv[2], "end"))
+		end = nrec - 1;
+	else {
+		end = strtoul(argv[1], 0, 0);
+		if (end >= nrec) {
+			fprintf(stderr,
+			"error: specified ending index is out of range\n");
+			return(-1);
+		}
+		if (start > end) {
+			fprintf(stderr,
+				"error: reverse index range specified\n");
+			return(-1);
+		}
+	}
+	memset(rec, 0xFF, 3);
+	for (idx = start; idx <= end; idx++) {
+		rc = update_bin_op(idx * 3, rec, 3);
+		if (rc < 0)
+			return(rc);
+	}
+	return(0);
+}