Skip to contentSkip to conversation

Support loading and saving custom remarks for config symbols

PATCH New Bernhard Kaindl 1 participant 4 messages Oct 28, 2009 4 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): cover.1256767265.git.aragorn@Anduril.(none)

#1 lore raw

PATCH 1/4 Support loading and saving custom remarks for config symbols

Add the infrastructure to load and save remarks for config symbols to the kconfig library functions conf_read() and conf_write()

This
- adds sym->remark
- extends conf_read() to call conf_read_remarks()
- adds conf_read_remarks() which
- reads remarks from a file and
- stores them in sym->remark
- extends conf_write() to save each sym->remark so that conf_read_remarks() will be able to reread them

To not keep any additional file when no remarks exist, and to stay completely out of the way when this feature is not used, conf_write() does not keep empty remarks files, so anyone not using this code will see no changes.

The filename of the remarks file is derived from the used config file name and path by appending "-remarks" to the config file name. So the default remarks file would be ".config-remarks".

This code supports one-line remarks without newlines. The changes to the tools (menuconfig, xconfig, config) also only support one-line remarks as they use the existing UI functions for editing strings.

---
 scripts/kconfig/confdata.c |   45 +++++++++++++++++++++++++++++++++++++++++--
 scripts/kconfig/expr.h     |    1 +
 2 files changed, 43 insertions(+), 3 deletions(-)
scripts/kconfig/confdata.c +42 -3
index 797a741..eee2b60 100644
@@ -152,6 +152,30 @@ static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p)
 	return 0;
 }
 
+/**
+ * Read remarks from -remarks file:
+ */
+void conf_read_remarks(const char *remfile)
+{
+	FILE *in;
+	char line[1024], *p, *p2;
+	struct symbol *sym;
+
+	sprintf(line, "%s-remarks", remfile ? remfile : conf_get_configname());
+	if (!(in = zconf_fopen(line)))
+		return;
+	while (fgets(line, sizeof(line), in)) {
+		if (!(p = strchr(line, ' '))) /* ' ' is our delimiter        */
+			continue;	      /* skip lines without one      */
+		*p++ = '\0';		      /* put a \0 there, advance     */
+		if ((p2 = strchr(p, '\n')))   /* look for \n after remark    */
+			*p2 = '\0';	      /* remove it, no \n in remarks */
+		if ((sym = sym_find(line)))   /* find the matching sym       */
+			sym->remark = strdup(p); /* and register the remark  */
+	}
+	fclose(in);
+}
+
 int conf_read_simple(const char *name, int def)
 {
 	FILE *in = NULL;
@@ -393,16 +417,18 @@ int conf_read(const char *name)
 
 	sym_add_change_count(conf_warnings || conf_unsaved);
 
+	conf_read_remarks(name);
 	return 0;
 }
 
 int conf_write(const char *name)
 {
-	FILE *out;
+	FILE *out, *rem;
+	struct stat sb;
 	struct symbol *sym;
 	struct menu *menu;
 	const char *basename;
-	char dirname[128], tmpname[128], newname[128];
+	char dirname[128], tmpname[128], newname[128], tmprem[128], newrem[128];
 	int type, l;
 	const char *str;
 	time_t now;
@@ -432,15 +458,19 @@ int conf_write(const char *name)
 		basename = conf_get_configname();
 
 	sprintf(newname, "%s%s", dirname, basename);
+	sprintf(newrem, "%s%s-remarks", dirname, basename);
 	env = getenv("KCONFIG_OVERWRITECONFIG");
 	if (!env || !*env) {
 		sprintf(tmpname, "%s.tmpconfig.%d", dirname, (int)getpid());
 		out = fopen(tmpname, "w");
+		sprintf(tmprem, "%s.tmpconfig-remarks.%d", dirname, (int)getpid());
+		rem = fopen(tmprem, "w");
 	} else {
 		*tmpname = 0;
 		out = fopen(newname, "w");
+		rem = fopen(newrem, "w");
 	}
-	if (!out)
+	if (!out || !rem)
 		return 1;
 
 	sym = sym_lookup("KERNELVERSION", 0);
@@ -528,6 +558,8 @@ int conf_write(const char *name)
 		}
 
 	next:
+		if (sym && sym->remark)
+			fprintf(rem, "%s %s\n", sym->name, sym->remark);
 		if (menu->list) {
 			menu = menu->list;
 			continue;
@@ -542,6 +574,7 @@ int conf_write(const char *name)
 		}
 	}
 	fclose(out);
+	fclose(rem);
 
 	if (*tmpname) {
 		strcat(dirname, basename);
@@ -549,7 +582,13 @@ int conf_write(const char *name)
 		rename(newname, dirname);
 		if (rename(tmpname, newname))
 			return 1;
+		sprintf(dirname, "%s.old", newrem);
+		rename(newrem, dirname);
+		if (rename(tmprem, newrem)) 
+			conf_warning("moving %s to %s failed!", tmprem, newrem);
 	}
