aboutsummaryrefslogtreecommitdiffstats
path: root/src/actions.c
diff options
context:
space:
mode:
authorAnastasis Grammenos <anastasis.gramm2@gmail.com>2018-09-19 23:59:37 +0300
committerAnastasis Grammenos <anastasis.gramm2@gmail.com>2018-09-19 23:59:37 +0300
commit22fca0324c162fa9a6abc5192aea2b5453c057b5 (patch)
treeb799fde22ee67221e69f8cf3c5445c0373a7cfca /src/actions.c
parent8702ce8bbd4d1435cc81fa8fcd7f5309d3c7b003 (diff)
downloadck-22fca0324c162fa9a6abc5192aea2b5453c057b5.tar.gz
ck-22fca0324c162fa9a6abc5192aea2b5453c057b5.tar.bz2
ck-22fca0324c162fa9a6abc5192aea2b5453c057b5.zip
Add list action (no docs)
Diffstat (limited to 'src/actions.c')
-rw-r--r--src/actions.c95
1 files changed, 82 insertions, 13 deletions
diff --git a/src/actions.c b/src/actions.c
index 3cce2f6..7d5276a 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -8,6 +8,9 @@
* GPLv3 (see LICENCE for the full notice)
*
* -------------------------------------------------------------------------- */
+#include <limits.h>
+#include <stdlib.h>
+
#include "actions.h"
#include "actionhelper.h"
#include "dblayer.h"
@@ -37,7 +40,6 @@ AddOpt make_add_options(cklist* args) {
/* since we are here, the first two argumens must exist */
AddOpt addOpt = {
.progName = list_get(args),
- .confPath = NULL,
.secret = 0,
.prime = 0,
.err = ADD_NO_ERR
@@ -48,7 +50,7 @@ AddOpt make_add_options(cklist* args) {
addOpt.err = ADD_ERR_WRONG_CONFIG;
return addOpt;
}
- addOpt.confPath = list_get(args);
+ realpath(list_get(args), addOpt.confPath);
while (list_next(args)) {
if (strcmp(list_get(args), "-s") == 0 && addOpt.secret == 0) {
@@ -163,8 +165,50 @@ int run_EDIT(UserOpt *opt, Conf *conf) {
return 1;
}
+ListOpt make_list_options(cklist *args) {
+ list_rewind(args);
+ ListOpt listOpt = {
+ ._lt = LT_NONE,
+ ._lst = LST_PLAIN,
+ .err = 0
+ };
+
+ if (list_size(args)) {
+ do {
+ if (strcmp(list_get(args), "-t") == 0) {
+ if (!list_next(args)) {
+ listOpt.err = 1;
+ break;
+ }
+ if (strcmp(list_get(args), "plain") == 0) {
+ listOpt._lst = LST_PLAIN;
+ }
+ else if (strcmp(list_get(args), "lisp") == 0) {
+ listOpt._lst = LST_LISP;
+ }
+ else if (strcmp(list_get(args), "python") == 0) {
+ listOpt._lst = LST_PYTHON;
+ }
+ else {
+ listOpt.err = 1;
+ }
+ }
+ else if (strcmp(list_get(args), "paths") == 0) {
+ listOpt._lt = LT_PATH;
+ }
+ else if (strcmp(list_get(args), "programs") == 0) {
+ listOpt._lt = LT_PROGRAM;
+ }
+ else {
+ listOpt.err = 1;
+ }
+ } while(list_next(args));
+ }
+ list_rewind(args);
+ return listOpt;
+}
+
int run_LIST(UserOpt *opt, Conf *conf) {
- printf("Running %s\n", "list");
DB db = open_DB(opt);
if (db.ptr == NULL) {
if (db.error == SQL_ERR_NO_TABLES) {
@@ -173,20 +217,46 @@ int run_LIST(UserOpt *opt, Conf *conf) {
return 0;
}
- cklist *paths = list_make_new();
+ cklist *list_type = list_make_new();
- list_get_paths(&db, paths);
-
- //list_print_lisp(paths);
- // list_print_python(opt->args);
- list_print(paths);
- list_free(paths);
+ ListOpt listOpt = make_list_options(opt->args);
+ if (listOpt.err) {
+ close_DB(&db);
+ list_free(list_type);
+ return 0;
+ }
+ switch(listOpt._lt) {
+ case LT_PATH:
+ list_get_paths(&db, list_type);
+ break;
+ case LT_PROGRAM:
+ list_get_programs(&db, list_type);
+ break;
+ case LT_NONE:
+ printf("What should I list? (paths, configs)\n");
+ close_DB(&db);
+ list_free(list_type);
+ return 0;
+ }
+ switch(listOpt._lst) {
+ case LST_PLAIN:
+ list_print(list_type);
+ break;
+ case LST_LISP:
+ list_print_lisp(list_type);
+ break;
+ case LST_PYTHON:
+ list_print_python(list_type);
+ }
close_DB(&db);
- return 0;
+ list_free(list_type);
+ return 1;
}
int run_SEARCH(UserOpt *opt, Conf *conf) {
printf("Running %s\n", "search");
+ DB db = open_DB(opt);
+ close_DB(&db);
return 0;
}
@@ -227,10 +297,9 @@ void print_EDIT_result(int ok) {
void print_LIST_result(int ok) {
if (ok) {
- printf("succes\n");
return;
}
- printf("Not Supported\n");
+ printf("Wrong list arguments\n");
}
void print_SEARCH_result(int ok) {