list.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  3. * See the copyright notice in the ACK home directory, in the file "Copyright".
  4. *
  5. */
  6. #include "ack.h"
  7. #include "list.h"
  8. #ifndef NORCSID
  9. static char rcs_id[] = "$Id$" ;
  10. static char rcs_list[] = RCS_LIST ;
  11. #endif
  12. /* List handling, operations allowed:
  13. adding strings to the list,
  14. throwing away whole lists,
  15. linearize a list.
  16. Routines:
  17. l_add(header,string) Add an element to a list.
  18. header List header, list_head *
  19. string String pointer, char *
  20. the string is NOT copied
  21. l_clear(header) Delete an whole list.
  22. header List header, list_head *
  23. l_throw(header) Delete a list of strings.
  24. header List header, list_head *
  25. */
  26. l_add(header,string) list_head *header ; char *string ; {
  27. register list_elem *new;
  28. /* NOSTRICT */
  29. new= (list_elem *)getcore(sizeof *new);
  30. l_content(*new)= string ;
  31. /* NOSTRICT */
  32. l_next(*new)= (list_elem *)0 ;
  33. if ( !header->ca_first ) {
  34. header->ca_first= new ;
  35. } else {
  36. header->ca_last->ca_next= new ;
  37. }
  38. header->ca_last= new ;
  39. }
  40. l_clear(header) list_head *header ; {
  41. register list_elem *old, *next;
  42. for ( old=header->ca_first ; old ; old= next ) {
  43. next= old->ca_next ;
  44. freecore((char *)old) ;
  45. }
  46. header->ca_first= (list_elem *) 0 ;
  47. header->ca_last = (list_elem *) 0 ;
  48. }
  49. l_throw(header) list_head *header ; {
  50. register list_elem *old, *next;
  51. for ( old=header->ca_first ; old ; old= next ) {
  52. throws(l_content(*old)) ;
  53. next= old->ca_next ;
  54. freecore((char *)old) ;
  55. }
  56. header->ca_first= (list_elem *) 0 ;
  57. header->ca_last = (list_elem *) 0 ;
  58. }