From fb7e3e1352aeca03909ae3720c8cae90fcd57186 Mon Sep 17 00:00:00 2001 From: gramanas Date: Tue, 8 May 2018 16:44:05 +0300 Subject: user args an now cklist type --- src/cklist.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'src/cklist.c') diff --git a/src/cklist.c b/src/cklist.c index 32352df..b2a7803 100644 --- a/src/cklist.c +++ b/src/cklist.c @@ -127,25 +127,36 @@ cklist* list_copy_part(cklist *ckl, int from, int until) { } void list_print_lisp(cklist *ckl) { - list_rewind(ckl); - printf("( \"%s\"", list_get(ckl)); - while (list_next(ckl)) { - if (ckl->pos == ckl->size-1) { - printf(", \"%s\" )\n", list_get(ckl)); + if (ckl->size > 0) { + list_rewind(ckl); + printf("( \"%s\"", list_get(ckl)); + if (ckl->size == 1) { + printf(" )\n"); } - else { - printf(", \"%s\"", list_get(ckl)); + while (list_next(ckl)) { + if (ckl->pos == ckl->size-1) { + printf(", \"%s\" )\n", list_get(ckl)); + } + else { + printf(", \"%s\"", list_get(ckl)); + } } + list_rewind(ckl); } - list_rewind(ckl); } void list_print(cklist *ckl) { - list_rewind(ckl); - while (list_next(ckl)) { - printf("%s\n", list_get(ckl)); + if (ckl->size > 0) { + list_rewind(ckl); + while (list_next(ckl)) { + printf("%s\n", list_get(ckl)); + } + list_rewind(ckl); } - list_rewind(ckl); +} + +int list_size(cklist *ckl) { + return ckl->size; } void list_free(cklist *ckl) { -- cgit v1.2.3