diff options
author | okan <okan> | 2012-11-07 14:39:44 +0000 |
---|---|---|
committer | okan <okan> | 2012-11-07 14:39:44 +0000 |
commit | 4b84287d1935144625bd506facbf56e8470ce5be (patch) | |
tree | 45eb44692584068d48048d73233c88badb846f3f /search.c | |
parent | dabc05034f56a14fb85e7b448b489f52a60ee600 (diff) | |
download | cwm-4b84287d1935144625bd506facbf56e8470ce5be.tar.gz cwm-4b84287d1935144625bd506facbf56e8470ce5be.tar.xz cwm-4b84287d1935144625bd506facbf56e8470ce5be.zip |
tab completion support for menus; from Alexander Polakov.
ok sthen@ on an older incarnation
Diffstat (limited to 'search.c')
-rw-r--r-- | search.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/search.c b/search.c index 8d58067..e19c9c8 100644 --- a/search.c +++ b/search.c @@ -29,9 +29,12 @@ #include <string.h> #include <stdio.h> #include <unistd.h> +#include <glob.h> #include "calmwm.h" +#define PATH_EXEC 0x1 + static int strsubmatch(char *, char *, int); /* @@ -161,6 +164,43 @@ search_print_client(struct menu *mi, int list) } } +static void +search_match_path(struct menu_q *menuq, struct menu_q *resultq, char *search, int flag) +{ + struct menu *mi; + char pattern[MAXPATHLEN]; + glob_t g; + int i; + + TAILQ_INIT(resultq); + + (void)strlcpy(pattern, search, sizeof(pattern)); + (void)strlcat(pattern, "*", sizeof(pattern)); + + if (glob(pattern, GLOB_MARK, NULL, &g) != 0) + return; + for (i = 0; i < g.gl_pathc; i++) { + if ((flag & PATH_EXEC) && access(g.gl_pathv[i], X_OK)) + continue; + mi = xcalloc(1, sizeof(*mi)); + (void)strlcpy(mi->text, g.gl_pathv[i], sizeof(mi->text)); + TAILQ_INSERT_TAIL(resultq, mi, resultentry); + } + globfree(&g); +} + +void +search_match_path_exec(struct menu_q *menuq, struct menu_q *resultq, char *search) +{ + return (search_match_path(menuq, resultq, search, PATH_EXEC)); +} + +void +search_match_path_any(struct menu_q *menuq, struct menu_q *resultq, char *search) +{ + return (search_match_path(menuq, resultq, search, 0)); +} + void search_match_text(struct menu_q *menuq, struct menu_q *resultq, char *search) { @@ -196,6 +236,14 @@ search_match_exec(struct menu_q *menuq, struct menu_q *resultq, char *search) } } +void +search_match_exec_path(struct menu_q *menuq, struct menu_q *resultq, char *search) +{ + search_match_exec(menuq, resultq, search); + if (TAILQ_EMPTY(resultq)) + search_match_path_exec(menuq, resultq, search); +} + static int strsubmatch(char *sub, char *str, int zeroidx) { |