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