diff options
Diffstat (limited to 'src/actionparser.c')
-rw-r--r-- | src/actionparser.c | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/src/actionparser.c b/src/actionparser.c index 82ae25e..deae72a 100644 --- a/src/actionparser.c +++ b/src/actionparser.c @@ -16,14 +16,17 @@ #include "actionparser.h" #include "ckutil.h" #include "ckinfo.h" +#include "ckerrlog.h" + +#define COMPONENT "action parser" /* accepted commands */ /* [0] is the count */ const char* const strINIT[] = {"3", "init", "i", "-i"}; const char* const strADD[] = {"3", "add", "a", "-a"}; -const char* const strDEL[] = {"3", "del", "d", "-d"}; +const char* const strDEL[] = {"4", "delete", "del","d", "-d"}; const char* const strEDIT[] = {"3", "edit", "e", "-e"}; -const char* const strLIST[] = {"5", "list", "l", "ls", "-l", "-ls"}; +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"}; @@ -236,7 +239,7 @@ void get_config(UserOpt *opt) { } char * defaultConf = ".ck"; char * home = getenv("HOME"); - opt->confDir = malloc(strlen(defaultConf) + 1 /* '/' */ + strlen(home)+1); + opt->confDir = malloc(strlen(defaultConf) + 1 /* '/' */ + strlen(home) + 1); str_join_dirname_with_basename(opt->confDir, home, defaultConf); // rewind @@ -244,20 +247,21 @@ void get_config(UserOpt *opt) { token = opts[pos]; } -void version() { +int 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); + return 1; } } // rewind pos = pos - 1; token = opts[pos]; + return 0; } void get_possible_action_strings(char *dest, CkAction ckAction) { @@ -316,27 +320,28 @@ void print_parser_error(UserOpt *opt) { sprintf(errStr, "Usage: ........"); break; } - printf("Parsing error\n%s\n", errStr); + ERR("%s", errStr); } void print_parser_help() { char names[STR_S]; - printf("ck - the config keeper\n"); - printf("Usage:\n"); + ckhelp("ck - the config keeper"); + ckhelp("Usage:"); get_possible_action_strings(names, CKA_INIT); - printf("Initialize: \t%s\n", names); + ckhelp("Initialize: \t%s", names); get_possible_action_strings(names, CKA_ADD); - printf("Add config: \t%s\n", names); + ckhelp("Add config: \t%s", names); get_possible_action_strings(names, CKA_DEL); - printf("Delete config: \t%s\n", names); + ckhelp("Delete config: \t%s", names); get_possible_action_strings(names, CKA_EDIT); - printf("Edit config: \t%s\n", names); + ckhelp("Edit config: \t%s", names); get_possible_action_strings(names, CKA_LIST); - printf("List configs: \t%s\n", names); + ckhelp("List configs: \t%s", names); get_possible_action_strings(names, CKA_SEARCH); - printf("Search: \t%s\n", names); + ckhelp("Search: \t%s", names); get_possible_action_strings(names, CKA_HELP); - printf("Print this: \t%s\n", names); + ckhelp("Print this: \t%s", names); + report_help(); } ActionParseResult parse_action(int argc, char* argv[], UserOpt *opt) { @@ -352,10 +357,13 @@ ActionParseResult parse_action(int argc, char* argv[], UserOpt *opt) { next_token(); /* handle version info */ - version(); + if (version()) { + return APR_VERSION; + } /* figure what is the config file */ get_config(opt); + cklog("Found ck configuration directory in %s", opt->confDir); /* find the action */ determine_action(opt); |