list.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 <stdlib.h>
  7. #include "ack.h"
  8. #include "list.h"
  9. #ifndef NORCSID
  10. static char rcs_id[] = "$Id$" ;
  11. static char rcs_list[] = RCS_LIST ;
  12. #endif
  13. /* List handling, operations allowed:
  14. adding strings to the list,
  15. throwing away whole lists,
  16. linearize a list.
  17. Routines:
  18. l_add(header,string) Add an element to a list.
  19. header List header, list_head *
  20. string String pointer, char *
  21. the string is NOT copied
  22. l_clear(header) Delete an whole list.
  23. header List header, list_head *
  24. l_throw(header) Delete a list of strings.
  25. header List header, list_head *
  26. */
  27. l_add(header,string) list_head *header ; char *string ; {
  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. l_clear(header) list_head *header ; {
  42. register list_elem *old, *next;
  43. for ( old=header->ca_first ; old ; old= next ) {
  44. next= old->ca_next ;
  45. freecore((char *)old) ;
  46. }
  47. header->ca_first= (list_elem *) 0 ;
  48. header->ca_last = (list_elem *) 0 ;
  49. }
  50. l_throw(header) list_head *header ; {
  51. register list_elem *old, *next;
  52. for ( old=header->ca_first ; old ; old= next ) {
  53. throws(l_content(*old)) ;
  54. next= old->ca_next ;
  55. freecore((char *)old) ;
  56. }
  57. header->ca_first= (list_elem *) 0 ;
  58. header->ca_last = (list_elem *) 0 ;
  59. }