-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsstdump.c
More file actions
98 lines (86 loc) · 2.07 KB
/
sstdump.c
File metadata and controls
98 lines (86 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* Copyright (c) 2016--2021 Wu, Xingbo <wuxb45@gmail.com>
*
* All rights reserved. No warranty, explicit or implicit, provided.
*/
#define _GNU_SOURCE
#include "lib.h"
#include "kv.h"
#include "sst.h"
static void
helper_message(void)
{
fprintf(stderr, "%s z <dir>\n", __func__);
fprintf(stderr, "%s x <dir> <seq> <nway>\n", __func__);
fprintf(stderr, "%s y <dir> <seq> <nway>\n", __func__);
fprintf(stderr, "%s X <dir> <seq> <nway> <output>\n", __func__);
fprintf(stderr, "%s Y <dir> <seq> <nway> <output>\n", __func__);
}
int
main(int argc, char ** argv)
{
if (argc < 3) {
helper_message();
return 0;
}
const char type = argv[1][0];
const char * const dirname = argv[2];
if (type == 'z') {
struct msstz * const z = msstz_open(dirname, 16, NULL);
if (!z) {
printf("open z at %s failed\n", dirname);
return 0;
}
struct msstv * const v = msstz_getv(z);
msstv_fprint(v, stdout);
msstz_putv(z, v);
return 0;
}
if (argc < 5) {
helper_message();
return 0;
}
const u64 seq = a2u64(argv[3]);
const u32 way = a2u32(argv[4]);
if (type == 'x') {
struct sst * const sst = sst_open(dirname, seq, way);
if (!sst) {
fprintf(stderr, "sst_open failed\n");
return 0;
}
sst_fprint(sst, stdout);
sst_destroy(sst);
return 0;
} else if (type == 'y') {
struct msst * const msst = mssty_open(dirname, seq, way);
if (!msst) {
fprintf(stderr, "mssty_open failed\n");
return 0;
}
mssty_fprint(msst, stdout);
mssty_destroy(msst);
return 0;
}
if (argc < 6) {
helper_message();
return 0;
}
if (type == 'X') {
struct sst * const sst = sst_open(dirname, seq, way);
if (!sst) {
fprintf(stderr, "sst_open failed\n");
return 0;
}
sst_dump(sst, argv[5]);
sst_destroy(sst);
} else if (type == 'Y') {
struct msst * const msst = mssty_open(dirname, seq, way);
if (!msst) {
fprintf(stderr, "mssty_open failed\n");
return 0;
}
mssty_dump(msst, argv[5]);
mssty_destroy(msst);
}
return 0;
}