1 /*
2 * Copyright (c) 2020, Rockchip Electronics Co., Ltd
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14 #define _GNU_SOURCE
15
16 #include "common.h"
17 #include ".j2s_generated.h"
18
main(int argc,char ** argv)19 int main(int argc, char** argv) {
20
21 FILE* fp = NULL;
22 size_t total = 0;
23 size_t wr_size = 0;
24
25 DASSERT_MSG(argc > 1, return -1,
26 "usage: %s <input header> [root struct]\n", argv[0]);
27
28 INFO("j2s2bin to file: %s\n", argv[1]);
29
30 j2s_ctx ctx;
31 _j2s_init(&ctx);
32
33 fp = fopen(argv[1],"wb+");
34 DASSERT_MSG(fp, return -1, "failed to open %s\n", argv[1]);
35
36 wr_size = fwrite(objs,sizeof(objs), 1, fp);
37 total = wr_size * sizeof(objs);
38 printf("write objs size: %zu, expected: %zu\n", wr_size * sizeof(objs), sizeof(objs));
39
40 wr_size = fwrite(structs,sizeof(structs), 1, fp);
41 total += wr_size * sizeof(structs);
42 printf("write structs size: %zu, expected: %zu\n", wr_size * sizeof(structs), sizeof(structs));
43
44 wr_size = fwrite(enums,sizeof(enums), 1, fp);
45 total += wr_size * sizeof(enums);
46 printf("write enums size: %zu, expected: %zu\n", wr_size * sizeof(enums), sizeof(enums));
47
48 wr_size = fwrite(enum_values,sizeof(enum_values), 1, fp);
49 total += wr_size * sizeof(enum_values);
50 printf("write enum_values size: %zu, expected: %zu\n", wr_size * sizeof(enum_values), sizeof(enum_values));
51
52 printf("write total size: %zu, expected: %zu\n", total,
53 sizeof(objs) + sizeof(structs) + sizeof(enums) + sizeof(enum_values));
54
55 fclose(fp);
56
57 return 0;
58 }
59