diff options
author | gramanas <anastasis.gramm2@gmail.com> | 2018-09-27 00:51:25 +0300 |
---|---|---|
committer | gramanas <anastasis.gramm2@gmail.com> | 2018-09-27 00:51:25 +0300 |
commit | 7286c9fc5b55df0499c7a8f28b5e61ec57e788cc (patch) | |
tree | 9aa8cd4c6ddd4e27d84dc94c6b91bdb0e380062d /src/actionparser.c | |
parent | a087fe8c11f6139e0e0d48f055f8184e906befce (diff) | |
download | ck-7286c9fc5b55df0499c7a8f28b5e61ec57e788cc.tar.gz ck-7286c9fc5b55df0499c7a8f28b5e61ec57e788cc.tar.bz2 ck-7286c9fc5b55df0499c7a8f28b5e61ec57e788cc.zip |
Add licence and version info
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); |