From 273589b4dbf45dc573b68baa3e5dc9c954982cd5 Mon Sep 17 00:00:00 2001 From: Oskari Timperi Date: Sun, 18 May 2014 10:54:17 +0300 Subject: add atom_list_append() and atom_list_length() --- atom.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ atom.h | 3 +++ 2 files changed, 51 insertions(+) diff --git a/atom.c b/atom.c index 9496390..9e33255 100644 --- a/atom.c +++ b/atom.c @@ -3,6 +3,7 @@ #include #include #include +#include struct atom true_atom = { ATOM_TRUE }; struct atom false_atom = { ATOM_FALSE }; @@ -140,6 +141,53 @@ void print_atom(struct atom *atom, int level) printf("\n"); } +struct atom *atom_list_append(struct atom *list, int count, ...) +{ + va_list ap; + struct atom *atom = NULL; + struct atom *last; + + LIST_FOREACH(last, list->list, entries) + { + if (!LIST_NEXT(last, entries)) + break; + } + + va_start(ap, count); + + do + { + atom = va_arg(ap, struct atom *); + + if (LIST_EMPTY(list->list)) + LIST_INSERT_HEAD(list->list, atom, entries); + else + LIST_INSERT_AFTER(last, atom, entries); + + last = atom; + } while (--count); + + va_end(ap); + + return list; +} + +int atom_list_length(struct atom *list) +{ + struct atom *atom; + int length = 0; + + if (IS_NIL(list)) + return 0; + + LIST_FOREACH(atom, list->list, entries) + { + ++length; + } + + return length; +} + #ifdef BUILD_TEST #include "test_util.h" diff --git a/atom.h b/atom.h index 251eb3a..f620af4 100644 --- a/atom.h +++ b/atom.h @@ -63,6 +63,9 @@ struct atom *atom_clone(); void print_atom(struct atom *atom, int level); +struct atom *atom_list_append(struct atom *list, int count, ...); +int atom_list_length(struct atom *list); + extern struct atom true_atom; extern struct atom false_atom; extern struct atom nil_atom; -- cgit v1.2.3