Annotation of libwww/Library/src/HTChunk.html, revision 2.14
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: /*
11: ** (c) COPYRIGHT CERN 1994.
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
27: HREF="http://info.cern.ch/hypertext/WWW/Library/User/Guide/Guide.html">
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:
43:
44: #ifdef SHORT_NAMES
45: #define HTChunkClear HTChClea
46: #define HTChunkPutc HTChPutc
47: #define HTChunkPuts HTChPuts
48: #define HTChunkCreate HTChCrea
49: #define HTChunkTerminate HTChTerm
50: #define HTChunkEnsure HtChEnsu
51: #endif
52:
53:
2.6 timbl 54: </PRE>
55: <H2>Create new chunk</H2>
56: <H3>On entry,</H3>
57: <DL>
58: <DT>growby
2.7 timbl 59: <DD> The number of bytes to allocate
2.6 timbl 60: at a time when the chunk is later
61: extended. Arbitrary but normally
62: a trade-off time vs. memory
63: </DL>
64:
65: <H3>On exit,</H3>
66: <DL>
67: <DT>returns
2.7 timbl 68: <DD> A chunk pointer to the new
2.6 timbl 69: chunk,
70: </DL>
71:
72: <PRE>
2.1 timbl 73: extern HTChunk * HTChunkCreate PARAMS((int growby));
74:
75:
2.6 timbl 76: </PRE>
77: <H2>Free a chunk</H2>
78: <H3>On entry,</H3>
79: <DL>
80: <DT>ch
2.7 timbl 81: <DD> A valid chunk pointer made by
82: HTChunkCreate()
2.6 timbl 83: </DL>
84:
85: <H3>On exit,</H3>
86: <DL>
87: <DT>ch
2.7 timbl 88: <DD> is invalid and may not be used.
2.6 timbl 89: </DL>
90:
91: <PRE>
2.1 timbl 92: extern void HTChunkFree PARAMS((HTChunk * ch));
93:
94:
2.6 timbl 95: </PRE>
96: <H2>Clear a chunk</H2>
97: <H3>On entry,</H3>
98: <DL>
99: <DT>ch
2.7 timbl 100: <DD> A valid chunk pointer made by
101: HTChunkCreate()
2.6 timbl 102: </DL>
103:
104: <H3>On exit,</H3>
105: <DL>
106: <DT>*ch
2.7 timbl 107: <DD> The size of the chunk is zero.
2.6 timbl 108: </DL>
109:
110: <PRE>
2.1 timbl 111: extern void HTChunkClear PARAMS((HTChunk * ch));
112:
113:
2.6 timbl 114: </PRE>
115: <H2>Ensure a chunk has a certain space
116: in</H2>
117: <H3>On entry,</H3>
118: <DL>
119: <DT>ch
2.7 timbl 120: <DD> A valid chunk pointer made by
121: HTChunkCreate()
2.6 timbl 122: <DT>s
2.7 timbl 123: <DD> The size required
2.6 timbl 124: </DL>
125:
126: <H3>On exit,</H3>
127: <DL>
128: <DT>*ch
2.7 timbl 129: <DD> Has size at least s
2.6 timbl 130: </DL>
131:
132: <PRE>
2.1 timbl 133: extern void HTChunkEnsure PARAMS((HTChunk * ch, int s));
134:
135:
2.6 timbl 136: </PRE>
137: <H2>Append a character to a chunk</H2>
138: <H3>On entry,</H3>
139: <DL>
140: <DT>ch
2.7 timbl 141: <DD> A valid chunk pointer made by
142: HTChunkCreate()
143: <DT>c
2.8 timbl 144: <DD> The character to be appended
2.6 timbl 145: </DL>
146:
2.7 timbl 147: <H3>On exit,</H3>
148: <DL>
149: <DT>*ch
2.8 timbl 150: <DD> Is one character bigger
2.7 timbl 151: </DL>
2.1 timbl 152:
2.7 timbl 153: <PRE>extern void HTChunkPutc PARAMS((HTChunk * ch, char c));
2.1 timbl 154:
2.6 timbl 155: </PRE>
156: <H2>Append a string to a chunk</H2>
157: <H3>On entry,</H3>
158: <DL>
159: <DT>ch
2.7 timbl 160: <DD> A valid chunk pointer made by
161: HTChunkCreate()
162: <DT>str
163: <DD> Tpoints to a zero-terminated
164: string to be appended
2.6 timbl 165: </DL>
166:
167: <H3>On exit,</H3>
168: <DL>
169: <DT>*ch
2.7 timbl 170: <DD> Is bigger by strlen(str)
2.6 timbl 171: </DL>
172:
173: <PRE>
2.1 timbl 174:
2.7 timbl 175: extern void HTChunkPuts PARAMS((HTChunk * ch, const char *str));
2.1 timbl 176:
177:
2.6 timbl 178: </PRE>
2.10 frystyk 179: <A NAME="Terminate"><H2>Append a zero character to a chunk</H2></A>
2.6 timbl 180: <PRE>
181: </PRE>
182: <H3>On entry,</H3>
183: <DL>
184: <DT>ch
2.7 timbl 185: <DD> A valid chunk pointer made by
186: HTChunkCreate()
2.6 timbl 187: </DL>
188:
189: <H3>On exit,</H3>
190: <DL>
191: <DT>*ch
2.7 timbl 192: <DD> Is one character bigger
2.6 timbl 193: </DL>
194:
195: <PRE>
2.1 timbl 196:
197: extern void HTChunkTerminate PARAMS((HTChunk * ch));
2.9 frystyk 198:
199: #endif
2.6 timbl 200:
2.8 timbl 201: </PRE>end</A></BODY>
202: </HTML>
Webmaster