]> granicus.if.org Git - mutt/commitdiff
Create mutt_buffer_add_printf().
authorKevin McCarthy <kevin@8t8.us>
Mon, 8 Oct 2018 17:48:29 +0000 (10:48 -0700)
committerKevin McCarthy <kevin@8t8.us>
Mon, 8 Oct 2018 17:49:23 +0000 (10:49 -0700)
Change mutt_buffer_printf() to overwrite the buffer contents, like
mutt_buffer_strcpy().

mutt_buffer_add*() functions append to the buffer contents.

buffer.c
buffer.h
imap/command.c
imap/imap.c
imap/message.c
imap/util.c
pattern.c

index b860f0e0bf4ae8269387a44b8cd128e2d44e3545..300b358298b6166dd04d6bf1b3275d78f5ba1cdb 100644 (file)
--- a/buffer.c
+++ b/buffer.c
@@ -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 */
index bde4d8dd1c338a397c4dc8adea0659e712c72a13..c9e40e3d509dc5a0c5689258625b1158eb2ed848 100644 (file)
--- a/buffer.h
+++ b/buffer.h
@@ -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);
index ebfeaccf5979427c015524f704b5c1ca082d9bcc..6d7c6f28c363575b4c7523c65174d9759185bb61 100644 (file)
@@ -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;
index b8c4bd727ae3389da654d0f449a04fff07db73a8..affc2d52ff7fbb883eeb2e28b04752ce8cd6c14d 100644 (file)
@@ -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;
index fc326752c8e46e5005c9f56d5ffbd30e4144da0d..339b3e53b34f4e6fd682597cf4e77ddb592bd66c 100644 (file)
@@ -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)
       {
index 63a0e47ac19ea99fc9e86c614646e13949d61e20..b675aac965d62e68b85256eb3a8ea0d0d1ff7067 100644 (file)
@@ -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;
index bfb38c86959e1660e9e8e61a20622e2af9c94291..f72d648d353ddb6341371d8fdd08360518cea8ec 100644 (file)
--- a/pattern.c
+++ b/pattern.c
@@ -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);