3 * Provide pools of strings
5 * (c) 1999 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of the mLib utilities library.
12 * mLib is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Library General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
17 * mLib is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with mLib; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 /*----- Header files ------------------------------------------------------*/
44 /*----- Data structures ---------------------------------------------------*/
46 typedef struct dspoolstr
{
48 struct dspoolstr
*next
;
51 typedef struct dspool
{
56 /*----- Functions provided ------------------------------------------------*/
58 /* --- @dspool_create@ --- *
60 * Arguments: @dspool *p@ = address of pool to create
61 * @size_t isz@ = initial size of new strings
65 * Use: Initializes a dynamic string pool.
68 extern void dspool_create(dspool */
*p*/
, size_t /*isz*/);
70 /* --- @dspool_destroy@ --- *
72 * Arguments: @dspool *p@ = pool to destroy
76 * Use: Releases all of the strings left in the pool. Any strings
77 * not put back into the pool aren't freed. However, the pool
78 * is still valid, and the active strings can be put back and
82 extern void dspool_destroy(dspool */
*p*/
);
84 /* --- @dspool_get@ --- *
86 * Arguments: @dspool *p@ = pointer to a string pool
88 * Returns: Pointer to a dynamic string.
90 * Use: Fetches a string from the pool. The string has space for at
91 * least @isz@ characters (where @isz@ is the size passed to
92 * @dspool_create@ for the pool).
95 extern dstr
*dspool_get(dspool */
*p*/
);
97 #define DSGET(p, d) do { \
102 _p->free = _s->next; \
104 _s = CREATE(dspoolstr); \
107 DENSURE(&_s->ds, _p->isz); \
112 /* --- @dspool_put@ --- *
114 * Arguments: @dspool *p@ = pointer to a string pool
115 * @dstr *d@ = pointer to a dynamic string from a string pool
119 * Use: Releases a dynamic string back into a string pool. It
120 * doesn't have to be the same pool the string actually came
121 * from, although it does have to have come from some string
125 extern void dspool_put(dspool */
*p*/
, dstr */
*d*/
);
127 #define DSPUT(p, d) do { \
129 dspoolstr *_s = (dspoolstr *)(d); \
131 _s->next = _p->free; \
135 /*----- That's all, folks -------------------------------------------------*/