#include <string.h>
#include <ctype.h>
+#include <lib-lib/mem.h>
+#include <lib-lib/str.h>
+
#include "buffer.h"
-#include "lib/mem.h"
-#include "lib/str.h"
#include "lib/debug.h"
/*
* 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));
- if (!b)
- return NULL;
- }
- else {
- mem_free(&b->data);
- }
- memset (b, 0, sizeof (BUFFER));
- return b;
+ if (!b) {
+ b = p_new(BUFFER, 1);
+ }
+ p_delete(&b->data);
+ p_clear(b, 1);
+ return 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;
b = mutt_buffer_init (b);
- b->data = str_dup (seed);
- b->dsize = str_len (seed);
+ b->data = m_strdup(seed);
+ b->dsize = m_strlen(seed);
b->dptr = (char *) b->data + b->dsize;
return b;
}
void mutt_buffer_addstr (BUFFER * buf, const char *s)
{
- mutt_buffer_add (buf, s, str_len (s));
+ mutt_buffer_add (buf, s, m_strlen(s));
}
void mutt_buffer_addch (BUFFER * buf, char c)
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.
* Always one byte bigger than necessary for the null terminator, and
* the buffer is always null-terminated */
-void mutt_buffer_add (BUFFER * buf, const char *s, size_t len)
+void mutt_buffer_add (BUFFER *buf, const char *s, size_t len)
{
size_t offset;
if (buf->dptr + len + 1 > buf->data + buf->dsize) {
offset = buf->dptr - buf->data;
buf->dsize += len < 128 ? 128 : len + 1;
- mem_realloc ((void **) &buf->data, buf->dsize);
+ p_realloc(&buf->data, buf->dsize);
buf->dptr = buf->data + offset;
}
memcpy (buf->dptr, s, len);
(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;
}
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;
/* read line */
- memset (&expn, 0, sizeof (expn));
+ p_clear(&expn, 1);
expn.data = mutt_read_line (NULL, &expn.dsize, fp, &line);
fclose (fp);
mutt_wait_filter (pid);
* 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);
+ expnlen = m_strlen(expn.data);
+ tok->dsize = expnlen + m_strlen(tok->dptr) + 1;
+ 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 == '"')
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);