1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
<HTML>
<HEAD>
<TITLE>HTChunk: Flexible array handling for libwww</TITLE></HEAD>
<BODY>
<H1>Chunk handling: Flexible arrays</H1>
This module implements a flexible array. It is a general utility module.
A chunk is a structure which may be extended. These routines create
and append data to chunks, automatically reallocating them as necessary.
It is garanteed that the array is '\0' terminated at all times, so the
terminating function, <A HREF="HTChunk.html#Terminate">HTChunkTerminate</A>
is only necessary to get the right size in the chunk structure.
<PRE>
#ifndef HTCHUNK_H
#define HTCHUNK_H
</PRE>
<PRE>typedef struct {
int size; /* In bytes */
int growby; /* Allocation unit in bytes */
int allocated; /* Current size of *data */
char * data; /* Pointer to malloced area or 0 */
} HTChunk;
#ifdef SHORT_NAMES
#define HTChunkClear HTChClea
#define HTChunkPutc HTChPutc
#define HTChunkPuts HTChPuts
#define HTChunkCreate HTChCrea
#define HTChunkTerminate HTChTerm
#define HTChunkEnsure HtChEnsu
#endif
</PRE>
<H2>Create new chunk</H2>
<H3>On entry,</H3>
<DL>
<DT>growby
<DD> The number of bytes to allocate
at a time when the chunk is later
extended. Arbitrary but normally
a trade-off time vs. memory
</DL>
<H3>On exit,</H3>
<DL>
<DT>returns
<DD> A chunk pointer to the new
chunk,
</DL>
<PRE>
extern HTChunk * HTChunkCreate PARAMS((int growby));
</PRE>
<H2>Free a chunk</H2>
<H3>On entry,</H3>
<DL>
<DT>ch
<DD> A valid chunk pointer made by
HTChunkCreate()
</DL>
<H3>On exit,</H3>
<DL>
<DT>ch
<DD> is invalid and may not be used.
</DL>
<PRE>
extern void HTChunkFree PARAMS((HTChunk * ch));
</PRE>
<H2>Clear a chunk</H2>
<H3>On entry,</H3>
<DL>
<DT>ch
<DD> A valid chunk pointer made by
HTChunkCreate()
</DL>
<H3>On exit,</H3>
<DL>
<DT>*ch
<DD> The size of the chunk is zero.
</DL>
<PRE>
extern void HTChunkClear PARAMS((HTChunk * ch));
</PRE>
<H2>Ensure a chunk has a certain space
in</H2>
<H3>On entry,</H3>
<DL>
<DT>ch
<DD> A valid chunk pointer made by
HTChunkCreate()
<DT>s
<DD> The size required
</DL>
<H3>On exit,</H3>
<DL>
<DT>*ch
<DD> Has size at least s
</DL>
<PRE>
extern void HTChunkEnsure PARAMS((HTChunk * ch, int s));
</PRE>
<H2>Append a character to a chunk</H2>
<H3>On entry,</H3>
<DL>
<DT>ch
<DD> A valid chunk pointer made by
HTChunkCreate()
<DT>c
<DD> The character to be appended
</DL>
<H3>On exit,</H3>
<DL>
<DT>*ch
<DD> Is one character bigger
</DL>
<PRE>extern void HTChunkPutc PARAMS((HTChunk * ch, char c));
</PRE>
<H2>Append a string to a chunk</H2>
<H3>On entry,</H3>
<DL>
<DT>ch
<DD> A valid chunk pointer made by
HTChunkCreate()
<DT>str
<DD> Tpoints to a zero-terminated
string to be appended
</DL>
<H3>On exit,</H3>
<DL>
<DT>*ch
<DD> Is bigger by strlen(str)
</DL>
<PRE>
extern void HTChunkPuts PARAMS((HTChunk * ch, const char *str));
</PRE>
<A NAME="Terminate"><H2>Append a zero character to a chunk</H2></A>
<PRE>
</PRE>
<H3>On entry,</H3>
<DL>
<DT>ch
<DD> A valid chunk pointer made by
HTChunkCreate()
</DL>
<H3>On exit,</H3>
<DL>
<DT>*ch
<DD> Is one character bigger
</DL>
<PRE>
extern void HTChunkTerminate PARAMS((HTChunk * ch));
#endif
</PRE>end</A></BODY>
</HTML>
|