[cwm patch 1/6] Implement shell-like tab-completion for menus

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[cwm patch 1/6] Implement shell-like tab-completion for menus

Alexander Polakov-2
window/application menu: tab completes the word.
exec menu: tab completes the word, when at the end
of the word file menu appears.

diff --git a/calmwm.h b/calmwm.h
index 3aaac3e..b365983 100644
--- a/calmwm.h
+++ b/calmwm.h
@@ -257,7 +257,7 @@ TAILQ_HEAD(cmd_q, cmd);
 struct menu {
  TAILQ_ENTRY(menu) entry;
  TAILQ_ENTRY(menu) resultentry;
-#define MENU_MAXENTRY 50
+#define MENU_MAXENTRY 200
  char text[MENU_MAXENTRY + 1];
  char print[MENU_MAXENTRY + 1];
  void *ctx;
@@ -354,6 +354,8 @@ void search_match_exec(struct menu_q *, struct menu_q *,
      char *);
 void search_match_text(struct menu_q *, struct menu_q *,
      char *);
+void search_match_path(struct menu_q *, struct menu_q *,
+     char *);
 void search_print_client(struct menu *, int);
 
 XineramaScreenInfo *screen_find_xinerama(struct screen_ctx *, int, int);
@@ -410,7 +412,7 @@ void mousefunc_window_raise(struct client_ctx *, void *);
 void mousefunc_window_resize(struct client_ctx *, void *);
 
 struct menu   *menu_filter(struct screen_ctx *, struct menu_q *,
-     char *, char *, int,
+     char *, char *, int, int,
      void (*)(struct menu_q *, struct menu_q *, char *),
      void (*)(struct menu *, int));
 void menu_init(struct screen_ctx *);
diff --git a/group.c b/group.c
index 17de904..f698cc7 100644
--- a/group.c
+++ b/group.c
@@ -395,7 +395,7 @@ group_menu(XButtonEvent *e)
  if (TAILQ_EMPTY(&menuq))
  return;
 
- mi = menu_filter(sc, &menuq, NULL, NULL, 0, NULL, NULL);
+ mi = menu_filter(sc, &menuq, NULL, NULL, 0, 0, NULL, NULL);
 
  if (mi == NULL || mi->ctx == NULL)
  goto cleanup;
diff --git a/kbfunc.c b/kbfunc.c
index a044a4c..224b9af 100644
--- a/kbfunc.c
+++ b/kbfunc.c
@@ -157,7 +157,7 @@ kbfunc_client_search(struct client_ctx *cc, union arg *arg)
  TAILQ_INSERT_TAIL(&menuq, mi, entry);
  }
 