+	if (!stat(newrem, &sb) && !sb.st_size)
+		unlink(newrem);
 
 	printf(_("#\n"
 		 "# configuration written to %s\n"
scripts/kconfig/expr.h +1 -0
index 6408fef..217e8cb 100644
@@ -77,6 +77,7 @@ enum {
 struct symbol {
 	struct symbol *next;
 	char *name;
+	char *remark;
 	enum symbol_type type;
 	struct symbol_value curr;
 	struct symbol_value def[S_DEF_COUNT];
Signature · 1 line
1.6.0.4

A message that is not in the archive (sent off-list or not yet received): b106dec1237ab723ae6a2404d42601bf20704bf3.1256767265.git.aragorn@Anduril.(none)

#3 lore raw

PATCH 2/4 menuconfig: allow editing of remarks for config symbols

Extend menuconfig to allow editing of remarks for config symbols:

Add a new key to lxdialog (currently '<') which, when pressed, is forwarded to menuconfig, which handles it similar to the search key ('/') which can be used at any time, but passes the currently selected menu entry to conf_remark()

conf_remark() is based on conf_string(), which allows to edit a string, but before, it checks if the passed menu entry is a config symbol, and if not it displays a short notice saying that it currently does not support editing comments for a pure menu entries without attached config symbol.

It then allows to edit a string, which is initialized from the sym->remark entry and if the user changed the string, it updates sym->remark and sets things up so that menuconfig asks to save the config before exiting, so the changed remark is saved in that go.

---
 scripts/kconfig/lxdialog/menubox.c |    3 ++
 scripts/kconfig/mconf.c            |   51 ++++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+), 0 deletions(-)
scripts/kconfig/lxdialog/menubox.c +3 -0
index fa9d633..6b6bc48 100644
@@ -383,6 +383,7 @@ do_resize:
 		case 'n':
 		case 'm':
 		case '/':
+		case '<':
 			/* save scroll info */
 			*s_scroll = scroll;
 			delwin(menu);
@@ -402,6 +403,8 @@ do_resize:
 				return 6;
 			case '/':
 				return 7;
+			case '<':
+				return 8;
 			}
 			return 0;
 		case 'h':
scripts/kconfig/mconf.c +51 -0

69 lines not on this page · raw message

Signature · 1 line
1.6.0.4

A message that is not in the archive (sent off-list or not yet received): 617c40ae9e206b4f246998fe075644c752bc0bc3.1256767265.git.aragorn@Anduril.(none)

#5 lore raw

PATCH 3/4 xconfig: allow editing of remarks for config symbols

Extend xconfig to allow editing of remarks for config symbols:

Add a new key to xconfig (currently '<') which, when pressed while a menu entry with a config symbol is selected, shows a QLineEdit (identical to the one used for string symbol editing) which is filled with sym->remark.

After the current config item looses focus or the user presses Escape/Return/Enter to close the QLineEdit, the QLineEdit saves the edited string to sym->remark and hides.

The new descendent of QLineEdit is called ConfigRemarkEdit and is mostly a copy of its silbling ConfigLineEdit, which is used for changing the values of int, hex and string values.

---
 scripts/kconfig/qconf.cc |   53 ++++++++++++++++++++++++++++++++++++++++++++++
 scripts/kconfig/qconf.h  |   19 ++++++++++++++++
 2 files changed, 72 insertions(+), 0 deletions(-)
scripts/kconfig/qconf.cc +53 -0
index 00c5150..58c74a0 100644
@@ -278,6 +278,54 @@ ConfigItem::~ConfigItem(void)
 	}
 }
 
+ConfigRemarkEdit::ConfigRemarkEdit(ConfigView* parent) : Parent(parent)
+{
+	connect(this, SIGNAL(lostFocus()), SLOT(hide()));
+	Parent::hide();
+}
+
+void ConfigRemarkEdit::show(ConfigItem* i)
+{
+	item = i;
+	if (item->menu->sym->remark)
+		setText(QString::fromLocal8Bit(item->menu->sym->remark));
+	else
+		setText(QString::null);
+	Parent::show();
+	setFocus();
+}
+
+void ConfigRemarkEdit::saveremark()
+{
+	if (item && item->menu && item->menu->sym) {
+		if (item->menu->sym->remark)
+			free(item->menu->sym->remark);
+		item->menu->sym->remark = strdup(text().latin1());
+		sym_set_changed(item->menu->sym);
+		sym_add_change_count(1);
+		sym_clear_all_valid();
+	}
+}
+
+void ConfigRemarkEdit::hide() {
+	saveremark();
+	Parent::hide();
+}
+
+void ConfigRemarkEdit::keyPressEvent(QKeyEvent* e)
+{
+	switch (e->key()) {
+	case Qt::Key_Escape:
+	case Qt::Key_Return:
+	case Qt::Key_Enter:
+		e->accept();
+		parent()->list->setFocus();
+		hide();
+		return;
+	}
+	Parent::keyPressEvent(e);
+}
+
 ConfigLineEdit::ConfigLineEdit(ConfigView* parent)
 	: Parent(parent)
 {
@@ -668,6 +716,10 @@ void ConfigList::keyPressEvent(QKeyEvent* ev)
 			emit menuSelected(menu);
 			break;
 		}
