Skip to contentSkip to conversation

kconfig:

DISCUSSION Sam Ravnborg 3 participants 14 messages Dec 30, 2004 – Jan 6, 2005 Kconfig

lore
Share & tools
lore
#0 lore raw

Hi Roman & lkml

Here follows a few kconfig patches.
Main purpose is to improve readability of the output when doing search and to inculde dependency information in the help text.

They are not pushed to my kbuild tree yet - will see if this generate any feedback first.

One will now see something like this when getting help on a menu item:

CONFIG_FOO
bla bla bla

depends on:
USB
selects:
HOTPLUG
selected by:
FW_LOADER

Empty lines are omitted - so a symbol that does not seletcs any other symbol the symbol line will not appear.

Let me know if you want me to push them towards mainstream.

Sam

#1 lore raw

kconfig: avoid temporary file

# This is a BitKeeper generated diff -Nru style patch. #
# ChangeSet
# 2004/12/30 22:30:10+01:00 [email protected]
# kconfig: avoid temporary file
#
# Use a growable string when building up result of searching - avoiding an additional
# temporary file. A temporary file is still used but on a higher level.
#
# Signed-off-by: Sam Ravnborg <[email protected]>
#

# scripts/kconfig/mconf.c
#   2004/12/30 22:29:51+01:00 [email protected] +78 -28
#   introduce a general growable string.
#   Allow us to skip one additional temporary file
# 
diff -Nru a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c
--- a/scripts/kconfig/mconf.c	2004-12-31 00:45:13 +01:00
+++ b/scripts/kconfig/mconf.c	2004-12-31 00:45:13 +01:00
@@ -104,7 +104,6 @@
 static void show_help(struct menu *menu);
 static void show_readme(void);
 static void show_file(const char *filename, const char *title, int r, int c);
-static void show_expr(struct menu *menu, FILE *fp);
 static void search_conf(char *pattern);
 static int regex_match(const char *string, regex_t *re);

@@ -113,6 +112,53 @@
static void cprint_done(void);
static int cprint(const char *fmt, ...);

+/* Growable string. Allocates memory as needed when string expands */ +struct gstr {
+ char *s;
+ size_t len;
+};
+
+static struct gstr str_init(void)
+{
+ struct gstr gs;
+ gs.s = malloc(sizeof(char) * 16);
+ strcpy(gs.s, "\0");
+ gs.len = 16;
+ return gs;
+}
+
+static void str_del(struct gstr *gs)
+{
+ if (gs->len && gs->s)
+ free(gs->s);
+ gs->s = NULL;
+ gs->len = 0;
+}
+
+static void str_add(struct gstr *gs, const char *s)
+{
+ size_t l = strlen(gs->s) + strlen(s) + 1;
+ if (l >= gs->len)
+ gs->s = realloc(gs->s, l);
+ gs->len = l;
+ strcat(gs->s, s);
+}
+
+static void str_printf(struct gstr *gs, const char *fmt, ...) +{
+ va_list ap;
+ char s[1024];
+ va_start(ap, fmt);
+ vsnprintf(s, sizeof(s), fmt, ap);
+ str_add(gs, s);
+ va_end(ap);
+}
+
+static const char *str_get(struct gstr *gs)
+{
+ return gs->s;
+}
+
static void init_wsize(void)
{
struct winsize ws;
@@ -289,36 +335,46 @@
return 1;
}

-static void show_expr(struct menu *menu, FILE *fp) +static void expr_print_str_helper(void *data, const char *str) +{
+ str_add((struct gstr*)data, str);
+}
+
+static void expr_str(struct expr *e, struct gstr *gs) +{
+ expr_print(e, expr_print_str_helper, gs, E_NONE);
+}
+
+static void show_expr(struct menu *menu, struct gstr *gs)
{
bool hit = false;
- fprintf(fp, "Depends:\n ");
+ str_add(gs, "Depends:\n ");
if (menu->prompt->visible.expr) {
if (!hit)
hit = true;
- expr_fprint(menu->prompt->visible.expr, fp);
+ expr_str(menu->prompt->visible.expr, gs);
}
if (!hit)
- fprintf(fp, "None");
+ str_add(gs, "None");
if (menu->sym) {
struct property *prop;
hit = false;
- fprintf(fp, "\nSelects:\n ");
+ str_add(gs, "\nSelects:\n ");
for_all_properties(menu->sym, prop, P_SELECT) {
if (!hit)
hit = true;
- expr_fprint(prop->expr, fp);
+ expr_str(prop->expr, gs);
}
if (!hit)
- fprintf(fp, "None");
+ str_add(gs, "None");
hit = false;
- fprintf(fp, "\nSelected by:\n ");
+ str_add(gs, "\nSelected by:\n ");
if (menu->sym->rev_dep.expr) {
hit = true;
- expr_fprint(menu->sym->rev_dep.expr, fp);
+ expr_str(menu->sym->rev_dep.expr, gs);
}
if (!hit)
- fprintf(fp, "None");
+ str_add(gs, "None");
}
}

