changeset 121:87b34a244901

fc-simtool: pb-erase-range command implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 28 Jan 2021 05:04:16 +0000
parents 70219d92c32e
children f18704e91393
files simtool/dispatch.c simtool/pberase.c
diffstat 2 files changed, 37 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/simtool/dispatch.c	Thu Jan 28 04:46:41 2021 +0000
+++ b/simtool/dispatch.c	Thu Jan 28 05:04:16 2021 +0000
@@ -21,6 +21,7 @@
 extern int cmd_pb_dump();
 extern int cmd_pb_erase();
 extern int cmd_pb_erase_one();
+extern int cmd_pb_erase_range();
 extern int cmd_pb_update();
 extern int cmd_pb_update_imm();
 extern int cmd_pb_update_imm_hex();
@@ -69,6 +70,7 @@
 	{"pb-dump", 1, 2, cmd_pb_dump},
 	{"pb-erase", 1, 1, cmd_pb_erase},
 	{"pb-erase-one", 2, 2, cmd_pb_erase_one},
+	{"pb-erase-range", 3, 3, cmd_pb_erase_range},
 	{"pb-update", 2, 2, cmd_pb_update},
 	{"pb-update-imm", 3, 4, cmd_pb_update_imm},
 	{"pb-update-imm-hex", 4, 4, cmd_pb_update_imm_hex},
--- a/simtool/pberase.c	Thu Jan 28 04:46:41 2021 +0000
+++ b/simtool/pberase.c	Thu Jan 28 05:04:16 2021 +0000
@@ -48,3 +48,38 @@
 	memset(record, 0xFF, curfile_record_len);
 	return update_rec_op(recno, 0x04, record, curfile_record_len);
 }
+
+cmd_pb_erase_range(argc, argv)
+	char **argv;
+{
+	int rc;
+	unsigned recno, startrec, endrec;
+	u_char record[255];
+
+	rc = phonebook_op_common(argv[1]);
+	if (rc < 0)
+		return(rc);
+	startrec = strtoul(argv[2], 0, 0);
+	if (startrec < 1 || startrec > curfile_record_count) {
+		fprintf(stderr,
+			"error: specified starting record number is invalid\n");
+		return(-1);
+	}
+	endrec = strtoul(argv[3], 0, 0);
+	if (endrec < 1 || endrec > curfile_record_count) {
+		fprintf(stderr,
+			"error: specified final record number is invalid\n");
+		return(-1);
+	}
+	if (startrec > endrec) {
+		fprintf(stderr, "error: reverse record range specified\n");
+		return(-1);
+	}
+	memset(record, 0xFF, curfile_record_len);
+	for (recno = startrec; recno <= endrec; recno++) {
+		rc = update_rec_op(recno, 0x04, record, curfile_record_len);
+		if (rc < 0)
+			return(rc);
+	}
+	return(0);
+}