+	case Qt::Key_Less:
+		if (item && item->menu && item->menu->sym && !sym_is_choice(item->menu->sym))
+			parent()->remarkEdit->show(item);
+		break;
 	case Qt::Key_Space:
 		changeValue(item);
 		break;
@@ -843,6 +895,7 @@ ConfigView::ConfigView(QWidget* parent, const char *name)
 	list = new ConfigList(this, name);
 	lineEdit = new ConfigLineEdit(this);
 	lineEdit->hide();
+	remarkEdit = new ConfigRemarkEdit(this);
 
 	this->nextView = viewList;
 	viewList = this;
scripts/kconfig/qconf.h +19 -0
index b3b5657..f8ee581 100644
@@ -29,6 +29,7 @@ class ConfigView;
 class ConfigList;
 class ConfigItem;
 class ConfigLineEdit;
+class ConfigRemarkEdit;
 class ConfigMainWindow;
 
 
@@ -197,6 +198,23 @@ public:
 	bool goParent;
 };
 
+class ConfigRemarkEdit : public QLineEdit {
+	Q_OBJECT
+	typedef class QLineEdit Parent;
+public:
+	ConfigRemarkEdit(ConfigView* parent);
+	ConfigView* parent(void) const
+	{
+		return (ConfigView*)Parent::parent();
+	}
+	void keyPressEvent(QKeyEvent *e);
+	void show(ConfigItem *i);
+	void hide();
+private:
+	ConfigItem *item;
+	void saveremark();
+};
+
 class ConfigLineEdit : public QLineEdit {
 	Q_OBJECT
 	typedef class QLineEdit Parent;
@@ -239,6 +257,7 @@ signals:
 public:
 	ConfigList* list;
 	ConfigLineEdit* lineEdit;
+	ConfigRemarkEdit* remarkEdit;
 
 	static ConfigView* viewList;
 	ConfigView* nextView;
Signature · 1 line
1.6.0.4

A message that is not in the archive (sent off-list or not yet received): 57715d006f612817fa5bc38146560ecd84605a05.1256767265.git.aragorn@Anduril.(none)

#7 lore raw

PATCH 4/4 make config / oldconfig: allow editing of remarks for config symbols

In conf_sym(), which is used for ask for all bool/tristate symbols, print sym->remark (if one exists) befor prompting for the option and analogous to help (triggered by an input beginning with '?'), when the user enters a line starting with '<', allow the user to enter a remark or update it.

This extension does not cover the configuration of string, integer or choice values. I leave this open for follow-up submission in case there is interest in the config symbol remarks in general and in really supporting these also fully in make config, oldconfig and (possibly) silbings.

PS:
make gconfig could also be considered for extension, but it does apparently does not have a great deal of string editing UI yet, so adding remarks to it would require finding a way to edit string symbols in it first.

---
 scripts/kconfig/conf.c |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)
scripts/kconfig/conf.c +19 -0
index 9960d1c..dc60a1d 100644
@@ -158,8 +158,11 @@ static int conf_sym(struct menu *menu)
 	struct symbol *sym = menu->sym;
 	int type;
 	tristate oldval, newval;
+	char *p;
 
 	while (1) {
+		if (sym->remark)
+			printf("Remark: %s\n", sym->remark);
 		printf("%*s%s ", indent - 1, "", _(menu->prompt->text));
 		if (sym->name)
 			printf("(%s) ", sym->name);
@@ -214,6 +217,8 @@ static int conf_sym(struct menu *menu)
 			break;
 		case '?':
 			goto help;
+		case '<':
+			goto remark;
 		default:
 			continue;
 		}
@@ -221,6 +226,20 @@ static int conf_sym(struct menu *menu)
 			return 0;
 help:
 		print_help(menu);
+		continue;
+remark:
+		if (sym->remark)
+			printf("Current Remark: %s\n", sym->remark);
+		printf("    New remark: ");
+		fgets(line, sizeof(line), stdin);
+
+		if ((p = strchr(line, '\n')))
+			*p = '\0';            /* no \n in remark */
+		if (line[0]) {
+			if (sym->remark)
+				free(sym->remark);
+			sym->remark = strdup(line);
+		}
 	}
 }
 
Signature · 1 line
1.6.0.4