@@ -327,19 +383,13 @@
struct symbol *sym = NULL;
struct menu *menu[32] = { 0 };
struct property *prop = NULL;
- FILE *fp = NULL;
+ struct gstr str = str_init();
bool hit = false;
int i, j, k, l;
regex_t re;

if (regcomp(&re, pattern, REG_EXTENDED|REG_NOSUB))
return;
-
- fp = fopen(".search.tmp", "w");
- if (fp == NULL) {
- perror("fopen");
- return;
- }
for_all_symbols(i, sym) {
if (!sym->name)
continue;
@@ -358,33 +408,33 @@
if (j > 0) {
if (!hit)
hit = true;
- fprintf(fp, "%s (%s)\n", prop->text, sym->name);
- fprintf(fp, "Location:\n");
+ str_printf(&str, "%s (%s)\n",
+ prop->text, sym->name);
+ str_add(&str, "Location:\n");
}
for (k = j-2, l=1; k > 0; k--, l++) {
const char *prompt = menu_get_prompt(menu[k]); if (menu[k]->sym)
- fprintf(fp, "%*c-> %s (%s)\n",
+ str_printf(&str, "%*c-> %s (%s)\n",
l, ' ', prompt, menu[k]->sym->name);
else
- fprintf(fp, "%*c-> %s\n",
+ str_printf(&str, "%*c-> %s\n",
l, ' ', prompt);
}
if (hit) {
- show_expr(menu[0], fp);
- fprintf(fp, "\n\n\n");
+ show_expr(menu[0], &str);
+ str_add(&str, "\n\n\n");
}
}
}
if (!hit)
- fprintf(fp, "No matches found.");
+ str_add(&str, "No matches found.");
regfree(&re);
- fclose(fp);
- show_file(".search.tmp", "Search Results", rows, cols);
- unlink(".search.tmp");
+ show_textbox("Search Results", str_get(&str), rows, cols);
+ str_del(&str);
}

static void build_conf(struct menu *menu)

#2 lore raw

Re: kconfig: avoid temporary file

Hi,

Quoted 4 lines · Sam Ravnborg
# scripts/kconfig/mconf.c
#   2004/12/30 22:29:51+01:00 [email protected] +78 -28
#   introduce a general growable string.
#   Allow us to skip one additional temporary file

I'm not really against the change, but the reason is weird. In the end the string is still written to a file anyway...

Review

Quoted 5 lines
(quoted diff) +5 -0
+/* Growable string. Allocates memory as needed when string expands */
+struct gstr {
+ char *s;
+ size_t len;
+};

I would prefer something more like this:

struct gstr {
int size;
char s[0];
};

and this would be better names for the functions:

struct gstr *str_new(void);
void str_free(struct gstr *gs);
void str_append(struct gstr *gs, const char *s);

It would be useful to have these sort of functions in the library, so we can e.g. use them to dynamically generate the help text.

bye, Roman

#3 lore raw

Re: kconfig: avoid temporary file

Quoted 3 lines · Roman Zippel

I'm not really against the change, but the reason is weird. In the end the string is still written to a file anyway...

Next step is to integrate Petr Baudis patch to link lxdialog with mconf. Then it is nice to get rid of the file based interface.

Quoted 13 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+/* Growable string. Allocates memory as needed when string expands */
+struct gstr {
+ char *s;
+ size_t len;
+};

I would prefer something more like this:

struct gstr {
int size;
char s[0];
};

Quoted 8 lines

and this would be better names for the functions:

struct gstr *str_new(void);
void str_free(struct gstr *gs);
void str_append(struct gstr *gs, const char *s);

It would be useful to have these sort of functions in the library, so we can e.g. use them to dynamically generate the help text.

I will update my patch with your suggestions later this week.

Sam

#4 lore raw

Re: kconfig: avoid temporary file

Hi,

