From patchwork Sat Sep 11 15:51:14 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Lacombe X-Patchwork-Id: 172072 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o8BFrsFp029069 for ; Sat, 11 Sep 2010 15:54:04 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752843Ab0IKPyD (ORCPT ); Sat, 11 Sep 2010 11:54:03 -0400 Received: from mail-gw0-f46.google.com ([74.125.83.46]:53064 "EHLO mail-gw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752394Ab0IKPyD (ORCPT ); Sat, 11 Sep 2010 11:54:03 -0400 Received: by mail-gw0-f46.google.com with SMTP id 17so1555732gwj.19 for ; Sat, 11 Sep 2010 08:54:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:date :message-id:x-mailer:in-reply-to:references; bh=FwFXA0Vn186HZA4Ev3GPmQfBy7WhoQIOVqUObEAh2Lo=; b=UB3VS5Jy/LsgDpTCHWShF/sUrD7nRvEvZ1+9QuVTcZ051c8Yt+s202N3mY02yTwd5F jtdHvhvTp8bED6hn/AlFtK1FQeMCm920xp+jbNIf+l3+BmuZFR2UhYpHGQ2/1jlqwXHn lLXJral9lWNemNL8XGRxU3sSyq9E3fTligeDs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=Ia78ersSeYtcA6hxO0/zuJpBCDNDlVQVZBFSGivdh2/kOwZQRdKtkr2MjLvtbhpo6Z Zu12PjRVy+5MyCeapk7zds/XIj1EFoTrndZmL6u0P+0wno5RPfWvaoL4lYpn1pxXAvEf TsIXcLmTAkm2ygP08+pYN9lXJSyffYe4fEg2I= Received: by 10.150.219.18 with SMTP id r18mr1096703ybg.172.1284220442859; Sat, 11 Sep 2010 08:54:02 -0700 (PDT) Received: from localhost.localdomain (69-165-136-93.dsl.teksavvy.com [69.165.136.93]) by mx.google.com with ESMTPS id m12sm4025812ybn.19.2010.09.11.08.54.01 (version=SSLv3 cipher=RC4-MD5); Sat, 11 Sep 2010 08:54:02 -0700 (PDT) From: Arnaud Lacombe To: Sam Ravnborg , Michal Marek Cc: linux-kbuild , Arnaud Lacombe Subject: [PATCH 07/15] kconfig: add a symbol string expansion helper Date: Sat, 11 Sep 2010 11:51:14 -0400 Message-Id: <1284220282-3500-8-git-send-email-lacombar@gmail.com> X-Mailer: git-send-email 1.7.2.30.gc37d7.dirty In-Reply-To: <1284220282-3500-1-git-send-email-lacombar@gmail.com> References: <1284220282-3500-1-git-send-email-lacombar@gmail.com> Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Sat, 11 Sep 2010 15:54:04 +0000 (UTC) diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h index 9a948c9..4531bad 100644 --- a/scripts/kconfig/lkc_proto.h +++ b/scripts/kconfig/lkc_proto.h @@ -28,6 +28,7 @@ P(symbol_hash,struct symbol *,[SYMBOL_HASHSIZE]); P(sym_lookup,struct symbol *,(const char *name, int flags)); P(sym_find,struct symbol *,(const char *name)); +P(sym_expand_string_value,const char *,(const char *in)); P(sym_re_search,struct symbol **,(const char *pattern)); P(sym_type_name,const char *,(enum symbol_type type)); P(sym_calc_value,void,(struct symbol *sym)); diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index 943712c..dc5dcf2 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -840,6 +840,55 @@ struct symbol *sym_find(const char *name) return symbol; } +/* + * Expand symbol's names embedded in the string given in argument. Symbols' + * name to be expanded shall be prefixed by a '$'. Unknown symbol expands to + * the empty string. + */ +const char *sym_expand_string_value(const char *in) +{ + const char *src; + char *res; + size_t reslen; + + reslen = strlen(in) + 1; + res = malloc(reslen); + res[0] = '\0'; + + while ((src = strchr(in, '$'))) { + char *p, name[SYMBOL_MAXLENGTH]; + const char *symval = ""; + struct symbol *sym; + size_t newlen; + + strncat(res, in, src - in); + src++; + + p = name; + while (isalnum(*src) || *src == '_') + *p++ = *src++; + *p = '\0'; + + sym = sym_find(name); + if (sym != NULL) { + sym_calc_value(sym); + symval = sym_get_string_value(sym); + } + + newlen = strlen(res) + strlen(symval) + strlen(src); + if (newlen > reslen) { + reslen = newlen; + realloc(res, reslen); + } + + strcat(res, symval); + in = src; + } + strcat(res, in); + + return res; +} + struct symbol **sym_re_search(const char *pattern) { struct symbol *sym, **sym_arr = NULL;