From 2f858a1adaef17241ca6fda973f2b867b25e1971 Mon Sep 17 00:00:00 2001 From: Brian Ashworth Date: Wed, 20 Nov 2019 22:10:03 -0500 Subject: input_cmd_xkb_file: allow shell path expansion This allows for shell path expansion for input_cmd_xkb_file. The logic has been extracted from output_cmd_background --- common/stringop.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'common') diff --git a/common/stringop.c b/common/stringop.c index ac7df296..0df2b33d 100644 --- a/common/stringop.c +++ b/common/stringop.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "list.h" #include "log.h" #include "stringop.h" @@ -309,3 +310,21 @@ char *argsep(char **stringp, const char *delim, char *matched) { } return start; } + +bool expand_path(char **path) { + wordexp_t p = {0}; + while (strstr(*path, " ")) { + *path = realloc(*path, strlen(*path) + 2); + char *ptr = strstr(*path, " ") + 1; + memmove(ptr + 1, ptr, strlen(ptr) + 1); + *ptr = '\\'; + } + if (wordexp(*path, &p, 0) != 0 || p.we_wordv[0] == NULL) { + wordfree(&p); + return false; + } + free(*path); + *path = join_args(p.we_wordv, p.we_wordc); + wordfree(&p); + return true; +} -- cgit v1.2.3