]> granicus.if.org Git - neomutt/commitdiff
move expand functions to library
authorRichard Russon <rich@flatcap.org>
Wed, 15 Aug 2018 14:03:12 +0000 (15:03 +0100)
committerRichard Russon <rich@flatcap.org>
Wed, 15 Aug 2018 14:03:12 +0000 (15:03 +0100)
curs_lib.c
mutt/file.c
mutt/file.h
muttlib.c
muttlib.h
pattern.c
query.c
rfc1524.c
sendlib.c

index 4c2e30e54ea5b7c019b0bf37603b79f0fa6fbabc..7d54af5d7d60b44b965e49816d314dfc2b10b63e 100644 (file)
@@ -258,7 +258,7 @@ void mutt_edit_file(const char *editor, const char *file)
   char cmd[HUGE_STRING];
 
   mutt_endwin();
-  mutt_expand_file_fmt(cmd, sizeof(cmd), editor, file);
+  mutt_file_expand_fmt_quote(cmd, sizeof(cmd), editor, file);
   if (mutt_system(cmd) != 0)
   {
     mutt_error(_("Error running \"%s\""), cmd);
@@ -528,7 +528,7 @@ int mutt_do_pager(const char *banner, const char *tempfile, int do_color, struct
     char cmd[STRING];
 
     mutt_endwin();
-    mutt_expand_file_fmt(cmd, sizeof(cmd), Pager, tempfile);
+    mutt_file_expand_fmt_quote(cmd, sizeof(cmd), Pager, tempfile);
     if (mutt_system(cmd) == -1)
     {
       mutt_error(_("Error running \"%s\""), cmd);
index 118ed06d74eef7822af53ea34664db10497017d6..338f434c51de6ce464aaf4310c53d5e0c360ba63 100644 (file)
@@ -1238,3 +1238,76 @@ int mutt_file_check_empty(const char *path)
 
   return st.st_size == 0;
 }
+
+/**
+ * mutt_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)
+{
+  char tmp[PATH_MAX];
+
+  mutt_file_quote_filename(tmp, sizeof(tmp), src);
+  mutt_file_expand_fmt(dest, destlen, fmt, tmp);
+}
+
+/**
+ * mutt_file_expand_fmt - 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
+ */
+void mutt_file_expand_fmt(char *dest, size_t destlen, const char *fmt, const char *src)
+{
+  const char *p = NULL;
+  char *d = NULL;
+  size_t slen;
+  bool found = false;
+
+  slen = mutt_str_strlen(src);
+  destlen--;
+
+  for (p = fmt, d = dest; (destlen != 0) && *p; p++)
+  {
+    if (*p == '%')
+    {
+      switch (p[1])
+      {
+        case '%':
+          *d++ = *p++;
+          destlen--;
+          break;
+        case 's':
+          found = true;
+          mutt_str_strfcpy(d, src, destlen + 1);
+          d += (destlen > slen) ? slen : destlen;
+          destlen -= (destlen > slen) ? slen : destlen;
+          p++;
+          break;
+        default:
+          *d++ = *p;
+          destlen--;
+          break;
+      }
+    }
+    else
+    {
+      *d++ = *p;
+      destlen--;
+    }
+  }
+
+  *d = '\0';
+
+  if (!found && (destlen > 0))
+  {
+    mutt_str_strcat(dest, destlen, " ");
+    mutt_str_strcat(dest, destlen, src);
+  }
+}
index f8d827ff2bf74c58b01925864a8ffbafdded76a6..87319d4a37529693457e6c216607f59a49464961 100644 (file)
@@ -44,6 +44,8 @@ int         mutt_file_chmod_rm_stat(const char *path, mode_t mode, struct stat *
 int         mutt_file_copy_bytes(FILE *in, FILE *out, size_t size);
 int         mutt_file_copy_stream(FILE *fin, FILE *fout);
 time_t      mutt_file_decrease_mtime(const char *f, struct stat *st);
+void        mutt_file_expand_fmt(char *dest, size_t destlen, const char *fmt, const char *src);
+void        mutt_file_expand_fmt_quote(char *dest, size_t destlen, const char *fmt, const char *src);
 int         mutt_file_fclose(FILE **f);
 FILE *      mutt_file_fopen(const char *path, const char *mode);
 int         mutt_file_fsync_close(FILE **f);
index cbe5a254f8f264bf20aa9928bb1cdf9c82256d9c..01c61bc729943599a70c211ea62c18d1d5bd9bc5 100644 (file)
--- a/muttlib.c
+++ b/muttlib.c
@@ -616,79 +616,6 @@ void mutt_pretty_mailbox(char *s, size_t buflen)
   }
 }
 
-/**
- * mutt_expand_file_fmt - Replace `%s` with a filename in a string
- * @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_expand_file_fmt(char *dest, size_t destlen, const char *fmt, const char *src)
-{
-  char tmp[PATH_MAX];
-
-  mutt_file_quote_filename(tmp, sizeof(tmp), src);
-  mutt_expand_fmt(dest, destlen, fmt, tmp);
-}
-
-/**
- * mutt_expand_fmt - Replace `%s` with a filename in a string
- * @param dest    Buffer for the result
- * @param destlen Length of buffer
- * @param fmt     printf-like format string
- * @param src     Filename to substitute
- */
-void mutt_expand_fmt(char *dest, size_t destlen, const char *fmt, const char *src)
-{
-  const char *p = NULL;
-  char *d = NULL;
-  size_t slen;
-  bool found = false;
-
-  slen = mutt_str_strlen(src);
-  destlen--;
-
-  for (p = fmt, d = dest; destlen && *p; p++)
-  {
-    if (*p == '%')
-    {
-      switch (p[1])
-      {
-        case '%':
-          *d++ = *p++;
-          destlen--;
-          break;
-        case 's':
-          found = true;
-          mutt_str_strfcpy(d, src, destlen + 1);
-          d += destlen > slen ? slen : destlen;
-          destlen -= destlen > slen ? slen : destlen;
-          p++;
-          break;
-        default:
-          *d++ = *p;
-          destlen--;
-          break;
-      }
-    }
-    else
-    {
-      *d++ = *p;
-      destlen--;
-    }
-  }
-
-  *d = '\0';
-
-  if (!found && destlen > 0)
-  {
-    mutt_str_strcat(dest, destlen, " ");
-    mutt_str_strcat(dest, destlen, src);
-  }
-}
-
 /**
  * mutt_check_overwrite - Ask the user if overwriting is necessary
  * @param[in]  attname   Attachment name
index 29b2fbef40c55f8800c64c929b3341e16eff0e25..ad5b17a12736ce2ca52dbcfa8cc91efd484d1da2 100644 (file)
--- a/muttlib.h
+++ b/muttlib.h
@@ -43,8 +43,6 @@ extern struct Regex *GecosMask;
 void        mutt_adv_mktemp(char *s, size_t l);
 int         mutt_check_overwrite(const char *attname, const char *path, char *fname, size_t flen, int *append, char **directory);
 void        mutt_encode_path(char *dest, size_t dlen, const char *src);
-void        mutt_expand_file_fmt(char *dest, size_t destlen, const char *fmt, const char *src);
-void        mutt_expand_fmt(char *dest, size_t destlen, const char *fmt, const char *src);
 void        mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const char *src, format_t *callback, unsigned long data, enum FormatFlag flags);
 char *      mutt_expand_path(char *s, size_t slen);
 char *      mutt_expand_path_regex(char *s, size_t slen, bool regex);
index a2f13a1b9e4bbf76e52be60641ca2a0b69a6e4a9..a7a47ffa8a1548f0394da668affa92b3340540c7 100644 (file)
--- a/pattern.c
+++ b/pattern.c
@@ -2128,7 +2128,7 @@ void mutt_check_simple(char *s, size_t len, const char *simple)
     {
       char tmp[LONG_STRING];
       quote_simple(s, tmp, sizeof(tmp));
-      mutt_expand_fmt(s, len, simple, tmp);
+      mutt_file_expand_fmt(s, len, simple, tmp);
     }
   }
 }
diff --git a/query.c b/query.c
index 9221dce2ec6d9525122e8efc4a29767995956317..b2506102214fa8246c4aa6565aeb95852b02df6f 100644 (file)
--- a/query.c
+++ b/query.c
@@ -139,7 +139,7 @@ static struct Query *run_query(char *s, int quiet)
   char *p = NULL;
   pid_t thepid;
 
-  mutt_expand_file_fmt(cmd, sizeof(cmd), QueryCommand, s);
+  mutt_file_expand_fmt_quote(cmd, sizeof(cmd), QueryCommand, s);
 
   thepid = mutt_create_filter(cmd, NULL, &fp, NULL);
   if (thepid < 0)
index b4d28d897813b919d1f978028fb6e465ed446704..b4077d2694aa71365e88ed6f7c238db03dd1a11b 100644 (file)
--- a/rfc1524.c
+++ b/rfc1524.c
@@ -519,7 +519,7 @@ int rfc1524_expand_filename(char *nametemplate, char *oldfile, char *newfile, si
   }
   else if (!oldfile)
   {
-    mutt_expand_fmt(newfile, nflen, nametemplate, "neomutt");
+    mutt_file_expand_fmt(newfile, nflen, nametemplate, "neomutt");
   }
   else /* oldfile && nametemplate */
   {
index 2102a6394038d571044c8de65392b9393ffb3a01..e109a13d4322a6fc7eb82509afb128d60ea0a494 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -1554,7 +1554,7 @@ static void run_mime_type_query(struct Body *att)
   int dummy = 0;
   pid_t thepid;
 
-  mutt_expand_file_fmt(cmd, sizeof(cmd), MimeTypeQueryCommand, att->filename);
+  mutt_file_expand_fmt_quote(cmd, sizeof(cmd), MimeTypeQueryCommand, att->filename);
 
   thepid = mutt_create_filter(cmd, NULL, &fp, &fperr);
   if (thepid < 0)