X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/mLib/blobdiff_plain/c6e0eaf00cd09a4e5237e70d8351049ec91d7653..573eadb534c42c4feace5e493cc135dd5e7b00d9:/dstr.h diff --git a/dstr.h b/dstr.h index cde6b6f..4272dd9 100644 --- a/dstr.h +++ b/dstr.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: dstr.h,v 1.9 1999/12/10 23:42:04 mdw Exp $ + * $Id: dstr.h,v 1.12 2002/01/13 13:30:48 mdw Exp $ * * Handle dynamically growing strings * @@ -30,6 +30,15 @@ /*----- Revision history --------------------------------------------------* * * $Log: dstr.h,v $ + * Revision 1.12 2002/01/13 13:30:48 mdw + * Change interface for @dstr_vputf@. + * + * 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. * @@ -83,15 +92,24 @@ #include #include +#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 */ + arena *a; /* Pointer to arena */ } 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 ------------------------------------------------*/ @@ -111,6 +129,7 @@ extern void dstr_create(dstr */*d*/); _dd->buf = 0; \ _dd->sz = 0; \ _dd->len = 0; \ + _dd->a = &arena_stdlib; \ } while (0) /* --- @dstr_destroy@ --- * @@ -127,7 +146,7 @@ extern void dstr_destroy(dstr */*d*/); #define DDESTROY(d) do { \ dstr *_d = (d); \ if (_d->buf) \ - free(_d->buf); \ + x_free(_d->a, _d->buf); \ DCREATE(_d); \ } while (0) @@ -216,7 +235,7 @@ extern void dstr_puts(dstr */*d*/, const char */*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; \ @@ -226,7 +245,7 @@ extern void dstr_puts(dstr */*d*/, const char */*s*/); * * Arguments: @dstr *d@ = pointer to a dynamic string block * @const char *p@ = pointer to @printf@-style format string - * @va_list ap@ = argument handle + * @va_list *ap@ = argument handle * * Returns: The number of characters written to the string. * @@ -234,7 +253,7 @@ extern void dstr_puts(dstr */*d*/, const char */*s*/); * supplied functions with @printf@-style interfaces. */ -extern int dstr_vputf(dstr */*d*/, const char */*p*/, va_list /*ap*/); +extern int dstr_vputf(dstr */*d*/, const char */*p*/, va_list */*ap*/); /* --- @dstr_putf@ --- * *