diff options
| author | tim <tim> | 1997-05-14 15:30:41 +0000 |
|---|---|---|
| committer | Toby Goodwin <toby@paccrat.org> | 2015-05-16 21:23:00 +0100 |
| commit | 53cf1b1c1c3f0c2b5067afccc2976b99a574a089 (patch) | |
| tree | a31f167c3779362e29ab377d662052b6257253a8 /list.c | |
| parent | b87bfedf65c289bf0ee5338c9e10492b70b1e8e0 (diff) | |
Initial revision
Diffstat (limited to 'list.c')
| -rw-r--r-- | list.c | 57 |
1 files changed, 0 insertions, 57 deletions
@@ -1,57 +0,0 @@ -/* list.c: routines for manipulating the List type */ - -#include "rc.h" - -/* - These list routines assign meta values of null to the resulting lists; - it is impossible to glob with the value of a variable unless this value - is rescanned with eval---therefore it is safe to throw away the meta-ness - of the list. -*/ - -/* free a list from malloc space */ - -extern void listfree(List *p) { - while (p != NULL) { - List *n = p->n; - efree(p->w); - efree(p); - p = n; - } -} - -/* Copy list into malloc space (for storing a variable) */ - -extern List *listcpy(List *s, void *(*alloc)(size_t)) { - List *top, *r; - for (top = r = NULL; s != NULL; s = s->n) { - if (top == NULL) - r = top = (*alloc)(sizeof (List)); - else - r = r->n = (*alloc)(sizeof (List)); - r->w = (*alloc)(strlen(s->w) + 1); - strcpy(r->w, s->w); - r->m = NULL; - } - if (r != NULL) - r->n = NULL; - return top; -} - -/* Length of list */ - -extern size_t listlen(List *s) { - size_t size; - for (size = 0; s != NULL; s = s->n) - size += strlen(s->w) + 1; - return size; -} - -/* Number of elements in list */ - -extern int listnel(List *s) { - int nel; - for (nel = 0; s != NULL; s = s->n) - nel++; - return nel; -} |