diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/actionhelper.c | 10 | ||||
-rw-r--r-- | src/actionhelper.h | 10 | ||||
-rw-r--r-- | src/actions.c | 21 | ||||
-rw-r--r-- | src/dblayer.c | 22 |
4 files changed, 28 insertions, 35 deletions
diff --git a/src/actionhelper.c b/src/actionhelper.c index 582333e..f0113bf 100644 --- a/src/actionhelper.c +++ b/src/actionhelper.c @@ -149,6 +149,16 @@ void add_make_link(const AddOpt *opt, const Conf *conf) { } } +void edit_print_suggested_configs(DB *db, const char *pName) { + char name[STR_M] = ""; + strcat(name, pName); + strcat(name, ":"); + cklist *paths = list_make_and_add(name); + get_program_paths(db, paths, pName, 1, 0); + list_print(paths); + list_free(paths); +} + ListOpt list_make_options(cklist *args) { list_rewind(args); ListOpt listOpt = { diff --git a/src/actionhelper.h b/src/actionhelper.h index f046ec9..2db4eeb 100644 --- a/src/actionhelper.h +++ b/src/actionhelper.h @@ -17,6 +17,7 @@ #include "actions.h" #include "ckutil.h" #include "cklist.h" +#include "dblayer.h" /*******/ /* ADD */ @@ -38,14 +39,7 @@ extern DelOpt del_make_options(cklist *args); /********/ /* EDIT */ /********/ -typedef enum edit_opt_return_code edit_rc; -enum edit_opt_return_code { - ERC_OK, - ERC_SUGGESTIONS, - ERC_ERR -}; - -extern edit_rc edit_get_config_or_suggestions(cklist* args, char *ret); +extern void edit_print_suggested_configs(DB *db, const char *pName); /********/ /* LIST */ diff --git a/src/actions.c b/src/actions.c index 1b4c9b5..74b6338 100644 --- a/src/actions.c +++ b/src/actions.c @@ -75,7 +75,6 @@ int run_ADD(UserOpt * opt, Conf *conf) { } int run_DEL(UserOpt * opt, Conf *conf) { - printf("Running del\n"); DB db = open_DB(opt); if (db.ptr == NULL) { if (db.error == SQL_ERR_NO_TABLES) { @@ -91,10 +90,10 @@ int run_DEL(UserOpt * opt, Conf *conf) { close_DB(&db); return 0; case DEL_ERR_WRONG_ARGS: - printf("wrong del args\n"); + ERR("Wrong delete arguments."); break; case DEL_ERR_WRONG_PATH: - printf("path %s doesnt exist\n", delOpt.arg); + ERR("Path %s doesnt exist.", delOpt.arg); } error: close_DB(&db); @@ -134,13 +133,7 @@ int run_EDIT(UserOpt *opt, Conf *conf) { /* If the program has many configs */ else { HELP("Ambiguous config. Please type the config name after the program."); - char name[STR_M] = ""; - strcat(name, pName); - strcat(name, ":"); - cklist *paths = list_make_and_add(name); - get_program_paths(&db, paths, pName, 1, 0); - list_print(paths); - list_free(paths); + edit_print_suggested_configs(&db, pName); goto error; } } @@ -150,13 +143,7 @@ int run_EDIT(UserOpt *opt, Conf *conf) { char *cName = list_get(opt->args); if (edit_get_config(&db, pName, confName, cName, &secret)) { ERR("Program %s doesn't have a config named %s", pName, cName); - char name[STR_M] = ""; - strcat(name, pName); - strcat(name, ":"); - cklist *paths = list_make_and_add(name); - get_program_paths(&db, paths, pName, 1, 0); - list_print(paths); - list_free(paths); + edit_print_suggested_configs(&db, pName); goto error; } } diff --git a/src/dblayer.c b/src/dblayer.c index 973d561..4218ef6 100644 --- a/src/dblayer.c +++ b/src/dblayer.c @@ -17,6 +17,9 @@ #include "dblayer.h" #include "dbhelper.h" #include "ckutil.h" +#include "ckerrlog.h" + +ERRLOG(ckdb); const char * const DB_FILE_NAME = "/ckdb"; @@ -809,26 +812,26 @@ int del_transaction_try(DB *db, char *arg, int conf) { if (conf) { // del conf int cid = get_config_id(db, arg); - printf("cid: %d\n", cid); if (cid < 0) { - PRINT_ERR("Config doesn't exist in the database.\n"); + ERR("Config doesn't exist in the database."); + return -1; } if (delete_conf(db, cid)) { - PRINT_ERR("Could not delete config from db.\n"); + ERR("Could not delete config from db."); return -1; } // handle relations pid = remove_conf_rel(db, cid); - printf("pid: %d\n", pid); + HELP("Deleted config: %s", arg); if (get_program_relations(db, pid) > 0) { - printf("More rels left\n"); goto end; } - } else { + } + else { pid = get_program_id(db, arg); } if (pid < 0) { - PRINT_ERR("Program not found in the db.\n"); + ERR("Program not found in the db."); return -1; } /* If we are deleting a proram we should delete everything that @@ -837,11 +840,10 @@ int del_transaction_try(DB *db, char *arg, int conf) { remove_all_configs(db, pid); } if(delete_prog(db, pid)) { - PRINT_ERR("Could not delete program from db.\n"); - } - if (db->error == SQL_ERR_SQLITE) { + ERR("Could not delete program from db."); return -1; } + HELP("Deleted program %s", conf ? "" : arg); end: __END_TRANSACTION__ return 0; |