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

mutt_buffer_add*() functions append to the buffer contents.

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

index ccacd751b3582b754fae78e401d5e66d06553c40..acf92924503e563945c7a86e0241f8b54e8ce826 100644 (file)
@@ -143,7 +143,7 @@ static int cmd_queue(struct ImapAccountData *adata, const char *cmdstr, int flag
   if (!cmd)
     return IMAP_CMD_BAD;
 
-  if (mutt_buffer_printf(adata->cmdbuf, "%s %s\r\n", cmd->seq, cmdstr) < 0)
+  if (mutt_buffer_add_printf(adata->cmdbuf, "%s %s\r\n", cmd->seq, cmdstr) < 0)
     return IMAP_CMD_BAD;
 
   return 0;
@@ -1383,7 +1383,7 @@ int imap_cmd_idle(struct ImapAccountData *adata)
     /* successfully entered IDLE state */
     adata->state = IMAP_IDLE;
     /* queue automatic exit when next command is issued */
-    mutt_buffer_printf(adata->cmdbuf, "DONE\r\n");
+    mutt_buffer_addstr(adata->cmdbuf, "DONE\r\n");
     rc = IMAP_CMD_OK;
   }
   if (rc != IMAP_CMD_OK)
index f2c89f245217c30a57af5c2e790b58a0f959488d..dba151264e29e194930e2bc42569e49614b48f79 100644 (file)
@@ -234,22 +234,22 @@ static int make_msg_set(struct ImapAccountData *adata, struct Buffer *buf,
         setstart = IMAP_EDATA(emails[n])->uid;
         if (!started)
         {
-          mutt_buffer_printf(buf, "%u", IMAP_EDATA(emails[n])->uid);
+          mutt_buffer_add_printf(buf, "%u", IMAP_EDATA(emails[n])->uid);
           started = true;
         }
         else
-          mutt_buffer_printf(buf, ",%u", IMAP_EDATA(emails[n])->uid);
+          mutt_buffer_add_printf(buf, ",%u", IMAP_EDATA(emails[n])->uid);
       }
       /* tie up if the last message also matches */
       else if (n == adata->ctx->mailbox->msg_count - 1)