- if ((mi = menu_filter(sc, &menuq, "window", NULL, 0,
+ if ((mi = menu_filter(sc, &menuq, "window", NULL, 0, 0,
     search_match_client, search_print_client)) != NULL) {
  cc = (struct client_ctx *)mi->ctx;
  if (cc->flags & CLIENT_HIDDEN)
@@ -192,7 +192,7 @@ kbfunc_menu_search(struct client_ctx *cc, union arg *arg)
  TAILQ_INSERT_TAIL(&menuq, mi, entry);
  }
 
- if ((mi = menu_filter(sc, &menuq, "application", NULL, 0,
+ if ((mi = menu_filter(sc, &menuq, "application", NULL, 0, 0,
     search_match_text, NULL)) != NULL)
  u_spawn(((struct cmd *)mi->ctx)->image);
 
@@ -303,7 +303,7 @@ kbfunc_exec(struct client_ctx *cc, union arg *arg)
  }
  xfree(path);
 
- if ((mi = menu_filter(sc, &menuq, label, NULL, 1,
+ if ((mi = menu_filter(sc, &menuq, label, NULL, 1, 1,
     search_match_exec, NULL)) != NULL) {
  if (mi->text[0] == '\0')
  goto out;
@@ -383,7 +383,7 @@ kbfunc_ssh(struct client_ctx *cc, union arg *arg)
  xfree(lbuf);
  (void)fclose(fp);
 
- if ((mi = menu_filter(sc, &menuq, "ssh", NULL, 1,
+ if ((mi = menu_filter(sc, &menuq, "ssh", NULL, 1, 0,
     search_match_exec, NULL)) != NULL) {
  if (mi->text[0] == '\0')
  goto out;
@@ -410,7 +410,7 @@ kbfunc_client_label(struct client_ctx *cc, union arg *arg)
  TAILQ_INIT(&menuq);
 
  /* dummy is set, so this will always return */
- mi = menu_filter(cc->sc, &menuq, "label", cc->label, 1,
+ mi = menu_filter(cc->sc, &menuq, "label", cc->label, 1, 0,
     search_match_text, NULL);
 
  if (!mi->abort) {
diff --git a/menu.c b/menu.c
index 79b283d..c40b8ba 100644
--- a/menu.c
+++ b/menu.c
@@ -37,10 +37,11 @@
 enum ctltype {
  CTL_NONE = -1,
  CTL_ERASEONE = 0, CTL_WIPE, CTL_UP, CTL_DOWN, CTL_RETURN,
- CTL_ABORT, CTL_ALL
+ CTL_TAB, CTL_ABORT, CTL_ALL
 };
 
 struct menu_ctx {
+ struct screen_ctx *sc;
  char searchstr[MENU_MAXENTRY + 1];
  char dispstr[MENU_MAXENTRY*2 + 1];
  char promptstr[MENU_MAXENTRY + 1];
@@ -53,6 +54,7 @@ struct menu_ctx {
  int entry;
  int width;
  int num;
+ int filecomplete;
  int x;
  int y;
      void (*match)(struct menu_q *, struct menu_q *, char *);
@@ -96,7 +98,7 @@ menu_init(struct screen_ctx *sc)
 
 struct menu *
 menu_filter(struct screen_ctx *sc, struct menu_q *menuq, char *prompt,
-    char *initial, int dummy,
+    char *initial, int dummy, int filecomplete,
     void (*match)(struct menu_q *, struct menu_q *, char *),
     void (*print)(struct menu *, int))
 {
@@ -117,6 +119,8 @@ menu_filter(struct screen_ctx *sc, struct menu_q *menuq, char *prompt,
  xsave = mc.x;
  ysave = mc.y;
 
+ mc.sc = sc;
+ mc.filecomplete = filecomplete;
  if (prompt == NULL) {
  evmask = MENUMASK;
  mc.promptstr[0] = '\0';
@@ -202,13 +206,40 @@ out:
  return (mi);
 }
 
+static char *
+menu_complete_path(struct screen_ctx *sc, char *label, char *space)
+{
+ struct menu *mi;
+ struct menu_q menuq;
+ char *path = NULL;
+
+ TAILQ_INIT(&menuq);
+ if ((mi = menu_filter(sc, &menuq, label, space, 1, 0,
+    search_match_path, NULL)) != NULL) {
+ if (mi->text[0] == '\0')
+ goto out;
+ path = xcalloc(1, MAXPATHLEN);
+ path[0] = '"';
+ strlcpy(path+1, mi->text, MAXPATHLEN);
+ strlcat(path, "\"", MAXPATHLEN);
+ }
+out:
+ if (mi != NULL && mi->dummy)
+ xfree(mi);
+ while ((mi = TAILQ_FIRST(&menuq)) != NULL) {
+ TAILQ_REMOVE(&menuq, mi, entry);
+ xfree(mi);
+ }
+ return path;
+}
+
 static struct menu *
 menu_handle_key(XEvent *e, struct menu_ctx *mc, struct menu_q *menuq,
     struct menu_q *resultq)
 {
  struct menu *mi;
  enum ctltype ctl;
- char chr;
+ char chr, *fcp, *sp;
  size_t len;
 
  if (menu_keycode(e->xkey.keycode, e->xkey.state, &ctl, &chr) < 0)
@@ -254,6 +285,40 @@ menu_handle_key(XEvent *e, struct menu_ctx *mc, struct menu_q *menuq,
  mc->searchstr[0] = '\0';
  mc->changed = 1;
  break;
+ case CTL_TAB:
+ if ((mi = TAILQ_FIRST(resultq)) != NULL) {
+ if (strncmp(mc->searchstr, mi->text,
+ strlen(mi->text)) == 0) {
+ goto filecomplete;
+ }
+ (void)strlcpy(mc->searchstr,
+ mi->text, sizeof(mc->searchstr));
+ mc->changed = 1;
+ break;
+ }
+filecomplete:
+ if (mc->filecomplete && mc->searchstr[0] != '\0') {
+ mi = xcalloc(1, sizeof *mi);
+ sp = strrchr(mc->searchstr, ' ');
+ if (sp != NULL) {
+ strlcpy(mi->text, mc->searchstr, sp - mc->searchstr + 1);
+ if (sp + 1 < mc->searchstr + strlen(mc->searchstr)-1)
+ sp++;
+ else
+ sp = NULL;
+ } else
+ strlcpy(mi->text, mc->searchstr, sizeof(mi->text));
+ fcp = menu_complete_path(mc->sc, mi->text, sp);
+ if (fcp) {
+ strlcat(mi->text, " ", sizeof(mi->text));
+ strlcat(mi->text, fcp, sizeof(mi->text));
+ xfree(fcp);
+ }
+ mi->dummy = 1;
+ return (mi);
+ }
+ mc->changed = 1;
+ /* FALLTHROUGH */
  case CTL_ALL:
  mc->list = !mc->list;
  break;
@@ -476,6 +541,9 @@ menu_keycode(KeyCode kc, u_int state, enum ctltype *ctl, char *chr)
  case XK_Return:
  *ctl = CTL_RETURN;
  break;
+ case XK_Tab:
+ *ctl = CTL_TAB;
+ break;
  case XK_Up:
  *ctl = CTL_UP;
  break;
diff --git a/mousefunc.c b/mousefunc.c
index 574ef62..8056e88 100644
--- a/mousefunc.c
+++ b/mousefunc.c
@@ -242,7 +242,7 @@ mousefunc_menu_unhide(struct client_ctx *cc, void *arg)
  if (TAILQ_EMPTY(&menuq))
  return;
 
- mi = menu_filter(sc, &menuq, NULL, NULL, 0, NULL, NULL);
+ mi = menu_filter(sc, &menuq, NULL, NULL, 0, 0, NULL, NULL);
  if (mi != NULL) {
  cc = (struct client_ctx *)mi->ctx;
  client_unhide(cc);
@@ -278,7 +278,7 @@ mousefunc_menu_cmd(struct client_ctx *cc, void *arg)
  if (TAILQ_EMPTY(&menuq))
  return;
 
- mi = menu_filter(sc, &menuq, NULL, NULL, 0, NULL, NULL);
+ mi = menu_filter(sc, &menuq, NULL, NULL, 0, 0, NULL, NULL);
  if (mi != NULL)
  u_spawn(((struct cmd *)mi->ctx)->image);
  else
diff --git a/search.c b/search.c
index 9db2f70..c9d94b2 100644
--- a/search.c
+++ b/search.c
@@ -29,6 +29,7 @@
 #include <string.h>
 #include <stdio.h>
 #include <unistd.h>
+#include <glob.h>
 
 #include "calmwm.h"
 
@@ -162,6 +163,31 @@ search_print_client(struct menu *mi, int list)
 }
 
 void
+search_match_path(struct menu_q *menuq, struct menu_q *resultq, char *search)
+{
+ struct menu *mi;
+ char pattern[MAXPATHLEN] = "*";
+ glob_t g;
+ int i;
+
+ TAILQ_INIT(resultq);
+
+ strlcpy(pattern, search, sizeof(pattern));
+ strlcat(pattern, "*", sizeof(pattern));
+
+ if (glob(pattern, GLOB_MARK, NULL, &g) != 0)
+ return;
+ for (i = 0; i < g.gl_matchc; i++) {
+ mi = xcalloc(1, sizeof(*mi));
+ (void)strlcpy(mi->text, g.gl_pathv[i],
+ sizeof(mi->text));
+ TAILQ_INSERT_TAIL(resultq, mi, resultentry);
+ TAILQ_INSERT_TAIL(menuq, mi, entry);
+ }
+ globfree(&g);
+}
+
+void
 search_match_text(struct menu_q *menuq, struct menu_q *resultq, char *search)
 {
  struct menu *mi;
--
1.7.6

Reply | Threaded
Open this post in threaded view
|

Re: [cwm patch 1/6] Implement shell-like tab-completion for menus

Stuart Henderson
On 2012/01/20 00:44, Alexander Polakov wrote:
> window/application menu: tab completes the word.
> exec menu: tab completes the word, when at the end
> of the word file menu appears.

I like this quite a lot, but there is a bug in a directory with a
lot of files, see http://junkpile.org/cwm-filelist.png

Reply | Threaded
Open this post in threaded view
|

Re: [cwm patch 1/6] Implement shell-like tab-completion for menus

Alexander Polakov-2
* Stuart Henderson <[hidden email]> [120408 13:42]:
> On 2012/01/20 00:44, Alexander Polakov wrote:
> > window/application menu: tab completes the word.
> > exec menu: tab completes the word, when at the end
> > of the word file menu appears.
>
> I like this quite a lot, but there is a bug in a directory with a
> lot of files, see http://junkpile.org/cwm-filelist.png
>

Here's an updated diff, tested on a directory with 5000 files.

diff --git a/calmwm.h b/calmwm.h
index 3aaac3e..b365983 100644
--- a/calmwm.h
+++ b/calmwm.h
@@ -257,7 +257,7 @@ TAILQ_HEAD(cmd_q, cmd);
 struct menu {
  TAILQ_ENTRY(menu) entry;
  TAILQ_ENTRY(menu) resultentry;
-#define MENU_MAXENTRY 50
+#define MENU_MAXENTRY 200
  char text[MENU_MAXENTRY + 1];
  char print[MENU_MAXENTRY + 1];
  void *ctx;
@@ -354,6 +354,8 @@ void search_match_exec(struct menu_q *, struct menu_q *,
      char *);
 void search_match_text(struct menu_q *, struct menu_q *,
      char *);
+void search_match_path(struct menu_q *, struct menu_q *,
+     char *);
 void search_print_client(struct menu *, int);
 
 XineramaScreenInfo *screen_find_xinerama(struct screen_ctx *, int, int);
@@ -410,7 +412,7 @@ void mousefunc_window_raise(struct client_ctx *, void *);
 void mousefunc_window_resize(struct client_ctx *, void *);
 
 struct menu   *menu_filter(struct screen_ctx *, struct menu_q *,
-     char *, char *, int,
+     char *, char *, int, int,
      void (*)(struct menu_q *, struct menu_q *, char *),
      void (*)(struct menu *, int));
 void menu_init(struct screen_ctx *);
diff --git a/group.c b/group.c
index 17de904..f698cc7 100644
--- a/group.c
+++ b/group.c
@@ -395,7 +395,7 @@ group_menu(XButtonEvent *e)
  if (TAILQ_EMPTY(&menuq))
  return;
 
- mi = menu_filter(sc, &menuq, NULL, NULL, 0, NULL, NULL);
+ mi = menu_filter(sc, &menuq, NULL, NULL, 0, 0, NULL, NULL);
 
  if (mi == NULL || mi->ctx == NULL)
  goto cleanup;
diff --git a/kbfunc.c b/kbfunc.c
index a044a4c..224b9af 100644
--- a/kbfunc.c
+++ b/kbfunc.c
@@ -157,7 +157,7 @@ kbfunc_client_search(struct client_ctx *cc, union arg *arg)
  TAILQ_INSERT_TAIL(&menuq, mi, entry);
  }
 
- if ((mi = menu_filter(sc, &menuq, "window", NULL, 0,
+ if ((mi = menu_filter(sc, &menuq, "window", NULL, 0, 0,
     search_match_client, search_print_client)) != NULL) {
  cc = (struct client_ctx *)mi->ctx;
  if (cc->flags & CLIENT_HIDDEN)
@@ -192,7 +192,7 @@ kbfunc_menu_search(struct client_ctx *cc, union arg *arg)
  TAILQ_INSERT_TAIL(&menuq, mi, entry);
  }
 
- if ((mi = menu_filter(sc, &menuq, "application", NULL, 0,
+ if ((mi = menu_filter(sc, &menuq, "application", NULL, 0, 0,
     search_match_text, NULL)) != NULL)
  u_spawn(((struct cmd *)mi->ctx)->image);
 
@@ -303,7 +303,7 @@ kbfunc_exec(struct client_ctx *cc, union arg *arg)
  }
  xfree(path);
 
- if ((mi = menu_filter(sc, &menuq, label, NULL, 1,
+ if ((mi = menu_filter(sc, &menuq, label, NULL, 1, 1,
     search_match_exec, NULL)) != NULL) {
  if (mi->text[0] == '\0')
  goto out;
@@ -383,7 +383,7 @@ kbfunc_ssh(struct client_ctx *cc, union arg *arg)
  xfree(lbuf);
  (void)fclose(fp);
 
- if ((mi = menu_filter(sc, &menuq, "ssh", NULL, 1,
+ if ((mi = menu_filter(sc, &menuq, "ssh", NULL, 1, 0,
     search_match_exec, NULL)) != NULL) {
  if (mi->text[0] == '\0')
  goto out;
@@ -410,7 +410,7 @@ kbfunc_client_label(struct client_ctx *cc, union arg *arg)
  TAILQ_INIT(&menuq);
 
  /* dummy is set, so this will always return */
- mi = menu_filter(cc->sc, &menuq, "label", cc->label, 1,
+ mi = menu_filter(cc->sc, &menuq, "label", cc->label, 1, 0,
     search_match_text, NULL);
 
  if (!mi->abort) {
diff --git a/menu.c b/menu.c
index 79b283d..746bf89 100644
--- a/menu.c
+++ b/menu.c
@@ -37,10 +37,11 @@
 enum ctltype {
  CTL_NONE = -1,
  CTL_ERASEONE = 0, CTL_WIPE, CTL_UP, CTL_DOWN, CTL_RETURN,
- CTL_ABORT, CTL_ALL
+ CTL_TAB, CTL_ABORT, CTL_ALL
 };
 
 struct menu_ctx {
+ struct screen_ctx *sc;
  char searchstr[MENU_MAXENTRY + 1];
  char dispstr[MENU_MAXENTRY*2 + 1];
  char promptstr[MENU_MAXENTRY + 1];
@@ -53,6 +54,7 @@ struct menu_ctx {
  int entry;
  int width;
  int num;
+ int filecomplete;
  int x;
  int y;
      void (*match)(struct menu_q *, struct menu_q *, char *);
@@ -96,7 +98,7 @@ menu_init(struct screen_ctx *sc)
 
 struct menu *
 menu_filter(struct screen_ctx *sc, struct menu_q *menuq, char *prompt,
-    char *initial, int dummy,
+    char *initial, int dummy, int filecomplete,
     void (*match)(struct menu_q *, struct menu_q *, char *),
     void (*print)(struct menu *, int))
 {
@@ -117,6 +119,8 @@ menu_filter(struct screen_ctx *sc, struct menu_q *menuq, char *prompt,
  xsave = mc.x;
  ysave = mc.y;
 
+ mc.sc = sc;
+ mc.filecomplete = filecomplete;
  if (prompt == NULL) {
  evmask = MENUMASK;
  mc.promptstr[0] = '\0';
@@ -202,13 +206,40 @@ out:
  return (mi);
 }
 
+static char *
+menu_complete_path(struct screen_ctx *sc, char *label, char *space)
+{
+ struct menu *mi;
+ struct menu_q menuq;
+ char *path = NULL;
+
+ TAILQ_INIT(&menuq);
+ if ((mi = menu_filter(sc, &menuq, label, space, 1, 0,
+    search_match_path, NULL)) != NULL) {
+ if (mi->text[0] == '\0')
+ goto out;
+ path = xcalloc(1, MAXPATHLEN);
+ path[0] = '"';
+ strlcpy(path+1, mi->text, MAXPATHLEN);
+ strlcat(path, "\"", MAXPATHLEN);
+ }
+out:
+ if (mi != NULL && mi->dummy)
+ xfree(mi);
+ while ((mi = TAILQ_FIRST(&menuq)) != NULL) {
+ TAILQ_REMOVE(&menuq, mi, entry);
+ xfree(mi);
+ }
+ return path;
+}
+
 static struct menu *
 menu_handle_key(XEvent *e, struct menu_ctx *mc, struct menu_q *menuq,
     struct menu_q *resultq)
 {
  struct menu *mi;
  enum ctltype ctl;
- char chr;
+ char chr, *fcp, *sp;
  size_t len;
 
  if (menu_keycode(e->xkey.keycode, e->xkey.state, &ctl, &chr) < 0)
@@ -254,6 +285,40 @@ menu_handle_key(XEvent *e, struct menu_ctx *mc, struct menu_q *menuq,
  mc->searchstr[0] = '\0';
  mc->changed = 1;
  break;
+ case CTL_TAB:
+ if ((mi = TAILQ_FIRST(resultq)) != NULL) {
+ if (strncmp(mc->searchstr, mi->text,
+ strlen(mi->text)) == 0) {
+ goto filecomplete;
+ }
+ (void)strlcpy(mc->searchstr,
+ mi->text, sizeof(mc->searchstr));
+ mc->changed = 1;
+ break;
+ }
+filecomplete:
+ if (mc->filecomplete && mc->searchstr[0] != '\0') {
+ mi = xcalloc(1, sizeof *mi);
+ sp = strrchr(mc->searchstr, ' ');
+ if (sp != NULL) {
+ strlcpy(mi->text, mc->searchstr, sp - mc->searchstr + 1);
+ if (sp + 1 < mc->searchstr + strlen(mc->searchstr)-1)
+ sp++;
+ else
+ sp = NULL;
+ } else
+ strlcpy(mi->text, mc->searchstr, sizeof(mi->text));
+ fcp = menu_complete_path(mc->sc, mi->text, sp);
+ if (fcp) {
+ strlcat(mi->text, " ", sizeof(mi->text));
+ strlcat(mi->text, fcp, sizeof(mi->text));
+ xfree(fcp);
+ }
+ mi->dummy = 1;
+ return (mi);
+ }
+ mc->changed = 1;
+ /* FALLTHROUGH */
  case CTL_ALL:
  mc->list = !mc->list;
  break;
@@ -385,9 +450,14 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq,
  TAILQ_FOREACH(mi, resultq, resultentry) {
  char *text = mi->print[0] != '\0' ?
     mi->print : mi->text;
+ int y = n * font_height(sc) + font_ascent(sc) + 1;
+
+ /* Stop drawing when menu doesn't fit the screen */
+ if (mc->y + y > ymax)
+ break;
 
  font_draw(sc, text, MIN(strlen(text), MENU_MAXENTRY),
-    sc->menuwin, 0, n * font_height(sc) + font_ascent(sc) + 1);
+    sc->menuwin, 0, y);
  n++;
  }
 
@@ -476,6 +546,9 @@ menu_keycode(KeyCode kc, u_int state, enum ctltype *ctl, char *chr)
  case XK_Return:
  *ctl = CTL_RETURN;
  break;
+ case XK_Tab:
+ *ctl = CTL_TAB;
+ break;
  case XK_Up:
  *ctl = CTL_UP;
  break;
diff --git a/mousefunc.c b/mousefunc.c
index 574ef62..8056e88 100644
--- a/mousefunc.c
+++ b/mousefunc.c
@@ -242,7 +242,7 @@ mousefunc_menu_unhide(struct client_ctx *cc, void *arg)
  if (TAILQ_EMPTY(&menuq))
  return;
 
- mi = menu_filter(sc, &menuq, NULL, NULL, 0, NULL, NULL);
+ mi = menu_filter(sc, &menuq, NULL, NULL, 0, 0, NULL, NULL);
  if (mi != NULL) {
  cc = (struct client_ctx *)mi->ctx;
  client_unhide(cc);
@@ -278,7 +278,7 @@ mousefunc_menu_cmd(struct client_ctx *cc, void *arg)
  if (TAILQ_EMPTY(&menuq))
  return;
 
- mi = menu_filter(sc, &menuq, NULL, NULL, 0, NULL, NULL);
+ mi = menu_filter(sc, &menuq, NULL, NULL, 0, 0, NULL, NULL);
  if (mi != NULL)
  u_spawn(((struct cmd *)mi->ctx)->image);
  else
diff --git a/search.c b/search.c
index 9db2f70..c9d94b2 100644
--- a/search.c
+++ b/search.c
@@ -29,6 +29,7 @@
 #include <string.h>
 #include <stdio.h>
 #include <unistd.h>
+#include <glob.h>
 
 #include "calmwm.h"
 
@@ -162,6 +163,31 @@ search_print_client(struct menu *mi, int list)
 }
 
 void
+search_match_path(struct menu_q *menuq, struct menu_q *resultq, char *search)
+{
+ struct menu *mi;
+ char pattern[MAXPATHLEN] = "*";
+ glob_t g;
+ int i;
+
+ TAILQ_INIT(resultq);
+
+ strlcpy(pattern, search, sizeof(pattern));
+ strlcat(pattern, "*", sizeof(pattern));
+
+ if (glob(pattern, GLOB_MARK, NULL, &g) != 0)
+ return;
+ for (i = 0; i < g.gl_matchc; i++) {
+ mi = xcalloc(1, sizeof(*mi));
+ (void)strlcpy(mi->text, g.gl_pathv[i],
+ sizeof(mi->text));
+ TAILQ_INSERT_TAIL(resultq, mi, resultentry);
+ TAILQ_INSERT_TAIL(menuq, mi, entry);
+ }
+ globfree(&g);
+}
+
+void
 search_match_text(struct menu_q *menuq, struct menu_q *resultq, char *search)
 {
  struct menu *mi;

--
Alexander Polakov | plhk.ru

Reply | Threaded
Open this post in threaded view
|

Re: [cwm patch 1/6] Implement shell-like tab-completion for menus

Ted Unangst-6
In reply to this post by Alexander Polakov-2
On Fri, Jan 20, 2012, Alexander Polakov wrote:

I'm not sure how you got your clock so wrong, but I almost missed all
your mails because they did not show up where I expected them.

Reply | Threaded
Open this post in threaded view
|

Re: [cwm patch 1/6] Implement shell-like tab-completion for menus

Alexander Polakov-2
* Ted Unangst <[hidden email]> [120408 18:06]:
> On Fri, Jan 20, 2012, Alexander Polakov wrote:
>
> I'm not sure how you got your clock so wrong, but I almost missed all
> your mails because they did not show up where I expected them.

My clock is fine, I sent the output of "git format-patch" to the list
(which proved to be the wrong thing to do) and the dates of the mails
are the dates when patches were committed to my local git tree.

Sorry for the inconvinience.

http://ompldr.org/vZGF2Mw
--
Alexander Polakov | plhk.ru