2999
|
1 /* str-list.c: define routines for string lists. |
|
2 |
|
3 Copyright (C) 1993 Karl Berry. |
|
4 |
|
5 This library is free software; you can redistribute it and/or |
|
6 modify it under the terms of the GNU Library General Public |
|
7 License as published by the Free Software Foundation; either |
|
8 version 2 of the License, or (at your option) any later version. |
|
9 |
|
10 This library is distributed in the hope that it will be useful, |
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 Library General Public License for more details. |
|
14 |
|
15 You should have received a copy of the GNU Library General Public |
|
16 License along with this library; if not, write to the Free Software |
|
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
|
18 |
|
19 #include <kpathsea/config.h> |
|
20 |
|
21 #include <kpathsea/str-list.h> |
|
22 |
|
23 |
|
24 /* See the .h file for comments. */ |
|
25 |
|
26 |
|
27 str_list_type |
|
28 str_list_init P1H(void) |
|
29 { |
|
30 str_list_type ret; |
|
31 |
|
32 STR_LIST_LENGTH (ret) = 0; |
|
33 STR_LIST (ret) = NULL; |
|
34 |
|
35 return ret; |
|
36 } |
|
37 |
|
38 |
|
39 void |
|
40 str_list_add P2C(str_list_type *, l, string, s) |
|
41 { |
|
42 STR_LIST_LENGTH (*l)++; |
|
43 XRETALLOC (STR_LIST (*l), STR_LIST_LENGTH (*l), string); |
|
44 STR_LIST_LAST_ELT (*l) = s; |
|
45 } |
|
46 |
|
47 |
|
48 /* May as well save some reallocations and do everything in a chunk |
|
49 instead of calling str_list_add on each element. */ |
|
50 |
|
51 void |
|
52 str_list_concat P2C(str_list_type *, target, str_list_type, more) |
|
53 { |
|
54 unsigned e; |
|
55 unsigned prev_len = STR_LIST_LENGTH (*target); |
|
56 |
|
57 STR_LIST_LENGTH (*target) += STR_LIST_LENGTH (more); |
|
58 XRETALLOC (STR_LIST (*target), STR_LIST_LENGTH (*target), string); |
|
59 |
|
60 for (e = 0; e < STR_LIST_LENGTH (more); e++) |
|
61 STR_LIST_ELT (*target, prev_len + e) = STR_LIST_ELT (more, e); |
|
62 } |
|
63 |
|
64 |
|
65 /* Free the list (but not the elements within it). */ |
|
66 |
|
67 void |
|
68 str_list_free P1C(str_list_type *, l) |
|
69 { |
|
70 if (STR_LIST (*l)) |
|
71 { |
|
72 free (STR_LIST (*l)); |
|
73 STR_LIST (*l) = NULL; |
|
74 } |
|
75 } |