chiark / gitweb /
More generated files.
[mLib] / dspool.c
CommitLineData
8262a224 1/* -*-c-*-
2 *
3 * $Id: dspool.c,v 1.1 1999/05/21 22:15:26 mdw Exp $
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
29/*----- Revision history --------------------------------------------------*
30 *
31 * $Log: dspool.c,v $
32 * Revision 1.1 1999/05/21 22:15:26 mdw
33 * Dynamic string pool system, based on an idea from the `sw-tools'
34 * project. Could do with more work to make it really good.
35 *
36 */
37
38/*----- Header files ------------------------------------------------------*/
39
40#include <stdio.h>
41
42#include "dspool.h"
43#include "dstr.h"
44#include "sub.h"
45
46/*----- Main code ---------------------------------------------------------*/
47
48/* --- @dspool_create@ --- *
49 *
50 * Arguments: @dspool *p@ = address of pool to create
51 * @size_t isz@ = initial size of new strings
52 *
53 * Returns: ---
54 *
55 * Use: Initializes a dynamic string pool.
56 */
57
58void dspool_create(dspool *p, size_t isz)
59{
60 p->free = 0;
61 p->isz = isz;
62}
63
64/* --- @dspool_destroy@ --- *
65 *
66 * Arguments: @dspool *p@ = pool to destroy
67 *
68 * Returns: ---
69 *
70 * Use: Releases all of the strings left in the pool. Any strings
71 * not put back into the pool aren't freed. However, the pool
72 * is still valid, and the active strings can be put back and
73 * released later.
74 */
75
76void dspool_destroy(dspool *p)
77{
78 dspoolstr *s = p->free;
79 while (s) {
80 dspoolstr *n = s->next;
81 DDESTROY(&s->ds);
82 DESTROY(s);
83 s = n;
84 }
85 p->free = 0;
86}
87
88/* --- @dspool_get@ --- *
89 *
90 * Arguments: @dspool *p@ = pointer to a string pool
91 *
92 * Returns: Pointer to a dynamic string.
93 *
94 * Use: Fetches a string from the pool. The string has space for at
95 * least @isz@ characters (where @isz@ is the size passed to
96 * @dspool_create@ for the pool).
97 */
98
99dstr *dspool_get(dspool *p) { dstr *d; DSGET(p, d); return (d); }
100
101/* --- @dspool_put@ --- *
102 *
103 * Arguments: @dspool *p@ = pointer to a string pool
104 * @dstr *d@ = pointer to a dynamic string from a string pool
105 *
106 * Returns: ---
107 *
108 * Use: Releases a dynamic string back into a string pool. It
109 * doesn't have to be the same pool the string actually came
110 * from, although it does have to have come from some string
111 * pool.
112 */
113
114void dspool_put(dspool *p, dstr *d) { DSPUT(p, d); }
115
116/*----- That's all, folks -------------------------------------------------*/