From 96df5969b11b9a64f95c0c28347154b06cfc9d15 Mon Sep 17 00:00:00 2001 From: Adam Spragg Date: Mon, 16 May 2022 14:25:16 +0100 Subject: Add -r/--format option to pick the format to save as Only version 0 is supported here. --- src/metaentry.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/metaentry.c') diff --git a/src/metaentry.c b/src/metaentry.c index 035901c..1eeed5b 100644 --- a/src/metaentry.c +++ b/src/metaentry.c @@ -434,9 +434,18 @@ mentries_tofile_v0(const struct metahash *mhash, FILE * to) /* Stores metaentries to a file */ void -mentries_tofile(const struct metahash *mhash, const char *path) +mentries_tofile(const struct metahash *mhash, const char *path, int format) { FILE *to; + char const * formatstr; + void(*tofile)(const struct metahash *, FILE *); + + switch (format) { + case 0: formatstr = VERSION_0; tofile = mentries_tofile_v0; break; + default: + msg(MSG_CRITICAL, "Unknown format %d\n", format); + exit(EXIT_FAILURE); + } to = fopen(path, "w"); if (!to) { @@ -446,9 +455,9 @@ mentries_tofile(const struct metahash *mhash, const char *path) } write_binary_string(SIGNATURE, SIGNATURELEN, to); - write_binary_string(VERSION_0, VERSIONLEN, to); + write_binary_string(formatstr, VERSIONLEN, to); - mentries_tofile_v0(mhash, to); + tofile(mhash, to); fclose(to); } -- cgit v1.2.1