diff options
author | gramanas <anastasis.gramm2@gmail.com> | 2018-11-17 19:49:52 +0200 |
---|---|---|
committer | gramanas <anastasis.gramm2@gmail.com> | 2018-11-17 19:49:52 +0200 |
commit | 21c92f735ff52ff98b50f7f9d8e8ab9c46dad557 (patch) | |
tree | 3b244ec29c3b3ad96fc141461bff4d141a36227a /src/list.c | |
parent | 8eb4df24eb30353bea82268440396e50ed8b1bbc (diff) | |
download | ck-21c92f735ff52ff98b50f7f9d8e8ab9c46dad557.tar.gz ck-21c92f735ff52ff98b50f7f9d8e8ab9c46dad557.tar.bz2 ck-21c92f735ff52ff98b50f7f9d8e8ab9c46dad557.zip |
Finish restructure and simplify include graph
Diffstat (limited to 'src/list.c')
-rw-r--r-- | src/list.c | 94 |
1 files changed, 90 insertions, 4 deletions
@@ -1,11 +1,21 @@ +/* list.c - the list action --------------------------------------------*- C -*- + * + * This file is part of ck, the config keeper + * + * ----------------------------------------------------------------------------- + * + * Copyright (C) 2018 Anastasis Grammenos + * GPLv3 (see LICENCE for the full notice) + * + * -------------------------------------------------------------------------- */ #include <libgen.h> -#include "actions.h" #include "dblayer.h" -#include "queries.h" #include "ckerrlog.h" -ListOpt list_make_options(cklist *args) { +ERRLOG(list); + +static ListOpt list_make_options(cklist *args) { list_rewind(args); ListOpt listOpt = { ._lt = LT_TREE, @@ -135,7 +145,7 @@ int list_get_programs(DB *db, cklist *ckl) { return 1; } -int list_get_path_program_tree(DB *db, cklist *ckl, int bName, int attr, const char *home) { +static int list_get_path_program_tree(DB *db, cklist *ckl, int bName, int attr, const char *home) { sqlite3_stmt *stmt; int rc; @@ -204,3 +214,79 @@ int list_get_path_program_tree(DB *db, cklist *ckl, int bName, int attr, const c return 1; } + +int run_LIST(UserOpt *opt, Conf *conf) { + DB db; + if (open_DB(&db, opt)) { + return -1; + } + + cklist *the_list = list_make_new(); + ListOpt listOpt = list_make_options(opt->args); + + if (listOpt.err) { + ERR("Wrong list options."); + goto error; + } + char tmp[STR_L] = ""; + switch(listOpt._lt) { + case LT_PATH: + list_get_paths(&db, the_list, listOpt.bName, listOpt.attr, conf->home_dir); + break; + case LT_PROGRAM: + list_get_programs(&db, the_list); + break; + case LT_TREE: + list_get_path_program_tree(&db, the_list, listOpt.bName, listOpt.attr, conf->home_dir); + list_print(the_list); + goto close; + case LT_CKCONF: + strcat(tmp, "ck configuration directory path: "); + strcat(tmp, opt->confDir); + list_add(the_list, tmp); +#define X(var, str, name) \ + strcpy(tmp, ""); \ + strcat(tmp, name); \ + strcat(tmp, ": "); \ + strcat(tmp, conf->var); \ + list_add(the_list, tmp); + CONFIG_VARIABLES_TABLE; +#undef X + list_print(the_list); + goto close; + case LT_PROG_CONFS: + if (!program_exists(&db, listOpt.pName)) { + ERR("Program %s doesn't exist in the database.", listOpt.pName); + goto error; + } + get_program_paths(&db, the_list, listOpt.pName, listOpt.bName, listOpt.attr, conf->home_dir); + break; + } + switch(listOpt._lst) { + case LST_PLAIN: + list_print(the_list); + break; + case LST_LISP: + list_print_lisp(the_list); + break; + case LST_PYTHON: + list_print_python(the_list); + } + close: + close_DB(&db); + list_free(the_list); + return 0; + error: + close_DB(&db); + list_free(the_list); + return -1; +} + +void print_LIST_help() { + ckhelp("ck list tree [-a] [-b]"); + ckhelp("ck list -p PROGRAM_NAME [-t list-type] [-a] [-b]"); + ckhelp("ck list programs [-t list-type] [-a] [-b]"); + ckhelp("ck list paths [-t list-type] [-a] [-b]"); + ckhelp("ck list ckconf"); + report_help(); +} |