Quoted 1 line · Sam Ravnborg

Next step is to integrate Petr Baudis patch to link lxdialog with mconf.

I had two major problems with his patch:
- it didn't resize when the terminal changed.
- window layering, old windows are not removed and just drawn over (this was especially a problem with help texts).

The current approach solves this rather nicely by just reinitialising everything.

#5 lore raw

Re: kconfig: avoid temporary file

Quoted 8 lines · Roman Zippel

Hi,

Quoted 1 line · Sam Ravnborg

Next step is to integrate Petr Baudis patch to link lxdialog with mconf.

I had two major problems with his patch:
- it didn't resize when the terminal changed.

Resize support will not be added until it works.

Quoted 2 lines

- window layering, old windows are not removed and just drawn over (this was especially a problem with help texts).

Did not see it as a problem as such - will try to play with it a bit more. I have the original patch more or less blindly applied. For an acceptable version a parts of it will be redone.

I also noticed that ESC was not working as usual.

Sam

#6 lore raw

Re: kconfig: avoid temporary file

Hi,

Quoted 3 lines · Sam Ravnborg
Quoted 1 line

- it didn't resize when the terminal changed.

Resize support will not be added until it works.

Well, please keep it mind. I don't want to lose this feature, because you had to rewrite everything once again.

Quoted 6 lines
Quoted 2 lines

- window layering, old windows are not removed and just drawn over (this was especially a problem with help texts).

Did not see it as a problem as such - will try to play with it a bit more. I have the original patch more or less blindly applied. For an acceptable version a parts of it will be redone.

Try to select help from an input or choice dialog - it's ugly. The current interface expects that only a single dialog window is visible at a time, maybe it's better to keep this behaviour for the first version, do some cleanups and add new features later.

Quoted 1 line

I also noticed that ESC was not working as usual.

Yes, now I remember that one too, but it's already some time ago, I tested this. :)

bye, Roman

#7 lore raw

kconfig: remove noise from show_expr

In reply to Sam Ravnborg

# This is a BitKeeper generated diff -Nru style patch. #
# ChangeSet
# 2004/12/31 00:36:09+01:00 [email protected]
# kconfig: remove noise from show_expr
#
# This makes readout more compact when searching for specific symbols
#
# Signed-off-by: Sam Ravnborg <[email protected]>
#

