All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Marek <mmarek@suse.cz>
To: Bernhard Kaindl <bernhard.kaindl@gmx.net>
Cc: linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org,
	Roman Zippel <zippel@linux-m68k.org>
Subject: [PATCH] Support loading and saving custom remarks in .config
Date: Wed, 25 Nov 2009 10:38:51 +0100	[thread overview]
Message-ID: <20091125093851.GA14314@sepie.suse.cz> (raw)
In-Reply-To: <4B0C57EA.1030400@suse.cz>

To make it easier for users to maintain their .config over time, add
support for one-line comments (remarks) attached to config option
assignments. The format is

  # some remark
  CONFIG_FOO=y
  # another remark
  # CONFIG_BAR is not set

If a config option is removed, the respective remark is removed as well.
This patch is based on a previous patch by Bernhard Kaindl.

Signed-off-by: Michal Marek <mmarek@suse.cz>
---
 scripts/kconfig/confdata.c |   52 +++++++++++++++++++++++++++++++++++++++++++-
 scripts/kconfig/expr.h     |    1 +
 2 files changed, 52 insertions(+), 1 deletions(-)

diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index b55e72f..daa7d78 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -152,13 +152,46 @@ static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p)
 	return 0;
 }
 
+static char *extract_remark(const char *line)
+{
+	const char *p;
+	char *res, *p2;
+	static const char *alnum =
+		"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+		"abcdefghijklmnopqrstuvwxyz"
+		"0123456789_";
+
+
+	if (!line || *line != '#')
+		return NULL;
+	line++;
+	line += strspn(line, " \t");
+	if (!*line || *line == '\n')
+		return NULL;
+	if (strncmp(line, "CONFIG_", sizeof("CONFIG_") - 1) != 0)
+		goto found;
+	p = line + strspn(line, alnum);
+	if (strcmp(p, " is not set\n") == 0)
+		return NULL;
+	/* skip commented out assignments */
+	if (p[1] == '=' && !strchr(p, ' ') && !strchr(p, '\t'))
+		return NULL;
+found:
+	res = strdup(line);
+	p2 = strchr(res, '\n');
+	if (p2)
+		*p2 = '\0';
+	return res;
+}
+
 int conf_read_simple(const char *name, int def)
 {
 	FILE *in = NULL;
 	char line[1024];
 	char *p, *p2;
 	struct symbol *sym;
-	int i, def_flags;
+	char *last_remark;
+	int i, def_flags, last_remark_lineno;
 
 	if (name) {
 		in = zconf_fopen(name);
@@ -195,6 +228,8 @@ load:
 	conf_lineno = 0;
 	conf_warnings = 0;
 	conf_unsaved = 0;
+	last_remark = NULL;
+	last_remark_lineno = 0;
 
 	def_flags = SYMBOL_DEF << def;
 	for_all_symbols(i, sym) {
@@ -215,8 +250,15 @@ load:
 	}
 
 	while (fgets(line, sizeof(line), in)) {
+		char *remark;
 		conf_lineno++;
 		sym = NULL;
+		remark = extract_remark(line);
+		if (remark) {
+			free(last_remark);
+			last_remark = remark;
+			last_remark_lineno = conf_lineno;
+		}
 		switch (line[0]) {
 		case '#':
 			if (memcmp(line + 2, "CONFIG_", 7))
@@ -309,6 +351,12 @@ load:
 			}
 			cs->def[def].tri = EXPR_OR(cs->def[def].tri, sym->def[def].tri);
 		}
+		if (sym && last_remark &&
+				last_remark_lineno == conf_lineno - 1) {
+			sym->remark = last_remark;
+			/* don't free() the string in the next iteration */
+			last_remark = NULL;
+		}
 	}
 	fclose(in);
 
@@ -484,6 +532,8 @@ int conf_write(const char *name)
 				if (modules_sym->curr.tri == no)
 					type = S_BOOLEAN;
 			}
+			if (sym->remark)
+				fprintf(out, "# %s\n", sym->remark);
 			switch (type) {
 			case S_BOOLEAN:
 			case S_TRISTATE:
diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h
index 6408fef..217e8cb 100644
--- a/scripts/kconfig/expr.h
+++ b/scripts/kconfig/expr.h
@@ -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];
-- 
1.6.4.2


      reply	other threads:[~2009-11-25  9:38 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-07  6:45 [PATCH/RFC 0/4] user remarks for config symbols Bernhard Kaindl
2009-11-07  6:45 ` [PATCH 1/4] Support loading and saving custom " Bernhard Kaindl
2009-11-07  6:45   ` [PATCH 2/4] menuconfig: allow editing of " Bernhard Kaindl
2009-11-07  6:45     ` [PATCH 3/4] xconfig: " Bernhard Kaindl
2009-11-07  6:45       ` [PATCH 4/4] make config / oldconfig: " Bernhard Kaindl
2009-11-12 12:16   ` [PATCH 1/4] Support loading and saving custom " Pavel Machek
2009-11-24 22:02   ` Michal Marek
2009-11-25  9:38     ` Michal Marek [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20091125093851.GA14314@sepie.suse.cz \
    --to=mmarek@suse.cz \
    --cc=bernhard.kaindl@gmx.net \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=zippel@linux-m68k.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.