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