diff mbox

Support loading and saving custom remarks in .config

Message ID 20091125093851.GA14314@sepie.suse.cz (mailing list archive)
State New, archived
Headers show

Commit Message

Michal Marek Nov. 25, 2009, 9:38 a.m. UTC
None
diff mbox

Patch

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];