1 /*- 2 * %sccs.include.proprietary.c% 3 */ 4 5 #ifndef lint 6 static char sccsid[] = "@(#)0.list.c 8.1 (Berkeley) 06/06/93"; 7 #endif /* not lint */ 8 9 #include <stdio.h> 10 #include "def.h" 11 12 struct list *consls(v,ls) /* make list */ 13 VERT v; 14 struct list *ls; 15 { 16 struct list *temp; 17 temp = challoc(sizeof(*temp)); 18 temp->elt = v; 19 temp->nxtlist = ls; 20 return(temp); 21 } 22 23 struct list *append(v,ls) /* return ls . v */ 24 VERT v; 25 struct list *ls; 26 { 27 struct list *temp; 28 if (!ls) return(consls(v,0)); 29 for (temp = ls; temp -> nxtlist; temp = temp->nxtlist) 30 ; 31 temp->nxtlist = consls(v,0); 32 return(ls); 33 } 34 35 36 freelst(ls) 37 struct list *ls; 38 { 39 if (!ls) return; 40 if (ls->nxtlist) 41 freelst(ls->nxtlist); 42 chfree(ls,sizeof(*ls)); 43 } 44 45 46 oneelt(ls) /* return w if w is only elt of ls, UNDEFINED otherwise */ 47 struct list *ls; 48 { 49 if (!ls) return(UNDEFINED); 50 if (ls->nxtlist) return(UNDEFINED); 51 return(ls->elt); 52 } 53 54 55 lslen(ls) /* return number of elements in list ls */ 56 struct list *ls; 57 { 58 int count; 59 struct list *lp; 60 count = 0; 61 for (lp = ls; lp; lp = lp->nxtlist) 62 ++count; 63 return(count); 64 } 65 66 67 prlst(ls) 68 struct list *ls; 69 { 70 struct list *lp; 71 for (lp = ls; lp; lp = lp->nxtlist) 72 printf("%d,",lp->elt); 73 fprintf(stderr,"\n"); 74 } 75