Pristine Ack-5.5
[Ack-5.5.git] / util / ack / list.c
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
7 #include "ack.h"
8 #include "list.h"
9
10 #ifndef NORCSID
11 static char rcs_id[] = "$Id: list.c,v 2.4 1994/06/24 10:12:46 ceriel Exp $" ;
12 static char rcs_list[] = RCS_LIST ;
13 #endif
14
15 /* List handling, operations allowed:
16         adding strings to the list,
17         throwing away whole lists,
18         linearize a list.
19
20 Routines:
21         l_add(header,string) Add an element to a list.
22                 header          List header, list_head *
23                 string          String pointer, char *
24                                         the string is NOT copied
25
26         l_clear(header)      Delete an whole list.
27                 header          List header, list_head *
28         
29         l_throw(header)      Delete a list of strings.
30                 header          List header, list_head *
31
32 */
33
34
35 l_add(header,string) list_head *header ; char *string ; {
36         register list_elem *new;
37
38         /* NOSTRICT */
39         new= (list_elem *)getcore(sizeof *new);
40         l_content(*new)= string ;
41         /* NOSTRICT */
42         l_next(*new)= (list_elem *)0 ;
43         if ( !header->ca_first ) {
44                 header->ca_first= new ;
45         } else {
46                 header->ca_last->ca_next= new ;
47         }
48         header->ca_last= new ;
49 }
50
51 l_clear(header) list_head *header ; {
52         register list_elem *old, *next;
53         for ( old=header->ca_first ; old ; old= next ) {
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 }
60
61 l_throw(header) list_head *header ; {
62         register list_elem *old, *next;
63         for ( old=header->ca_first ; old ; old= next ) {
64                 throws(l_content(*old)) ;
65                 next= old->ca_next ;
66                 freecore((char *)old) ;
67         }
68         header->ca_first= (list_elem *) 0 ;
69         header->ca_last = (list_elem *) 0 ;
70 }