From 310b60793c9e87eb2a13a7c0396c09634ca08a22 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 15 Jan 2012 13:50:40 +0100 Subject: Add %F and %N printf sequences for escaped file name (closes #77) --- src/slideshow.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src') diff --git a/src/slideshow.c b/src/slideshow.c index 42aaf2e..189357d 100644 --- a/src/slideshow.c +++ b/src/slideshow.c @@ -381,6 +381,29 @@ void feh_action_run(feh_file * file, char *action) return; } +char *shell_escape(char *input) +{ + static char ret[1024]; + unsigned int out = 0, in = 0; + + ret[out++] = '\''; + for (in = 0; input[in] && (out < (sizeof(ret) - 7)); in++) { + if (input[in] == '\'') { + ret[out++] = '\''; + ret[out++] = '"'; + ret[out++] = '\''; + ret[out++] = '"'; + ret[out++] = '\''; + } + else + ret[out++] = input[in]; + } + ret[out++] = '\''; + ret[out++] = '\0'; + + return ret; +} + char *feh_printf(char *str, feh_file * file) { char *c; @@ -397,10 +420,18 @@ char *feh_printf(char *str, feh_file * file) if (file) strcat(ret, file->filename); break; + case 'F': + if (file) + strcat(ret, shell_escape(file->filename)); + break; case 'n': if (file) strcat(ret, file->name); break; + case 'N': + if (file) + strcat(ret, shell_escape(file->name)); + break; case 'w': if (file && (file->info || !feh_file_info_load(file, NULL))) { snprintf(buf, sizeof(buf), "%d", file->info->width); -- cgit v1.2.3