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

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.22    ! frystyk    56: #define HTChunkCreate(growby) HTChunk_new(growby)
        !            57: extern HTChunk * HTChunk_new (int growby);
2.18      frystyk    58: </PRE>
2.1       timbl      59: 
2.18      frystyk    60: <H2>Free a chunk</H2>
2.1       timbl      61: 
2.18      frystyk    62: Free a chunk created by <CODE>HTChunkCreate</CODE>from memory
2.6       timbl      63: 
                     64: <PRE>
2.22    ! frystyk    65: #define HTChunkFree(ch) HTChunk_delete(ch)
        !            66: extern void HTChunk_delete (HTChunk * ch);
2.18      frystyk    67: </PRE>
2.1       timbl      68: 
2.18      frystyk    69: <H2>Clear a chunk</H2>
2.1       timbl      70: 
2.18      frystyk    71: Keep the chunk in memory but clear all data kept inside.
2.6       timbl      72: 
                     73: <PRE>
2.22    ! frystyk    74: #define HTChunkClear(ch) HTChunk_clear(ch)
        !            75: extern void HTChunk_clear (HTChunk * ch);
2.18      frystyk    76: </PRE>
2.1       timbl      77: 
2.18      frystyk    78: <H2>Ensure a chunk has a certain space in</H2>
2.1       timbl      79: 
2.18      frystyk    80: Make sure that a chunk has a certain size. If this is not the case
                     81: then the chunk is expanded. Nothing is done if the current size if
                     82: bigger than the size requested.
2.6       timbl      83: 
                     84: <PRE>
2.22    ! frystyk    85: #define HTChunkEnsure(ch, s) HTChunk_ensure(ch, s)
        !            86: extern void HTChunk_ensure (HTChunk * ch, int s);
2.18      frystyk    87: </PRE>
2.1       timbl      88: 
2.18      frystyk    89: <H2>Append a character to a chunk</H2>
2.1       timbl      90: 
2.18      frystyk    91: Add the character and increment the size of the chunk by one character
                     92: 
                     93: <PRE>
2.22    ! frystyk    94: #define HTChunkPutc(ch, c) HTChunk_putc(ch, c)
        !            95: extern void HTChunk_putc (HTChunk * ch, char c);
2.6       timbl      96: </PRE>
2.1       timbl      97: 
2.18      frystyk    98: <H2>Append a string to a  chunk</H2>
                     99: 
                    100: Add the string and increment the size of the chunk by the length of
                    101: the string (without the trailing zero)
2.1       timbl     102: 
2.18      frystyk   103: <PRE>
2.22    ! frystyk   104: #define HTChunkPuts(ch, str) HTChunk_puts(ch, str)
        !           105: extern void HTChunk_puts (HTChunk * ch, CONST char *str);
        !           106: </PRE>
        !           107: 
        !           108: <H2>Append a block to a chunk</H2>
        !           109: 
        !           110: Add the block and increment the size of the chunk by the len
        !           111: 
        !           112: <PRE>
        !           113: extern void HTChunk_putb (HTChunk * ch, CONST char *block, int len);
2.6       timbl     114: </PRE>
2.18      frystyk   115: 
                    116: <A NAME="Terminate"><H2>Zero Terminate a chunk</H2></A>
                    117: 
                    118: As a chunk often is a dynamic string, it needs to be terminated by a
                    119: zero in order to be used in C. However, <B>by default</B> any chunk
                    120: <EM>is</EM> always zero terminated, so the only purpose of this
                    121: function is to increment the size counter with one corresponding to
                    122: the zero.
2.6       timbl     123: 
                    124: <PRE>
2.22    ! frystyk   125: #define HTChunkTerminate(ch) HTChunk_terminate(ch)
        !           126: extern void HTChunk_terminate (HTChunk * ch);
2.18      frystyk   127: </PRE>
2.1       timbl     128: 
2.18      frystyk   129: <H2>Return Pointer to Data</H2>
2.1       timbl     130: 
2.18      frystyk   131: This define converts a chunk to a normal char pointer so that it can
                    132: be parsed to any ANSI C string function.
2.1       timbl     133: 
2.18      frystyk   134: <PRE>
2.22    ! frystyk   135: #define HTChunkData(me)         ((me) ? (me)->data : NULL)
        !           136: #define HTChunk_data(me)         ((me) ? (me)->data : NULL)
2.6       timbl     137: </PRE>
2.18      frystyk   138: 
                    139: <H2>Return Current Size</H2>
                    140: 
                    141: Returns the current size of the chunk
                    142: 
2.6       timbl     143: <PRE>
2.22    ! frystyk   144: #define HTChunkSize(me)         ((me) ? (me)->size : -1)
        !           145: #define HTChunk_size(me)         ((me) ? (me)->size : -1)
2.6       timbl     146: </PRE>
                    147: 
                    148: <PRE>
2.18      frystyk   149: #endif
                    150: </PRE>
2.1       timbl     151: 
2.18      frystyk   152: End of Declaration
2.6       timbl     153: 
2.18      frystyk   154: </BODY>
2.8       timbl     155: </HTML>

Webmaster