<HTML>
<HEAD>
<TITLE>HTChunk: Flexible array handling for libwww</TITLE>
</HEAD>
<BODY>
<H1>Chunk handling: Flexible arrays</H1>
<PRE>
/*
** (c) COPYRIGHT MIT 1995.
** Please first read the full copyright statement in the file COPYRIGH.
*/
</PRE>
This module implements a flexible array. It is a general utility
module. A chunk is a structure which may be extended. These routines
create and append data to chunks, automatically reallocating them as
necessary. It is garanteed that the array is <B>'\0'</B> terminated
at all times, so the terminating function, <A
HREF="HTChunk.html#Terminate">HTChunkTerminate</A> is only necessary
to adjust the size in the chunk structure (the <B>'\0'</B> counts as a
character when counting the size of the chunk. <P>
This module is implemented by <A HREF="HTChunk.c">HTChunk.c</A>, and
it is a part of the <A
HREF="http://www.w3.org/hypertext/WWW/Library/">
W3C Reference Library</A>.
<PRE>
#ifndef HTCHUNK_H
#define HTCHUNK_H
</PRE>
<PRE>typedef struct {
int size; /* In bytes */
int growby; /* Allocation unit in bytes */
int allocated; /* Current size of *data */
char * data; /* Pointer to malloced area or 0 */
} HTChunk;
</PRE>
<H2>Create new chunk</H2>
<H3>On entry,</H3>
<DL>
<DT>growby
<DD> The number of bytes to allocate
at a time when the chunk is later
extended. Arbitrary but normally
a trade-off time vs. memory
</DL>
<H3>On exit,</H3>
<DL>
<DT>returns
<DD> A chunk pointer to the new
chunk,
</DL>
<PRE>
extern HTChunk * HTChunkCreate PARAMS((int growby));
</PRE>
<H2>Free a chunk</H2>
<H3>On entry,</H3>
<DL>
<DT>ch
<DD> A valid chunk pointer made by
HTChunkCreate()
</DL>
<H3>On exit,</H3>
<DL>
<DT>ch
<DD> is invalid and may not be used.
</DL>
<PRE>
extern void HTChunkFree PARAMS((HTChunk * ch));
</PRE>
<H2>Clear a chunk</H2>
<H3>On entry,</H3>
<DL>
<DT>ch
<DD> A valid chunk pointer made by
HTChunkCreate()
</DL>
<H3>On exit,</H3>
<DL>
<DT>*ch
<DD> The size of the chunk is zero.
</DL>
<PRE>
extern void HTChunkClear PARAMS((HTChunk * ch));
</PRE>
<H2>Ensure a chunk has a certain space
in</H2>
<H3>On entry,</H3>
<DL>
<DT>ch
<DD> A valid chunk pointer made by
HTChunkCreate()
<DT>s
<DD> The size required
</DL>
<H3>On exit,</H3>
<DL>
<DT>*ch
<DD> Has size at least s
</DL>
<PRE>
extern void HTChunkEnsure PARAMS((HTChunk * ch, int s));
</PRE>
<H2>Append a character to a chunk</H2>
<H3>On entry,</H3>
<DL>
<DT>ch
<DD> A valid chunk pointer made by
HTChunkCreate()
<DT>c
<DD> The character to be appended
</DL>
<H3>On exit,</H3>
<DL>
<DT>*ch
<DD> Is one character bigger
</DL>
<PRE>extern void HTChunkPutc PARAMS((HTChunk * ch, char c));
</PRE>
<H2>Append a string to a chunk</H2>
<H3>On entry,</H3>
<DL>
<DT>ch
<DD> A valid chunk pointer made by
HTChunkCreate()
<DT>str
<DD> Tpoints to a zero-terminated
string to be appended
</DL>
<H3>On exit,</H3>
<DL>
<DT>*ch
<DD> Is bigger by strlen(str)
</DL>
<PRE>
extern void HTChunkPuts PARAMS((HTChunk * ch, const char *str));
</PRE>
<A NAME="Terminate"><H2>Append a zero character to a chunk</H2></A>
<PRE>
</PRE>
<H3>On entry,</H3>
<DL>
<DT>ch
<DD> A valid chunk pointer made by
HTChunkCreate()
</DL>
<H3>On exit,</H3>
<DL>
<DT>*ch
<DD> Is one character bigger
</DL>
<PRE>
extern void HTChunkTerminate PARAMS((HTChunk * ch));
#endif
</PRE>end</A></BODY>
</HTML>
Webmaster