From 598e0522de924a50ea9c640955daab8512029eb4 Mon Sep 17 00:00:00 2001 From: gramanas Date: Tue, 9 Oct 2018 20:53:30 +0300 Subject: Better list --- src/dblayer.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) (limited to 'src/dblayer.c') diff --git a/src/dblayer.c b/src/dblayer.c index 4290a7a..973d561 100644 --- a/src/dblayer.c +++ b/src/dblayer.c @@ -478,9 +478,10 @@ int edit_get_config(DB *db, const char *pName, char *ret, const char *cName, int sqlite3_finalize(stmt); return flag; } + return -1; } -int edit_get_avaliable_paths(DB *db, cklist *ckl, const char* pName) { +int get_program_paths(DB *db, cklist *ckl, const char* pName, int bname, int attr) { int pid = get_program_id(db, pName); /* error */ if (pid == -2) { @@ -493,6 +494,10 @@ int edit_get_avaliable_paths(DB *db, cklist *ckl, const char* pName) { int rc; 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_ID); @@ -506,21 +511,32 @@ int edit_get_avaliable_paths(DB *db, cklist *ckl, const char* pName) { return -2; } - char name[STR_M] = ""; - strcat(name, pName); - strcat(name, ":"); - list_add(ckl, name); while (sqlite3_step(stmt) == SQLITE_ROW) { char *tmp = strdup((char *)sqlite3_column_text(stmt, 0)); char entry[STR_M] = ""; - strcat(entry, "|- "); - strcat(entry, basename(tmp)); + if (bname) { + strcat(entry, basename(tmp)); + } + else { + strcat(entry, tmp); + } + if (attr) { + /* secret */ + if (sqlite3_column_int(stmt, 1)) { + strcat(entry, " [s]"); + } + /* primary */ + if (sqlite3_column_int(stmt, 2)) { + strcat(entry, " [p]"); + } + } list_add(ckl, entry); free(tmp); } sqlite3_finalize(stmt); return 0; } + return -1; } int list_get_paths(DB *db, cklist *ckl, int attr) { @@ -732,15 +748,11 @@ int get_program_relations(DB *db, int pid) { int get_config_number(DB *db, char* pName) { int pid = get_program_id(db, pName); - /* error */ - if (pid == -2) { - return -1; - } - /* program exists */ if (pid > -1) { return get_program_relations(db, pid); } + return -1; } /* Removes the relationship of `cid` with the corresponding program. -- cgit v1.2.3