* [PATCH] Searching parameters in menuconfig
@ 2004-08-31 7:52 Yuval Turgeman
2004-08-31 9:08 ` Andrew Morton
2004-08-31 14:33 ` Roman Zippel
0 siblings, 2 replies; 4+ messages in thread
From: Yuval Turgeman @ 2004-08-31 7:52 UTC (permalink / raw)
To: sam; +Cc: linux-kernel
Added support for searching parameters in make menuconfig.
Can be compiled with gcc-2.95 now...
( If I didn't mention this before, pressing '/' invokes the search window )
Signed-off-by: Yuval Turgeman <yuvalt@gmail.com>
scripts/kconfig/mconf.c | 101 ++++++++++++++++++++++++++++++++++++++++++++-
scripts/lxdialog/menubox.c | 10 ++++
2 files changed, 110 insertions(+), 1 deletion(-)
diff -uprN linux-vanilla/scripts/kconfig/mconf.c linux/scripts/kconfig/mconf.c
--- linux-vanilla/scripts/kconfig/mconf.c 2004-08-14
13:54:51.000000000 +0300
+++ linux/scripts/kconfig/mconf.c 2004-08-31 10:15:56.000000000 +0300
@@ -28,7 +28,7 @@ static const char menu_instructions[] =
"<Enter> selects submenus --->. "
"Highlighted letters are hotkeys. "
"Pressing <Y> includes, <N> excludes, <M> modularizes features. "
- "Press <Esc><Esc> to exit, <?> for Help. "
+ "Press <Esc><Esc> to exit, <?> for Help, </> for Search. "
"Legend: [*] built-in [ ] excluded <M> module < > module capable",
radiolist_instructions[] =
"Use the arrow keys to navigate this window or "
@@ -102,6 +102,7 @@ static void show_textbox(const char *tit
static void show_helptext(const char *title, const char *text);
static void show_help(struct menu *menu);
static void show_readme(void);
+static void search_conf(char *);
static void cprint_init(void);
static int cprint1(const char *fmt, ...);
@@ -274,6 +275,86 @@ static int exec_conf(void)
return WEXITSTATUS(stat);
}
+static struct menu *do_search(struct menu *menu, struct symbol *sym)
+{
+ struct menu *child, *ret;
+ /* Ignore invisible menus ?
+ if (!menu_is_visible(menu))
+ return NULL;
+ */
+
+ if ( menu->sym ) {
+ if ( menu->sym->name && !strcmp(menu->sym->name, sym->name )) {
+ return menu;
+ }
+ }
+ for (child = menu->list; child; child = child->next) {
+ ret = do_search(child, sym);
+ if ( ret ) return ret;
+ }
+ return NULL;
+}
+
+static void search_conf(char *search_str)
+{
+ struct symbol *sym = NULL;
+ struct menu *menu[32] = { 0 };
+ struct menu *submenu = NULL;
+ FILE *fp = NULL;
+ char *prompt = NULL;
+ int i, j, k;
+ bool hit = false;
+
+ fp = fopen(".search.tmp", "w");
+ if ( fp == NULL ) {
+ perror("fopen");
+ return;
+ }
+ for_all_symbols(i, sym) {
+ if ( sym->name && strstr(sym->name, search_str) ) {
+ submenu = do_search(&rootmenu, sym);
+ j = 0;
+ while ( submenu ) {
+ menu[j++] = submenu;
+ submenu = submenu->parent;
+ }
+ if ( j > 0 ) {
+ if ( sym->prop && sym->prop->text ) {
+ fprintf(fp, "%s (%s)\n",
sym->prop->text, sym->name);
+ } else {
+ fprintf(fp, "%s\n", sym->name);
+ }
+ }
+ for (k = j-2; k > 0; k-- ) {
+ if ( ! hit ) hit = true;
+ submenu = menu[k];
+ prompt = (char*)menu_get_prompt(submenu);
+ if ( submenu->sym ) {
+ fprintf(fp, " -> %s (%s)\n",
prompt, submenu->sym->name);
+ } else {
+ fprintf(fp, " -> %s\n", prompt);
+ }
+ }
+ if ( hit )
+ fprintf(fp, "\n");
+ }
+ }
+ if ( ! hit ) {
+ fprintf(fp, "No matches found.");
+ }
+ fclose(fp);
+ do {
+ cprint_init();
+ cprint("--title");
+ cprint("Search Results");
+ cprint("--textbox");
+ cprint(".search.tmp");
+ cprint("%d", rows);
+ cprint("%d", cols);
+ } while (exec_conf() < 0);
+ unlink(".search.tmp");
+}
+
static void build_conf(struct menu *menu)
{
struct symbol *sym;
@@ -436,6 +517,7 @@ static void conf(struct menu *menu)
const char *prompt = menu_get_prompt(menu);
struct symbol *sym;
char active_entry[40];
+ char *search_str = NULL;
int stat, type, i;
unlink("lxdialog.scrltmp");
@@ -463,6 +545,23 @@ static void conf(struct menu *menu)
cprint(" Save Configuration to an Alternate File");
}
stat = exec_conf();
+ if ( stat == 26 ) {
+ if ( ! strlen(input_buf) ) continue;
+ search_str =
(char*)malloc(sizeof(char)*sizeof(input_buf));
+ if ( search_str == NULL ) {
+ perror("malloc");
+ continue;
+ }
+ /* Capitalizing the string */
+ for ( i = 0; input_buf[i]; i++ ) {
+ search_str[i] = toupper(input_buf[i]);
+ }
+ search_str[i] = '\0';
+ /* Searching and displaying all matches */
+ search_conf( search_str );
+ free(search_str);
+ continue;
+ }
if (stat < 0)
continue;
diff -uprN linux-vanilla/scripts/lxdialog/menubox.c
linux/scripts/lxdialog/menubox.c
--- linux-vanilla/scripts/lxdialog/menubox.c 2004-08-14
13:56:22.000000000 +0300
+++ linux/scripts/lxdialog/menubox.c 2004-08-31 10:15:56.000000000 +0300
@@ -276,6 +276,16 @@ dialog_menu (const char *title, const ch
while (key != ESC) {
key = wgetch(menu);
+ if ( key == '/' ) {
+ int ret = dialog_inputbox("Search Configuration Parameter",
+
"Enter Keyword", height, width,
+
(char *) NULL);
+ if ( ret == 0 )
+ {
+ fprintf(stderr, "%s", dialog_input_result);
+ return 26;
+ }
+ }
if (key < 256 && isalpha(key)) key = tolower(key);
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] Searching parameters in menuconfig
2004-08-31 7:52 [PATCH] Searching parameters in menuconfig Yuval Turgeman
@ 2004-08-31 9:08 ` Andrew Morton
2004-08-31 14:33 ` Roman Zippel
1 sibling, 0 replies; 4+ messages in thread
From: Andrew Morton @ 2004-08-31 9:08 UTC (permalink / raw)
To: Yuval Turgeman; +Cc: sam, linux-kernel
Yuval Turgeman <yuvalt@gmail.com> wrote:
>
> Added support for searching parameters in make menuconfig.
> Can be compiled with gcc-2.95 now...
> ( If I didn't mention this before, pressing '/' invokes the search window )
Your mailer wordwrapped the patch.
I already fixed the gcc-2.95 thing.
Please make any changes relative to the below:
--- 25/scripts/kconfig/mconf.c~searching-for-parameters-in-make-menuconfig 2004-08-31 01:55:58.000000000 -0700
+++ 25-akpm/scripts/kconfig/mconf.c 2004-08-31 02:00:54.300526448 -0700
@@ -28,7 +28,7 @@ static const char menu_instructions[] =
"<Enter> selects submenus --->. "
"Highlighted letters are hotkeys. "
"Pressing <Y> includes, <N> excludes, <M> modularizes features. "
- "Press <Esc><Esc> to exit, <?> for Help. "
+ "Press <Esc><Esc> to exit, <?> for Help, </> for Search. "
"Legend: [*] built-in [ ] excluded <M> module < > module capable",
radiolist_instructions[] =
"Use the arrow keys to navigate this window or "
@@ -102,6 +102,7 @@ static void show_textbox(const char *tit
static void show_helptext(const char *title, const char *text);
static void show_help(struct menu *menu);
static void show_readme(void);
+static void search_conf(char *);
static void cprint_init(void);
static int cprint1(const char *fmt, ...);
@@ -274,6 +275,86 @@ static int exec_conf(void)
return WEXITSTATUS(stat);
}
+static struct menu *do_search(struct menu *menu, struct symbol *sym)
+{
+ struct menu *child, *ret;
+ /* Ignore invisible menus ?
+ if (!menu_is_visible(menu))
+ return NULL;
+ */
+
+ if (menu->sym) {
+ if (menu->sym->name && !strcmp(menu->sym->name, sym->name))
+ return menu;
+ }
+ for (child = menu->list; child; child = child->next) {
+ ret = do_search(child, sym);
+ if (ret)
+ return ret;
+ }
+ return NULL;
+}
+
+static void search_conf(char *search_str)
+{
+ struct symbol *sym;
+ struct menu *menu[32] = { 0 };
+ int i, j, k;
+ FILE *fp;
+ bool hit = false;
+
+ fp = fopen(".search.tmp", "w");
+ if (fp == NULL) {
+ perror("fopen");
+ return;
+ }
+ for_all_symbols(i, sym) {
+ if (sym->name && strstr(sym->name, search_str)) {
+ struct menu *submenu = do_search(&rootmenu, sym);
+
+ j = 0;
+ while (submenu) {
+ menu[j++] = submenu;
+ submenu = submenu->parent;
+ }
+ if (j > 0) {
+ if (sym->prop && sym->prop->text)
+ fprintf(fp, "%s (%s)\n",
+ sym->prop->text, sym->name);
+ else
+ fprintf(fp, "%s\n", sym->name);
+ }
+ for (k = j-2; k > 0; k--) {
+ if (!hit)
+ hit = true;
+ submenu = menu[k];
+ const char *prompt = menu_get_prompt(submenu);
+ if (submenu->sym)
+ fprintf(fp, " -> %s (%s)\n",
+ prompt, submenu->sym->name);
+ else
+ fprintf(fp, " -> %s\n", prompt);
+ }
+ if (hit)
+ fprintf(fp, "\n");
+ }
+ }
+ if (!hit)
+ fprintf(fp, "No matches found.");
+ fclose(fp);
+
+ do {
+ cprint_init();
+ cprint("--title");
+ cprint("Search Results");
+ cprint("--textbox");
+ cprint(".search.tmp");
+ cprint("%d", rows);
+ cprint("%d", cols);
+ } while (exec_conf() < 0);
+ unlink(".search.tmp");
+}
+
static void build_conf(struct menu *menu)
{
struct symbol *sym;
@@ -463,6 +544,25 @@ static void conf(struct menu *menu)
cprint(" Save Configuration to an Alternate File");
}
stat = exec_conf();
+ if (stat == 26) {
+ char *search_str;
+
+ if (!strlen(input_buf))
+ continue;
+ search_str = malloc(sizeof(char)*sizeof(input_buf));
+ if (search_str == NULL) {
+ perror("malloc");
+ continue;
+ }
+ /* Capitalizing the string */
+ for (i = 0; input_buf[i]; i++)
+ search_str[i] = toupper(input_buf[i]);
+ search_str[i] = '\0';
+ /* Searching and displaying all matches */
+ search_conf(search_str);
+ free(search_str);
+ continue;
+ }
if (stat < 0)
continue;
diff -puN scripts/lxdialog/menubox.c~searching-for-parameters-in-make-menuconfig scripts/lxdialog/menubox.c
--- 25/scripts/lxdialog/menubox.c~searching-for-parameters-in-make-menuconfig 2004-08-31 01:55:58.000000000 -0700
+++ 25-akpm/scripts/lxdialog/menubox.c 2004-08-31 01:57:40.000000000 -0700
@@ -276,6 +276,15 @@ dialog_menu (const char *title, const ch
while (key != ESC) {
key = wgetch(menu);
+ if ( key == '/' ) {
+ int ret = dialog_inputbox("Search Configuration Parameter",
+ "Enter Keyword", height, width,
+ (char *) NULL);
+ if (ret == 0) {
+ fprintf(stderr, "%s", dialog_input_result);
+ return 26;
+ }
+ }
if (key < 256 && isalpha(key)) key = tolower(key);
_
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] Searching parameters in menuconfig
2004-08-31 7:52 [PATCH] Searching parameters in menuconfig Yuval Turgeman
2004-08-31 9:08 ` Andrew Morton
@ 2004-08-31 14:33 ` Roman Zippel
2004-08-31 15:12 ` Yuval Turgeman
1 sibling, 1 reply; 4+ messages in thread
From: Roman Zippel @ 2004-08-31 14:33 UTC (permalink / raw)
To: Yuval Turgeman; +Cc: sam, linux-kernel
Hi,
On Tue, 31 Aug 2004, Yuval Turgeman wrote:
> Added support for searching parameters in make menuconfig.
> Can be compiled with gcc-2.95 now...
Andrew already commented on the coding style, so I can skip that.
> +static struct menu *do_search(struct menu *menu, struct symbol *sym)
> +{
> + struct menu *child, *ret;
> + /* Ignore invisible menus ?
> + if (!menu_is_visible(menu))
> + return NULL;
> + */
> +
> + if ( menu->sym ) {
> + if ( menu->sym->name && !strcmp(menu->sym->name, sym->name )) {
> + return menu;
> + }
> + }
> + for (child = menu->list; child; child = child->next) {
> + ret = do_search(child, sym);
> + if ( ret ) return ret;
> + }
> + return NULL;
> +}
You get to this information easier by iterating over the properties
attached to a symbol (sym->prop) and a symbol can have multiple menu
prompts, you show only the first one (which might not be the right one)
and sym->prop->text might not even be a menu prompt at all.
It would be nice to actually make it really useful, by first building a
list of found symbols (and possibly allow wildcards for searching) and
generate a menu of this. After a symbol is selected, build a new menu with
all the prompts, which could also include the option to change parent
symbols.
bye, Roman
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] Searching parameters in menuconfig
2004-08-31 14:33 ` Roman Zippel
@ 2004-08-31 15:12 ` Yuval Turgeman
0 siblings, 0 replies; 4+ messages in thread
From: Yuval Turgeman @ 2004-08-31 15:12 UTC (permalink / raw)
To: Roman Zippel; +Cc: sam, linux-kernel
On Tue, 31 Aug 2004 16:33:36 +0200 (CEST), Roman Zippel
<zippel@linux-m68k.org> wrote:
> Andrew already commented on the coding style, so I can skip that.
Yeah sorry about that... I didn't read the CodingStyle doc... I'll pay
more attention to it from now on.
> You get to this information easier by iterating over the properties
> attached to a symbol (sym->prop) and a symbol can have multiple menu
> prompts, you show only the first one (which might not be the right one)
> and sym->prop->text might not even be a menu prompt at all.
Ok, I wasn't aware that a symbol could be located in several submenus
- I just tried to follow the build_conf routine.
> It would be nice to actually make it really useful, by first building a
> list of found symbols (and possibly allow wildcards for searching) and
> generate a menu of this. After a symbol is selected, build a new menu with
> all the prompts, which could also include the option to change parent
> symbols.
Yeah I tought about it also - I guess I'll try to implement this soon.
The usability of the search can be improved a lot... this was just a
tiny prototype to help me find the parameter i was missing. :-)
Thanks!
--
Yuval Turgeman
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2004-08-31 15:14 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-08-31 7:52 [PATCH] Searching parameters in menuconfig Yuval Turgeman
2004-08-31 9:08 ` Andrew Morton
2004-08-31 14:33 ` Roman Zippel
2004-08-31 15:12 ` Yuval Turgeman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox