diff options
author | June McEnroe <june@causal.agency> | 2018-11-24 23:41:11 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2018-11-24 23:41:11 -0500 |
commit | 89c9ceded12d3e31a45a81a94d9035a476719d17 (patch) | |
tree | 6ce1a41b2e760a2fe75a7a7982919916d6d3f176 /bin/edi/edi.c | |
parent | Add premature serialization to edi (diff) | |
download | src-89c9ceded12d3e31a45a81a94d9035a476719d17.tar.gz src-89c9ceded12d3e31a45a81a94d9035a476719d17.zip |
Implement deserialization in edi
Diffstat (limited to '')
-rw-r--r-- | bin/edi/edi.c | 28 |
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)) { |