diff options
author | Anastasis Grammenos <anastasis.gramm2@gmail.com> | 2018-09-21 18:43:38 +0300 |
---|---|---|
committer | Anastasis Grammenos <anastasis.gramm2@gmail.com> | 2018-09-21 18:43:38 +0300 |
commit | dba9e5352a9ff792a71fbaede28f013b5d03daae (patch) | |
tree | ca063edee4568912e9d7a6b6ddf09f801005e7fa /src/actionhelper.c | |
parent | 8693064200ad015a6b6d07f99a3170fa89012a71 (diff) | |
download | ck-dba9e5352a9ff792a71fbaede28f013b5d03daae.tar.gz ck-dba9e5352a9ff792a71fbaede28f013b5d03daae.tar.bz2 ck-dba9e5352a9ff792a71fbaede28f013b5d03daae.zip |
Small refactoring in actions
Diffstat (limited to 'src/actionhelper.c')
-rw-r--r-- | src/actionhelper.c | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/src/actionhelper.c b/src/actionhelper.c index c4c1f34..5007b62 100644 --- a/src/actionhelper.c +++ b/src/actionhelper.c @@ -48,6 +48,48 @@ void move_config(const AddOpt *opt, const Conf *conf, char *ret) { } } +AddOpt add_make_options(cklist *args) { + list_rewind(args); + /* since we are here, the first two argumens must exist */ + AddOpt addOpt = { + .progName = list_get(args), + .secret = 0, + .prime = 0, + .err = ADD_NO_ERR + }; + + list_next(args); + if (!util_is_file_rw(list_get(args))) { + addOpt.err = ADD_ERR_WRONG_CONFIG; + return addOpt; + } + realpath(list_get(args), addOpt.confPath); + + while (list_next(args)) { + if (strcmp(list_get(args), "-s") == 0 && addOpt.secret == 0) { + addOpt.secret = 1; + } else if (strcmp(list_get(args), "-p") == 0 && addOpt.prime == 0) { + addOpt.prime = 1; + } else { + addOpt.err = ADD_ERR_WRONG_FLAGS; + return addOpt; + } + } + list_rewind(args); + return addOpt; +} + +void add_print_opts(AddOpt *opt) { + printf("Program:\t%s\nConfig:\t\t%s\n", opt->progName, opt->confPath); + if (opt->prime && opt->secret) { + printf("Options:\tsecret, primary\n"); + } else if (opt->prime) { + printf("Options:\tprimary\n"); + } else if (opt->secret) { + printf("Options:\tsecret\n"); + } +} + void add_make_link(const AddOpt *opt, const Conf *conf) { char newPath[STR_L]; @@ -67,3 +109,106 @@ edit_get_config_or_suggestions(cklist *args, char *ret) { UNUSED(ret); return ERC_ERR; } + +ListOpt list_make_options(cklist *args) { + list_rewind(args); + ListOpt listOpt = { + ._lt = LT_NONE, + ._lst = LST_PLAIN, + .err = 0 + }; + + if (list_size(args)) { + do { + if (strcmp(list_get(args), "-t") == 0) { + if (!list_next(args)) { + listOpt.err = 1; + break; + } + if (strcmp(list_get(args), "plain") == 0) { + listOpt._lst = LST_PLAIN; + } + else if (strcmp(list_get(args), "lisp") == 0) { + listOpt._lst = LST_LISP; + } + else if (strcmp(list_get(args), "python") == 0) { + listOpt._lst = LST_PYTHON; + } + else { + listOpt.err = 1; + } + } + else if (strcmp(list_get(args), "paths") == 0) { + listOpt._lt = LT_PATH; + } + else if (strcmp(list_get(args), "programs") == 0) { + listOpt._lt = LT_PROGRAM; + } + else if (strcmp(list_get(args), "tree") == 0) { + listOpt._lt = LT_TREE; + } + else { + listOpt.err = 1; + } + } while(list_next(args)); + } + list_rewind(args); + return listOpt; +} + +/*****************/ +/* PRINT RESULTS */ +/*****************/ + +void print_INIT_result(int ok) { + if (ok) { + printf("Initialized empty ckdb.\n"); + } +} + +void print_ADD_result(int ok) { + if (ok) { + printf("ckdb updated succesfully.\n"); + return; + } + printf("Could not complete add transaction.\n"); +} + +void print_DEL_result(int ok) { + if (ok) { + printf("succes\n"); + return; + } + printf("Not Supported\n"); +} + +void print_EDIT_result(int ok) { + if (ok) { + printf("succes\n"); + return; + } + printf("failure\n"); +} + +void print_LIST_result(int ok) { + if (ok) { + return; + } + printf("Wrong list arguments\n"); +} + +void print_SEARCH_result(int ok) { + if (ok) { + printf("succes\n"); + return; + } + printf("Not Supported\n"); +} + +void print_HELP_result(int ok) { + if (ok) { + printf("succes\n"); + return; + } + printf("failure\n"); +} |