diff options
author | Brian Ashworth <bosrsf04@gmail.com> | 2019-11-20 22:10:03 -0500 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-11-21 10:36:15 -0500 |
commit | 2f858a1adaef17241ca6fda973f2b867b25e1971 (patch) | |
tree | 4942dfcbd3eeea04092ff1b40791b8c25e1f4403 /common | |
parent | 66725f2e274df6e18f8190b1307c517e7cb27949 (diff) |
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
Diffstat (limited to 'common')
-rw-r--r-- | common/stringop.c | 19 |
1 files changed, 19 insertions, 0 deletions
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 <stdlib.h> #include <string.h> #include <strings.h> +#include <wordexp.h> #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; +} |