aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnastasis Grammenos <anastasis.gramm2@gmail.com>2018-10-07 20:00:43 +0300
committerAnastasis Grammenos <anastasis.gramm2@gmail.com>2018-10-07 20:00:43 +0300
commitf67f2c3d5b67f54dae2c2c2754f43b4351445c80 (patch)
treea980a065833e49d84ddd56994b1720adf100a06e
parent02aa2496d9eaf5c6f1234df1f91b8e312ee10022 (diff)
downloadck-f67f2c3d5b67f54dae2c2c2754f43b4351445c80.tar.gz
ck-f67f2c3d5b67f54dae2c2c2754f43b4351445c80.tar.bz2
ck-f67f2c3d5b67f54dae2c2c2754f43b4351445c80.zip
add list_exists fucntion
-rw-r--r--src/actionparser.c8
-rw-r--r--src/cklist.c12
-rw-r--r--src/cklist.h3
-rw-r--r--unit/ck-test.c17
4 files changed, 31 insertions, 9 deletions
diff --git a/src/actionparser.c b/src/actionparser.c
index 266f771..25c7c19 100644
--- a/src/actionparser.c
+++ b/src/actionparser.c
@@ -389,10 +389,10 @@ int parse_action(int argc, char* argv[], UserOpt *opt) {
/* If the remaining arguments are < 2
* print help and exit */
- if (optNum - pos < 2) {
- print_parser_help();
- return -1;
- }
+ /* if (optNum - pos < 2) { */
+ /* print_parser_help(); */
+ /* return -1; */
+ /* } */
/* find the action */
determine_action(opt);
diff --git a/src/cklist.c b/src/cklist.c
index 14d5d82..e142feb 100644
--- a/src/cklist.c
+++ b/src/cklist.c
@@ -186,6 +186,18 @@ void list_print_concat(cklist *ckl) {
}
}
+int list_exists(cklist *ckl, char *str) {
+ if (ckl->size > 0) {
+ list_rewind(ckl);
+ do {
+ if (strcmp(list_get(ckl), str) == 0) {
+ return 1;
+ }
+ } while (list_next(ckl));
+ }
+ return 0;
+}
+
int list_size(cklist *ckl) {
return ckl->size;
}
diff --git a/src/cklist.h b/src/cklist.h
index 346e55f..95fd088 100644
--- a/src/cklist.h
+++ b/src/cklist.h
@@ -48,6 +48,9 @@ extern cklist* list_copy_until(cklist *ckl, int index);
* copy from (>=) until (<) */
extern cklist* list_copy_part(cklist *ckl, int from, int until);
+/* return 1 if str exists in the list, 0 otherwise */
+extern int list_exists(cklist *ckl, char *str);
+
/* rewinds */
extern void list_print_lisp(cklist *ckl);
extern void list_print_python(cklist *ckl);
diff --git a/unit/ck-test.c b/unit/ck-test.c
index b907576..1264431 100644
--- a/unit/ck-test.c
+++ b/unit/ck-test.c
@@ -5,11 +5,11 @@
#include "cklist.h"
/* total number of unit tests */
-#define TOTAL 1
+#define TOTAL 2
-#define CK_UNIT_TESTS \
- X(ck_list_init, "Basic cklist test")
- // X(ck_list_add, "Add elements to ck list")
+#define CK_UNIT_TESTS \
+ X(ck_list_init, "Basic cklist test") \
+ X(ck_list_exists, "Test list exists function")
void ck_list_init() {
cklist *ckl1 = list_make_new();
@@ -25,7 +25,14 @@ void ck_list_init() {
list_free(ckl2);
}
-void ck_list_add() {
+void ck_list_exists() {
+ cklist *ckl = list_make_new();
+ list_add(ckl, "first");
+ list_add(ckl, "second");
+ assert(list_exists(ckl, "first"));
+ assert(list_exists(ckl, "second"));
+ assert(!list_exists(ckl, "thrid"));
+ list_free(ckl);
}
int main() {