aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt4
-rw-r--r--src/actionhelper.h2
-rw-r--r--src/actions.h2
-rw-r--r--src/clparser.c (renamed from src/actionparser.c)69
-rw-r--r--src/clparser.h (renamed from src/actionparser.h)18
-rw-r--r--src/confparser.h2
-rw-r--r--src/dbhelper.h2
7 files changed, 37 insertions, 62 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e3ea656..8d88de5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -55,7 +55,7 @@ configure_file(
set(ckBin_src ${SRC_DIR}/ck.c)
set(ckUnitTest_src ${UNIT_TEST_DIR}/ck-test.c)
set(ckLib_src
- ${SRC_DIR}/actionparser.c
+ ${SRC_DIR}/clparser.c
${SRC_DIR}/actions.c
${SRC_DIR}/actionhelper.c
${SRC_DIR}/confparser.c
@@ -67,7 +67,7 @@ set(ckLib_src
)
set(ckLib_hdr
- ${SRC_DIR}/actionparser.h
+ ${SRC_DIR}/clparser.h
${SRC_DIR}/actions.h
${SRC_DIR}/actionhelper.h
${SRC_DIR}/confparser.h
diff --git a/src/actionhelper.h b/src/actionhelper.h
index 0c96a8a..f7da0dd 100644
--- a/src/actionhelper.h
+++ b/src/actionhelper.h
@@ -56,7 +56,7 @@ int restore_make_links(cklist *from, cklist *to);
/************************/
/* PRINT RESULTS & HELP */
/************************/
-#define X(ACTION) \
+#define X(ACTION) \
void print_##ACTION##_result(int err); \
void print_##ACTION##_help(void);
CK_ACTIONS
diff --git a/src/actions.h b/src/actions.h
index aa8cf44..d261cc6 100644
--- a/src/actions.h
+++ b/src/actions.h
@@ -17,7 +17,7 @@
#define ACTIONS_H
#include "ckutil.h"
-#include "actionparser.h"
+#include "clparser.h"
#include "confparser.h"
#define X(ACTION) \
diff --git a/src/actionparser.c b/src/clparser.c
index 398ba5e..6dbd62a 100644
--- a/src/actionparser.c
+++ b/src/clparser.c
@@ -1,4 +1,4 @@
-/* actionparser.c - Action parser for ck -------------------------------*- C -*-
+/* clparser.c - Command line parser for ck -----------------------------*- C -*-
*
* This file is part of ck, the config keeper
*
@@ -9,10 +9,11 @@
*
* -------------------------------------------------------------------------- */
#include "ckutil.h"
-#include "actionparser.h"
+#include "clparser.h"
#include "confparser.h"
#include "ckinfo.h"
#include "ckerrlog.h"
+#include "actionhelper.h"
ERRLOG(parser);
@@ -59,7 +60,7 @@ int next_token() {
}
}
-void fill_args_list(int arg_num, UserOpt *opt) {
+static void fill_args_list(int arg_num, UserOpt *opt) {
for (int i = 0; i < arg_num; i++) {
if (next_token()) {
list_add(opt->args, token);
@@ -71,7 +72,7 @@ void fill_args_list(int arg_num, UserOpt *opt) {
* `pos` should be at 2
* like so "ck ACTION ..."
* ^ */
-int parse_INIT(UserOpt *opt) {
+static int parse_INIT(UserOpt *opt) {
/* INIT expects 2 arguments
* starting from 0 */
int arg_num = 2;
@@ -84,7 +85,7 @@ int parse_INIT(UserOpt *opt) {
return 0;
}
-int parse_ADD(UserOpt *opt) {
+static int parse_ADD(UserOpt *opt) {
/* ADD expects 2 to 4 arguments */
if (optNum < pos + 2
|| optNum > pos + 4) {
@@ -97,7 +98,7 @@ int parse_ADD(UserOpt *opt) {
return 0;
}
-int parse_DEL(UserOpt *opt) {
+static int parse_DEL(UserOpt *opt) {
/* DEL expects 1 to 2 arguments */
if (optNum < pos + 1
|| optNum > pos + 2) {
@@ -110,7 +111,7 @@ int parse_DEL(UserOpt *opt) {
return 0;
}
-int parse_EDIT(UserOpt *opt) {
+static int parse_EDIT(UserOpt *opt) {
/* EDIT expects 1 to 2 arguments */
if (optNum < pos + 1
|| optNum > pos + 2) {
@@ -123,7 +124,7 @@ int parse_EDIT(UserOpt *opt) {
return 0;
}
-int parse_LIST(UserOpt *opt) {
+static int parse_LIST(UserOpt *opt) {
/* List expects 1 to 6 arguments */
if (optNum < pos + 1
|| optNum > pos + 6) {
@@ -136,7 +137,7 @@ int parse_LIST(UserOpt *opt) {
return 0;
}
-int parse_SEARCH(UserOpt *opt) {
+static int parse_SEARCH(UserOpt *opt) {
/* Search expects a maximum of 1 argument */
if (optNum < pos + 1
|| optNum > pos + 1) {
@@ -149,7 +150,7 @@ int parse_SEARCH(UserOpt *opt) {
return 0;
}
-int parse_HELP(UserOpt *opt) {
+static int parse_HELP(UserOpt *opt) {
/* Help expects a maximum of 1 argument */
if (optNum < pos + 1
|| optNum > pos + 1) {
@@ -162,7 +163,7 @@ int parse_HELP(UserOpt *opt) {
return 0;
}
-int parse_RESTORE(UserOpt *opt) {
+static int parse_RESTORE(UserOpt *opt) {
/* Restore expects 1 to 2 arguments */
if (optNum < pos + 1
|| optNum > pos + 2) {
@@ -175,7 +176,7 @@ int parse_RESTORE(UserOpt *opt) {
return 0;
}
-void determine_action(UserOpt *opt) {
+static void determine_action(UserOpt *opt) {
/* get action */
if (!next_token()) {
opt->action = CK_WRONG_ACTION;
@@ -190,7 +191,7 @@ void determine_action(UserOpt *opt) {
return;
}
-int parse_vals(UserOpt *opt) {
+static int parse_vals(UserOpt *opt) {
/* find the action */
determine_action(opt);
if (opt->action == CK_WRONG_ACTION) {
@@ -225,7 +226,7 @@ CkAction parser_get_action(const char *name, char *actionName) {
return CK_WRONG_ACTION;
}
-UserOpt make_empty_user_opt() {
+static UserOpt make_empty_user_opt() {
UserOpt opt;
opt.action = CK_WRONG_ACTION;
opt.err = PERR_NOERR;
@@ -245,7 +246,7 @@ void free_user_opt(UserOpt *opt) {
}
/* find the correct config */
-int get_config(UserOpt *opt) {
+static int get_config(UserOpt *opt) {
/* If it's a cli option */
if (next_token()) {
for (int i = 1; i < atoi(strConfDir[0]) + 1; i++) {
@@ -277,7 +278,7 @@ int get_config(UserOpt *opt) {
return find_config(opt);
}
-int version() {
+static int version() {
/* get first token */
if (next_token()) {
for (int i = 1; i < atoi(strVersion[0]) + 1; i++) {
@@ -293,7 +294,7 @@ int version() {
return 0;
}
-void verbose() {
+static void verbose() {
/* get first token */
if (next_token()) {
for (int i = 1; i < atoi(strVerbose1[0]) + 1; i++) {
@@ -340,8 +341,7 @@ char * get_possible_action_strings(char *dest, CkAction ckAction) {
return dest;
}
-void print_parser_error(UserOpt *opt) {
- char errStr[STR_L] = "";
+static void print_parser_error(UserOpt *opt) {
char names[STR_M] = "";
get_possible_action_strings(names, opt->action);
@@ -351,34 +351,17 @@ void print_parser_error(UserOpt *opt) {
case PERR_UNKNOWN_ACTION:
ERR("Unknown action: %s", token);
return;
- case PERR_INIT_WRONG:
- sprintf(errStr, "Initialize database\nUsage: %s version_control_dir secret_dir", names);
+#define X(ACTION) \
+ case PERR_ ##ACTION## _WRONG: \
+ HELP("Usage:\n%s", names); \
+ print_##ACTION##_help(); \
break;
- case PERR_ADD_WRONG:
- sprintf(errStr, "Add config \nUsage: %s ProgramName ConfigPath [-s](secret) [-p](primary)", names);
- break;
- case PERR_DEL_WRONG:
- sprintf(errStr, "Delete config or program\nUsage: %s {ProgramName} | {-c ConfigPath (as shown by ck list)}", names);
- break;
- case PERR_EDIT_WRONG:
- sprintf(errStr, "Edit config with $EDITOR (%s)\nUsage: %s ProgramName [configBasename]", getenv("EDITOR"), names);
- break;
- case PERR_LIST_WRONG:
- sprintf(errStr, "List programs, configs and more\nUsage: %s {programs|paths|-p ProgramName} [-t list-type] | {tree | ckconf} [-a] [-b]", names);
- break;
- case PERR_SEARCH_WRONG:
- sprintf(errStr, "Search through the configs with grep\nUsage: %s search-term", names);
- break;
- case PERR_HELP_WRONG:
- sprintf(errStr, "Get help for a ck action.\nUsage: %s action", names);
- break;
- case PERR_RESTORE_WRONG:
- sprintf(errStr, "Restore links of programs.\nUsage: %s {all} | {-p programName}", names);
+ CK_ACTIONS;
+#undef X
}
- HELP("%s", errStr);
}
-void print_parser_help() {
+static void print_parser_help() {
char names[STR_M] = "";
ckhelp("ck - the config keeper");
ckhelp("Usage:");
diff --git a/src/actionparser.h b/src/clparser.h
index 24ad763..9b22b87 100644
--- a/src/actionparser.h
+++ b/src/clparser.h
@@ -1,4 +1,4 @@
-/* actionparser.h - Action parser for ck -------------------------------*- C -*-
+/* clparser.h - Command line parser for ck -----------------------------*- C -*-
*
* This file is part of ck, the config keeper
*
@@ -9,14 +9,14 @@
*
* -----------------------------------------------------------------------------
*
- * The code here and in actionparser.c is responsible for parsing
+ * The code here and in clparser.c is responsible for parsing
* the user's input from the command line and return a struct
* of the user's options ready to be handled by the rest of the
* procedures.
*
* -------------------------------------------------------------------------- */
-#ifndef ACTIONPARSER_H
-#define ACTIONPARSER_H
+#ifndef CLPARSER_H
+#define CLPARSER_H
#include "cklist.h"
@@ -49,14 +49,6 @@ enum CkActions {
};
typedef enum CkActions CkAction;
-enum ActionParserResults {
- APR_OK,
- APR_ERR,
- APR_HELP,
- APR_VERSION
-};
-typedef enum ActionParserResults ActionParseResult;
-
typedef struct UserOptions UserOpt;
struct UserOptions {
ParseError err;
@@ -73,4 +65,4 @@ CkAction parser_get_action(const char *name, char *actionName);
char * get_possible_action_strings(char *dest, CkAction ckAction);
void free_user_opt(UserOpt *opt);
-#endif // ACTIONPARSER_H
+#endif // CLPARSER_H
diff --git a/src/confparser.h b/src/confparser.h
index 11ada7f..ebcf0c7 100644
--- a/src/confparser.h
+++ b/src/confparser.h
@@ -16,7 +16,7 @@
#ifndef CONFPARSER_H
#define CONFPARSER_H
-#include "actionparser.h"
+#include "clparser.h"
#define CONFIG_VARIABLES_TABLE \
X(vc_dir, " version_control_dir = %s ", "Version Control directory") \
diff --git a/src/dbhelper.h b/src/dbhelper.h
index 86e3a99..31559cc 100644
--- a/src/dbhelper.h
+++ b/src/dbhelper.h
@@ -18,7 +18,7 @@
#include <sqlite3.h>
-#include "actionparser.h"
+#include "clparser.h"
#include "ckutil.h"
/********************/