summaryrefslogtreecommitdiff
path: root/list.c
diff options
context:
space:
mode:
authorByron Rakitzis <byron@archone.tamu.edu>1992-05-27 00:00:01 +0100
committerToby Goodwin <toby@paccrat.org>2015-05-16 21:22:56 +0100
commit26bb34cf036027dfa22dfae8d8fc2f6bfd6acb75 (patch)
tree589705b2492ce4681760846d9ca45600f0af298d /list.c
release: rc-1.4
Diffstat (limited to 'list.c')
-rw-r--r--list.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/list.c b/list.c
new file mode 100644
index 0000000..f795485
--- /dev/null
+++ b/list.c
@@ -0,0 +1,57 @@
+/* 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;
+}