chiark / gitweb /
Various manual fixes.
[mLib] / dspool.c
CommitLineData
8262a224 1/* -*-c-*-
2 *
8656dc50 3 * $Id: dspool.c,v 1.2 2004/04/08 01:36:11 mdw Exp $
8262a224 4 *
5 * Provide pools of strings
6 *
7 * (c) 1999 Straylight/Edgeware
8 */
9
10/*----- Licensing notice --------------------------------------------------*
11 *
12 * This file is part of the mLib utilities library.
13 *
14 * mLib is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU Library General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
18 *
19 * mLib is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Library General Public License for more details.
23 *
24 * You should have received a copy of the GNU Library General Public
25 * License along with mLib; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 */
28
8262a224 29/*----- Header files ------------------------------------------------------*/
30
31#include <stdio.h>
32
33#include "dspool.h"
34#include "dstr.h"
35#include "sub.h"
36
37/*----- Main code ---------------------------------------------------------*/
38
39/* --- @dspool_create@ --- *
40 *
41 * Arguments: @dspool *p@ = address of pool to create
42 * @size_t isz@ = initial size of new strings
43 *
44 * Returns: ---
45 *
46 * Use: Initializes a dynamic string pool.
47 */
48
49void dspool_create(dspool *p, size_t isz)
50{
51 p->free = 0;
52 p->isz = isz;
53}
54
55/* --- @dspool_destroy@ --- *
56 *
57 * Arguments: @dspool *p@ = pool to destroy
58 *
59 * Returns: ---
60 *
61 * Use: Releases all of the strings left in the pool. Any strings
62 * not put back into the pool aren't freed. However, the pool
63 * is still valid, and the active strings can be put back and
64 * released later.
65 */
66
67void dspool_destroy(dspool *p)
68{
69 dspoolstr *s = p->free;
70 while (s) {
71 dspoolstr *n = s->next;
72 DDESTROY(&s->ds);
73 DESTROY(s);
74 s = n;
75 }
76 p->free = 0;
77}
78
79/* --- @dspool_get@ --- *
80 *
81 * Arguments: @dspool *p@ = pointer to a string pool
82 *
83 * Returns: Pointer to a dynamic string.
84 *
85 * Use: Fetches a string from the pool. The string has space for at
86 * least @isz@ characters (where @isz@ is the size passed to
87 * @dspool_create@ for the pool).
88 */
89
90dstr *dspool_get(dspool *p) { dstr *d; DSGET(p, d); return (d); }
91
92/* --- @dspool_put@ --- *
93 *
94 * Arguments: @dspool *p@ = pointer to a string pool
95 * @dstr *d@ = pointer to a dynamic string from a string pool
96 *
97 * Returns: ---
98 *
99 * Use: Releases a dynamic string back into a string pool. It
100 * doesn't have to be the same pool the string actually came
101 * from, although it does have to have come from some string
102 * pool.
103 */
104
105void dspool_put(dspool *p, dstr *d) { DSPUT(p, d); }
106
107/*----- That's all, folks -------------------------------------------------*/