1*2e2caf59SThomas Veerman /* $NetBSD: strlist.h,v 1.3 2009/01/16 21:15:34 dsl Exp $ */ 2*2e2caf59SThomas Veerman 3*2e2caf59SThomas Veerman /*- 4*2e2caf59SThomas Veerman * Copyright (c) 2008 - 2009 The NetBSD Foundation, Inc. 5*2e2caf59SThomas Veerman * All rights reserved. 6*2e2caf59SThomas Veerman * 7*2e2caf59SThomas Veerman * This code is derived from software contributed to The NetBSD Foundation 8*2e2caf59SThomas Veerman * by David Laight. 9*2e2caf59SThomas Veerman * 10*2e2caf59SThomas Veerman * Redistribution and use in source and binary forms, with or without 11*2e2caf59SThomas Veerman * modification, are permitted provided that the following conditions 12*2e2caf59SThomas Veerman * are met: 13*2e2caf59SThomas Veerman * 1. Redistributions of source code must retain the above copyright 14*2e2caf59SThomas Veerman * notice, this list of conditions and the following disclaimer. 15*2e2caf59SThomas Veerman * 2. Redistributions in binary form must reproduce the above copyright 16*2e2caf59SThomas Veerman * notice, this list of conditions and the following disclaimer in the 17*2e2caf59SThomas Veerman * documentation and/or other materials provided with the distribution. 18*2e2caf59SThomas Veerman * 3. Neither the name of The NetBSD Foundation nor the names of its 19*2e2caf59SThomas Veerman * contributors may be used to endorse or promote products derived 20*2e2caf59SThomas Veerman * from this software without specific prior written permission. 21*2e2caf59SThomas Veerman * 22*2e2caf59SThomas Veerman * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 23*2e2caf59SThomas Veerman * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 24*2e2caf59SThomas Veerman * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 25*2e2caf59SThomas Veerman * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 26*2e2caf59SThomas Veerman * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27*2e2caf59SThomas Veerman * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28*2e2caf59SThomas Veerman * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29*2e2caf59SThomas Veerman * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30*2e2caf59SThomas Veerman * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31*2e2caf59SThomas Veerman * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32*2e2caf59SThomas Veerman * POSSIBILITY OF SUCH DAMAGE. 33*2e2caf59SThomas Veerman */ 34*2e2caf59SThomas Veerman 35*2e2caf59SThomas Veerman #ifndef _STRLIST_H 36*2e2caf59SThomas Veerman #define _STRLIST_H 37*2e2caf59SThomas Veerman 38*2e2caf59SThomas Veerman typedef struct { 39*2e2caf59SThomas Veerman char *si_str; 40*2e2caf59SThomas Veerman unsigned int si_info; 41*2e2caf59SThomas Veerman } strlist_item_t; 42*2e2caf59SThomas Veerman 43*2e2caf59SThomas Veerman typedef struct { 44*2e2caf59SThomas Veerman unsigned int sl_num; 45*2e2caf59SThomas Veerman unsigned int sl_max; 46*2e2caf59SThomas Veerman strlist_item_t *sl_items; 47*2e2caf59SThomas Veerman } strlist_t; 48*2e2caf59SThomas Veerman 49*2e2caf59SThomas Veerman void strlist_init(strlist_t *); 50*2e2caf59SThomas Veerman void strlist_clean(strlist_t *); 51*2e2caf59SThomas Veerman void strlist_add_str(strlist_t *, char *, unsigned int); 52*2e2caf59SThomas Veerman 53*2e2caf59SThomas Veerman #define strlist_num(sl) ((sl)->sl_num) 54*2e2caf59SThomas Veerman #define strlist_str(sl, n) ((sl)->sl_items[n].si_str) 55*2e2caf59SThomas Veerman #define strlist_info(sl, n) ((sl)->sl_items[n].si_info) 56*2e2caf59SThomas Veerman #define strlist_set_info(sl, n, v) ((void)((sl)->sl_items[n].si_info = (v))) 57*2e2caf59SThomas Veerman 58*2e2caf59SThomas Veerman #define STRLIST_FOREACH(v, sl, index) \ 59*2e2caf59SThomas Veerman if ((sl)->sl_items != NULL) \ 60*2e2caf59SThomas Veerman for (index = 0; (v = strlist_str(sl, index)) != NULL; index++) 61*2e2caf59SThomas Veerman 62*2e2caf59SThomas Veerman #endif /* _STRLIST_H */ 63