From: Jeff Mahoney <jeffm@suse.com>
To: Sam Ravnborg <sam@ravnborg.org>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Roman Zippel <zippel@linux-m68k.org>,
linux-kbuild@vger.kernel.org
Subject: [PATCH 1/2] kconfig: add support for type handlers
Date: Fri, 25 Feb 2011 19:44:37 -0500 [thread overview]
Message-ID: <4D684CF5.2060206@suse.com> (raw)
In-Reply-To: <20110225060706.GA12723@merkur.ravnborg.org>
This patch adds type handlers for compressed config files. Initial
support provides callouts for gzip and bzip2, but there's no reason
others could be added if demand is there.
This is intended to allow /proc/config.gz be a configuration source
for 'make oldconfig' when .config is absent.
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
scripts/kconfig/zconf.l | 50 ++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 48 insertions(+), 2 deletions(-)
--- a/scripts/kconfig/zconf.l
+++ b/scripts/kconfig/zconf.l
@@ -256,6 +256,44 @@ static void zconf_endhelp(void)
BEGIN(INITIAL);
}
+static const struct type_handler {
+ const char *suffix;
+ const char *command;
+} type_handlers[] = {
+ {
+ .suffix = ".gz",
+ .command = "zcat",
+ },
+ {
+ .suffix = ".bz2",
+ .command = "bzcat",
+ },
+ /* Whatever other algorithms you like */
+ {}
+};
+
+static const struct type_handler *get_type_handler(const char *name)
+{
+ char *p = rindex(name, '.');
+ if (p) {
+ const struct type_handler *ops = type_handlers;
+ for (ops = type_handlers; ops->suffix; ops++) {
+ if (!strcasecmp(ops->suffix, p))
+ break;
+ }
+ if (!ops->suffix)
+ return NULL;
+ return ops;
+ }
+ return NULL;
+}
+
+static FILE *zconf_popen(const char *command, const char *name)
+{
+ char cmdbuf[PATH_MAX + strlen(command) + 2];
+ snprintf(cmdbuf, sizeof(cmdbuf), "%s %s", command, name);
+ return popen(cmdbuf, "r");
+}
/*
* Try to open specified file with following names:
@@ -267,15 +305,23 @@ static void zconf_endhelp(void)
*/
FILE *zconf_fopen(const char *name)
{
+ const struct type_handler *handler = get_type_handler(name);
char *env, fullname[PATH_MAX+1];
FILE *f;
- f = fopen(name, "r");
+ if (handler)
+ f = zconf_popen(handler->command, name);
+ else
+ f = fopen(name, "r");
+
if (!f && name != NULL && name[0] != '/') {
env = getenv(SRCTREE);
if (env) {
sprintf(fullname, "%s/%s", env, name);
- f = fopen(fullname, "r");
+ if (handler)
+ f = zconf_popen(handler->command, fullname);
+ else
+ f = fopen(fullname, "r");
}
}
return f;
--
Jeff Mahoney
SUSE Labs
next prev parent reply other threads:[~2011-02-26 0:44 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-25 2:35 [PATCH] Add ``cloneconfig'' target Jeff Mahoney
2011-02-25 6:07 ` Sam Ravnborg
2011-02-26 0:44 ` Jeff Mahoney [this message]
2011-02-26 1:28 ` [PATCH 1/2] kconfig: add support for type handlers Arnaud Lacombe
2011-02-26 17:27 ` Jeff Mahoney
2011-02-26 0:44 ` [PATCH 2/2] kconfig: Use /proc/config.gz as a configuration source Jeff Mahoney
2011-02-26 19:47 ` [PATCH] Add ``cloneconfig'' target Arnaud Lacombe
2011-02-26 22:18 ` Sam Ravnborg
2011-02-26 23:03 ` Arnaud Lacombe
2011-02-26 23:28 ` Arnaud Lacombe
2011-02-27 18:44 ` Sam Ravnborg
2011-02-27 9:03 ` Geert Uytterhoeven
2011-02-27 17:13 ` Arnaud Lacombe
2011-02-27 17:54 ` Jeff Mahoney
2011-02-26 22:47 ` Miguel Ojeda
2011-02-26 22:57 ` Arnaud Lacombe
2011-02-26 23:16 ` Miguel Ojeda
2011-02-26 23:26 ` Arnaud Lacombe
2011-02-26 23:38 ` Jeff Mahoney
2011-02-26 23:50 ` Arnaud Lacombe
2011-02-26 23:34 ` Jeff Mahoney
2011-02-26 23:53 ` Arnaud Lacombe
2011-02-26 19:50 ` Arnaud Lacombe
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=4D684CF5.2060206@suse.com \
--to=jeffm@suse.com \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sam@ravnborg.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox