Annotation of libwww/Library/src/HTChunk.html, revision 2.20

2.8       timbl       1: <HTML>
                      2: <HEAD>
2.18      frystyk     3: <TITLE>Dynamic Array Class</TITLE>
2.20    ! frystyk     4: <!-- Changed by: Henrik Frystyk Nielsen, 14-Nov-1995 -->
2.11      frystyk     5: </HEAD>
2.6       timbl       6: <BODY>
2.11      frystyk     7: 
2.18      frystyk     8: <H1>Dynamic Array Class</H1>
2.10      frystyk     9: 
2.11      frystyk    10: <PRE>
                     11: /*
2.16      frystyk    12: **     (c) COPYRIGHT MIT 1995.
2.11      frystyk    13: **     Please first read the full copyright statement in the file COPYRIGH.
                     14: */
                     15: </PRE>
                     16: 
2.14      frystyk    17: This module implements a flexible array. It is a general utility
                     18: module.  A chunk is a structure which may be extended.  These routines
                     19: create and append data to chunks, automatically reallocating them as
                     20: necessary.  It is garanteed that the array is <B>'\0'</B> terminated
                     21: at all times, so the terminating function, <A
                     22: HREF="HTChunk.html#Terminate">HTChunkTerminate</A> is only necessary
                     23: to adjust the size in the chunk structure (the <B>'\0'</B> counts as a
                     24: character when counting the size of the chunk. <P>
2.10      frystyk    25: 
2.11      frystyk    26: This module is implemented by <A HREF="HTChunk.c">HTChunk.c</A>, and
2.20    ! frystyk    27: it is a part of the <A HREF="http://www.w3.org/pub/WWW/Library/"> W3C
        !            28: Reference Library</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.18      frystyk    36: <H2>Private Data Structure</H2>
                     37: 
                     38: This structure should not be referenced outside this module
                     39: 
                     40: <PRE>
                     41: typedef struct {
2.1       timbl      42:        int     size;           /* In bytes                     */
                     43:        int     growby;         /* Allocation unit in bytes     */
                     44:        int     allocated;      /* Current size of *data        */
                     45:        char *  data;           /* Pointer to malloced area or 0 */
                     46: } HTChunk;
2.18      frystyk    47: </PRE>
2.1       timbl      48: 
2.6       timbl      49: <H2>Create new chunk</H2>
2.18      frystyk    50: 
                     51: Create a new chunk and specify the number of bytes to allocate at a
                     52: time when the chunk is later extended. Arbitrary but normally a
                     53: trade-off time vs. memory
2.6       timbl      54: 
                     55: <PRE>
2.20    ! frystyk    56: extern HTChunk * HTChunkCreate (int growby);
2.18      frystyk    57: </PRE>
2.1       timbl      58: 
2.18      frystyk    59: <H2>Free a chunk</H2>
2.1       timbl      60: 
2.18      frystyk    61: Free a chunk created by <CODE>HTChunkCreate</CODE>from memory
2.6       timbl      62: 
                     63: <PRE>
2.20    ! frystyk    64: extern void HTChunkFree (HTChunk * ch);
2.18      frystyk    65: </PRE>
2.1       timbl      66: 
2.18      frystyk    67: <H2>Clear a chunk</H2>
2.1       timbl      68: 
2.18      frystyk    69: Keep the chunk in memory but clear all data kept inside.
2.6       timbl      70: 
                     71: <PRE>
2.20    ! frystyk    72: extern void HTChunkClear (HTChunk * ch);
2.18      frystyk    73: </PRE>
2.1       timbl      74: 
2.18      frystyk    75: <H2>Ensure a chunk has a certain space in</H2>
2.1       timbl      76: 
2.18      frystyk    77: Make sure that a chunk has a certain size. If this is not the case
                     78: then the chunk is expanded. Nothing is done if the current size if
                     79: bigger than the size requested.
2.6       timbl      80: 
                     81: <PRE>
2.20    ! frystyk    82: extern void HTChunkEnsure (HTChunk * ch, int s);
2.18      frystyk    83: </PRE>
2.1       timbl      84: 
2.18      frystyk    85: <H2>Append a character to a chunk</H2>
2.1       timbl      86: 
2.18      frystyk    87: Add the character and increment the size of the chunk by one character
                     88: 
                     89: <PRE>
2.20    ! frystyk    90: extern void HTChunkPutc (HTChunk * ch, char c);
2.6       timbl      91: </PRE>
2.1       timbl      92: 
2.18      frystyk    93: <H2>Append a string to a  chunk</H2>
                     94: 
                     95: Add the string and increment the size of the chunk by the length of
                     96: the string (without the trailing zero)
2.1       timbl      97: 
2.18      frystyk    98: <PRE>
2.20    ! frystyk    99: extern void HTChunkPuts (HTChunk * ch, const char *str);
2.6       timbl     100: </PRE>
2.18      frystyk   101: 
                    102: <A NAME="Terminate"><H2>Zero Terminate a chunk</H2></A>
                    103: 
                    104: As a chunk often is a dynamic string, it needs to be terminated by a
                    105: zero in order to be used in C. However, <B>by default</B> any chunk
                    106: <EM>is</EM> always zero terminated, so the only purpose of this
                    107: function is to increment the size counter with one corresponding to
                    108: the zero.
2.6       timbl     109: 
                    110: <PRE>
2.20    ! frystyk   111: extern void HTChunkTerminate (HTChunk * ch);
2.18      frystyk   112: </PRE>
2.1       timbl     113: 
2.18      frystyk   114: <H2>Return Pointer to Data</H2>
2.1       timbl     115: 
2.18      frystyk   116: This define converts a chunk to a normal char pointer so that it can
                    117: be parsed to any ANSI C string function.
2.1       timbl     118: 
2.18      frystyk   119: <PRE>
                    120: #define HTChunkData(me)                ((me) ? (me)-&gt;data : NULL)
2.6       timbl     121: </PRE>
2.18      frystyk   122: 
                    123: <H2>Return Current Size</H2>
                    124: 
                    125: Returns the current size of the chunk
                    126: 
2.6       timbl     127: <PRE>
2.18      frystyk   128: #define HTChunkSize(me)                ((me) ? (me)-&gt;size : -1)
2.6       timbl     129: </PRE>
                    130: 
                    131: <PRE>
2.18      frystyk   132: #endif
                    133: </PRE>
2.1       timbl     134: 
2.18      frystyk   135: End of Declaration
2.6       timbl     136: 
2.18      frystyk   137: </BODY>
2.8       timbl     138: </HTML>

Webmaster