diff options
author | Daniel Friesel <derf@finalrewind.org> | 2012-01-15 13:50:40 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2012-01-15 13:50:40 +0100 |
commit | 310b60793c9e87eb2a13a7c0396c09634ca08a22 (patch) | |
tree | 797f93774e7fae0c03eadca9b3f8b90582e8e2d9 /src | |
parent | 919298ad43bff814c91ed7bc4a402b72db6fa9a5 (diff) |
Add %F and %N printf sequences for escaped file name (closes #77)
Diffstat (limited to 'src')
-rw-r--r-- | src/slideshow.c | 31 |
1 files changed, 31 insertions, 0 deletions
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); |