X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/mLib/blobdiff_plain/c6e0eaf00cd09a4e5237e70d8351049ec91d7653..ec6770ddae55110cf71b73e2bce70150a39a17c3:/lbuf.h diff --git a/lbuf.h b/lbuf.h index 21968e2..9f290b8 100644 --- a/lbuf.h +++ b/lbuf.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: lbuf.h,v 1.3 1999/12/10 23:42:04 mdw Exp $ + * $Id: lbuf.h,v 1.5 2001/01/20 12:06:01 mdw Exp $ * * Block-to-line buffering * @@ -30,6 +30,12 @@ /*----- Revision history --------------------------------------------------* * * $Log: lbuf.h,v $ + * Revision 1.5 2001/01/20 12:06:01 mdw + * Define flags with macros, to ensure unsignedness. + * + * Revision 1.4 2000/06/17 10:38:14 mdw + * Add support for variable buffer sizes. + * * Revision 1.3 1999/12/10 23:42:04 mdw * Change header file guard names. * @@ -93,6 +99,10 @@ #include +#ifndef MLIB_ARENA_H +# include "arena.h" +#endif + /*----- Data structures ---------------------------------------------------*/ /* --- The buffer structure --- * @@ -106,14 +116,14 @@ typedef struct lbuf { void (*func)(char */*s*/, void */*p*/); /* Handler function */ void *p; /* Argument for handler */ size_t len; /* Length of data in buffer */ + size_t sz; /* Buffer size */ unsigned f; /* Various useful state flags */ - char buf[256]; /* The actual buffer */ + arena *a; /* Memory allocation arena */ + char *buf; /* The actual buffer */ } lbuf; -enum { - LBUF_CR = 1, /* Read a carriage return */ - LBUF_ENABLE = 2 /* Buffer is currently enabled */ -}; +#define LBUF_CR 1u /* Read a carriage return */ +#define LBUF_ENABLE 2u /* Buffer is currently enabled */ /*----- Functions provided ------------------------------------------------*/ @@ -186,6 +196,18 @@ extern size_t lbuf_free(lbuf */*b*/, char **/*p*/); extern void lbuf_snarf(lbuf */*b*/, const void */*p*/, size_t /*sz*/); +/* --- @lbuf_setsize@ --- * + * + * Arguments: @lbuf *b@ = pointer to buffer block + * @size_t sz@ = requested maximum line size + * + * Returns: --- + * + * Use: Allocates a buffer of the requested size reading lines. + */ + +extern void lbuf_setsize(lbuf */*b*/, size_t /*sz*/); + /* --- @lbuf_init@ --- * * * Arguments: @lbuf *b@ = pointer to buffer block @@ -202,6 +224,17 @@ extern void lbuf_init(lbuf */*b*/, void (*/*func*/)(char */*s*/, void */*p*/), void */*p*/); +/* --- @lbuf_destroy@ --- * + * + * Arguments: @lbuf *b@ = pointer to buffer block + * + * Returns: --- + * + * Use: Deallocates a line buffer and frees any resources it owned. + */ + +extern void lbuf_destroy(lbuf */*b*/); + /*----- That's all, folks -------------------------------------------------*/ #ifdef __cplusplus