10f38d8d9SDavid E. O'Brien.\" $NetBSD: stringlist.3,v 1.5 1999/03/22 19:44:46 garbled Exp $ 24ce2d5b5SMike Smith.\" 30f38d8d9SDavid E. O'Brien.\" Copyright (c) 1997, 1999 The NetBSD Foundation, Inc. 44ce2d5b5SMike Smith.\" All rights reserved. 54ce2d5b5SMike Smith.\" 64ce2d5b5SMike Smith.\" This file was contributed to The NetBSD Foundation by Luke Mewburn. 74ce2d5b5SMike Smith.\" 84ce2d5b5SMike Smith.\" Redistribution and use in source and binary forms, with or without 94ce2d5b5SMike Smith.\" modification, are permitted provided that the following conditions 104ce2d5b5SMike Smith.\" are met: 114ce2d5b5SMike Smith.\" 1. Redistributions of source code must retain the above copyright 124ce2d5b5SMike Smith.\" notice, this list of conditions and the following disclaimer. 134ce2d5b5SMike Smith.\" 2. Redistributions in binary form must reproduce the above copyright 144ce2d5b5SMike Smith.\" notice, this list of conditions and the following disclaimer in the 154ce2d5b5SMike Smith.\" documentation and/or other materials provided with the distribution. 164ce2d5b5SMike Smith.\" 3. All advertising materials mentioning features or use of this software 174ce2d5b5SMike Smith.\" must display the following acknowledgement: 184ce2d5b5SMike Smith.\" This product includes software developed by the NetBSD 194ce2d5b5SMike Smith.\" Foundation, Inc. and its contributors. 204ce2d5b5SMike Smith.\" 4. Neither the name of The NetBSD Foundation nor the names of its 214ce2d5b5SMike Smith.\" contributors may be used to endorse or promote products derived 224ce2d5b5SMike Smith.\" from this software without specific prior written permission. 234ce2d5b5SMike Smith.\" 244ce2d5b5SMike Smith.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 254ce2d5b5SMike Smith.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 264ce2d5b5SMike Smith.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 274ce2d5b5SMike Smith.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE 284ce2d5b5SMike Smith.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 294ce2d5b5SMike Smith.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 304ce2d5b5SMike Smith.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 314ce2d5b5SMike Smith.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 324ce2d5b5SMike Smith.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 334ce2d5b5SMike Smith.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 344ce2d5b5SMike Smith.\" POSSIBILITY OF SUCH DAMAGE. 354ce2d5b5SMike Smith.\" 367f3dea24SPeter Wemm.\" $FreeBSD$ 37fbc400a6SNik Clayton.\" 380f38d8d9SDavid E. O'Brien.Dd November 28, 1999 39a307d598SRuslan Ermilov.Os 404ce2d5b5SMike Smith.Dt STRINGLIST 3 414ce2d5b5SMike Smith.Sh NAME 424ce2d5b5SMike Smith.Nm stringlist , 434ce2d5b5SMike Smith.Nm sl_init , 444ce2d5b5SMike Smith.Nm sl_add , 454ce2d5b5SMike Smith.Nm sl_free , 464ce2d5b5SMike Smith.Nm sl_find 474ce2d5b5SMike Smith.Nd stringlist manipulation functions 4825bb73e0SAlexey Zelkin.Sh LIBRARY 4925bb73e0SAlexey Zelkin.Lb libc 504ce2d5b5SMike Smith.Sh SYNOPSIS 5132eef9aeSRuslan Ermilov.In stringlist.h 524ce2d5b5SMike Smith.Ft StringList * 534ce2d5b5SMike Smith.Fn sl_init 540f38d8d9SDavid E. O'Brien.Ft int 554ce2d5b5SMike Smith.Fn sl_add "StringList *sl" "char *item" 564ce2d5b5SMike Smith.Ft void 574ce2d5b5SMike Smith.Fn sl_free "StringList *sl" "int freeall" 584ce2d5b5SMike Smith.Ft char * 594ce2d5b5SMike Smith.Fn sl_find "StringList *sl" "char *item" 604ce2d5b5SMike Smith.Sh DESCRIPTION 614ce2d5b5SMike SmithThe 624ce2d5b5SMike Smith.Nm 634ce2d5b5SMike Smithfunctions manipulate stringlists, which are lists of 644ce2d5b5SMike Smithstrings that extend automatically if necessary. 654ce2d5b5SMike Smith.Pp 664ce2d5b5SMike SmithThe 675c564baeSRuslan Ermilov.Vt StringList 684ce2d5b5SMike Smithstructure has the following definition: 694ce2d5b5SMike Smith.Bd -literal -offset indent 704ce2d5b5SMike Smithtypedef struct _stringlist { 714ce2d5b5SMike Smith char **sl_str; 724ce2d5b5SMike Smith size_t sl_max; 734ce2d5b5SMike Smith size_t sl_cur; 744ce2d5b5SMike Smith} StringList; 754ce2d5b5SMike Smith.Ed 764ce2d5b5SMike Smith.Pp 774ce2d5b5SMike Smith.Bl -tag -width "sl_str" -offset indent 785c564baeSRuslan Ermilov.It Va sl_str 794ce2d5b5SMike Smitha pointer to the base of the array containing the list. 805c564baeSRuslan Ermilov.It Va sl_max 814ce2d5b5SMike Smiththe size of 825c564baeSRuslan Ermilov.Va sl_str . 835c564baeSRuslan Ermilov.It Va sl_cur 844ce2d5b5SMike Smiththe offset in 855c564baeSRuslan Ermilov.Va sl_str 864ce2d5b5SMike Smithof the current element. 874ce2d5b5SMike Smith.El 884ce2d5b5SMike Smith.Pp 894ce2d5b5SMike SmithThe following stringlist manipulation functions are available: 904ce2d5b5SMike Smith.Bl -tag -width "sl_init()" 914ce2d5b5SMike Smith.It Fn sl_init 924ce2d5b5SMike SmithCreate a stringlist. 934ce2d5b5SMike SmithReturns a pointer to a 940f38d8d9SDavid E. O'Brien.Vt StringList , 950f38d8d9SDavid E. O'Brienor 960f38d8d9SDavid E. O'Brien.Dv NULL 970f38d8d9SDavid E. O'Brienin case of failure. 984ce2d5b5SMike Smith.It Fn sl_free 994ce2d5b5SMike SmithReleases memory occupied by 1005c564baeSRuslan Ermilov.Fa sl 1014ce2d5b5SMike Smithand the 1025c564baeSRuslan Ermilov.Fa sl->sl_str 1034ce2d5b5SMike Smitharray. 1044ce2d5b5SMike SmithIf 1055c564baeSRuslan Ermilov.Fa freeall 1064ce2d5b5SMike Smithis non-zero, then each of the items within 1075c564baeSRuslan Ermilov.Fa sl->sl_str 1084ce2d5b5SMike Smithis released as well. 1094ce2d5b5SMike Smith.It Fn sl_add 1104ce2d5b5SMike SmithAdd 1115c564baeSRuslan Ermilov.Fa item 1124ce2d5b5SMike Smithto 1135c564baeSRuslan Ermilov.Fa sl->sl_str 1144ce2d5b5SMike Smithat 1155c564baeSRuslan Ermilov.Fa sl->sl_cur , 1164ce2d5b5SMike Smithextending the size of 1170f38d8d9SDavid E. O'Brien.Fa sl->sl_str . 118522ccf3fSRuslan ErmilovReturns zero upon success, \-1 upon failure. 1194ce2d5b5SMike Smith.It Fn sl_find 1204ce2d5b5SMike SmithFind 1215c564baeSRuslan Ermilov.Fa item 1224ce2d5b5SMike Smithin 1235c564baeSRuslan Ermilov.Fa sl , 12436a142c4SRuslan Ermilovreturning NULL if it is not found. 1254ce2d5b5SMike Smith.El 1264ce2d5b5SMike Smith.Sh SEE ALSO 1274ce2d5b5SMike Smith.Xr free 3 , 1284ce2d5b5SMike Smith.Xr malloc 3 1290f38d8d9SDavid E. O'Brien.Sh HISTORY 1300f38d8d9SDavid E. O'BrienThe 1310f38d8d9SDavid E. O'Brien.Nm 1320f38d8d9SDavid E. O'Brienfunctions appeared in 1330f38d8d9SDavid E. O'Brien.Fx 2.2.6 1340f38d8d9SDavid E. O'Brienand 1350f38d8d9SDavid E. O'Brien.Nx 1.3 . 136