1 /* Id: strlist.h,v 1.3 2014/12/24 09:55:32 plunky Exp */ 2 /* $NetBSD: strlist.h,v 1.1.1.2 2016/02/09 20:28:56 plunky Exp $ */ 3 4 /*- 5 * Copyright (c) 2011 Joerg Sonnenberger <joerg@NetBSD.org>. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in 16 * the documentation and/or other materials provided with the 17 * distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 22 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 23 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 24 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 27 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 29 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 */ 32 33 #ifndef STRLIST_H 34 #define STRLIST_H 35 36 #include <stddef.h> 37 #include <stdio.h> 38 39 struct string { 40 struct string *next; 41 char *value; 42 }; 43 44 struct strlist { 45 struct string *first; 46 struct string *last; 47 }; 48 49 void strlist_init(struct strlist *); 50 void strlist_free(struct strlist *); 51 void strlist_make_array(const struct strlist *, char ***, size_t *); 52 void strlist_print(const struct strlist *, FILE *, int); 53 54 void strlist_prepend(struct strlist *, const char *); 55 void strlist_prepend_nocopy(struct strlist *, char *); 56 void strlist_prepend_list(struct strlist *, const struct strlist *); 57 void strlist_append(struct strlist *, const char *); 58 void strlist_append_nocopy(struct strlist *, char *); 59 void strlist_append_list(struct strlist *, const struct strlist *); 60 void strlist_append_array(struct strlist *, const char * const *); 61 62 #define STRLIST_FIRST(head) ((head)->first) 63 #define STRLIST_NEXT(elem) ((elem)->next) 64 #define STRLIST_FOREACH(var, head) \ 65 for ((var) = STRLIST_FIRST(head); \ 66 (var) != NULL; \ 67 (var) = STRLIST_NEXT(var)) 68 #define STRLIST_FOREACH_MUTABLE(var, head, var2) \ 69 for ((var) = STRLIST_FIRST(head); \ 70 (var) != NULL && ((var2) = STRLIST_NEXT(var), 1); \ 71 (var) = (var2)) 72 #define STRLIST_EMPTY(head) (STRLIST_FIRST(head) == NULL) 73 74 #endif /* STRLIST_H */ 75