summaryrefslogtreecommitdiff
path: root/src/metaentry.c
diff options
context:
space:
mode:
authorAdam Spragg <adam@spra.gg>2022-05-16 14:25:16 +0100
committerAdam Spragg <adam@spra.gg>2022-05-18 17:19:40 +0100
commit96df5969b11b9a64f95c0c28347154b06cfc9d15 (patch)
treed6e7caa88adb474e32acc4992dc1787b12e88878 /src/metaentry.c
parent0ae5e697e83fef2f200dfdcf16caebc8a15a9681 (diff)
Add -r/--format option to pick the format to save as
Only version 0 is supported here.
Diffstat (limited to 'src/metaentry.c')
-rw-r--r--src/metaentry.c15
1 files changed, 12 insertions, 3 deletions
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);
}