# scripts/kconfig/mconf.c
#   2004/12/31 00:35:50+01:00 [email protected] +7 -17
#   avoid printing empty information in show_expr
#   increase buffer size in str_printf - people write that big text blocks
# 
diff -Nru a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c
--- a/scripts/kconfig/mconf.c	2004-12-31 00:45:40 +01:00
+++ b/scripts/kconfig/mconf.c	2004-12-31 00:45:40 +01:00
@@ -147,7 +147,7 @@
 static void str_printf(struct gstr *gs, const char *fmt, ...)
 {
 	va_list ap;
-	char s[1024];
+	char s[4096];
 	va_start(ap, fmt);
 	vsnprintf(s, sizeof(s), fmt, ap);
 	str_add(gs, s);
@@ -347,34 +347,24 @@

static void show_expr(struct menu *menu, struct gstr *gs) {
- bool hit = false;
- str_add(gs, "Depends:\n ");
if (menu->prompt->visible.expr) {
- if (!hit)
- hit = true;
+ str_add(gs, "\ndepends on:\n ");
expr_str(menu->prompt->visible.expr, gs);
}
- if (!hit)
- str_add(gs, "None");
if (menu->sym) {
struct property *prop;
- hit = false;
- str_add(gs, "\nSelects:\n ");
+ bool hit = false;
for_all_properties(menu->sym, prop, P_SELECT) {
- if (!hit)
+ if (!hit) {
+ str_add(gs, "\nselects:\n ");
hit = true;
+ }
expr_str(prop->expr, gs);
}
- if (!hit)
- str_add(gs, "None");
- hit = false;
- str_add(gs, "\nSelected by:\n ");
if (menu->sym->rev_dep.expr) {
- hit = true;
+ str_add(gs, "\nselected by:\n ");
expr_str(menu->sym->rev_dep.expr, gs);
}
- if (!hit)
- str_add(gs, "None");
}
}

#8 lore raw

kconfig: help includes dependency information

In reply to Sam Ravnborg

# This is a BitKeeper generated diff -Nru style patch. #
# ChangeSet
# 2004/12/31 00:43:45+01:00 [email protected]
# kconfig: help includes dependency information
#

#   When selecting help on a menu item display
#   "depends on:"
#   "selects:"
#   "selected by:"
#   
#   Only relevant headlines are displayed - so if no "selects:" appear then this menu
#   does not select a specific symbol.
#   Loosly based on a patch by: Cal Peake <[email protected]>
#   
#   Signed-off-by: Sam Ravnborg <[email protected]>
# 
# scripts/kconfig/mconf.c
#   2004/12/31 00:43:27+01:00 [email protected] +5 -5
#   display
#   "depends on:"
#   "selects:"
#   "selected by:"
#   
#   information when selecting help on a menu
# 
diff -Nru a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c
--- a/scripts/kconfig/mconf.c	2004-12-31 00:46:29 +01:00
+++ b/scripts/kconfig/mconf.c	2004-12-31 00:46:29 +01:00
@@ -732,17 +732,17 @@
 static void show_help(struct menu *menu)
 {
 	const char *help;
-	char *helptext;
 	struct symbol *sym = menu->sym;

help = sym->help;
if (!help)
help = nohelp_text;
if (sym->name) {
- helptext = malloc(strlen(sym->name) + strlen(help) + 16);
- sprintf(helptext, "CONFIG_%s:\n\n%s", sym->name, help);
- show_helptext(menu_get_prompt(menu), helptext);
- free(helptext);
+ struct gstr str = str_init();
+ str_printf(&str, "CONFIG_%s:\n\n%s", sym->name, help);
+ show_expr(menu, &str);
+ show_helptext(menu_get_prompt(menu), str_get(&str));
+ str_del(&str);
} else
show_helptext(menu_get_prompt(menu), help);
}

#9 lore raw

Re: kconfig: help includes dependency information

Hi Sam,

nice to have this information available now.

Quoted 6 lines · Sam Ravnborg

# This is a BitKeeper generated diff -Nru style patch. #
# ChangeSet
# 2004/12/31 00:43:45+01:00 [email protected]
# kconfig: help includes dependency information
#

Quoted 8 lines
#   When selecting help on a menu item display
#   "depends on:"
#   "selects:"
#   "selected by:"

#
# Only relevant headlines are displayed - so if no "selects:" appear then
this menu # does not select a specific symbol.
# Loosly based on a patch by: Cal Peake <[email protected]>

I would prefer this information at the END of the help text, since it is actually most useful to developers and more advanced users and thus equals in value to the old notice how a module is called.

If I call for help, I usually like to know WHAT it is and then WHY I might need it.

Using the verbose config information and linking to their help texts would make it even more user friendly in my opinion.

"depends on:" is not really needed, since you usually cannot select any option, where you didn't fulfill the dependencies, AFAICS.

Regards

Ingo Oeser

#10 lore raw

Re: kconfig: help includes dependency information

Quoted 4 lines · Ingo Oeser

I would prefer this information at the END of the help text, since it is actually most useful to developers and more advanced users and thus equals in value to the old notice how a module is called.

Thats where it is placed.

Quoted 2 lines

Using the verbose config information and linking to their help texts would make it even more user friendly in my opinion.

verbose config option - please explain what you have in mind here.

Quoted 2 lines

"depends on:" is not really needed, since you usually cannot select any option, where you didn't fulfill the dependencies, AFAICS.

It is sometimes usefull to see what a specific config option is dependent of. But you are right that it is not visible in menuconfig (today) when "depends on" is not satisfied.

I'm digging through Petr Baudis patch to link lxdialog with kconfig - and when finished I may look into extending menuconfig a bit.

Sam

#11 lore raw

Re: kconfig: help includes dependency information

Hi Sam,
hi Roman,

Quoted 4 lines · Sam Ravnborg
Quoted 2 lines

Using the verbose config information and linking to their help texts would make it even more user friendly in my opinion.

verbose config option - please explain what you have in mind here.

Example from drivers/char/Kconfig:

SERIAL_NONSTANDARD - the config option
"Non-standard serial port support" - the verbose config option

please present the latter to the user, if not done already.

Quoted 6 lines
Quoted 2 lines

"depends on:" is not really needed, since you usually cannot select any option, where you didn't fulfill the dependencies, AFAICS.

It is sometimes usefull to see what a specific config option is dependent of. But you are right that it is not visible in menuconfig (today) when "depends on" is not satisfied.

Yes, I've been told later, that you see that in xconfig. I only use either menuconfig or oldconfig, so I've never seen that before ;-)

