chiark
/
gitweb
/
~mdw
/
mLib
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Generate the CRC table rather than hardcoding it.
[mLib]
/
dstr.h
diff --git
a/dstr.h
b/dstr.h
index 3ef27ea01df2de0de709f4f99c678b89a0d4f1d1..538dd33a0f8653d48d85b9b7d9d278317551212d 100644
(file)
--- a/
dstr.h
+++ b/
dstr.h
@@
-1,6
+1,6
@@
/* -*-c-*-
*
/* -*-c-*-
*
- * $Id: dstr.h,v 1.
8 1999/07/14 19:45:24
mdw Exp $
+ * $Id: dstr.h,v 1.
11 2000/06/17 10:37:39
mdw Exp $
*
* Handle dynamically growing strings
*
*
* Handle dynamically growing strings
*
@@
-30,6
+30,15
@@
/*----- Revision history --------------------------------------------------*
*
* $Log: dstr.h,v $
/*----- Revision history --------------------------------------------------*
*
* $Log: dstr.h,v $
+ * Revision 1.11 2000/06/17 10:37:39 mdw
+ * Add support for arena management.
+ *
+ * Revision 1.10 1999/12/22 15:39:51 mdw
+ * Fix argument reuse in DPUTS.
+ *
+ * Revision 1.9 1999/12/10 23:42:04 mdw
+ * Change header file guard names.
+ *
* Revision 1.8 1999/07/14 19:45:24 mdw
* Prevent some macros from re-evaluating their arguments.
*
* Revision 1.8 1999/07/14 19:45:24 mdw
* Prevent some macros from re-evaluating their arguments.
*
@@
-57,8
+66,8
@@
*
*/
*
*/
-#ifndef DSTR_H
-#define DSTR_H
+#ifndef
MLIB_
DSTR_H
+#define
MLIB_
DSTR_H
#ifdef __cplusplus
extern "C" {
#ifdef __cplusplus
extern "C" {
@@
-80,15
+89,24
@@
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
+#ifndef MLIB_ALLOC_H
+# include "alloc.h"
+#endif
+
+#ifndef MLIB_ARENA_H
+# include "arena.h"
+#endif
+
/*----- Data structures ---------------------------------------------------*/
typedef struct dstr {
char *buf; /* Pointer to string buffer */
size_t sz; /* Size of the buffer */
size_t len; /* Length of the string */
/*----- Data structures ---------------------------------------------------*/
typedef struct dstr {
char *buf; /* Pointer to string buffer */
size_t sz; /* Size of the buffer */
size_t len; /* Length of the string */
+ arena *a; /* Pointer to arena */
} dstr;
} dstr;
-#define DSTR_INIT { 0, 0, 0
}
/* How to initialize one */
+#define DSTR_INIT { 0, 0, 0
, &arena_stdlib }
/* How to initialize one */
/*----- Functions provided ------------------------------------------------*/
/*----- Functions provided ------------------------------------------------*/
@@
-108,6
+126,7
@@
extern void dstr_create(dstr */*d*/);
_dd->buf = 0; \
_dd->sz = 0; \
_dd->len = 0; \
_dd->buf = 0; \
_dd->sz = 0; \
_dd->len = 0; \
+ _dd->a = &arena_stdlib; \
} while (0)
/* --- @dstr_destroy@ --- *
} while (0)
/* --- @dstr_destroy@ --- *
@@
-124,13
+143,13
@@
extern void dstr_destroy(dstr */*d*/);
#define DDESTROY(d) do { \
dstr *_d = (d); \
if (_d->buf) \
#define DDESTROY(d) do { \
dstr *_d = (d); \
if (_d->buf) \
-
free(_d->buf);
\
+
x_free(_d->a, _d->buf);
\
DCREATE(_d); \
} while (0)
/* --- @dstr_reset@ --- *
*
DCREATE(_d); \
} while (0)
/* --- @dstr_reset@ --- *
*
- * Arguments: @dstr *d@ = pointer to a dyna
im
c string block
+ * Arguments: @dstr *d@ = pointer to a dyna
mi
c string block
*
* Returns: ---
*
*
* Returns: ---
*
@@
-213,7
+232,7
@@
extern void dstr_puts(dstr */*d*/, const char */*s*/);
#define DPUTS(d, s) do { \
dstr *_d = (d); \
const char *_s = (s); \
#define DPUTS(d, s) do { \
dstr *_d = (d); \
const char *_s = (s); \
- size_t _sz = strlen(
s);
\
+ size_t _sz = strlen(
_s);
\
DENSURE(_d, _sz + 1); \
memcpy(_d->buf + _d->len, _s, _sz + 1); \
_d->len += _sz; \
DENSURE(_d, _sz + 1); \
memcpy(_d->buf + _d->len, _s, _sz + 1); \
_d->len += _sz; \