diff options
author | gramanas <anastasis.gramm2@gmail.com> | 2018-11-14 13:35:43 +0200 |
---|---|---|
committer | gramanas <anastasis.gramm2@gmail.com> | 2018-11-14 13:35:43 +0200 |
commit | 822f7d839a1b5dc967cfb2988170ed836ae8c0d8 (patch) | |
tree | ad9ff5446bfb1438803fc26f76572a70b1c803d4 /src | |
parent | e693fc02f6cb25a06dc53af2edd68c66e3ed4b32 (diff) | |
download | ck-822f7d839a1b5dc967cfb2988170ed836ae8c0d8.tar.gz ck-822f7d839a1b5dc967cfb2988170ed836ae8c0d8.tar.bz2 ck-822f7d839a1b5dc967cfb2988170ed836ae8c0d8.zip |
minor code cleanup
Diffstat (limited to 'src')
-rw-r--r-- | src/actions.c | 2 | ||||
-rw-r--r-- | src/dblayer.c | 60 |
2 files changed, 25 insertions, 37 deletions
diff --git a/src/actions.c b/src/actions.c index 965ed5c..dde18ef 100644 --- a/src/actions.c +++ b/src/actions.c @@ -308,7 +308,7 @@ int run_HELP(UserOpt *opt, Conf *conf) { #define X(ACTION) \ case CKA_##ACTION: \ get_possible_action_strings(tmp, CKA_##ACTION); \ - HELP("%s:\n%s", #ACTION, tmp); \ + HELP("%s", tmp); \ print_##ACTION##_help(); \ return 0; CK_ACTIONS diff --git a/src/dblayer.c b/src/dblayer.c index d3fd49e..97a93db 100644 --- a/src/dblayer.c +++ b/src/dblayer.c @@ -496,6 +496,21 @@ int edit_get_config(DB *db, const char *pName, char *ret, const char *cName, int return -1; } +static void decorate_entry(char *entry, int secret, int primary, const char *path) { + if (primary) { + strcat(entry, " [p]"); + } + + if (secret) { + strcat(entry, " [s]"); + } + /* root */ + if (util_is_link_owned_by_root(path)) { + strcat(entry, " [root]"); + } +} + + int get_program_paths(DB *db, cklist *ckl, const char* pName, int bname, int attr, const char *home) { int pid = get_program_id(db, pName); /* error */ @@ -542,18 +557,9 @@ int get_program_paths(DB *db, cklist *ckl, const char* pName, int bname, int att } } if (attr) { - /* primary */ - if (sqlite3_column_int(stmt, 2)) { - strcat(entry, " [p]"); - } - /* secret */ - if (sqlite3_column_int(stmt, 1)) { - strcat(entry, " [s]"); - } - /* root */ - if (util_is_link_owned_by_root((char *)sqlite3_column_text(stmt, 0))) { - strcat(entry, " [root]"); - } + decorate_entry(entry, sqlite3_column_int(stmt, 1), + sqlite3_column_int(stmt, 2), + (char *)sqlite3_column_text(stmt, 0)); } list_add(ckl, entry); free(tmp); @@ -593,18 +599,9 @@ int list_get_paths(DB *db, cklist *ckl, int bName, int attr, const char *home) { } free(tmp); if (attr) { - /* primary */ - if (sqlite3_column_int(stmt, 2)) { - strcat(path, " [p]"); - } - /* secret */ - if (sqlite3_column_int(stmt, 1)) { - strcat(path, " [s]"); - } - /* root */ - if (util_is_link_owned_by_root((char *)sqlite3_column_text(stmt, 0))) { - strcat(path, " [root]"); - } + decorate_entry(path, sqlite3_column_int(stmt, 1), + sqlite3_column_int(stmt, 2), + (char *)sqlite3_column_text(stmt, 0)); } list_add(ckl, path); } @@ -690,18 +687,9 @@ int list_get_path_program_tree(DB *db, cklist *ckl, int bName, int attr, const c } free(tmp); if (attr) { - /* primary */ - if (sqlite3_column_int(stmt2, 2)) { - strcat(treePath, " [p]"); - } - /* secret */ - if (sqlite3_column_int(stmt2, 1)) { - strcat(treePath, " [s]"); - } - /* root */ - if (util_is_link_owned_by_root((char *)sqlite3_column_text(stmt2, 0))) { - strcat(treePath, " [root]"); - } + decorate_entry(treePath, sqlite3_column_int(stmt2, 1), + sqlite3_column_int(stmt2, 2), + (char *)sqlite3_column_text(stmt2, 0)); } list_add(ckl, treePath); } |