From 405afc36e0929d887188be09a5886f79ff0ea1c4 Mon Sep 17 00:00:00 2001 From: gramanas Date: Sat, 22 Sep 2018 12:58:22 +0300 Subject: Standarize error codes --- src/actions.c | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'src/actions.c') diff --git a/src/actions.c b/src/actions.c index 8f89484..e75c885 100644 --- a/src/actions.c +++ b/src/actions.c @@ -22,17 +22,17 @@ int run_INIT(UserOpt * opt, Conf *conf) { if (db_exists(opt)) { printf("Current configuration file location: %s\n", opt->confDir); PRINT_ERR("ck is already initialized."); - return 0; + return 1; } if (init_create_config_file(opt)) { - return 0; + return 1; } DB db = init_make_DB(opt); if (db.error == SQL_NO_ERR) { init_make_tables(&db); } sqlite3_close(db.ptr); - return 1; + return 0; } int run_ADD(UserOpt * opt, Conf *conf) { @@ -41,7 +41,7 @@ int run_ADD(UserOpt * opt, Conf *conf) { if (db.error == SQL_ERR_NO_TABLES) { PRINT_ERR("The database file is currupted. Run ck init anew."); } - return 0; + return 1; } AddOpt addOpt = add_make_options(opt->args); switch (addOpt.err) { @@ -50,30 +50,31 @@ int run_ADD(UserOpt * opt, Conf *conf) { case ADD_ERR_WRONG_CONFIG: PRINT_ERR("The config file specified doesn't exist."); close_DB(&db); - return 0; + return 1; case ADD_ERR_WRONG_FLAGS: PRINT_ERR("Flags are: -s for secret and -p for primary."); close_DB(&db); - return 0; + return 1; } add_print_opts(&addOpt); - if (add_transaction_begin(&db, &addOpt) == 0) { + /* Try adding the new config to the DB */ + if (add_transaction_try(&db, &addOpt)) { close_DB(&db); - return 0; + return 1; } close_DB(&db); add_make_link(&addOpt, conf); char err[STR_M]; if (add_err_message(err)) { PRINT_ERR(err); - return 0; + return 1; } - return 1; + return 0; } int run_DEL(UserOpt * opt, Conf *conf) { printf("Running %s\n", "del"); - return 0; + return 1; } int run_EDIT(UserOpt *opt, Conf *conf) { @@ -83,7 +84,7 @@ int run_EDIT(UserOpt *opt, Conf *conf) { if (db.error == SQL_ERR_NO_TABLES) { PRINT_ERR("The database file is currupted. Run ck init anew."); } - return 0; + return 1; } list_rewind(opt->args); @@ -97,7 +98,7 @@ int run_EDIT(UserOpt *opt, Conf *conf) { } else { PRINT_ERR("No primary config"); close_DB(&db); - return 0; + return 1; } } else { close_DB(&db); @@ -110,7 +111,6 @@ int run_EDIT(UserOpt *opt, Conf *conf) { case ERC_SUGGESTIONS: return 1; } - return 1; } close_DB(&db); @@ -120,7 +120,7 @@ int run_EDIT(UserOpt *opt, Conf *conf) { strcat(command, " "); strcat(command, confPath); system(command); - return 1; + return 0; } int run_LIST(UserOpt *opt, Conf *conf) { @@ -130,7 +130,7 @@ int run_LIST(UserOpt *opt, Conf *conf) { if (db.error == SQL_ERR_NO_TABLES) { printf("no tables\n"); } - return 0; + return 1; } cklist *list_type = list_make_new(); @@ -139,7 +139,7 @@ int run_LIST(UserOpt *opt, Conf *conf) { if (listOpt.err) { close_DB(&db); list_free(list_type); - return 0; + return 1; } switch(listOpt._lt) { case LT_PATH: @@ -153,12 +153,12 @@ int run_LIST(UserOpt *opt, Conf *conf) { list_print(list_type); close_DB(&db); list_free(list_type); - return 1; + return 0; case LT_NONE: printf("What should I list? (paths, configs)\n"); close_DB(&db); list_free(list_type); - return 0; + return 1; } switch(listOpt._lst) { case LST_PLAIN: @@ -172,17 +172,17 @@ int run_LIST(UserOpt *opt, Conf *conf) { } close_DB(&db); list_free(list_type); - return 1; + return 0; } int run_SEARCH(UserOpt *opt, Conf *conf) { printf("Running %s\n", "search"); DB db = open_DB(opt); close_DB(&db); - return 0; + return 1; } int run_HELP(UserOpt *opt, Conf *conf) { printf("Running %s\n", "help"); - return 0; + return 1; } -- cgit v1.2.3