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 | |
parent | a087fe8c11f6139e0e0d48f055f8184e906befce (diff) | |
download | ck-7286c9fc5b55df0499c7a8f28b5e61ec57e788cc.tar.gz ck-7286c9fc5b55df0499c7a8f28b5e61ec57e788cc.tar.bz2 ck-7286c9fc5b55df0499c7a8f28b5e61ec57e788cc.zip |
Add licence and version info
Diffstat (limited to 'src')
-rw-r--r-- | src/actionparser.c | 27 | ||||
-rw-r--r-- | src/actions.c | 1 | ||||
-rw-r--r-- | src/ckinfo.h.in | 18 |
3 files changed, 44 insertions, 2 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); diff --git a/src/actions.c b/src/actions.c index b164779..54e781b 100644 --- a/src/actions.c +++ b/src/actions.c @@ -154,7 +154,6 @@ int run_LIST(UserOpt *opt, Conf *conf) { list_free(list_type); return 0; case LT_NONE: - printf("What should I list? (paths, configs)\n"); close_DB(&db); list_free(list_type); return 1; diff --git a/src/ckinfo.h.in b/src/ckinfo.h.in new file mode 100644 index 0000000..3b7f843 --- /dev/null +++ b/src/ckinfo.h.in @@ -0,0 +1,18 @@ +#ifndef CK_INFO_H +#define CK_INFO_H + +#include <stdio.h> + +#define CK_MAJOR_VERSION @ck_MAJOR_VERSION@ +#define CK_MINOR_VERSION @ck_MINOR_VERSION@ + + +extern void print_version() { + printf("ck version %d.%d\n", CK_MAJOR_VERSION, CK_MINOR_VERSION); + printf("ck Copyright (C) 2018 gramanas\n\ +This program comes with ABSOLUTELY NO WARRANTY.\n\ +This is free software, and you are welcome to redistribute it under\n\ +certain condition. See the LICENCE file in the source tree for details.\n"); +} + +#endif /* CK_INFO_H */ |