lkml.org 
[lkml]   [2009]   [Nov]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH] Support loading and saving custom remarks in .config
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


\
 
 \ /
  Last update: 2009-11-25 10:41    [W:0.236 / U:0.108 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site