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);
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);
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);
+ }
+}
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);
}
}
-/**
- * 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
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);
{
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);
}
}
}
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)
}
else if (!oldfile)
{
- mutt_expand_fmt(newfile, nflen, nametemplate, "neomutt");
+ mutt_file_expand_fmt(newfile, nflen, nametemplate, "neomutt");
}
else /* oldfile && nametemplate */
{
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)