Commit ab45d190 authored by Roman Zippel's avatar Roman Zippel Committed by Sam Ravnborg

kconfig: create links in info window

Extend the expression print helper function to allow customization of the
symbol output and use it to add links to the info window.
Signed-off-by: default avatarRoman Zippel <zippel@linux-m68k.org>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarSam Ravnborg <sam@ravnborg.org>
parent 7fc925fd
...@@ -1013,73 +1013,73 @@ int expr_compare_type(enum expr_type t1, enum expr_type t2) ...@@ -1013,73 +1013,73 @@ int expr_compare_type(enum expr_type t1, enum expr_type t2)
#endif #endif
} }
void expr_print(struct expr *e, void (*fn)(void *, const char *), void *data, int prevtoken) void expr_print(struct expr *e, void (*fn)(void *, struct symbol *, const char *), void *data, int prevtoken)
{ {
if (!e) { if (!e) {
fn(data, "y"); fn(data, NULL, "y");
return; return;
} }
if (expr_compare_type(prevtoken, e->type) > 0) if (expr_compare_type(prevtoken, e->type) > 0)
fn(data, "("); fn(data, NULL, "(");
switch (e->type) { switch (e->type) {
case E_SYMBOL: case E_SYMBOL:
if (e->left.sym->name) if (e->left.sym->name)
fn(data, e->left.sym->name); fn(data, e->left.sym, e->left.sym->name);
else else
fn(data, "<choice>"); fn(data, NULL, "<choice>");
break; break;
case E_NOT: case E_NOT:
fn(data, "!"); fn(data, NULL, "!");
expr_print(e->left.expr, fn, data, E_NOT); expr_print(e->left.expr, fn, data, E_NOT);
break; break;
case E_EQUAL: case E_EQUAL:
fn(data, e->left.sym->name); fn(data, e->left.sym, e->left.sym->name);
fn(data, "="); fn(data, NULL, "=");
fn(data, e->right.sym->name); fn(data, e->right.sym, e->right.sym->name);
break; break;
case E_UNEQUAL: case E_UNEQUAL:
fn(data, e->left.sym->name); fn(data, e->left.sym, e->left.sym->name);
fn(data, "!="); fn(data, NULL, "!=");
fn(data, e->right.sym->name); fn(data, e->right.sym, e->right.sym->name);
break; break;
case E_OR: case E_OR:
expr_print(e->left.expr, fn, data, E_OR); expr_print(e->left.expr, fn, data, E_OR);
fn(data, " || "); fn(data, NULL, " || ");
expr_print(e->right.expr, fn, data, E_OR); expr_print(e->right.expr, fn, data, E_OR);
break; break;
case E_AND: case E_AND:
expr_print(e->left.expr, fn, data, E_AND); expr_print(e->left.expr, fn, data, E_AND);
fn(data, " && "); fn(data, NULL, " && ");
expr_print(e->right.expr, fn, data, E_AND); expr_print(e->right.expr, fn, data, E_AND);
break; break;
case E_CHOICE: case E_CHOICE:
fn(data, e->right.sym->name); fn(data, e->right.sym, e->right.sym->name);
if (e->left.expr) { if (e->left.expr) {
fn(data, " ^ "); fn(data, NULL, " ^ ");
expr_print(e->left.expr, fn, data, E_CHOICE); expr_print(e->left.expr, fn, data, E_CHOICE);
} }
break; break;
case E_RANGE: case E_RANGE:
fn(data, "["); fn(data, NULL, "[");
fn(data, e->left.sym->name); fn(data, e->left.sym, e->left.sym->name);
fn(data, " "); fn(data, NULL, " ");
fn(data, e->right.sym->name); fn(data, e->right.sym, e->right.sym->name);
fn(data, "]"); fn(data, NULL, "]");
break; break;
default: default:
{ {
char buf[32]; char buf[32];
sprintf(buf, "<unknown type %d>", e->type); sprintf(buf, "<unknown type %d>", e->type);
fn(data, buf); fn(data, NULL, buf);
break; break;
} }
} }
if (expr_compare_type(prevtoken, e->type) > 0) if (expr_compare_type(prevtoken, e->type) > 0)
fn(data, ")"); fn(data, NULL, ")");
} }
static void expr_print_file_helper(void *data, const char *str) static void expr_print_file_helper(void *data, struct symbol *sym, const char *str)
{ {
fwrite(str, strlen(str), 1, data); fwrite(str, strlen(str), 1, data);
} }
...@@ -1089,7 +1089,7 @@ void expr_fprint(struct expr *e, FILE *out) ...@@ -1089,7 +1089,7 @@ void expr_fprint(struct expr *e, FILE *out)
expr_print(e, expr_print_file_helper, out, E_NONE); expr_print(e, expr_print_file_helper, out, E_NONE);
} }
static void expr_print_gstr_helper(void *data, const char *str) static void expr_print_gstr_helper(void *data, struct symbol *sym, const char *str)
{ {
str_append((struct gstr*)data, str); str_append((struct gstr*)data, str);
} }
......
...@@ -39,4 +39,4 @@ P(prop_get_type_name,const char *,(enum prop_type type)); ...@@ -39,4 +39,4 @@ P(prop_get_type_name,const char *,(enum prop_type type));
/* expr.c */ /* expr.c */
P(expr_compare_type,int,(enum expr_type t1, enum expr_type t2)); P(expr_compare_type,int,(enum expr_type t1, enum expr_type t2));
P(expr_print,void,(struct expr *e, void (*fn)(void *, const char *), void *data, int prevtoken)); P(expr_print,void,(struct expr *e, void (*fn)(void *, struct symbol *, const char *), void *data, int prevtoken));
...@@ -925,6 +925,8 @@ void ConfigInfoView::setShowDebug(bool b) ...@@ -925,6 +925,8 @@ void ConfigInfoView::setShowDebug(bool b)
_showDebug = b; _showDebug = b;
if (menu) if (menu)
menuInfo(); menuInfo();
else if (sym)
symbolInfo();
emit showDebugChanged(b); emit showDebugChanged(b);
} }
} }
...@@ -943,13 +945,42 @@ void ConfigInfoView::setSource(const QString& name) ...@@ -943,13 +945,42 @@ void ConfigInfoView::setSource(const QString& name)
const char *p = name.latin1(); const char *p = name.latin1();
menu = NULL; menu = NULL;
sym = NULL;
switch (p[0]) { switch (p[0]) {
case 'm': case 'm':
if (sscanf(p, "m%p", &menu) == 1) struct menu *m;
if (sscanf(p, "m%p", &m) == 1 && menu != m) {
menu = m;
menuInfo(); menuInfo();
}
break; break;
case 's':
struct symbol *s;
if (sscanf(p, "s%p", &s) == 1 && sym != s) {
sym = s;
symbolInfo();
} }
break;
}
}
void ConfigInfoView::symbolInfo(void)
{
QString str;
str += "<big>Symbol: <b>";
str += print_filter(sym->name);
str += "</b></big><br><br>value: ";
str += print_filter(sym_get_string_value(sym));
str += "<br>visibility: ";
str += sym->visible == yes ? "y" : sym->visible == mod ? "m" : "n";
str += "<br>";
str += debug_info(sym);
setText(str);
} }
void ConfigInfoView::menuInfo(void) void ConfigInfoView::menuInfo(void)
...@@ -965,12 +996,20 @@ void ConfigInfoView::menuInfo(void) ...@@ -965,12 +996,20 @@ void ConfigInfoView::menuInfo(void)
head += "</b></big>"; head += "</b></big>";
if (sym->name) { if (sym->name) {
head += " ("; head += " (";
if (showDebug())
head += QString().sprintf("<a href=\"s%p\">", sym);
head += print_filter(sym->name); head += print_filter(sym->name);
if (showDebug())
head += "</a>";
head += ")"; head += ")";
} }
} else if (sym->name) { } else if (sym->name) {
head += "<big><b>"; head += "<big><b>";
if (showDebug())
head += QString().sprintf("<a href=\"s%p\">", sym);
head += print_filter(sym->name); head += print_filter(sym->name);
if (showDebug())
head += "</a>";
head += "</b></big>"; head += "</b></big>";
} }
head += "<br><br>"; head += "<br><br>";
...@@ -1015,9 +1054,9 @@ QString ConfigInfoView::debug_info(struct symbol *sym) ...@@ -1015,9 +1054,9 @@ QString ConfigInfoView::debug_info(struct symbol *sym)
switch (prop->type) { switch (prop->type) {
case P_PROMPT: case P_PROMPT:
case P_MENU: case P_MENU:
debug += "prompt: "; debug += QString().sprintf("prompt: <a href=\"m%p\">", prop->menu);
debug += print_filter(_(prop->text)); debug += print_filter(_(prop->text));
debug += "<br>"; debug += "</a><br>";
break; break;
case P_DEFAULT: case P_DEFAULT:
debug += "default: "; debug += "default: ";
...@@ -1088,9 +1127,17 @@ QString ConfigInfoView::print_filter(const QString &str) ...@@ -1088,9 +1127,17 @@ QString ConfigInfoView::print_filter(const QString &str)
return res; return res;
} }
void ConfigInfoView::expr_print_help(void *data, const char *str) void ConfigInfoView::expr_print_help(void *data, struct symbol *sym, const char *str)
{ {
reinterpret_cast<QString*>(data)->append(print_filter(str)); QString* text = reinterpret_cast<QString*>(data);
QString str2 = print_filter(str);
if (sym && sym->name && !(sym->flags & SYMBOL_CONST)) {
*text += QString().sprintf("<a href=\"s%p\">", sym);
*text += str2;
*text += "</a>";
} else
*text += str2;
} }
QPopupMenu* ConfigInfoView::createPopupMenu(const QPoint& pos) QPopupMenu* ConfigInfoView::createPopupMenu(const QPoint& pos)
......
...@@ -260,13 +260,15 @@ public slots: ...@@ -260,13 +260,15 @@ public slots:
void showDebugChanged(bool); void showDebugChanged(bool);
protected: protected:
void symbolInfo(void);
void menuInfo(void); void menuInfo(void);
QString debug_info(struct symbol *sym); QString debug_info(struct symbol *sym);
static QString print_filter(const QString &str); static QString print_filter(const QString &str);
static void expr_print_help(void *data, const char *str); static void expr_print_help(void *data, struct symbol *sym, const char *str);
QPopupMenu* createPopupMenu(const QPoint& pos); QPopupMenu* createPopupMenu(const QPoint& pos);
void contentsContextMenuEvent(QContextMenuEvent *e); void contentsContextMenuEvent(QContextMenuEvent *e);
struct symbol *sym;
struct menu *menu; struct menu *menu;
bool _showDebug; bool _showDebug;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment