From 89c9ceded12d3e31a45a81a94d9035a476719d17 Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Sat, 24 Nov 2018 23:41:11 -0500 Subject: Implement deserialization in edi --- bin/edi/edi.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'bin/edi/edi.c') 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 . */ +#include #include +#include #include #include #include @@ -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)) { -- cgit 1.4.1