From 68efbf97390ddac355c3b54a5d825e74fb4b208d Mon Sep 17 00:00:00 2001 From: gramanas Date: Mon, 14 May 2018 01:14:15 +0300 Subject: small fixes --- src/actionparser.c | 4 ++-- src/actions.c | 6 +++--- src/cklist.c | 11 +++++++++++ src/cklist.h | 1 + src/confparser.c | 18 ++++++------------ 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/actionparser.c b/src/actionparser.c index 6c3cb77..55fe79c 100644 --- a/src/actionparser.c +++ b/src/actionparser.c @@ -55,7 +55,7 @@ int next_token() { /* copy the option from the list * to the UserOpt struct */ -void get_opt(int position, UserOpt *opt) { +void get_opt(UserOpt *opt) { /* get arg */ next_token(); list_add(opt->args, token); @@ -63,7 +63,7 @@ void get_opt(int position, UserOpt *opt) { void fill_args_list(int arg_num, UserOpt *opt) { for (int i = 0; i < arg_num; i++) { - get_opt(i, opt); + get_opt(opt); } } diff --git a/src/actions.c b/src/actions.c index 2dafd0b..680ae68 100644 --- a/src/actions.c +++ b/src/actions.c @@ -206,7 +206,7 @@ void print_DEL_result(int ok) { printf("succes\n"); return; } - printf("failure\n"); + printf("Not Supported\n"); } void print_EDIT_result(int ok) { @@ -222,7 +222,7 @@ void print_LIST_result(int ok) { printf("succes\n"); return; } - printf("failure\n"); + printf("Not Supported\n"); } void print_SEARCH_result(int ok) { @@ -230,7 +230,7 @@ void print_SEARCH_result(int ok) { printf("succes\n"); return; } - printf("failure\n"); + printf("Not Supported\n"); } void print_HELP_result(int ok) { diff --git a/src/cklist.c b/src/cklist.c index b2a7803..d22ee49 100644 --- a/src/cklist.c +++ b/src/cklist.c @@ -60,6 +60,17 @@ char* list_get(cklist *ckl) { return ckl->arr[ckl->pos]; } +char* list_get_at(cklist *ckl, int pos) { + if (ckl->pos == -1) { + return NULL; + } + if (ckl->pos >= ckl->size + || pos >= ckl->size) { + return NULL; + } + return ckl->arr[pos]; +} + void list_rewind(cklist *ckl) { ckl->pos = 0; } diff --git a/src/cklist.h b/src/cklist.h index e303ebc..a7f5cc2 100644 --- a/src/cklist.h +++ b/src/cklist.h @@ -29,6 +29,7 @@ extern void list_rewind(cklist *ckl); extern int list_next(cklist *ckl); extern char* list_get(cklist *ckl); +extern char* list_get_at(cklist *ckl, int pos); extern int list_size(cklist *ckl); diff --git a/src/confparser.c b/src/confparser.c index 2d17c81..5754dfa 100644 --- a/src/confparser.c +++ b/src/confparser.c @@ -139,16 +139,13 @@ void free_conf(Conf *conf) { } int init_create_config_file(UserOpt *opt) { - list_rewind(opt->args); - - if (!util_file_exists(list_get(opt->args))) { - printf("Version control directory: %s\ndoes not exist.\n", list_get(opt->args)); + if (!util_file_exists(list_get_at(opt->args, 0))) { + printf("Version control directory: %s\ndoes not exist.\n", list_get_at(opt->args, 0)); return 1; } - list_next(opt->args); - if (!util_file_exists(list_get(opt->args))) { - printf("Secret directory: %s\ndoes not exist.\n", list_get(opt->args)); + if (!util_file_exists(list_get_at(opt->args, 1))) { + printf("Secret directory: %s\ndoes not exist.\n", list_get_at(opt->args, 1)); return 1; } @@ -163,20 +160,17 @@ int init_create_config_file(UserOpt *opt) { return 1; } - list_rewind(opt->args); char tmp[200]; strcpy(tmp, "version_control_dir = "); - strcat(tmp, list_get(opt->args)); + strcat(tmp, list_get_at(opt->args, 0)); strcat(tmp, "\n"); fputs(tmp, f); - list_next(opt->args); strcpy(tmp, "secret_dir = "); - strcat(tmp, list_get(opt->args)); + strcat(tmp, list_get_at(opt->args, 1)); strcat(tmp, "\n"); fputs(tmp, f); fclose(f); - list_rewind(opt->args); return 0; } -- cgit v1.2.3