-        mutt_buffer_printf(buf, ":%u", IMAP_EDATA(emails[n])->uid);
+        mutt_buffer_add_printf(buf, ":%u", IMAP_EDATA(emails[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 && (emails[n]->active || n == adata->ctx->mailbox->msg_count - 1))
     {
       if (IMAP_EDATA(emails[n - 1])->uid > setstart)
-        mutt_buffer_printf(buf, ":%u", IMAP_EDATA(emails[n - 1])->uid);
+        mutt_buffer_add_printf(buf, ":%u", IMAP_EDATA(emails[n - 1])->uid);
       setstart = 0;
     }
   }
@@ -1221,11 +1221,11 @@ int imap_exec_msgset(struct ImapAccountData *adata, const char *pre,
   do
   {
     cmd->dptr = cmd->data;
-    mutt_buffer_printf(cmd, "%s ", pre);
+    mutt_buffer_add_printf(cmd, "%s ", pre);
     rc = make_msg_set(adata, cmd, flag, changed, invert, &pos);
     if (rc > 0)
     {
-      mutt_buffer_printf(cmd, " %s", post);
+      mutt_buffer_add_printf(cmd, " %s", post);
       if (imap_exec(adata, cmd->data, IMAP_CMD_QUEUE))
       {
         rc = -1;
index fd44be413333b9a1b3806f1a5dfadead85b87648..56c6299ac01eac4ce1440f9c7f0bd4635724e3cb 100644 (file)
@@ -583,9 +583,9 @@ static void imap_fetch_msn_seqset(struct Buffer *b, struct ImapAccountData *adat
         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;
     }
   }
@@ -594,7 +594,7 @@ static void imap_fetch_msn_seqset(struct Buffer *b, struct ImapAccountData *adat
   if ((chunks == 150) || (mutt_str_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);
   }
 }
 
@@ -996,7 +996,7 @@ static int read_headers_fetch_new(struct ImapAccountData *adata, unsigned int ms
       imap_fetch_msn_seqset(b, adata, 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;
     char *cmd = NULL;
@@ -1568,7 +1568,7 @@ int imap_copy_messages(struct Context *ctx, struct Email *e, char *dest, bool de
     else
     {
       mutt_message(_("Copying message %d to %s..."), e->index + 1, mbox);
-      mutt_buffer_printf(&cmd, "UID COPY %u %s", IMAP_EDATA(e)->uid, mmbox);
+      mutt_buffer_add_printf(&cmd, "UID COPY %u %s", IMAP_EDATA(e)->uid, mmbox);
 
       if (e->active && e->changed)
       {
index 00f4a48195dba4a31fe7146727a545adca5e11e0..660d9821938741b28cf12d3303c040277979706c 100644 (file)
@@ -261,9 +261,9 @@ static void imap_msn_index_to_uid_seqset(struct Buffer *b, struct ImapAccountDat
         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 58c37e2fca1a7851cd5db0da188c55bf371c4517..4a2ff41d255f53247404ca9f73fec388c1b45e2a 100644 (file)
@@ -146,21 +146,20 @@ void mutt_buffer_free(struct Buffer **p)
 }
 
 /**
- * mutt_buffer_printf - Format a string into a Buffer
+ * buffer_printf - Format a string into a Buffer
  * @param buf Buffer
  * @param fmt printf-style format string
- * @param ... Arguments to be formatted
+ * @param ap  Arguments to be formatted
  * @retval num Characters written
  */
-int mutt_buffer_printf(struct Buffer *buf, const char *fmt, ...)
+static int buffer_printf(struct Buffer *buf, const char *fmt, va_list ap)
 {
   if (!buf)
     return 0;
 
-  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)
@@ -186,12 +185,48 @@ int mutt_buffer_printf(struct Buffer *buf, const char *fmt, ...)
   if (len > 0)
     buf->dptr += len;
 
-  va_end(ap);
   va_end(ap_retry);
 
   return len;
 }
 
+/**
+ * mutt_buffer_printf - Format a string overwriting a Buffer
+ * @param buf Buffer
+ * @param fmt printf-style format string
+ * @param ... Arguments to be formatted
+ * @retval num Characters written
+ */
+int mutt_buffer_printf(struct Buffer *buf, const char *fmt, ...)
+{
+  va_list ap;
+
+  va_start(ap, fmt);
+  mutt_buffer_reset(buf);
+  int len = buffer_printf(buf, fmt, ap);
+  va_end(ap);
+
+  return len;
+}
+
+/**
+ * mutt_buffer_add_printf - Format a string appending a Buffer
+ * @param buf Buffer
+ * @param fmt printf-style format string
+ * @param ... Arguments to be formatted
+ * @retval num Characters written
+ */
+int mutt_buffer_add_printf(struct Buffer *buf, const char *fmt, ...)
+{
+  va_list ap;
+
+  va_start(ap, fmt);
+  int len = buffer_printf(buf, fmt, ap);
+  va_end(ap);
+
+  return len;
+}
+
 /**
  * mutt_buffer_addstr - Add a string to a Buffer
  * @param buf Buffer to add to
index 2c0fbdaf68e0dec083c89d67fad0bf839873e99b..5bd2a4d2a0bbadbcec352381e85647be7c903262 100644 (file)
@@ -46,6 +46,7 @@ struct Buffer
 size_t         mutt_buffer_add          (struct Buffer *buf, const char *s, size_t len);
 size_t         mutt_buffer_addch        (struct Buffer *buf, char c);
 size_t         mutt_buffer_addstr       (struct Buffer *buf, const char *s);
+int            mutt_buffer_add_printf   (struct Buffer *buf, const char *fmt, ...);
 struct Buffer *mutt_buffer_alloc        (size_t size);
 void           mutt_buffer_free         (struct Buffer **p);
 struct Buffer *mutt_buffer_from         (const char *seed);
index 6ca93642a7e7e6cb53df6bcc7aebeea4eb0feebd..36c6e1f69494a1c3f1773b31b7558b8f5217c545 100644 (file)
--- a/pattern.c
+++ b/pattern.c
@@ -226,7 +226,7 @@ static bool eat_regex(struct Pattern *pat, struct Buffer *s, struct Buffer *err)
     if (r != 0)
     {
       regerror(r, pat->p.regex, 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.regex);
       return false;