Regards

Ingo Oeser

#12 lore raw
In reply to Sam Ravnborg

Hi,

Quoted 3 lines · Sam Ravnborg

Here follows a few kconfig patches.
Main purpose is to improve readability of the output when doing search and to inculde dependency information in the help text.

I completely missed that the search patch was already merged... :-( It wasn't ready yet, it was still a quick hack. I attached a patch which does the basic cleanup, so that it not only works for the trivial cases.

bye, Roman

 kconfig/lkc_proto.h |    1 
 kconfig/mconf.c     |  202 +++++++++++++++++++++-------------------------------
 kconfig/symbol.c    |   35 +++++++++
 lxdialog/menubox.c  |   11 --
 4 files changed, 123 insertions(+), 126 deletions(-)
scripts/lxdialog/menubox.c +2 -9
Index: linux-2.6.10/scripts/lxdialog/menubox.c
===================================================================
@@ -276,15 +276,6 @@ 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);
 
@@ -408,6 +399,7 @@ dialog_menu (const char *title, const ch
 	case 'y':
 	case 'n':
 	case 'm':
+	case '/':
 	    /* save scroll info */
 	    if ( (f=fopen("lxdialog.scrltmp","w")) != NULL ) {
 		fprintf(f,"%d\n",scroll);
@@ -421,6 +413,7 @@ dialog_menu (const char *title, const ch
             case 'n': return 4;
             case 'm': return 5;
             case ' ': return 6;
+            case '/': return 7;
             }
 	    return 0;
 	case 'h':
scripts/kconfig/symbol.c +35 -0
Index: linux-2.6.10/scripts/kconfig/symbol.c
===================================================================
@@ -6,6 +6,7 @@
 #include <ctype.h>
 #include <stdlib.h>
 #include <string.h>
+#include <regex.h>
 #include <sys/utsname.h>
 
 #define LKC_DIRECT_LINK
@@ -656,6 +657,40 @@ struct symbol *sym_find(const char *name
 	return symbol;
 }
 
+struct symbol **sym_re_search(const char *pattern, int flags)
+{
+	struct symbol *sym, **sym_arr = NULL;
+	int i, cnt, size;
+	regex_t re;
+
+	cnt = size = 0;
+	if (regcomp(&re, pattern, REG_EXTENDED|REG_NOSUB|REG_ICASE))
+		return NULL;
+
+	for_all_symbols(i, sym) {       
+		if (sym->flags & SYMBOL_CONST || !sym->name) 
+			continue;
+		if (regexec(&re, sym->name, 0, NULL, 0))
+			continue;
+		if (cnt + 1 >= size) {
+			void *tmp = sym_arr;
+			size += 16;
+			sym_arr = realloc(sym_arr, size * sizeof(struct symbol *));
+			if (!sym_arr) {
+				free(tmp);
+				return NULL;
+			}
+		}
+		sym_arr[cnt++] = sym;
+	}
+	if (sym_arr)
+		sym_arr[cnt] = NULL;
+	regfree(&re);
+
+	return sym_arr;
+}
+
+
 struct symbol *sym_check_deps(struct symbol *sym);
 
 static struct symbol *sym_check_expr_deps(struct expr *e)
scripts/kconfig/mconf.c +85 -117

263 lines not on this page · raw message

scripts/kconfig/lkc_proto.h +1 -0
Index: linux-2.6.10/scripts/kconfig/lkc_proto.h
===================================================================
@@ -18,6 +18,7 @@ P(sym_change_count,int,);
 
 P(sym_lookup,struct symbol *,(const char *name, int isconst));
 P(sym_find,struct symbol *,(const char *name));
+P(sym_re_search,struct symbol **,(const char *pattern, int flags));
 P(sym_type_name,const char *,(enum symbol_type type));
 P(sym_calc_value,void,(struct symbol *sym));
 P(sym_get_type,enum symbol_type,(struct symbol *sym));
#13 lore raw
Quoted 11 lines · Roman Zippel

Hi,

Quoted 3 lines · Sam Ravnborg

Here follows a few kconfig patches.
Main purpose is to improve readability of the output when doing search and to inculde dependency information in the help text.

I completely missed that the search patch was already merged... :-( It wasn't ready yet, it was still a quick hack. I attached a patch which does the basic cleanup, so that it not only works for the trivial cases.

Thanks - looks good at first sight.
I will give it a spin and post updated kconfig patches.

Sam