home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / libpics / htchunk.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  6.4 KB  |  193 lines

  1.  
  2. /*  W3 Copyright statement 
  3. Copyright 1995 by: Massachusetts Institute of Technology (MIT), INRIA</H2>
  4.  
  5. This W3C software is being provided by the copyright holders under the
  6. following license. By obtaining, using and/or copying this software,
  7. you agree that you have read, understood, and will comply with the
  8. following terms and conditions: 
  9.  
  10. Permission to use, copy, modify, and distribute this software and its
  11. documentation for any purpose and without fee or royalty is hereby
  12. granted, provided that the full text of this NOTICE appears on
  13. <EM>ALL</EM> copies of the software and documentation or portions
  14. thereof, including modifications, that you make. 
  15.  
  16. <B>THIS SOFTWARE IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO
  17. REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED.  BY WAY OF EXAMPLE,
  18. BUT NOT LIMITATION, COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR
  19. WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR
  20. THAT THE USE OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY
  21. THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
  22. COPYRIGHT HOLDERS WILL BEAR NO LIABILITY FOR ANY USE OF THIS SOFTWARE
  23. OR DOCUMENTATION.
  24.  
  25. The name and trademarks of copyright holders may NOT be used
  26. in advertising or publicity pertaining to the software without
  27. specific, written prior permission.  Title to copyright in this
  28. software and any associated documentation will at all times remain
  29. with copyright holders. 
  30. */
  31. /*                                                   W3C Reference Library libwww Chunk Class
  32.                                      THE CHUNK CLASS
  33.                                              
  34.  */
  35. /*
  36. **      (c) COPYRIGHT MIT 1995.
  37. **      Please first read the full copyright statement in the file COPYRIGH.
  38. */
  39. /*
  40.  
  41.    The Chunk Class  defines a way to automatically handle dynamic strings and other data
  42.    types. You create a chunk with an initial size and it will then automatically grow to
  43.    accomodate added data to the chunk. It is a general utility module. It is garanteed
  44.    that the array is '\0' terminated at all times (and hence is a valid C type string).
  45.    The method HTChunkTerminate can be used to explicitly add a terminating '\0'and then to
  46.    include this character in the chunk size. If left out, the terminating character is
  47.    _not_ considered part of the chunk.
  48.    
  49.    _Note_: The names without a "_" (made as a #define's) are only provided for backwards
  50.    compatibility and should not be used.
  51.    
  52.    This module is implemented by HTChunk.c, and it is a part of the W3C Reference Library.
  53.    
  54.  */
  55. #ifndef HTCHUNK_H
  56. #define HTCHUNK_H
  57.  
  58. /*
  59.  
  60. THE CHUNK CLASS
  61.  
  62.    This structure should not be referenced outside this module! We only keep it here to
  63.    maintain high performance. _Don't _use it directly!
  64.    
  65.  */
  66. typedef struct {
  67.         int     size;           /* In bytes                     */
  68.         int     growby;         /* Allocation unit in bytes     */
  69.         int     allocated;      /* Current size of *data        */
  70.         char *  data;           /* Pointer to malloced area or 0 */
  71. } HTChunk;
  72. /*
  73.  
  74. CREATE NEW CHUNK
  75.  
  76.    Create a new chunk and specify the number of bytes to allocate at a time when the chunk
  77.    is later extended. Arbitrary but normally a trade-off time vs. memory
  78.    
  79.  */
  80. #define HTChunkCreate(growby) HTChunk_new(growby)
  81. extern HTChunk * HTChunk_new (int growby);
  82. /*
  83.  
  84. FREE A CHUNK
  85.  
  86.    Free a chunk created by HTChunkCreatefrom memory
  87.    
  88.  */
  89. #define HTChunkFree(ch) HTChunk_delete(ch)
  90. extern void HTChunk_delete (HTChunk * ch);
  91. /*
  92.  
  93. CLEAR A CHUNK
  94.  
  95.    Keep the chunk in memory but clear all data kept inside. This can be used if you know
  96.    that you can reuse the allocated memory instead of allocating new memory.
  97.    
  98.  */
  99. #define HTChunkClear(ch) HTChunk_clear(ch)
  100. extern void HTChunk_clear (HTChunk * ch);
  101. /*
  102.  
  103. ENSURE A CHUNK HAS A CERTAIN AMOUNT OF FREE SPACE
  104.  
  105.    Make sure that a chunk has a certain size. If this is not the case then the chunk is
  106.    expanded. Nothing is done if the current size if bigger than the size requested.
  107.    
  108.  */
  109. #define HTChunkEnsure(ch, s) HTChunk_ensure(ch, s)
  110. extern void HTChunk_ensure (HTChunk * ch, int s);
  111. /*
  112.  
  113. APPEND A CHARACTER TO A CHUNK
  114.  
  115.    Add the character and increment the size of the chunk by one character
  116.    
  117.  */
  118. #define HTChunkPutc(ch, c) HTChunk_putc(ch, c)
  119. extern void HTChunk_putc (HTChunk * ch, char c);
  120. /*
  121.  
  122. APPEND A STRING TO A CHUNK
  123.  
  124.    Add the string and increment the size of the chunk by the length of the string (without
  125.    the trailing zero)
  126.    
  127.  */
  128. #define HTChunkPuts(ch, str) HTChunk_puts(ch, str)
  129. extern void HTChunk_puts (HTChunk * ch, const char *str);
  130. /*
  131.  
  132. APPEND A BLOCK TO A CHUNK
  133.  
  134.    Add the block and increment the size of the chunk by the len
  135.    
  136.  */
  137. extern void HTChunk_putb (HTChunk * ch, const char *block, int len);
  138.  
  139. /*
  140.  
  141. ZERO TERMINATE A CHUNK
  142.  
  143.    As a chunk often is a dynamic string, it needs to be terminated by a zero in order to
  144.    be used in C. However, _by default_ any chunk is _always_ zero terminated, so the only
  145.    purpose of this function is to increment the size counter with one corresponding to the
  146.    zero.
  147.    
  148.  */
  149. #define HTChunkTerminate(ch)    HTChunk_terminate(ch)
  150. #define HTChunk_terminate(ch)   HTChunk_putc((ch), '\0')
  151. /*
  152.  
  153. RETURN POINTER TO DATA
  154.  
  155.    This define converts a chunk to a normal char pointer so that it can be parsed to any
  156.    ANSI C string function.
  157.    
  158.  */
  159. #define HTChunkData(me)         ((me) ? (me)->data : NULL)
  160. #define HTChunk_data(me)         ((me) ? (me)->data : NULL)
  161. /*
  162.  
  163. CSTRING CONVERSIONS
  164.  
  165.    A Chunk may be build from an allocated string. The chunk assumes control of the passes
  166.    string, elminating the need for additional allocations and string copies.
  167.    Once a string is built, the chunk may be destroyed and the string kept around.
  168.    
  169.  */
  170. extern HTChunk * HTChunk_fromCString    (char * str, int grow);
  171. extern char * HTChunk_toCString         (HTChunk * ch);
  172. /*
  173.  
  174. RETURN CURRENT SIZE
  175.  
  176.    Returns the current size of the chunk
  177.    
  178.  */
  179. #define HTChunkSize(me)         ((me) ? (me)->size : -1)
  180. #define HTChunk_size(me)         ((me) ? (me)->size : -1)
  181. /*
  182.  
  183.  */
  184. #endif
  185. /*
  186.  
  187.    
  188.    ___________________________________
  189.    
  190.                            @(#) $Id: htchunk.h,v 3.1 1998/03/28 03:32:06 ltabb Exp $
  191.                                                                                           
  192.     */
  193.