home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume20 / rc / part04 / list.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-22  |  984 b   |  61 lines

  1. /* list.c: routines for manipulating the List type */
  2.  
  3. #include "rc.h"
  4. #include "utils.h"
  5. #include "list.h"
  6.  
  7. /*
  8.    These list routines assign meta values of null to the resulting lists;
  9.    it is impossible to glob with the value of a variable unless this value
  10.    is rescanned with eval---therefore it is safe to throw away the meta-ness
  11.    of the list.
  12. */
  13.  
  14. /* free a list from malloc space */
  15.  
  16. void listfree(List *p) {
  17.     if (p == NULL)
  18.         return;
  19.     listfree(p->n);
  20.     efree(p->w);
  21.     efree(p);
  22. }
  23.  
  24. /* copy of list in malloc space (for storing a variable) */
  25.  
  26. List *listcpy(List *s) {
  27.     List *r;
  28.  
  29.     if (s == NULL)
  30.         return NULL;
  31.  
  32.     r = enew(List);
  33.     r->w = ecpy(s->w);
  34.     r->m = NULL;
  35.     r->n = listcpy(s->n);
  36.  
  37.     return r;
  38. }
  39.  
  40. /* length of list */
  41.  
  42. SIZE_T listlen(List *s) {
  43.     SIZE_T size;
  44.  
  45.     for (size = 0; s != NULL; s = s->n)
  46.         size += strlen(s->w) + 1;
  47.  
  48.     return size;
  49. }
  50.  
  51. /* number of elements in list */
  52.  
  53. int listnel(List *s) {
  54.     int nel;
  55.  
  56.     for (nel = 0; s != NULL; s = s->n)
  57.         nel++;
  58.  
  59.     return nel;
  60. }
  61.