X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=buffer.c;h=cfe19be62455be1f3c668577123deab706d376f0;hb=23002a877577341cfd68687e58348e0ca01b1ac5;hp=e8c638f49cd1828c78f8e8d59c68cf7193de32f9;hpb=bbc4fd52516a8afefbd14c77e34f8389d6f0a6ed;p=apps%2Fmadmutt.git diff --git a/buffer.c b/buffer.c index e8c638f..cfe19be 100644 --- a/buffer.c +++ b/buffer.c @@ -14,6 +14,8 @@ #include #include +#include + #include "buffer.h" #include "lib/mem.h" @@ -27,15 +29,15 @@ * Disregards the 'destroy' flag, which seems reserved for caller. * This is bad, but there's no apparent protocol for it. */ -BUFFER *mutt_buffer_init (BUFFER * b) +BUFFER *mutt_buffer_init(BUFFER *b) { if (!b) { - b = mem_malloc (sizeof (BUFFER)); + b = p_new(BUFFER, 1); if (!b) return NULL; } else { - mem_free(&b->data); + p_delete(&b->data); } memset (b, 0, sizeof (BUFFER)); return b; @@ -49,7 +51,7 @@ BUFFER *mutt_buffer_init (BUFFER * b) * Disregards the 'destroy' flag, which seems reserved for caller. * This is bad, but there's no apparent protocol for it. */ -BUFFER *mutt_buffer_from (BUFFER * b, char *seed) +BUFFER *mutt_buffer_from (BUFFER * b, const char *seed) { if (!seed) return NULL; @@ -76,9 +78,9 @@ void mutt_buffer_free (BUFFER ** p) if (!p || !*p) return; - mem_free (&(*p)->data); + p_delete(&(*p)->data); /* dptr is just an offset to data and shouldn't be freed */ - mem_free (p); + p_delete(p); } /* dynamically grows a BUFFER to accomodate s, in increments of 128 bytes. @@ -115,7 +117,7 @@ int mutt_extract_token (BUFFER * dest, BUFFER * tok, int flags) (ch == '#' && !(flags & M_TOKEN_COMMENT)) || (ch == '=' && (flags & M_TOKEN_EQUAL)) || (ch == ';' && !(flags & M_TOKEN_SEMICOLON)) || - ((flags & M_TOKEN_PATTERN) && strchr ("~!|", ch))) + ((flags & M_TOKEN_PATTERN) && strchr ("~=!|", ch))) break; } @@ -204,10 +206,10 @@ int mutt_extract_token (BUFFER * dest, BUFFER * tok, int flags) cmd = str_substrdup (tok->dptr, pc); if ((pid = mutt_create_filter (cmd, NULL, &fp, NULL)) < 0) { debug_print (1, ("unable to fork command: %s\n", cmd)); - mem_free (&cmd); + p_delete(&cmd); return (-1); } - mem_free (&cmd); + p_delete(&cmd); tok->dptr = pc + 1; @@ -223,21 +225,21 @@ int mutt_extract_token (BUFFER * dest, BUFFER * tok, int flags) * the token */ if (expn.data && qc) { mutt_buffer_addstr (dest, expn.data); - mem_free (&expn.data); + p_delete(&expn.data); } else if (expn.data) { expnlen = str_len (expn.data); tok->dsize = expnlen + str_len (tok->dptr) + 1; - ptr = mem_malloc (tok->dsize); + ptr = xmalloc(tok->dsize); memcpy (ptr, expn.data, expnlen); strcpy (ptr + expnlen, tok->dptr); /* __STRCPY_CHECKED__ */ if (tok->destroy) - mem_free (&tok->data); + p_delete(&tok->data); tok->data = ptr; tok->dptr = ptr; tok->destroy = 1; /* mark that the caller should destroy this data */ ptr = NULL; - mem_free (&expn.data); + p_delete(&expn.data); } } else if (ch == '$' && (!qc || qc == '"') @@ -257,9 +259,13 @@ int mutt_extract_token (BUFFER * dest, BUFFER * tok, int flags) var = str_substrdup (tok->dptr, pc); tok->dptr = pc; } - if (var && (env = getenv (var))) - mutt_buffer_addstr (dest, env); - mem_free (&var); + if (var) { + char tmp[STRING]; + if ((env = getenv (var)) || + (mutt_option_value (var, tmp, sizeof (tmp)) && (env = tmp))) + mutt_buffer_addstr (dest, env); + } + p_delete(&var); } else mutt_buffer_addch (dest, ch);