diff options
author | gramanas <anastasis.gramm2@gmail.com> | 2018-09-26 12:07:48 +0300 |
---|---|---|
committer | gramanas <anastasis.gramm2@gmail.com> | 2018-09-26 12:07:48 +0300 |
commit | 7d0d0e5f1570f06564e07f5e55b9bef9db517f8b (patch) | |
tree | e8007bd87a3cb264346cd0da5544bd1f8f0400ac | |
parent | ba6ff53bebd1ea6c51f12ba5dd218dcce8348df1 (diff) | |
download | ck-7d0d0e5f1570f06564e07f5e55b9bef9db517f8b.tar.gz ck-7d0d0e5f1570f06564e07f5e55b9bef9db517f8b.tar.bz2 ck-7d0d0e5f1570f06564e07f5e55b9bef9db517f8b.zip |
list can now show attributes (secret, primary)
-rw-r--r-- | src/actionhelper.c | 5 | ||||
-rw-r--r-- | src/actionparser.c | 4 | ||||
-rw-r--r-- | src/actions.c | 8 | ||||
-rw-r--r-- | src/actions.h | 1 | ||||
-rw-r--r-- | src/argumentparser.h | 14 | ||||
-rw-r--r-- | src/dbhelper.c | 6 | ||||
-rw-r--r-- | src/dbhelper.h | 2 | ||||
-rw-r--r-- | src/dblayer.c | 38 | ||||
-rw-r--r-- | src/dblayer.h | 4 |
9 files changed, 53 insertions, 29 deletions
diff --git a/src/actionhelper.c b/src/actionhelper.c index e0876eb..c3b1b81 100644 --- a/src/actionhelper.c +++ b/src/actionhelper.c @@ -115,11 +115,16 @@ ListOpt list_make_options(cklist *args) { ListOpt listOpt = { ._lt = LT_NONE, ._lst = LST_PLAIN, + .attr = 0, .err = 0 }; if (list_size(args)) { do { + if (strcmp(list_get(args), "-a") == 0) { + listOpt.attr = 1; + continue; + } if (strcmp(list_get(args), "-t") == 0) { if (!list_next(args)) { listOpt.err = 1; diff --git a/src/actionparser.c b/src/actionparser.c index 580eb01..3e193ff 100644 --- a/src/actionparser.c +++ b/src/actionparser.c @@ -113,7 +113,7 @@ int parse_EDIT(UserOpt *opt) { } int parse_LIST(UserOpt *opt) { /* List expects a maximum of than 3 arguments */ - if (optNum > pos + 3) { + if (optNum > pos + 4) { opt->err = PERR_LIST_WRONG; return -1; } @@ -277,7 +277,7 @@ void print_parser_error(UserOpt *opt) { sprintf(errStr, "Edit config with $EDITOR\nUsage: %s ProgramName or configBasename (or both)", names); break; case PERR_LIST_WRONG: - sprintf(errStr, "List programs, configs and more\nUsage: %s value-to-list (or tree) [-t list-type]", names); + sprintf(errStr, "List programs, configs and more\nUsage: %s value-to-list (or tree) [-t list-type] [-a]", names); break; case PERR_SEARCH_WRONG: sprintf(errStr, "Search through the configs with grep\nUsage: %s search-term", names); diff --git a/src/actions.c b/src/actions.c index efffc1b..b164779 100644 --- a/src/actions.c +++ b/src/actions.c @@ -133,8 +133,8 @@ int run_LIST(UserOpt *opt, Conf *conf) { } cklist *list_type = list_make_new(); - ListOpt listOpt = list_make_options(opt->args); + if (listOpt.err) { close_DB(&db); list_free(list_type); @@ -142,13 +142,13 @@ int run_LIST(UserOpt *opt, Conf *conf) { } switch(listOpt._lt) { case LT_PATH: - list_get_paths(&db, list_type); + list_get_paths(&db, list_type, listOpt.attr); break; case LT_PROGRAM: list_get_programs(&db, list_type); break; case LT_TREE: - list_get_path_program_tree(&db, list_type); + list_get_path_program_tree(&db, list_type, listOpt.attr); list_print(list_type); close_DB(&db); list_free(list_type); @@ -183,7 +183,7 @@ int run_SEARCH(UserOpt *opt, Conf *conf) { } DB db = open_DB(opt); cklist *paths = list_make_new(); - list_get_paths(&db, paths); + list_get_paths(&db, paths, 0); close_DB(&db); if (list_size(paths)) { do { diff --git a/src/actions.h b/src/actions.h index 414c098..5e32164 100644 --- a/src/actions.h +++ b/src/actions.h @@ -59,6 +59,7 @@ typedef struct ListOptions ListOpt; struct ListOptions { ListType _lt; ListShowType _lst; + int attr; int err; }; diff --git a/src/argumentparser.h b/src/argumentparser.h deleted file mode 100644 index 8189b38..0000000 --- a/src/argumentparser.h +++ /dev/null @@ -1,14 +0,0 @@ -/* argumentparser.h - Argument parser for ck------------------------*- C -*- */ -#ifndef ARGUMENTPARSER_H -#define ARGUMENTPARSER_H -#define INIT_ALIAS \ - - -#define ARGUMENT_TABLE \ - X(init, ) - -typedef enum ParseResults ParseResult; - -extern ParseResult parse(int argc, char *argv[]); - -#endif // ARGUMENTPARSER_H diff --git a/src/dbhelper.c b/src/dbhelper.c index d0c2795..b183770 100644 --- a/src/dbhelper.c +++ b/src/dbhelper.c @@ -170,9 +170,13 @@ void dbh_format_query_select_from_joined_like(char *query, const char *selection strcpy(query, tmp); } -void dbh_form_query_select_paths(char *query) { +void dbh_form_query_select_paths_with_attributes(char *query) { char tmp[STR_L] = "SELECT "; strcat(tmp, COL_CONFIG_PATH); + strcat(tmp, ","); + strcat(tmp, COL_CONFIG_SECRET); + strcat(tmp, ","); + strcat(tmp, COL_CONFIG_PRIMARY); strcat(tmp, " FROM "); strcat(tmp, TBL_CONFIG); strcat(tmp, ";"); diff --git a/src/dbhelper.h b/src/dbhelper.h index 44b9aa0..b2f4abe 100644 --- a/src/dbhelper.h +++ b/src/dbhelper.h @@ -56,7 +56,7 @@ extern void dhb_form_query_insert_relationship(char *query); extern void dhb_form_query_find_program(char *query); extern void dhb_form_query_find_config(char *query); extern void dhb_form_query_find_relationship(char *query); -extern void dbh_form_query_select_paths(char *query); +extern void dbh_form_query_select_paths_with_attributes(char *query); extern void dbh_form_query_select_programs(char *query); extern void dbh_form_query_select_from_joined_eq(char *query, const char *selection, const char* condition); extern void dbh_form_query_select_from_joined_like(char *query, const char *selection, const char* condition); diff --git a/src/dblayer.c b/src/dblayer.c index dbd772e..128ad2c 100644 --- a/src/dblayer.c +++ b/src/dblayer.c @@ -412,12 +412,12 @@ int edit_get_prime_config_from_program(DB *db, char *pName, char *ret, int *secr return 0; } -int list_get_paths(DB *db, cklist *ckl) { +int list_get_paths(DB *db, cklist *ckl, int attr) { sqlite3_stmt *stmt; int rc; char sql[STR_M]; - dbh_form_query_select_paths(sql); + dbh_form_query_select_paths_with_attributes(sql); rc = sqlite3_prepare_v2(db->ptr, sql, -1, &stmt, 0); if (rc != SQLITE_OK) { @@ -425,7 +425,19 @@ int list_get_paths(DB *db, cklist *ckl) { } while (sqlite3_step(stmt) == SQLITE_ROW) { - list_add(ckl, (char *)sqlite3_column_text(stmt, 0)); + char path[STR_L] = ""; + strcat(path, (char *)sqlite3_column_text(stmt, 0)); + if (attr) { + /* secret */ + if (sqlite3_column_int(stmt, 1)) { + strcat(path, " [s]"); + } + /* primary */ + if (sqlite3_column_int(stmt, 2)) { + strcat(path, " [p]"); + } + } + list_add(ckl, path); } sqlite3_finalize(stmt); @@ -452,7 +464,7 @@ int list_get_programs(DB *db, cklist *ckl) { return 1; } -int list_get_path_program_tree(DB *db, cklist *ckl) { +int list_get_path_program_tree(DB *db, cklist *ckl, int attr) { sqlite3_stmt *stmt; int rc; @@ -474,11 +486,17 @@ int list_get_path_program_tree(DB *db, cklist *ckl) { char sql2[STR_L]; + char selection[STR_M] = COL_CONFIG_PATH; + strcat(selection, ","); + strcat(selection, COL_CONFIG_SECRET); + strcat(selection, ","); + strcat(selection, COL_CONFIG_PRIMARY); + char condition[STR_M] = TBL_PROGRAM; strcat(condition, "."); strcat(condition, COL_PROGRAM_NAME); - dbh_form_query_select_from_joined_eq(sql2, COL_CONFIG_PATH, condition); + dbh_form_query_select_from_joined_eq(sql2, selection, condition); rc2 = sqlite3_prepare_v2(db->ptr, sql2, -1, &stmt2, 0); if (rc2 != SQLITE_OK) { @@ -489,6 +507,16 @@ int list_get_path_program_tree(DB *db, cklist *ckl) { while (sqlite3_step(stmt2) == SQLITE_ROW) { char treePath[STR_L] = "|- "; strcat(treePath, (char *)sqlite3_column_text(stmt2, 0)); + if (attr) { + /* secret */ + if (sqlite3_column_int(stmt2, 1)) { + strcat(treePath, " [s]"); + } + /* primary */ + if (sqlite3_column_int(stmt2, 2)) { + strcat(treePath, " [p]"); + } + } list_add(ckl, treePath); } sqlite3_finalize(stmt2); diff --git a/src/dblayer.h b/src/dblayer.h index da54632..6ba4e27 100644 --- a/src/dblayer.h +++ b/src/dblayer.h @@ -68,8 +68,8 @@ extern int edit_get_prime_config_from_program(DB *db, char *pName, char *ret, in /* list */ /********/ -extern int list_get_paths(DB *db, cklist *ckl); +extern int list_get_paths(DB *db, cklist *ckl, int attr); extern int list_get_programs(DB *db, cklist *ckl); -extern int list_get_path_program_tree(DB *db, cklist *ckl); +extern int list_get_path_program_tree(DB *db, cklist *ckl, int attr); #endif /* DBLAYER_H */ |