Commit 1e1d7b7a authored by Kevin J. McCarthy's avatar Kevin J. McCarthy

Create mutt_buffer_add_printf().

Change mutt_buffer_printf() to overwrite the buffer contents, like
mutt_buffer_strcpy().

mutt_buffer_add*() functions append to the buffer contents.
parent 2d373eba
......@@ -96,12 +96,11 @@ void mutt_buffer_increase_size (BUFFER *buf, size_t new_size)
}
}
int mutt_buffer_printf (BUFFER* buf, const char* fmt, ...)
static int _mutt_buffer_add_printf (BUFFER* buf, const char* fmt, va_list ap)
{
va_list ap, ap_retry;
va_list ap_retry;
int len, blen, doff;
va_start (ap, fmt);
va_copy (ap_retry, ap);
if (!buf->dptr)
......@@ -126,12 +125,36 @@ int mutt_buffer_printf (BUFFER* buf, const char* fmt, ...)
if (len > 0)
buf->dptr += len;
va_end (ap);
va_end (ap_retry);
return len;
}
int mutt_buffer_printf (BUFFER* buf, const char* fmt, ...)
{
va_list ap;
int rv;
va_start (ap, fmt);
mutt_buffer_clear (buf);
rv = _mutt_buffer_add_printf (buf, fmt, ap);
va_end (ap);
return rv;
}
int mutt_buffer_add_printf (BUFFER* buf, const char* fmt, ...)
{
va_list ap;
int rv;
va_start (ap, fmt);
rv = _mutt_buffer_add_printf (buf, fmt, ap);
va_end (ap);
return rv;
}
/* Dynamically grows a BUFFER to accommodate s, in increments of 128 bytes.
* Always one byte bigger than necessary for the null terminator, and
* the buffer is always null-terminated */
......
......@@ -40,10 +40,14 @@ void mutt_buffer_clear (BUFFER *);
void mutt_buffer_increase_size (BUFFER *, size_t);
/* These two replace the buffer contents. */
int mutt_buffer_printf (BUFFER*, const char*, ...);
void mutt_buffer_strcpy (BUFFER *, const char *);
/* These append to the buffer. */
int mutt_buffer_add_printf (BUFFER*, const char*, ...);
void mutt_buffer_addstr (BUFFER*, const char*);
void mutt_buffer_addch (BUFFER*, char);
void mutt_buffer_strcpy (BUFFER *, const char *);
void mutt_buffer_pool_init (void);
......
......@@ -362,7 +362,7 @@ int imap_cmd_idle (IMAP_DATA* idata)
/* successfully entered IDLE state */
idata->state = IMAP_IDLE;
/* queue automatic exit when next command is issued */
mutt_buffer_printf (idata->cmdbuf, "DONE\r\n");
mutt_buffer_addstr (idata->cmdbuf, "DONE\r\n");
rc = IMAP_CMD_OK;
}
if (rc != IMAP_CMD_OK)
......@@ -425,7 +425,7 @@ static int cmd_queue (IMAP_DATA* idata, const char* cmdstr, int flags)
if (!(cmd = cmd_new (idata)))
return IMAP_CMD_BAD;
if (mutt_buffer_printf (idata->cmdbuf, "%s %s\r\n", cmd->seq, cmdstr) < 0)
if (mutt_buffer_add_printf (idata->cmdbuf, "%s %s\r\n", cmd->seq, cmdstr) < 0)
return IMAP_CMD_BAD;
return 0;
......
......@@ -1016,22 +1016,22 @@ static int imap_make_msg_set (IMAP_DATA* idata, BUFFER* buf, int flag,
setstart = HEADER_DATA (hdrs[n])->uid;
if (started == 0)
{
mutt_buffer_printf (buf, "%u", HEADER_DATA (hdrs[n])->uid);
mutt_buffer_add_printf (buf, "%u", HEADER_DATA (hdrs[n])->uid);
started = 1;
}
else
mutt_buffer_printf (buf, ",%u", HEADER_DATA (hdrs[n])->uid);
mutt_buffer_add_printf (buf, ",%u", HEADER_DATA (hdrs[n])->uid);
}
/* tie up if the last message also matches */
else if (n == idata->ctx->msgcount-1)
mutt_buffer_printf (buf, ":%u", HEADER_DATA (hdrs[n])->uid);
mutt_buffer_add_printf (buf, ":%u", HEADER_DATA (hdrs[n])->uid);
}
/* End current set if message doesn't match or we've reached the end
* of the mailbox via inactive messages following the last match. */
else if (setstart && (hdrs[n]->active || n == idata->ctx->msgcount-1))
{
if (HEADER_DATA (hdrs[n-1])->uid > setstart)
mutt_buffer_printf (buf, ":%u", HEADER_DATA (hdrs[n-1])->uid);
mutt_buffer_add_printf (buf, ":%u", HEADER_DATA (hdrs[n-1])->uid);
setstart = 0;
}
}
......@@ -1083,11 +1083,11 @@ int imap_exec_msgset (IMAP_DATA* idata, const char* pre, const char* post,
do
{
cmd->dptr = cmd->data;
mutt_buffer_printf (cmd, "%s ", pre);
mutt_buffer_add_printf (cmd, "%s ", pre);
rc = imap_make_msg_set (idata, cmd, flag, changed, invert, &pos);
if (rc > 0)
{
mutt_buffer_printf (cmd, " %s", post);
mutt_buffer_add_printf (cmd, " %s", post);
if (imap_exec (idata, cmd->data, IMAP_CMD_QUEUE))
{
rc = -1;
......
......@@ -175,9 +175,9 @@ static void imap_fetch_msn_seqset (BUFFER *b, IMAP_DATA *idata, unsigned int msn
break;
if (state == 1)
mutt_buffer_printf (b, "%u", range_begin);
mutt_buffer_add_printf (b, "%u", range_begin);
else if (state == 2)
mutt_buffer_printf (b, "%u:%u", range_begin, range_end);
mutt_buffer_add_printf (b, "%u:%u", range_begin, range_end);
state = 0;
}
}
......@@ -186,7 +186,7 @@ static void imap_fetch_msn_seqset (BUFFER *b, IMAP_DATA *idata, unsigned int msn
if (chunks == 150 || mutt_strlen (b->data) > 500)
{
b->dptr = b->data;
mutt_buffer_printf (b, "%u:%u", msn_begin, msn_end);
mutt_buffer_add_printf (b, "%u:%u", msn_begin, msn_end);
}
}
......@@ -721,7 +721,7 @@ static int read_headers_fetch_new (IMAP_DATA *idata, unsigned int msn_begin,
imap_fetch_msn_seqset (b, idata, msn_begin, msn_end);
}
else
mutt_buffer_printf (b, "%u:%u", msn_begin, msn_end);
mutt_buffer_add_printf (b, "%u:%u", msn_begin, msn_end);
fetch_msn_end = msn_end;
safe_asprintf (&cmd, "FETCH %s (UID FLAGS INTERNALDATE RFC822.SIZE %s)",
......@@ -1317,7 +1317,7 @@ int imap_copy_messages (CONTEXT* ctx, HEADER* h, char* dest, int delete)
else
{
mutt_message (_("Copying message %d to %s..."), h->index+1, mbox);
mutt_buffer_printf (&cmd, "UID COPY %u %s", HEADER_DATA (h)->uid, mmbox);
mutt_buffer_add_printf (&cmd, "UID COPY %u %s", HEADER_DATA (h)->uid, mmbox);
if (h->active && h->changed)
{
......
......@@ -121,9 +121,9 @@ static void imap_msn_index_to_uid_seqset (BUFFER *b, IMAP_DATA *idata)
mutt_buffer_addch (b, ',');
if (state == 1)
mutt_buffer_printf (b, "%u", range_begin);
mutt_buffer_add_printf (b, "%u", range_begin);
else if (state == 2)
mutt_buffer_printf (b, "%u:%u", range_begin, range_end);
mutt_buffer_add_printf (b, "%u:%u", range_begin, range_end);
state = 1;
range_begin = cur_uid;
......
......@@ -298,7 +298,7 @@ static int eat_regexp (pattern_t *pat, BUFFER *s, BUFFER *err)
if (r)
{
regerror (r, pat->p.rx, errmsg, sizeof (errmsg));
mutt_buffer_printf (err, "'%s': %s", buf.data, errmsg);
mutt_buffer_add_printf (err, "'%s': %s", buf.data, errmsg);
FREE (&buf.data);
FREE (&pat->p.rx);
return (-1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment