diff options
| author | Oskari Timperi <oskari.timperi@iki.fi> | 2014-05-18 10:54:17 +0300 |
|---|---|---|
| committer | Oskari Timperi <oskari.timperi@iki.fi> | 2014-05-18 10:54:17 +0300 |
| commit | 273589b4dbf45dc573b68baa3e5dc9c954982cd5 (patch) | |
| tree | 0549823f5c2cd043ef9102a16e7c7176bdf48671 | |
| parent | cece5aa4d3c0ac2364045d1adda8c36e9359adc2 (diff) | |
| download | lispish-273589b4dbf45dc573b68baa3e5dc9c954982cd5.tar.gz lispish-273589b4dbf45dc573b68baa3e5dc9c954982cd5.zip | |
add atom_list_append() and atom_list_length()
| -rw-r--r-- | atom.c | 48 | ||||
| -rw-r--r-- | atom.h | 3 |
2 files changed, 51 insertions, 0 deletions
@@ -3,6 +3,7 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> +#include <stdarg.h> 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" @@ -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; |
