changeset 88:ae831b21ef77

lnd-restore command implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 17 Feb 2021 07:16:31 +0000
parents bc862d41f96b
children 629be330f92b
files simtool/dispatch.c simtool/pbrestore.c
diffstat 2 files changed, 50 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/simtool/dispatch.c	Wed Feb 17 07:04:05 2021 +0000
+++ b/simtool/dispatch.c	Wed Feb 17 07:16:31 2021 +0000
@@ -27,6 +27,7 @@
 extern int cmd_imsi();
 extern int cmd_lnd_dump();
 extern int cmd_lnd_erase();
+extern int cmd_lnd_restore();
 extern int cmd_lnd_write();
 extern int cmd_opl_dump();
 extern int cmd_pb_dump();
@@ -117,6 +118,7 @@
 	{"imsi", 0, 0, cmd_imsi},
 	{"lnd-dump", 0, 1, cmd_lnd_dump},
 	{"lnd-erase", 0, 0, cmd_lnd_erase},
+	{"lnd-restore", 1, 1, cmd_lnd_restore},
 	{"lnd-write", 1, 2, cmd_lnd_write},
 	{"opl-dump", 0, 0, cmd_opl_dump},
 	{"pb-dump", 1, 2, cmd_pb_dump},
--- a/simtool/pbrestore.c	Wed Feb 17 07:04:05 2021 +0000
+++ b/simtool/pbrestore.c	Wed Feb 17 07:16:31 2021 +0000
@@ -200,3 +200,51 @@
 	fclose(inf);
 	return(0);
 }
+
+cmd_lnd_restore(argc, argv)
+	char **argv;
+{
+	int rc;
+	FILE *inf;
+	int lineno;
+	char linebuf[1024];
+	u_char *databuf;
+
+	rc = select_ef_lnd();
+	if (rc < 0)
+		return(rc);
+	databuf = malloc(curfile_total_size);
+	if (!databuf) {
+		perror("malloc for full EF_LND");
+		return(-1);
+	}
+	inf = fopen(argv[1], "r");
+	if (!inf) {
+		perror(argv[1]);
+		free(databuf);
+		return(-1);
+	}
+	memset(databuf, 0xFF, curfile_total_size);
+	for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) {
+		if (!index(linebuf, '\n')) {
+			fprintf(stderr,
+				"%s line %d: too long or missing newline\n",
+				argv[1], lineno);
+			fclose(inf);
+			free(databuf);
+			return(-1);
+		}
+		if (linebuf[0] != '#' || !isdigit(linebuf[1]))
+			continue;
+		rc = process_record(linebuf, databuf, argv[1], lineno);
+		if (rc < 0) {
+			fclose(inf);
+			free(databuf);
+			return(rc);
+		}
+	}
+	fclose(inf);
+	rc = restore_bin_cyclic(databuf);
+	free(databuf);
+	return(rc);
+}