]> granicus.if.org Git - neomutt/commitdiff
Convert mutt_expand_file_fmt() to accept struct Buffer dest parameter
authorKevin McCarthy <kevin@8t8.us>
Tue, 9 Apr 2019 22:20:51 +0000 (15:20 -0700)
committerRichard Russon <rich@flatcap.org>
Tue, 30 Apr 2019 16:45:37 +0000 (17:45 +0100)
mutt_expand_fmt() will be converted in the next commit, at the same
time as rfc1524_expand_filename().

Co-authored-by: Richard Russon <rich@flatcap.org>
curs_lib.c
mutt/file.c
mutt/file.h
query.c
sendlib.c

index acfb26ad729ae4f4f924aca5682055f69ad69e43..f49d0b98f3cd3ee8dcfbd2a2bd5850807482ec31 100644 (file)
@@ -307,18 +307,20 @@ int mutt_get_field_unbuffered(const char *msg, char *buf, size_t buflen, Complet
  */
 void mutt_edit_file(const char *editor, const char *file)
 {
-  char cmd[STR_COMMAND];
+  struct Buffer *cmd = mutt_buffer_pool_get();
 
   mutt_endwin();
-  mutt_file_expand_fmt_quote(cmd, sizeof(cmd), editor, file);
-  if (mutt_system(cmd) != 0)
+  mutt_buffer_file_expand_fmt_quote(cmd, editor, file);
+  if (mutt_system(mutt_b2s(cmd)) != 0)
   {
-    mutt_error(_("Error running \"%s\""), cmd);
+    mutt_error(_("Error running \"%s\""), mutt_b2s(cmd));
   }
   /* the terminal may have been resized while the editor owned it */
   mutt_resize_screen();
   keypad(stdscr, true);
   clearok(stdscr, true);
+
+  mutt_buffer_pool_release(&cmd);
 }
 
 /**
@@ -574,18 +576,19 @@ int mutt_do_pager(const char *banner, const char *tempfile, PagerFlags do_color,
     rc = mutt_pager(banner, tempfile, do_color, info);
   else
   {
-    char cmd[256];
+    struct Buffer *cmd = mutt_buffer_pool_get();
 
     mutt_endwin();
-    mutt_file_expand_fmt_quote(cmd, sizeof(cmd), C_Pager, tempfile);
-    if (mutt_system(cmd) == -1)
+    mutt_buffer_file_expand_fmt_quote(cmd, C_Pager, tempfile);
+    if (mutt_system(mutt_b2s(cmd)) == -1)
     {
-      mutt_error(_("Error running \"%s\""), cmd);
+      mutt_error(_("Error running \"%s\""), mutt_b2s(cmd));
       rc = -1;
     }
     else
       rc = 0;
     mutt_file_unlink(tempfile);
+    mutt_buffer_pool_release(&cmd);
   }
 
   return rc;
index ae8cae3f956261d252219e0d6fd82ff9dec561be..cf6ec013e49c0db8dd40f479d25131afe7ae7ffa 100644 (file)
@@ -1356,20 +1356,21 @@ int mutt_file_check_empty(const char *path)
 }
 
 /**
- * mutt_file_expand_fmt_quote - Replace `%s` in a string with a filename
+ * mutt_buffer_file_expand_fmt_quote - Replace `%s` in a string with a filename
  * @param dest    Buffer for the result
- * @param destlen Length of buffer
  * @param fmt     printf-like format string
  * @param src     Filename to substitute
  *
  * This function also quotes the file to prevent shell problems.
  */
-void mutt_file_expand_fmt_quote(char *dest, size_t destlen, const char *fmt, const char *src)
+void mutt_buffer_file_expand_fmt_quote(struct Buffer *dest, const char *fmt, const char *src)
 {
   char tmp[PATH_MAX];
 
   mutt_file_quote_filename(src, tmp, sizeof(tmp));
-  mutt_file_expand_fmt(dest, destlen, fmt, tmp);
+  /* TODO: this will be fixed in the next commit */
+  mutt_file_expand_fmt(dest->data, dest->dsize, fmt, tmp);
+  mutt_buffer_fix_dptr(dest);
 }
 
 /**
index 8928d43fa229253d62534ba4301fb2aed874db4f..1237d7de493e294447649af6596401e616b6faeb 100644 (file)
@@ -122,5 +122,6 @@ void        mutt_file_unlink_empty(const char *path);
 int         mutt_file_unlock(int fd);
 
 void        mutt_buffer_quote_filename(struct Buffer *buf, const char *filename);
+void        mutt_buffer_file_expand_fmt_quote(struct Buffer *dest, const char *fmt, const char *src);
 
 #endif /* MUTT_LIB_FILE_H */
diff --git a/query.c b/query.c
index b21e8d22c0297a47025ba901e1b5b3513cfc8bcf..88cac09579ac5c9d697a8b087edcb6aadb4e85d7 100644 (file)
--- a/query.c
+++ b/query.c
@@ -138,22 +138,25 @@ static struct Query *run_query(char *s, int quiet)
   FILE *fp = NULL;
   struct Query *first = NULL;
   struct Query *cur = NULL;
-  char cmd[STR_COMMAND];
   char *buf = NULL;
   size_t buflen;
   int dummy = 0;
   char msg[256];
   char *p = NULL;
   pid_t pid;
+  struct Buffer *cmd = mutt_buffer_pool_get();
 
-  mutt_file_expand_fmt_quote(cmd, sizeof(cmd), C_QueryCommand, s);
+  mutt_buffer_file_expand_fmt_quote(cmd, C_QueryCommand, s);
 
-  pid = mutt_create_filter(cmd, NULL, &fp, NULL);
+  pid = mutt_create_filter(mutt_b2s(cmd), NULL, &fp, NULL);
   if (pid < 0)
   {
-    mutt_debug(LL_DEBUG1, "unable to fork command: %s\n", cmd);
+    mutt_debug(LL_DEBUG1, "unable to fork command: %s\n", mutt_b2s(cmd));
+    mutt_buffer_pool_release(&cmd);
     return 0;
   }
+  mutt_buffer_pool_release(&cmd);
+
   if (!quiet)
     mutt_message(_("Waiting for response..."));
   fgets(msg, sizeof(msg), fp);
index deacc9db5628d8eb46c5d1a9b6ab585a7887f5c9..afeeeca960436108bbc667685a8af1a9c358b14d 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -1554,20 +1554,22 @@ struct Body *mutt_make_message_attach(struct Mailbox *m, struct Email *e, bool a
 static void run_mime_type_query(struct Body *att)
 {
   FILE *fp, *fp_err;
-  char cmd[STR_COMMAND];
   char *buf = NULL;
   size_t buflen;
   int dummy = 0;
   pid_t pid;
+  struct Buffer *cmd = mutt_buffer_pool_get();
 
-  mutt_file_expand_fmt_quote(cmd, sizeof(cmd), C_MimeTypeQueryCommand, att->filename);
+  mutt_buffer_file_expand_fmt_quote(cmd, C_MimeTypeQueryCommand, att->filename);
 
-  pid = mutt_create_filter(cmd, NULL, &fp, &fp_err);
+  pid = mutt_create_filter(mutt_b2s(cmd), NULL, &fp, &fp_err);
   if (pid < 0)
   {
-    mutt_error(_("Error running \"%s\""), cmd);
+    mutt_error(_("Error running \"%s\""), mutt_b2s(cmd));
+    mutt_buffer_pool_release(&cmd);
     return;
   }
+  mutt_buffer_pool_release(&cmd);
 
   buf = mutt_file_read_line(buf, &buflen, fp, &dummy, 0);
   if (buf)