1 /* str-list.h: declarations for string lists.
2 
3    Copyright 1993, 1994, 2007, 2008, 2010, 2012 Karl Berry.
4    Copyright 1999, 2005 Olaf Weber.
5 
6    This library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Lesser General Public
8    License as published by the Free Software Foundation; either
9    version 2.1 of the License, or (at your option) any later version.
10 
11    This library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Lesser General Public License for more details.
15 
16    You should have received a copy of the GNU Lesser General Public License
17    along with this library; if not, see <http://www.gnu.org/licenses/>.  */
18 
19 #ifndef KPATHSEA_STR_LIST_H
20 #define KPATHSEA_STR_LIST_H
21 
22 #include <kpathsea/c-proto.h>
23 #include <kpathsea/types.h>
24 
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 /* Lists of strings; used for, e.g., directory lists.  */
31 typedef struct
32 {
33   unsigned length;
34   string *list;
35 } str_list_type;
36 
37 /* Lists of const strings; used for, e.g., hash tables.  */
38 typedef struct
39 {
40   unsigned length;
41   const_string *list;
42 } cstr_list_type;
43 
44 #define STR_LIST_LENGTH(l) ((l).length)
45 #define STR_LIST(l) ((l).list)
46 #define STR_LIST_ELT(l, n) STR_LIST (l)[n]
47 #define STR_LIST_LAST_ELT(l) STR_LIST_ELT (l, STR_LIST_LENGTH (l) - 1)
48 
49 #ifdef MAKE_KPSE_DLL /* libkpathsea internal only */
50 
51 /* Return a new, empty, list.  */
52 static inline str_list_type
str_list_init(void)53 str_list_init (void)
54 {
55   str_list_type ret;
56 
57   STR_LIST_LENGTH (ret) = 0;
58   STR_LIST (ret) = NULL;
59 
60   return ret;
61 }
62 static inline cstr_list_type
cstr_list_init(void)63 cstr_list_init (void)
64 {
65   cstr_list_type ret;
66 
67   STR_LIST_LENGTH (ret) = 0;
68   STR_LIST (ret) = NULL;
69 
70   return ret;
71 }
72 
73 #endif /* MAKE_KPSE_DLL */
74 
75 /* Append the string S to the list L.  It's up to the caller to not
76    deallocate S; we don't copy it.  Also up to the caller to terminate
77    the list with a null entry.  */
78 extern KPSEDLL void str_list_add (str_list_type *l, string s);
79 extern KPSEDLL void cstr_list_add (cstr_list_type *l, const_string s);
80 
81 #ifdef MAKE_KPSE_DLL /* libkpathsea internal only */
82 
83 /* Append all the elements from MORE to TARGET.  */
84 extern void str_list_concat (str_list_type * target, str_list_type more);
85 
86 /* Free the space for the list elements (but not the list elements
87    themselves).  */
88 extern void str_list_free (str_list_type *l);
89 
90 /* Append each element of MORE to each element of TARGET.  */
91 extern void str_list_concat_elements
92   (str_list_type *target, str_list_type more);
93 
94 /* Remove duplicate elements from L, freeing their space.  */
95 extern void str_list_uniqify (str_list_type *l);
96 
97 #endif /* MAKE_KPSE_DLL */
98 
99 #ifdef __cplusplus
100 }
101 #endif
102 
103 #endif /* not KPATHSEA_STR_LIST_H */
104