More debianization
[erwise] / Cl / WWWLibrary / HTChunk.h
1 /*              Chunk handling: Flexible arrays
2 **              ===============================
3 **
4 ** This module implements a flexible array. It is a general utility module.
5 ** A chunk is a structure which may be extended.  These routines create
6 ** and append data to chnuks, automatically reallocating them as necessary.
7 **
8 */
9
10
11 typedef struct {
12         int     size;           /* In bytes                     */
13         int     growby;         /* Allocation unit in bytes     */
14         int     allocated;      /* Current size of *data        */
15         char *  data;           /* Pointer to malloced area or 0 */
16 } HTChunk;
17
18
19 #ifdef SHORT_NAMES
20 #define HTChunkClear            HTChClea
21 #define HTChunkPutc             HTChPutc
22 #define HTChunkPuts             HTChPuts
23 #define HTChunkCreate           HTChCrea
24 #define HTChunkTerminate        HTChTerm
25 #define HTChunkEnsure           HtChEnsu
26 #endif
27
28
29 /*      Create new chunk
30 **
31 ** On entry,
32 **
33 **      growby          The number of bytes to allocate at a time
34 **                      when the chunk is later extended. Arbitrary but
35 **                      normally a trade-off time vs. memory
36 **
37 ** On exit,
38 **      returns         A chunk pointer to the new chunk,
39 */
40 extern HTChunk * HTChunkCreate PARAMS((int growby));
41
42
43 /*      Clear a chunk
44 **
45 ** On entry,
46 **      ch      A valid chunk pointer made by HTChunkCreate()
47 **
48 ** On exit,
49 **      *ch     The size of the chunk is zero.
50 */
51 extern void HTChunkClear PARAMS((HTChunk * ch));
52
53
54 /*      Ensure a chunk has a certain space in
55 **
56 ** On entry,
57 **      ch      A valid chunk pointer made by HTChunkCreate()
58 **      s       The size required
59 **
60 ** On exit,
61 **      *ch     Has size at least s
62 */
63 extern void HTChunkEnsure PARAMS((HTChunk * ch, int s));
64
65
66 /*      Append a character to a  chunk
67 **
68 ** On entry,
69 **      ch      A valid chunk pointer made by HTChunkCreate()
70 **      c       The character to be appended
71 ** On exit,
72 **      *ch     Is one character bigger
73 */
74
75 extern void HTChunkPutc PARAMS((HTChunk * ch, char c));
76
77 /*      Append a string to a  chunk
78 **
79 ** On entry,
80 **      ch      A valid chunk pointer made by HTChunkCreate()
81 **      s       Tpoints to a zero-terminated string to be appended
82 ** On exit,
83 **      *ch     Is bigger by strlen(s)
84 */
85
86 extern void HTChunkPuts PARAMS((HTChunk * ch, const char *s));
87
88
89 /*      Append a zero character to a  chunk
90 **
91 ** On entry,
92 **      ch      A valid chunk pointer made by HTChunkCreate()
93 ** On exit,
94 **      *ch     Is one character bigger
95 */
96
97 extern void HTChunkTerminate PARAMS((HTChunk * ch));