lkml.org 
[lkml]   [2011]   [Feb]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [PATCH 1/2] kconfig: add support for type handlers
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 02/25/2011 08:28 PM, Arnaud Lacombe wrote:
> Hi,
>
> On Fri, Feb 25, 2011 at 7:44 PM, Jeff Mahoney <jeffm@suse.com> wrote:
>> 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.
>>
> this can be trivially scripted, any reason it _has_ to be done within kconfig ?

This is what the original patch I posted did, and I was asked to teach
kconfig how to do it itself.

- -Jeff


>> 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
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>


- --
Jeff Mahoney
SUSE Labs
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.16 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org/

iEYEARECAAYFAk1pOBcACgkQLPWxlyuTD7JlJACfVPh3NV+X5cz7l8BYgxkf1E2j
mGsAoIpMp0AMjIjl5mm3OaR2H3N65PpP
=Sd++
-----END PGP SIGNATURE-----


\
 
 \ /
  Last update: 2011-02-26 18:31    [W:0.058 / U:0.868 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site