#ifndef _BUFFER_H_
#define _BUFFER_H_

/* PURPOSE:
 *    BUFFER.H: Public data types and functions for the Buffer type.
 * HISTORY:
 *    Ian D. Allen   idallen@freenet.carleton.ca
 */

#include "mem.h"

#define BF_EMPTY(b) ((b)->cursize <= 1)  /* nothing but NUL */

typedef struct Buffer {
	char *buf;	/* pointer returned by malloc */
	int maxsize;	/* size of space allocated by malloc */
	int cursize;	/* amount of space currently used (incl NUL) */
	int incr;	/* increment to add if/when growing maxsize */
} Buffer;

Buffer *bf_alloc(	/* RET: an initialized, empty buffer */
	int size,	/* IN: initial maxsize to allocate */
	int incr	/* IN: increment by which to grow maxsize */
);
void bf_addch(
	Buffer *buf,	/* IN/OUT: an initialized buffer */
	char ch		/* IN: the character to append to the buffer */
);
void bf_addstr(
	Buffer *buf,	/* IN/OUT: an initialized buffer */
	char *str	/* IN: string to add to end of buffer */
);
void bf_clear(
	Buffer *buf	/* IN/OUT: an initialized buffer */
);
void bf_valid(
	Buffer *buf	/* IN: an initialized buffer */
);
void bf_free(
	Buffer *buf	/* IN: an initialized buffer */
);

#endif /*_BUFFER_H_*/
