summary refs log tree commit diff
path: root/search.c
diff options
context:
space:
mode:
authorcanacar <canacar>2008-09-03 04:39:12 +0000
committercanacar <canacar>2008-09-03 04:39:12 +0000
commita0082c58a4a95d05f452cfa3da7eaf4e1eb17dba (patch)
tree94f7d9008262ceba8259c143a67b232737d6cd17 /search.c
parent04441482d4ceab6eab0eaadc5188997a245bf061 (diff)
downloadcwm-a0082c58a4a95d05f452cfa3da7eaf4e1eb17dba.tar.gz
cwm-a0082c58a4a95d05f452cfa3da7eaf4e1eb17dba.tar.xz
cwm-a0082c58a4a95d05f452cfa3da7eaf4e1eb17dba.zip
Keep the exec menu entries sorted.
Go for it okan@
Diffstat (limited to 'search.c')
-rw-r--r--search.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/search.c b/search.c
index c09a010..24730c5 100644
--- a/search.c
+++ b/search.c
@@ -175,13 +175,23 @@ search_match_text(struct menu_q *menuq, struct menu_q *resultq, char *search)
 void
 search_match_exec(struct menu_q *menuq, struct menu_q *resultq, char *search)
 {
-	struct menu	*mi;
+	struct menu	*mi, *mj;
 
 	TAILQ_INIT(resultq);
 
-	TAILQ_FOREACH(mi, menuq, entry)
-		if (_strsubmatch(search, mi->text, 1))
+	TAILQ_FOREACH(mi, menuq, entry) {
+		if (_strsubmatch(search, mi->text, 1) == 0)
+			continue;
+		for (mj = TAILQ_FIRST(resultq); mj != NULL;
+		     mj = TAILQ_NEXT(mj, resultentry)) {
+			if (strcasecmp(mi->text, mj->text) < 0) {
+				TAILQ_INSERT_BEFORE(mj, mi, resultentry);
+				break;
+			}
+		}
+		if (mj == NULL)
 			TAILQ_INSERT_TAIL(resultq, mi, resultentry);
+	}
 }
 
 static int