summary refs log tree commit diff
path: root/bin/edi/edi.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--bin/edi/edi.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/bin/edi/edi.c b/bin/edi/edi.c
index e8024073..a0231785 100644
--- a/bin/edi/edi.c
+++ b/bin/edi/edi.c
@@ -14,7 +14,9 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <err.h>
 #include <locale.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sysexits.h>
@@ -28,6 +30,32 @@ int main(int argc, char *argv[]) {
 
 	struct File file = fileAlloc(strdup(argv[1]));
 	fileRead(&file);
+	
+	struct Edit edit = { file.buf, file.log };
+
+	FILE *store = fopen("store.edi", "w");
+	if (!store) err(EX_CANTCREAT, "store.edi");
+
+	enum Error error = storeWrite(store, &edit);
+	if (error) {
+		if (error > Errno) errc(EX_IOERR, error - Errno, "store.edi");
+		else errx(EX_IOERR, "store.edi: %d", error);
+	}
+
+	fclose(store);
+	if (ferror(store)) err(EX_IOERR, "store.edi");
+
+	store = fopen("store.edi", "r");
+	if (!store) err(EX_CANTCREAT, "store.edi");
+
+	error = storeRead(store, &edit);
+	if (error) {
+		if (error > Errno) errc(EX_IOERR, error - Errno, "store.edi");
+		else errx(EX_DATAERR, "store.edi: %d", error);
+	}
+
+	file.buf = edit.buf;
+	file.log = edit.log;
 
 	const struct Table *table = logTable(&file.log);
 	for (struct Iter it = iter(table, 0); it.ch != WEOF; it = iterNext(it)) {