home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / par150o2.zip / buffer.h < prev    next >
C/C++ Source or Header  |  1996-01-21  |  2KB  |  79 lines

  1. /*********************/
  2. /* buffer.h          */
  3. /* for Par 1.50      */
  4. /* Copyright 1996 by */
  5. /* Adam M. Costello  */
  6. /*********************/
  7.  
  8. /* This is ANSI C code. */
  9.  
  10.  
  11. /* Note: Those functions declared here which do not use errmsg    */
  12. /* always succeed, provided that they are passed valid arguments. */
  13.  
  14.  
  15. #include "errmsg.h"
  16.  
  17. #include <stddef.h>
  18.  
  19.  
  20. typedef struct buffer buffer;
  21.  
  22.  
  23. buffer *newbuffer(size_t itemsize, errmsg_t errmsg);
  24.  
  25.   /* newbuffer(itemsize,errmsg) returns a pointer to a    */
  26.   /* new empty buffer which holds items of size itemsize. */
  27.   /* itemsize must not be 0.  Returns NULL on failure.    */
  28.  
  29.  
  30. void freebuffer(buffer *buf);
  31.  
  32.   /* freebuffer(buf) frees the memory associated with */
  33.   /* *buf.  buf may not be used after this call.      */
  34.  
  35.  
  36. void clearbuffer(buffer *buf);
  37.  
  38.   /* clearbuffer(buf) removes  */
  39.   /* all items from *buf, but  */
  40.   /* does not free any memory. */
  41.  
  42.  
  43. void additem(buffer *buf, const void *item, errmsg_t errmsg);
  44.  
  45.   /* additem(buf,item,errmsg) copies *item to the end of     */
  46.   /* *buf.  item must point to an object of the proper size  */
  47.   /* for *buf.  If additem() fails, *buf will be unaffected. */
  48.  
  49.  
  50. int numitems(buffer *buf);
  51.  
  52.   /* numitems(buf) returns the number of items in *buf. */
  53.  
  54.  
  55. void *copyitems(buffer *buf, errmsg_t errmsg);
  56.  
  57.   /* copyitems(buf,errmsg) returns an array of objects of */
  58.   /* the proper size for *buf, one for each item in *buf, */
  59.   /* or NULL if there are no items in buf.  The elements  */
  60.   /* of the array are copied from the items in *buf, in   */
  61.   /* order.  The array is allocated with malloc(), so it  */
  62.   /* may be freed with free().  Returns NULL on failure.  */
  63.  
  64.  
  65. void *nextitem(buffer *buf);
  66.  
  67.   /* When buf was created by newbuffer, a pointer associated with buf  */
  68.   /* was initialized to point at the first slot in *buf.  If there is  */
  69.   /* an item in the slot currently pointed at, nextitem(buf) advances  */
  70.   /* the pointer to the next slot and returns the old value.  If there */
  71.   /* is no item in the slot, nextitem(buf) leaves the pointer where it */
  72.   /* is and returns NULL.                                              */
  73.  
  74.  
  75. void rewindbuffer(buffer *buf);
  76.  
  77.   /* rewindbuffer(buf) resets the pointer used by   */
  78.   /* nextitem() to point at the first slot in *buf. */
  79.