-
Notifications
You must be signed in to change notification settings - Fork 1
/
migrate.c
30 lines (28 loc) · 943 Bytes
/
migrate.c
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
#include <stdio.h>
#include <string.h>
#include <simple_protobuf.h>
#include "dict.h"
#include "old_dict.h"
DICTBLK dict;
dict_t d;
int main(int argc, char** argv) {
if(argc == 3) {
uint32_t* items_len = align_struct(sizeof(dict_t), 2, d.key, d.data);
FILE* old = fopen(argv[1], "rb");
FILE* new = fopen(argv[2], "wb");
if(old && new) {
while(fread(&dict, DICTBLKSZ, 1, old) > 0) {
uint8_t ks = dict.keysize;
dict.key[ks] = 0;
uint8_t ds = dict.datasize;
dict.data[ds] = 0;
memset(&d, 0, sizeof(dict_t));
memcpy(d.key, dict.key, ks);
memcpy(d.data, dict.data, ds);
set_pb(new, items_len, sizeof(dict_t), &d);
}
fclose(old);
fclose(new);
} else puts("Open file error.");
} else puts("Usage: <old_dict> <new_dict>");
}