| 1 |
/* str-list.h: declarations for string lists. |
| 2 |
|
| 3 |
Copyright 1993, 1994, 2007, 2008, 2010, 2012, 2018 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_EMPTY(l) (STR_LIST_LENGTH (l) == 0) |
| 46 |
|
| 47 |
#define STR_LIST(l) ((l).list) |
| 48 |
#define STR_LIST_ELT(l, n) (STR_LIST (l)[n]) |
| 49 |
#define STR_LIST_FIRST_ELT(l) STR_LIST_ELT ((l), 0) |
| 50 |
#define STR_LIST_LAST_ELT(l) STR_LIST_ELT ((l), STR_LIST_LENGTH (l) - 1) |
| 51 |
|
| 52 |
#ifdef MAKE_KPSE_DLL /* libkpathsea internal only */ |
| 53 |
|
| 54 |
/* Return a new, empty, list. */ |
| 55 |
static inline str_list_type |
| 56 |
str_list_init (void) |
| 57 |
{ |
| 58 |
str_list_type ret; |
| 59 |
|
| 60 |
STR_LIST_LENGTH (ret) = 0; |
| 61 |
STR_LIST (ret) = NULL; |
| 62 |
|
| 63 |
return ret; |
| 64 |
} |
| 65 |
static inline cstr_list_type |
| 66 |
cstr_list_init (void) |
| 67 |
{ |
| 68 |
cstr_list_type ret; |
| 69 |
|
| 70 |
STR_LIST_LENGTH (ret) = 0; |
| 71 |
STR_LIST (ret) = NULL; |
| 72 |
|
| 73 |
return ret; |
| 74 |
} |
| 75 |
|
| 76 |
#endif /* MAKE_KPSE_DLL */ |
| 77 |
|
| 78 |
/* Append the string S to the list L. It's up to the caller to not |
| 79 |
deallocate S; we don't copy it. Also up to the caller to terminate |
| 80 |
the list with a null entry. */ |
| 81 |
extern KPSEDLL void str_list_add (str_list_type *l, string s); |
| 82 |
extern KPSEDLL void cstr_list_add (cstr_list_type *l, const_string s); |
| 83 |
|
| 84 |
#ifdef MAKE_KPSE_DLL /* libkpathsea internal only */ |
| 85 |
|
| 86 |
/* Append all the elements from MORE to TARGET. */ |
| 87 |
extern void str_list_concat (str_list_type * target, str_list_type more); |
| 88 |
|
| 89 |
/* Free the space for the list elements (but not the list elements |
| 90 |
themselves). */ |
| 91 |
extern void str_list_free (str_list_type *l); |
| 92 |
|
| 93 |
/* Append each element of MORE to each element of TARGET. */ |
| 94 |
extern void str_list_concat_elements |
| 95 |
(str_list_type *target, str_list_type more); |
| 96 |
|
| 97 |
/* Remove duplicate elements from L, freeing their space. */ |
| 98 |
extern void str_list_uniqify (str_list_type *l); |
| 99 |
|
| 100 |
#endif /* MAKE_KPSE_DLL */ |
| 101 |
|
| 102 |
#ifdef __cplusplus |
| 103 |
} |
| 104 |
#endif |
| 105 |
|
| 106 |
#endif /* not KPATHSEA_STR_LIST_H */ |