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