aboutsummaryrefslogtreecommitdiffstats
path: root/src/dblayer.c
diff options
context:
space:
mode:
authorgramanas <anastasis.gramm2@gmail.com>2018-11-14 13:35:43 +0200
committergramanas <anastasis.gramm2@gmail.com>2018-11-14 13:35:43 +0200
commit822f7d839a1b5dc967cfb2988170ed836ae8c0d8 (patch)
treead9ff5446bfb1438803fc26f76572a70b1c803d4 /src/dblayer.c
parente693fc02f6cb25a06dc53af2edd68c66e3ed4b32 (diff)
downloadck-822f7d839a1b5dc967cfb2988170ed836ae8c0d8.tar.gz
ck-822f7d839a1b5dc967cfb2988170ed836ae8c0d8.tar.bz2
ck-822f7d839a1b5dc967cfb2988170ed836ae8c0d8.zip
minor code cleanup
Diffstat (limited to 'src/dblayer.c')
-rw-r--r--src/dblayer.c60
1 files changed, 24 insertions, 36 deletions
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);
}