list.c 1.5 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 <stdio.h>
  7. #include <stdlib.h>
  8. #include "ack.h"
  9. #include "list.h"
  10. /* List handling, operations allowed:
  11. adding strings to the list,
  12. throwing away whole lists,
  13. linearize a list.
  14. Routines:
  15. l_add(header,string) Add an element to a list.
  16. header List header, list_head *
  17. string String pointer, char *
  18. the string is NOT copied
  19. l_clear(header) Delete an whole list.
  20. header List header, list_head *
  21. l_throw(header) Delete a list of strings.
  22. header List header, list_head *
  23. */
  24. void l_add(list_head *header, char *string)
  25. {
  26. register list_elem *new;
  27. /* NOSTRICT */
  28. new= (list_elem *)getcore(sizeof *new);
  29. l_content(*new)= string ;
  30. /* NOSTRICT */
  31. l_next(*new)= (list_elem *)0 ;
  32. if ( !header->ca_first ) {
  33. header->ca_first= new ;
  34. } else {
  35. header->ca_last->ca_next= new ;
  36. }
  37. header->ca_last= new ;
  38. }
  39. void l_clear(list_head *header)
  40. {
  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. void l_throw(list_head *header)
  50. {
  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. }