diff options
Diffstat (limited to 'src/actionparser.c')
-rw-r--r-- | src/actionparser.c | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/actionparser.c b/src/actionparser.c index 3e193ff..0057e7f 100644 --- a/src/actionparser.c +++ b/src/actionparser.c @@ -15,6 +15,7 @@ * -------------------------------------------------------------------------- */ #include "actionparser.h" #include "ckutil.h" +#include "ckinfo.h" /* accepted commands */ /* [0] is the count */ @@ -26,6 +27,7 @@ const char* const strLIST[] = {"5", "list", "l", "ls", "-l", "-ls"}; const char* const strSEARCH[] = {"3", "search", "s", "-s"}; const char* const strHELP[] = {"5", "help", "h", "-?", "-h", "--help"}; const char* const strConfDir[] = {"4", "config", "conf", "c", "-c"}; +const char* const strVersion[] = {"4", "version", "--version", "-v", "-V"}; /* Number of opts */ static int optNum; @@ -100,6 +102,7 @@ int parse_ADD(UserOpt *opt) { int parse_DEL(UserOpt *opt) { return -1; } + int parse_EDIT(UserOpt *opt) { /* EDIT expects 1 to 2 arguments */ if (optNum <= pos || optNum > pos + 2) { @@ -111,9 +114,10 @@ int parse_EDIT(UserOpt *opt) { fill_args_list(arg_num, opt); return 1; } + int parse_LIST(UserOpt *opt) { /* List expects a maximum of than 3 arguments */ - if (optNum > pos + 4) { + if (optNum <= pos || optNum > pos + 4) { opt->err = PERR_LIST_WRONG; return -1; } @@ -122,6 +126,7 @@ int parse_LIST(UserOpt *opt) { fill_args_list(arg_num, opt); return 1; } + int parse_SEARCH(UserOpt *opt) { /* Search expects a maximum of 1 argument */ if (optNum > pos + 1) { @@ -133,6 +138,7 @@ int parse_SEARCH(UserOpt *opt) { fill_args_list(arg_num, opt); return 1; } + int parse_HELP(UserOpt *opt) { return -1; } @@ -230,6 +236,22 @@ void get_config(UserOpt *opt) { token = opts[pos]; } +void version() { + /* get first token */ + next_token(); + + for (int i = 1; i < atoi(strVersion[0]) + 1; i++) { + if (strcmp(token, strVersion[i]) == 0) { + print_version(); + exit(0); + } + } + + // rewind + pos = pos - 1; + token = opts[pos]; +} + void get_possible_action_strings(char *dest, CkAction ckAction) { char buf[STR_S]; switch (ckAction) { @@ -321,6 +343,9 @@ ActionParseResult parse_action(int argc, char* argv[], UserOpt *opt) { /* skip the program name */ next_token(); + /* handle version info */ + version(); + /* figure what is the config file */ get_config(opt); |