diff simtool/pbrestore.c @ 88:ae831b21ef77

lnd-restore command implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 17 Feb 2021 07:16:31 +0000
parents bc862d41f96b
children 9c10afbb745a
line wrap: on
line diff
--- 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);
+}