From patchwork Wed Nov 25 09:38:51 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Marek X-Patchwork-Id: 62737 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id nAP9dfdv026206 for ; Wed, 25 Nov 2009 09:39:41 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758512AbZKYJit (ORCPT ); Wed, 25 Nov 2009 04:38:49 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1758529AbZKYJis (ORCPT ); Wed, 25 Nov 2009 04:38:48 -0500 Received: from cantor.suse.de ([195.135.220.2]:57781 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758487AbZKYJir (ORCPT ); Wed, 25 Nov 2009 04:38:47 -0500 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.221.2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.suse.de (Postfix) with ESMTP id AAF228FEA2; Wed, 25 Nov 2009 10:38:52 +0100 (CET) Received: by sepie.suse.cz (Postfix, from userid 10020) id 2375276415; Wed, 25 Nov 2009 10:38:51 +0100 (CET) Date: Wed, 25 Nov 2009 10:38:51 +0100 From: Michal Marek To: Bernhard Kaindl Cc: linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, Roman Zippel Subject: [PATCH] Support loading and saving custom remarks in .config Message-ID: <20091125093851.GA14314@sepie.suse.cz> References: <4B0C57EA.1030400@suse.cz> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <4B0C57EA.1030400@suse.cz> User-Agent: Mutt/1.5.20 (2009-06-14) Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org 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];