list.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. void l_add(list_head *header, char *string)
  27. {
  28. register list_elem *new;
  29. /* NOSTRICT */
  30. new= (list_elem *)getcore(sizeof *new);
  31. l_content(*new)= string ;
  32. /* NOSTRICT */
  33. l_next(*new)= (list_elem *)0 ;
  34. if ( !header->ca_first ) {
  35. header->ca_first= new ;
  36. } else {
  37. header->ca_last->ca_next= new ;
  38. }
  39. header->ca_last= new ;
  40. }
  41. void l_clear(list_head *header)
  42. {
  43. register list_elem *old, *next;
  44. for ( old=header->ca_first ; old ; old= next ) {
  45. next= old->ca_next ;
  46. freecore((char *)old) ;
  47. }
  48. header->ca_first= (list_elem *) 0 ;
  49. header->ca_last = (list_elem *) 0 ;
  50. }
  51. void l_throw(list_head *header)
  52. {
  53. register list_elem *old, *next;
  54. for ( old=header->ca_first ; old ; old= next ) {
  55. throws(l_content(*old)) ;
  56. next= old->ca_next ;
  57. freecore((char *)old) ;
  58. }
  59. header->ca_first= (list_elem *) 0 ;
  60. header->ca_last = (list_elem *) 0 ;
  61. }