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