]>
git.cameronkatri.com Git - mandoc.git/blob - compat_stringlist.c
9 /* $Id: compat_stringlist.c,v 1.5 2015/05/21 00:13:43 schwarze Exp $ */
11 * Copyright (c) 1994 Christos Zoulas <christos@netbsd.org>
12 * All rights reserved.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
24 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
27 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 #include "compat_stringlist.h"
41 #define _SL_CHUNKSIZE 20
44 * sl_init(): Initialize a string list
51 sl
= malloc(sizeof(StringList
));
56 sl
->sl_max
= _SL_CHUNKSIZE
;
57 sl
->sl_str
= reallocarray(NULL
, sl
->sl_max
, sizeof(char *));
58 if (sl
->sl_str
== NULL
)
65 * sl_add(): Add an item to the string list
68 sl_add(StringList
*sl
, char *name
)
70 if (sl
->sl_cur
== sl
->sl_max
- 1) {
71 sl
->sl_max
+= _SL_CHUNKSIZE
;
72 sl
->sl_str
= reallocarray(sl
->sl_str
,
73 sl
->sl_max
, sizeof(char *));
74 if (sl
->sl_str
== NULL
)
77 sl
->sl_str
[sl
->sl_cur
++] = name
;
83 * sl_free(): Free a stringlist
86 sl_free(StringList
*sl
, int all
)
94 for (i
= 0; i
< sl
->sl_cur
; i
++)
103 * sl_find(): Find a name in the string list
106 sl_find(StringList
*sl
, const char *name
)
110 for (i
= 0; i
< sl
->sl_cur
; i
++)
111 if (strcmp(sl
->sl_str
[i
], name
) == 0)
112 return sl
->sl_str
[i
];