-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
38 lines (29 loc) · 1 KB
/
main.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
31
32
33
34
35
36
37
38
#include "twkg.h"
void print_help() {
fprintf(stderr,
"usage: twkg [gen|rec] metafile [tang_db_dir if rec | p if gen] < wifi_json\n\n\
generate: twkg gen /usr/share/twkg/metafile.bin 3 < /tmp/wifi.json\n\
reconstruct: twkg rec /usr/share/twkg/metafile.bin /tmp/tang/db/ < ubus call iwinfo scan '{\"device\":\"phy0-ap0\"}'\n");
}
int main(int argc, char **argv) {
if(argc != 4) goto arg_err;
const char *mode = argv[1];
const char *metafile_path = argv[2];
TKGNetworksArray_t input_nets = {};
int input_n = 0;
TKGStatus_t tkgret = tkg_load_nets(&input_nets, &input_n, "/dev/stdin");
if (tkgret != TKG_OK) {
printf("Error loading networks from stdin\n");
return 1;
}
if (strcmp(mode, "gen") == 0) {
const int input_p = atoi(argv[3]);
return tkg_run_generate(metafile_path, &input_nets, input_p);
} else if (strcmp(mode, "rec") == 0) {
return tkg_run_recreate(metafile_path, &input_nets, argv[3]);
}
arg_err:
// invalid mode or usage error
print_help();
return 1;
}