BSD 3 development
[unix-history] / usr / src / cmd / struct / 0.list.c
CommitLineData
42d6e430
BJ
1#include <stdio.h>
2#include "def.h"
3
4struct list *consls(v,ls) /* make list */
5VERT v;
6struct list *ls;
7 {
8 struct list *temp;
9 temp = challoc(sizeof(*temp));
10 temp->elt = v;
11 temp->nxtlist = ls;
12 return(temp);
13 }
14
15struct list *append(v,ls) /* return ls . v */
16VERT v;
17struct list *ls;
18 {
19 struct list *temp;
20 if (!ls) return(consls(v,0));
21 for (temp = ls; temp -> nxtlist; temp = temp->nxtlist)
22 ;
23 temp->nxtlist = consls(v,0);
24 return(ls);
25 }
26
27
28freelst(ls)
29struct list *ls;
30 {
31 if (!ls) return;
32 if (ls->nxtlist)
33 freelst(ls->nxtlist);
34 chfree(ls,sizeof(*ls));
35 }
36
37
38oneelt(ls) /* return w if w is only elt of ls, UNDEFINED otherwise */
39struct list *ls;
40 {
41 if (!ls) return(UNDEFINED);
42 if (ls->nxtlist) return(UNDEFINED);
43 return(ls->elt);
44 }
45
46
47lslen(ls) /* return number of elements in list ls */
48struct list *ls;
49 {
50 int count;
51 struct list *lp;
52 count = 0;
53 for (lp = ls; lp; lp = lp->nxtlist)
54 ++count;
55 return(count);
56 }
57
58
59prlst(ls)
60struct list *ls;
61 {
62 struct list *lp;
63 for (lp = ls; lp; lp = lp->nxtlist)
64 printf("%d,",lp->elt);
65 fprintf(stderr,"\n");
66 }