diff simtool/plmnsel.c @ 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
line wrap: on
line diff
--- 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);
+}