From 822f7d839a1b5dc967cfb2988170ed836ae8c0d8 Mon Sep 17 00:00:00 2001 From: gramanas Date: Wed, 14 Nov 2018 13:35:43 +0200 Subject: minor code cleanup --- src/dblayer.c | 60 ++++++++++++++++++++++++----------------------------------- 1 file changed, 24 insertions(+), 36 deletions(-) (limited to 'src/dblayer.c') 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); } -- cgit v1.2.3