From b5c6af696633ad0c78f262dc2f40d088c367f6a1 Mon Sep 17 00:00:00 2001 From: leo-arch Date: Fri, 6 Dec 2024 00:32:51 -0300 Subject: [PATCH] Fix: 'sel str*' works, but 'desel str*' doesn't --- src/checks.c | 1 + src/selection.c | 23 ++++++++++++----------- src/strings.c | 18 +++++++++++++----- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/checks.c b/src/checks.c index 8ce363ce..ad89a7c5 100644 --- a/src/checks.c +++ b/src/checks.c @@ -64,6 +64,7 @@ check_glob_char(const char *str, const int gflag) { if (!str || !*str) return 0; + return strpbrk(str, (gflag == GLOB_ONLY) ? GLOB_CHARS : GLOB_REGEX_CHARS) ? 1 : 0; } diff --git a/src/selection.c b/src/selection.c index 4e218f3f..d88dd4c0 100644 --- a/src/selection.c +++ b/src/selection.c @@ -1106,22 +1106,23 @@ static int deselect_from_args(char **args) { char **ds = xnmalloc(args_n + 1, sizeof(char *)); - size_t j, k = 0; + size_t i, j = 0; - for (j = 1; j <= args_n; j++) { - char *pp = normalize_path(args[j], strlen(args[j])); - if (!pp) + for (i = 1; i <= args_n; i++) { + char *ptr = normalize_path(args[i], strlen(args[i])); + if (!ptr) continue; - ds[k] = savestring(pp, strlen(pp)); - k++; - free(pp); + + ds[j] = savestring(ptr, strlen(ptr)); + j++; + + free(ptr); } - ds[k] = (char *)NULL; - if (desel_entries(ds, args_n, 0) == FUNC_FAILURE) - return FUNC_FAILURE; + ds[j] = (char *)NULL; - return FUNC_SUCCESS; + return (desel_entries(ds, j, 0) == FUNC_FAILURE + ? FUNC_FAILURE : FUNC_SUCCESS); } /* Desel screen: take user input and return an array of input substrings, diff --git a/src/strings.c b/src/strings.c index ab266bc4..db45471e 100644 --- a/src/strings.c +++ b/src/strings.c @@ -2611,13 +2611,21 @@ glob_expand(char **cmd) if (!cmd || !cmd[0] || !*cmd[0]) return 0; - /* Do not expand if command is deselect, sel or untrash, just to - * allow the use of "*" for desel and untrash ("ds *" and "u *"), - * and to let the sel function handle glob patterns itself. */ + /* In case of 'desel', allow glob expansion onyl if the first parameter + * is not "*", in which the deselect function itself takes care of + * deselecting all files. */ + if (sel_n > 0 && cmd[1] && *cmd[1] + && (strcmp(cmd[0], "ds") == 0 || strcmp(cmd[0], "desel") == 0)) { + if (*cmd[1] == '*' && !cmd[1][1]) + return 0; + return (check_glob_char(cmd[1], GLOB_REGEX)); + } - if (strcmp(cmd[0], "s") != 0 && strcmp(cmd[0], "sel") != 0 + /* Do not expand if command is sel or untrash, just to allow the use + * of "*" for desel and untrash ("ds *" and "u *"), and to let the + * sel function handle glob patterns itself. */ - && strcmp(cmd[0], "ds") != 0 && strcmp(cmd[0], "desel") != 0 + if (strcmp(cmd[0], "s") != 0 && strcmp(cmd[0], "sel") != 0 && strcmp(cmd[0], "u") != 0 && strcmp(cmd[0], "undel") != 0 && strcmp(cmd[0], "untrash") != 0