summary refs log tree commit diff
path: root/bin/edi/edi.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-11-24 23:41:11 -0500
committerJune McEnroe <june@causal.agency>2018-11-24 23:41:11 -0500
commit3c090cf56c2ac6f5cb656508c9dd311555a98f41 (patch)
tree34288de349a5b2796eef681e1565683dca9a543c /bin/edi/edi.c
parentAdd premature serialization to edi (diff)
downloadsrc-3c090cf56c2ac6f5cb656508c9dd311555a98f41.tar.gz
src-3c090cf56c2ac6f5cb656508c9dd311555a98f41.zip
Implement deserialization in edi
Diffstat (limited to 'bin/edi/edi.c')
-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 3a52e228..9418f1d9 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)) {