aboutsummaryrefslogtreecommitdiff
path: root/c_implementation/src/ak_fs_main.c
blob: e39954473d9297b9ef118484b4b316746d28cf48 (plain)
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
#include <getopt.h>
#include <stdio.h>
#include <libaklog.h>
#include <libakfs.h>

static int ak_fs_usage()
{
    ak_log_debug(__func__, "Available commands:");
    ak_log_debug(__func__, "akfs --list");
    ak_log_debug(__func__, "akfs --cfm <map hash>");
    return 1;
}

int ak_fs_main(int argc, char** argv)
{
    int option;
    int logind = 0;
    akfs_map_v3 map;
    static struct option long_options[] = {
        {"help", no_argument, 0, 'h'},
        {"list", no_argument, 0, 'l'},
        {"cfm", required_argument, 0, 'C'},
        {0,0,0,0}
    };
    while(1)
    {
        option = getopt_long(argc, argv, "hlC:", long_options, &logind);
        if ( option == -1 ) return ak_fs_usage();
        switch(option)
        {
            case 'h':
                return ak_fs_usage();
            case 'l':
                return ak_fs_ls();
            case 'C':
                ak_fs_map_v3_init(&map);
                if ( ak_fs_sha512sum_string_to_struct(optarg, &map.mh) != 0 ) return -1;
                if ( ak_fs_map_v3_open_from_file(&map) != 0 ) return -2;
                return ak_fs_cfm(&map);
            default:
                printf("double lol\n");
                return 4;
        }
    }
    return 0;
}

int main(int argc, char **argv)
{
    return ak_fs_main(argc, argv);
}