aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/actions.c10
-rw-r--r--src/actions.h3
-rw-r--r--src/dblayer.c46
-rw-r--r--src/dblayer.h1
4 files changed, 59 insertions, 1 deletions
diff --git a/src/actions.c b/src/actions.c
index 7d5276a..c084e8f 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -199,6 +199,9 @@ ListOpt make_list_options(cklist *args) {
else if (strcmp(list_get(args), "programs") == 0) {
listOpt._lt = LT_PROGRAM;
}
+ else if (strcmp(list_get(args), "tree") == 0) {
+ listOpt._lt = LT_TREE;
+ }
else {
listOpt.err = 1;
}
@@ -209,6 +212,7 @@ ListOpt make_list_options(cklist *args) {
}
int run_LIST(UserOpt *opt, Conf *conf) {
+ UNUSED(conf);
DB db = open_DB(opt);
if (db.ptr == NULL) {
if (db.error == SQL_ERR_NO_TABLES) {
@@ -232,6 +236,12 @@ int run_LIST(UserOpt *opt, Conf *conf) {
case LT_PROGRAM:
list_get_programs(&db, list_type);
break;
+ case LT_TREE:
+ list_get_path_program_tree(&db, list_type);
+ list_print(list_type);
+ close_DB(&db);
+ list_free(list_type);
+ return 1;
case LT_NONE:
printf("What should I list? (paths, configs)\n");
close_DB(&db);
diff --git a/src/actions.h b/src/actions.h
index 0e8d445..e462e74 100644
--- a/src/actions.h
+++ b/src/actions.h
@@ -49,7 +49,8 @@ typedef enum ListTypes ListType;
enum ListTypes {
LT_PATH,
LT_PROGRAM,
- LT_NONE
+ LT_TREE,
+ LT_NONE,
};
typedef enum ListShowTypes ListShowType;
diff --git a/src/dblayer.c b/src/dblayer.c
index 2e19c5a..f97b70c 100644
--- a/src/dblayer.c
+++ b/src/dblayer.c
@@ -451,3 +451,49 @@ int list_get_programs(DB *db, cklist *ckl) {
return 1;
}
+
+int list_get_path_program_tree(DB *db, cklist *ckl) {
+ sqlite3_stmt *stmt;
+ int rc;
+
+ char sql[STR_M];
+ dbh_form_query_select_programs(sql);
+
+ rc = sqlite3_prepare_v2(db->ptr, sql, -1, &stmt, 0);
+ if (rc != SQLITE_OK) {
+ return -2;
+ }
+
+ while (sqlite3_step(stmt) == SQLITE_ROW) {
+ char programName[STR_M];
+ strcat(programName, (char *)sqlite3_column_text(stmt, 0));
+ strcat(programName, ":");
+ list_add(ckl, programName);
+ sqlite3_stmt *stmt2;
+ int rc2;
+
+ char sql2[STR_L];
+
+ 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);
+
+ rc2 = sqlite3_prepare_v2(db->ptr, sql2, -1, &stmt2, 0);
+ if (rc2 != SQLITE_OK) {
+ return -2;
+ }
+
+ sqlite3_bind_text(stmt2, 1, (char *)sqlite3_column_text(stmt, 0), -1, 0);
+ while (sqlite3_step(stmt2) == SQLITE_ROW) {
+ char treePath[STR_L] = "|- ";
+ strcat(treePath, (char *)sqlite3_column_text(stmt2, 0));
+ list_add(ckl, treePath);
+ }
+ sqlite3_finalize(stmt2);
+ }
+ sqlite3_finalize(stmt);
+
+ return 1;
+}
diff --git a/src/dblayer.h b/src/dblayer.h
index 58b0f0c..620d3e6 100644
--- a/src/dblayer.h
+++ b/src/dblayer.h
@@ -69,5 +69,6 @@ extern int edit_get_prime_config_from_program(DB *db, char *pName, char *ret, in
extern int list_get_paths(DB *db, cklist *ckl);
extern int list_get_programs(DB *db, cklist *ckl);
+extern int list_get_path_program_tree(DB *db, cklist *ckl);
#endif /* DBLAYER_H */