chiark / gitweb /
Release 2.0.6.
[mLib] / lbuf.h
diff --git a/lbuf.h b/lbuf.h
index 21968e28fd6e371bedf4f73a98cf60da7c9bcb46..1e2a9641ae93f81b01d7f7e6ab5c19e487f9fb16 100644 (file)
--- a/lbuf.h
+++ b/lbuf.h
@@ -1,13 +1,13 @@
 /* -*-c-*-
  *
- * $Id: lbuf.h,v 1.3 1999/12/10 23:42:04 mdw Exp $
+ * $Id: lbuf.h,v 1.8 2004/04/08 01:36:13 mdw Exp $
  *
  * Block-to-line buffering
  *
  * (c) 1999 Straylight/Edgeware
  */
 
-/*----- Licensing notice --------------------------------------------------* 
+/*----- Licensing notice --------------------------------------------------*
  *
  * This file is part of the mLib utilities library.
  *
  * it under the terms of the GNU Library General Public License as
  * published by the Free Software Foundation; either version 2 of the
  * License, or (at your option) any later version.
- * 
+ *
  * mLib is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU Library General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Library General Public
  * License along with mLib; if not, write to the Free
  * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  * MA 02111-1307, USA.
  */
 
-/*----- Revision history --------------------------------------------------* 
- *
- * $Log: lbuf.h,v $
- * Revision 1.3  1999/12/10 23:42:04  mdw
- * Change header file guard names.
- *
- * Revision 1.2  1999/05/17 20:36:08  mdw
- * Make the magical constants for the buffer flags uppercase.
- *
- * Revision 1.1  1999/05/14 21:01:14  mdw
- * Integrated `select' handling bits from the background resolver project.
- *
- */
-
 #ifndef MLIB_LBUF_H
 #define MLIB_LBUF_H
 
 
 #include <stddef.h>
 
+#ifndef MLIB_ARENA_H
+#  include "arena.h"
+#endif
+
 /*----- Data structures ---------------------------------------------------*/
 
 /* --- The buffer structure --- *
  * that.
  */
 
+struct lbuf;
+
+typedef void lbuf_func(char */*s*/, size_t /*len*/, void */*p*/);
+
 typedef struct lbuf {
-  void (*func)(char */*s*/, void */*p*/); /* Handler function */
+  lbuf_func *func;                     /* Handler function */
   void *p;                             /* Argument for handler */
   size_t len;                          /* Length of data in buffer */
+  size_t sz;                           /* Buffer size */
+  unsigned delim;                      /* Delimiter to look for */
   unsigned f;                          /* Various useful state flags */
-  char buf[256];                       /* The actual buffer */
+  arena *a;                            /* Memory allocation arena */
+  char *buf;                           /* The actual buffer */
 } lbuf;
 
+#define LBUF_CR 1u                     /* Read a carriage return */
+#define LBUF_ENABLE 2u                 /* Buffer is currently enabled */
+#define LBUF_CLOSE 4u                  /* Buffer is now closed */
+
 enum {
-  LBUF_CR = 1,                         /* Read a carriage return */
-  LBUF_ENABLE = 2                      /* Buffer is currently enabled */
+  LBUF_CRLF = 256,
+  LBUF_STRICTCRLF = 257
 };
 
 /*----- Functions provided ------------------------------------------------*/
@@ -186,10 +187,22 @@ 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
- *             @void (*func)(char *s, void *p)@ = handler function
+ *             @lbuf_func *func@ = handler function
  *             @void *p@ = argument pointer for @func@
  *
  * Returns:    ---
@@ -198,9 +211,18 @@ extern void lbuf_snarf(lbuf */*b*/, const void */*p*/, size_t /*sz*/);
  *             passed to @func@ for processing.
  */
 
-extern void lbuf_init(lbuf */*b*/,
-                     void (*/*func*/)(char */*s*/, void */*p*/),
-                     void */*p*/);
+extern void lbuf_init(lbuf */*b*/, lbuf_func */*func*/, 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 -------------------------------------------------*/