175592Sru/* Id: strlist.h,v 1.3 2014/12/24 09:55:32 plunky Exp */ 275592Sru/* $NetBSD: strlist.h,v 1.1.1.2 2016/02/09 20:28:56 plunky Exp $ */ 318142Spst 418142Spst/*- 575592Sru * Copyright (c) 2011 Joerg Sonnenberger <joerg@NetBSD.org>. 618142Spst * All rights reserved. 718142Spst * 818142Spst * Redistribution and use in source and binary forms, with or without 918142Spst * modification, are permitted provided that the following conditions 1018142Spst * are met: 1118142Spst * 1218142Spst * 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 39struct string { 40 struct string *next; 41 char *value; 42}; 43 44struct strlist { 45 struct string *first; 46 struct string *last; 47}; 48 49void strlist_init(struct strlist *); 50void strlist_free(struct strlist *); 51void strlist_make_array(const struct strlist *, char ***, size_t *); 52void strlist_print(const struct strlist *, FILE *, int); 53 54void strlist_prepend(struct strlist *, const char *); 55void strlist_prepend_nocopy(struct strlist *, char *); 56void strlist_prepend_list(struct strlist *, const struct strlist *); 57void strlist_append(struct strlist *, const char *); 58void strlist_append_nocopy(struct strlist *, char *); 59void strlist_append_list(struct strlist *, const struct strlist *); 60void 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