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

2.8       timbl       1: <HTML>
                      2: <HEAD>
2.18      frystyk     3: <TITLE>Dynamic Array Class</TITLE>
2.23    ! frystyk     4: <!-- Changed by: Henrik Frystyk Nielsen,  9-Dec-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
2.23    ! frystyk    28: Reference Library</A>. <P>
        !            29: 
        !            30: <IMG SRC="../../Icons/32x32/caution.gif" ALT="NOTE"> The names
        !            31: without a "_" (made as a <CODE>#define</CODE>'s) are only provided for
        !            32: backwards compatibility and should not be used.
2.10      frystyk    33: 
                     34: <PRE>
                     35: #ifndef HTCHUNK_H
2.9       frystyk    36: #define HTCHUNK_H
2.12      roeber     37: 
2.9       frystyk    38: </PRE>
                     39: 
2.18      frystyk    40: <H2>Private Data Structure</H2>
                     41: 
2.23    ! frystyk    42: This structure should not be referenced outside this module!
2.18      frystyk    43: 
                     44: <PRE>
                     45: typedef struct {
2.1       timbl      46:        int     size;           /* In bytes                     */
                     47:        int     growby;         /* Allocation unit in bytes     */
                     48:        int     allocated;      /* Current size of *data        */
                     49:        char *  data;           /* Pointer to malloced area or 0 */
                     50: } HTChunk;
2.18      frystyk    51: </PRE>
2.1       timbl      52: 
2.6       timbl      53: <H2>Create new chunk</H2>
2.18      frystyk    54: 
                     55: Create a new chunk and specify the number of bytes to allocate at a
                     56: time when the chunk is later extended. Arbitrary but normally a
                     57: trade-off time vs. memory
2.6       timbl      58: 
                     59: <PRE>
2.22      frystyk    60: #define HTChunkCreate(growby) HTChunk_new(growby)
                     61: extern HTChunk * HTChunk_new (int growby);
2.18      frystyk    62: </PRE>
2.1       timbl      63: 
2.18      frystyk    64: <H2>Free a chunk</H2>
2.1       timbl      65: 
2.18      frystyk    66: Free a chunk created by <CODE>HTChunkCreate</CODE>from memory
2.6       timbl      67: 
                     68: <PRE>
2.22      frystyk    69: #define HTChunkFree(ch) HTChunk_delete(ch)
                     70: extern void HTChunk_delete (HTChunk * ch);
2.18      frystyk    71: </PRE>
2.1       timbl      72: 
2.18      frystyk    73: <H2>Clear a chunk</H2>
2.1       timbl      74: 
2.18      frystyk    75: Keep the chunk in memory but clear all data kept inside.
2.6       timbl      76: 
                     77: <PRE>
2.22      frystyk    78: #define HTChunkClear(ch) HTChunk_clear(ch)
                     79: extern void HTChunk_clear (HTChunk * ch);
2.18      frystyk    80: </PRE>
2.1       timbl      81: 
2.18      frystyk    82: <H2>Ensure a chunk has a certain space in</H2>
2.1       timbl      83: 
2.18      frystyk    84: Make sure that a chunk has a certain size. If this is not the case
                     85: then the chunk is expanded. Nothing is done if the current size if
                     86: bigger than the size requested.
2.6       timbl      87: 
                     88: <PRE>
2.22      frystyk    89: #define HTChunkEnsure(ch, s) HTChunk_ensure(ch, s)
                     90: extern void HTChunk_ensure (HTChunk * ch, int s);
2.18      frystyk    91: </PRE>
2.1       timbl      92: 
2.18      frystyk    93: <H2>Append a character to a chunk</H2>
2.1       timbl      94: 
2.18      frystyk    95: Add the character and increment the size of the chunk by one character
                     96: 
                     97: <PRE>
2.22      frystyk    98: #define HTChunkPutc(ch, c) HTChunk_putc(ch, c)
                     99: extern void HTChunk_putc (HTChunk * ch, char c);
2.6       timbl     100: </PRE>
2.1       timbl     101: 
2.18      frystyk   102: <H2>Append a string to a  chunk</H2>
                    103: 
                    104: Add the string and increment the size of the chunk by the length of
                    105: the string (without the trailing zero)
2.1       timbl     106: 
2.18      frystyk   107: <PRE>
2.22      frystyk   108: #define HTChunkPuts(ch, str) HTChunk_puts(ch, str)
                    109: extern void HTChunk_puts (HTChunk * ch, CONST char *str);
                    110: </PRE>
                    111: 
                    112: <H2>Append a block to a chunk</H2>
                    113: 
                    114: Add the block and increment the size of the chunk by the len
                    115: 
                    116: <PRE>
                    117: extern void HTChunk_putb (HTChunk * ch, CONST char *block, int len);
2.6       timbl     118: </PRE>
2.18      frystyk   119: 
                    120: <A NAME="Terminate"><H2>Zero Terminate a chunk</H2></A>
                    121: 
                    122: As a chunk often is a dynamic string, it needs to be terminated by a
                    123: zero in order to be used in C. However, <B>by default</B> any chunk
                    124: <EM>is</EM> always zero terminated, so the only purpose of this
                    125: function is to increment the size counter with one corresponding to
                    126: the zero.
2.6       timbl     127: 
                    128: <PRE>
2.22      frystyk   129: #define HTChunkTerminate(ch) HTChunk_terminate(ch)
                    130: extern void HTChunk_terminate (HTChunk * ch);
2.18      frystyk   131: </PRE>
2.1       timbl     132: 
2.18      frystyk   133: <H2>Return Pointer to Data</H2>
2.1       timbl     134: 
2.18      frystyk   135: This define converts a chunk to a normal char pointer so that it can
                    136: be parsed to any ANSI C string function.
2.1       timbl     137: 
2.18      frystyk   138: <PRE>
2.22      frystyk   139: #define HTChunkData(me)         ((me) ? (me)->data : NULL)
                    140: #define HTChunk_data(me)         ((me) ? (me)->data : NULL)
2.6       timbl     141: </PRE>
2.18      frystyk   142: 
                    143: <H2>Return Current Size</H2>
                    144: 
                    145: Returns the current size of the chunk
                    146: 
2.6       timbl     147: <PRE>
2.22      frystyk   148: #define HTChunkSize(me)         ((me) ? (me)->size : -1)
                    149: #define HTChunk_size(me)         ((me) ? (me)->size : -1)
2.6       timbl     150: </PRE>
                    151: 
                    152: <PRE>
2.18      frystyk   153: #endif
                    154: </PRE>
2.1       timbl     155: 
2.18      frystyk   156: End of Declaration
2.6       timbl     157: 
2.18      frystyk   158: </BODY>
2.8       timbl     159: </HTML>

Webmaster