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

2.8       timbl       1: <HTML>
                      2: <HEAD>
2.26      frystyk     3: <TITLE>W3C Reference Library libwww Dynamic Array Class</TITLE>
2.24      frystyk     4: <!-- Changed by: Henrik Frystyk Nielsen,  5-Feb-1996 -->
2.27    ! eric        5: <!-- Changed by: Eric Prud'hommeaux, 18-Mar-1996 -->
2.11      frystyk     6: </HEAD>
2.6       timbl       7: <BODY>
2.11      frystyk     8: 
2.18      frystyk     9: <H1>Dynamic Array Class</H1>
2.10      frystyk    10: 
2.11      frystyk    11: <PRE>
                     12: /*
2.16      frystyk    13: **     (c) COPYRIGHT MIT 1995.
2.11      frystyk    14: **     Please first read the full copyright statement in the file COPYRIGH.
                     15: */
                     16: </PRE>
                     17: 
2.14      frystyk    18: This module implements a flexible array. It is a general utility
                     19: module.  A chunk is a structure which may be extended.  These routines
                     20: create and append data to chunks, automatically reallocating them as
                     21: necessary.  It is garanteed that the array is <B>'\0'</B> terminated
                     22: at all times, so the terminating function, <A
                     23: HREF="HTChunk.html#Terminate">HTChunkTerminate</A> is only necessary
                     24: to adjust the size in the chunk structure (the <B>'\0'</B> counts as a
                     25: character when counting the size of the chunk. <P>
2.10      frystyk    26: 
2.11      frystyk    27: This module is implemented by <A HREF="HTChunk.c">HTChunk.c</A>, and
2.20      frystyk    28: it is a part of the <A HREF="http://www.w3.org/pub/WWW/Library/"> W3C
2.23      frystyk    29: Reference Library</A>. <P>
                     30: 
                     31: <IMG SRC="../../Icons/32x32/caution.gif" ALT="NOTE"> The names
                     32: without a "_" (made as a <CODE>#define</CODE>'s) are only provided for
                     33: backwards compatibility and should not be used.
2.10      frystyk    34: 
                     35: <PRE>
                     36: #ifndef HTCHUNK_H
2.9       frystyk    37: #define HTCHUNK_H
2.12      roeber     38: 
2.9       frystyk    39: </PRE>
                     40: 
2.18      frystyk    41: <H2>Private Data Structure</H2>
                     42: 
2.23      frystyk    43: This structure should not be referenced outside this module!
2.18      frystyk    44: 
                     45: <PRE>
                     46: typedef struct {
2.1       timbl      47:        int     size;           /* In bytes                     */
                     48:        int     growby;         /* Allocation unit in bytes     */
                     49:        int     allocated;      /* Current size of *data        */
                     50:        char *  data;           /* Pointer to malloced area or 0 */
                     51: } HTChunk;
2.18      frystyk    52: </PRE>
2.1       timbl      53: 
2.6       timbl      54: <H2>Create new chunk</H2>
2.18      frystyk    55: 
                     56: Create a new chunk and specify the number of bytes to allocate at a
                     57: time when the chunk is later extended. Arbitrary but normally a
                     58: trade-off time vs. memory
2.6       timbl      59: 
                     60: <PRE>
2.22      frystyk    61: #define HTChunkCreate(growby) HTChunk_new(growby)
                     62: extern HTChunk * HTChunk_new (int growby);
2.18      frystyk    63: </PRE>
2.1       timbl      64: 
2.18      frystyk    65: <H2>Free a chunk</H2>
2.1       timbl      66: 
2.18      frystyk    67: Free a chunk created by <CODE>HTChunkCreate</CODE>from memory
2.6       timbl      68: 
                     69: <PRE>
2.22      frystyk    70: #define HTChunkFree(ch) HTChunk_delete(ch)
                     71: extern void HTChunk_delete (HTChunk * ch);
2.18      frystyk    72: </PRE>
2.1       timbl      73: 
2.18      frystyk    74: <H2>Clear a chunk</H2>
2.1       timbl      75: 
2.18      frystyk    76: Keep the chunk in memory but clear all data kept inside.
2.6       timbl      77: 
                     78: <PRE>
2.22      frystyk    79: #define HTChunkClear(ch) HTChunk_clear(ch)
                     80: extern void HTChunk_clear (HTChunk * ch);
2.18      frystyk    81: </PRE>
2.1       timbl      82: 
2.18      frystyk    83: <H2>Ensure a chunk has a certain space in</H2>
2.1       timbl      84: 
2.18      frystyk    85: Make sure that a chunk has a certain size. If this is not the case
                     86: then the chunk is expanded. Nothing is done if the current size if
                     87: bigger than the size requested.
2.6       timbl      88: 
                     89: <PRE>
2.22      frystyk    90: #define HTChunkEnsure(ch, s) HTChunk_ensure(ch, s)
                     91: extern void HTChunk_ensure (HTChunk * ch, int s);
2.18      frystyk    92: </PRE>
2.1       timbl      93: 
2.18      frystyk    94: <H2>Append a character to a chunk</H2>
2.1       timbl      95: 
2.18      frystyk    96: Add the character and increment the size of the chunk by one character
                     97: 
                     98: <PRE>
2.22      frystyk    99: #define HTChunkPutc(ch, c) HTChunk_putc(ch, c)
                    100: extern void HTChunk_putc (HTChunk * ch, char c);
2.6       timbl     101: </PRE>
2.1       timbl     102: 
2.18      frystyk   103: <H2>Append a string to a  chunk</H2>
                    104: 
                    105: Add the string and increment the size of the chunk by the length of
                    106: the string (without the trailing zero)
2.1       timbl     107: 
2.18      frystyk   108: <PRE>
2.22      frystyk   109: #define HTChunkPuts(ch, str) HTChunk_puts(ch, str)
2.25      frystyk   110: extern void HTChunk_puts (HTChunk * ch, const char *str);
2.22      frystyk   111: </PRE>
                    112: 
                    113: <H2>Append a block to a chunk</H2>
                    114: 
                    115: Add the block and increment the size of the chunk by the len
                    116: 
                    117: <PRE>
2.25      frystyk   118: extern void HTChunk_putb (HTChunk * ch, const char *block, int len);
2.6       timbl     119: </PRE>
2.18      frystyk   120: 
                    121: <A NAME="Terminate"><H2>Zero Terminate a chunk</H2></A>
                    122: 
                    123: As a chunk often is a dynamic string, it needs to be terminated by a
                    124: zero in order to be used in C. However, <B>by default</B> any chunk
                    125: <EM>is</EM> always zero terminated, so the only purpose of this
                    126: function is to increment the size counter with one corresponding to
                    127: the zero.
2.6       timbl     128: 
                    129: <PRE>
2.24      frystyk   130: #define HTChunkTerminate(ch)   HTChunk_terminate(ch)
                    131: #define HTChunk_terminate(ch)  HTChunk_putc((ch), '\0')
2.18      frystyk   132: </PRE>
2.1       timbl     133: 
2.18      frystyk   134: <H2>Return Pointer to Data</H2>
2.1       timbl     135: 
2.18      frystyk   136: This define converts a chunk to a normal char pointer so that it can
                    137: be parsed to any ANSI C string function.
2.1       timbl     138: 
2.18      frystyk   139: <PRE>
2.22      frystyk   140: #define HTChunkData(me)         ((me) ? (me)->data : NULL)
                    141: #define HTChunk_data(me)         ((me) ? (me)->data : NULL)
2.27    ! eric      142: </PRE>
        !           143: 
        !           144: <A NAME="CString"><H2>CString conversions</H2></A>
        !           145: 
        !           146: A Chunk may be build from an allocated string. The chunk assumes control 
        !           147: of the passes string, elminating the need for additional allocations and
        !           148: string copies.<BR>
        !           149: Once a string is built, the chunk may be destroyed and the string kept 
        !           150: around.
        !           151: 
        !           152: <PRE>
        !           153: extern HTChunk * HTChunk_fromCString (char * str, int grow);
        !           154: extern char * HTChunk_toCString (HTChunk * ch);
2.6       timbl     155: </PRE>
2.18      frystyk   156: 
                    157: <H2>Return Current Size</H2>
                    158: 
                    159: Returns the current size of the chunk
                    160: 
2.6       timbl     161: <PRE>
2.22      frystyk   162: #define HTChunkSize(me)         ((me) ? (me)->size : -1)
                    163: #define HTChunk_size(me)         ((me) ? (me)->size : -1)
2.6       timbl     164: </PRE>
                    165: 
                    166: <PRE>
2.18      frystyk   167: #endif
                    168: </PRE>
2.1       timbl     169: 
2.18      frystyk   170: End of Declaration
2.6       timbl     171: 
2.18      frystyk   172: </BODY>
2.8       timbl     173: </HTML>

Webmaster