diff options
author | Anastasis Grammenos <anastasis.gramm2@gmail.com> | 2018-10-04 17:20:37 +0300 |
---|---|---|
committer | Anastasis Grammenos <anastasis.gramm2@gmail.com> | 2018-10-04 17:20:37 +0300 |
commit | 764a205fe9676afcdb94998b5e553d650bda86ba (patch) | |
tree | d3d0650a60218e6a470a7a9d9e0bfbf9860a8833 /src/actionparser.c | |
parent | 9c24e438b689af042672182f6d87f824ef435492 (diff) | |
download | ck-764a205fe9676afcdb94998b5e553d650bda86ba.tar.gz ck-764a205fe9676afcdb94998b5e553d650bda86ba.tar.bz2 ck-764a205fe9676afcdb94998b5e553d650bda86ba.zip |
Errlog with cklist, verbose flag, bugfix in search
Diffstat (limited to 'src/actionparser.c')
-rw-r--r-- | src/actionparser.c | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/src/actionparser.c b/src/actionparser.c index deae72a..d5ad071 100644 --- a/src/actionparser.c +++ b/src/actionparser.c @@ -18,7 +18,7 @@ #include "ckinfo.h" #include "ckerrlog.h" -#define COMPONENT "action parser" +ERRLOG(action parser); /* accepted commands */ /* [0] is the count */ @@ -30,7 +30,9 @@ const char* const strLIST[] = {"5", "list", "ls", "l", "-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"}; +const char* const strVersion[] = {"2", "version", "--version"}; +const char* const strVerbose1[] = {"2", "--verbose", "-v"}; +const char* const strVerbose2[] = {"2", "--Verbose", "-V"}; /* Number of opts */ static int optNum; @@ -140,7 +142,7 @@ int parse_LIST(UserOpt *opt) { int parse_SEARCH(UserOpt *opt) { /* Search expects a maximum of 1 argument */ - if (optNum > pos + 1) { + if (optNum <= pos || optNum > pos + 1) { opt->err = PERR_SEARCH_WRONG; return -1; } @@ -264,6 +266,29 @@ int version() { return 0; } +void verbose() { + /* get first token */ + next_token(); + + for (int i = 1; i < atoi(strVerbose1[0]) + 1; i++) { + if (strcmp(token, strVerbose1[i]) == 0) { + errlog_set_verbose(1);; + return; + } + } + + for (int i = 1; i < atoi(strVerbose2[0]) + 1; i++) { + if (strcmp(token, strVerbose2[i]) == 0) { + errlog_set_verbose(2);; + return; + } + } + + // rewind + pos = pos - 1; + token = opts[pos]; +} + void get_possible_action_strings(char *dest, CkAction ckAction) { char buf[STR_S]; switch (ckAction) { @@ -361,6 +386,9 @@ ActionParseResult parse_action(int argc, char* argv[], UserOpt *opt) { return APR_VERSION; } + /* set verbose level */ + verbose(); + /* figure what is the config file */ get_config(opt); cklog("Found ck configuration directory in %s", opt->confDir); |