Received: by 10.223.185.116 with SMTP id b49csp1045468wrg; Fri, 16 Feb 2018 11:24:13 -0800 (PST) X-Google-Smtp-Source: AH8x225pp2TmBKRyCScBCwLbLXAj7ZPDdBq4xaEagm4CSwQaaGDUIfH1Yl6r+TnMl3iqQq7vwm6N X-Received: by 2002:a17:902:4683:: with SMTP id p3-v6mr6739623pld.408.1518809053007; Fri, 16 Feb 2018 11:24:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518809052; cv=none; d=google.com; s=arc-20160816; b=Oi8SkuQnAK6UPnTS9MJKgBmnROJ/FvMkxnrxFIVPH7MNnpHKPFqJ5OurSK5MTWDau7 V2kvo7LbKCO7k7OMOlP+3TGRCpJUuE2kMx0uT3ucFklCwtl1Ph1oz/U06iC2i36COrpT RK5gn+l/UTg/c87WY/hhQZr7iX8FlIUl3IktjVLw+9hLY3BflZx6A/pqpkQbtMiXTmzY 7L4pHIVF4pfGqK27uLWZcFvWNjPCLUh39K+wxqMVIPw3sqZEqDV/ICnRT8sjLuy/XhM/ UzcOXecaNceaMRctE6Odvna/1+wCwgR7VkeTZ5vdaRKETHmb2t11LOTM8C08UNZMCIoh suQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter :arc-authentication-results; bh=6bDWmuezbI5Hm+gjpVvP4x2GJkY1+VLq+ILtVxXeZbM=; b=iXVAFO2uzQBl/jw0QuUpAWa1ox9nSZJnS2+64NwfvmnViG5os7RnU3acNuJnudKAwV Myt1heewFjSsS3OJyKHMY5VcyMvccP62cZHFIma/2ERGroFgFmghxPgup9aVpHl/IxJk FpHODBXlFu6Wo8x6aNrwc4DYqyidCa73msgJOBeNrQ2+h62oKkIKntJu5AJba6r9AkcL w6FoMlhZak1eGdLFWRBLYTezs1XSWlInF/wtNQL7LdptvRF59aJa4A9+DaOhCZlUNi0T UY0/2GWGC1bsJ8iLiQef7T0VXQa38IOSjP9mFMih2o/fBHNFJcoHe1fYfWaSf46nzz3f J52Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=2nv9Jg/J; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h73si838235pfk.231.2018.02.16.11.23.58; Fri, 16 Feb 2018 11:24:12 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=2nv9Jg/J; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752508AbeBPSsL (ORCPT + 99 others); Fri, 16 Feb 2018 13:48:11 -0500 Received: from conuserg-07.nifty.com ([210.131.2.74]:57758 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752623AbeBPSlS (ORCPT ); Fri, 16 Feb 2018 13:41:18 -0500 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-07.nifty.com with ESMTP id w1GIdBT8013418; Sat, 17 Feb 2018 03:39:16 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com w1GIdBT8013418 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1518806357; bh=6bDWmuezbI5Hm+gjpVvP4x2GJkY1+VLq+ILtVxXeZbM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2nv9Jg/JLTu1f+2uFHUqFKdVbN5hSZhImE14eOpzWiF0YbaeKazAxh9vz/y3G7edy sfvoo3Wm46M3qDlie9ty6hjb5E3tezXhCHf0Nsb2uL/9wFLrEU/uIVzoR4B/DRb5Gw AZUkHC36Wb/ZhKpJfvcSseJhEeOX47FLZhL33CGAJYBEmEiFvXtzqVwMdspppb/ieE DtEUcl+aj7vfEg3uponlYc4amoxso4J/WhZB9uTcb/Ege+ExdVYekoOdkO1Bba8tJu ew3CUvF9gG0I01RI6C0lWCwhmwS0oID6vl1HST4VYjBw6nxkRTr/4Dhn5R+WkAlTgU tsj06LU4gFPiQ== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org, Linus Torvalds Cc: Greg Kroah-Hartman , Arnd Bergmann , Kees Cook , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Michal Marek , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH 05/23] kconfig: move and rename sym_expand_string_value() Date: Sat, 17 Feb 2018 03:38:33 +0900 Message-Id: <1518806331-7101-6-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518806331-7101-1-git-send-email-yamada.masahiro@socionext.com> References: <1518806331-7101-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This helper expands symbols contained in a string. I am about to change it to expand environments instead of symbols. Also, I will add function expansion later. Rename it to expand_string_value(), and move it to util.c, which is a more suitable place. Signed-off-by: Masahiro Yamada --- scripts/kconfig/lkc.h | 1 + scripts/kconfig/lkc_proto.h | 1 - scripts/kconfig/symbol.c | 53 ------------------------------------------- scripts/kconfig/util.c | 55 ++++++++++++++++++++++++++++++++++++++++++++- scripts/kconfig/zconf.y | 2 +- 5 files changed, 56 insertions(+), 56 deletions(-) diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h index 2d5ec2d..fb2503a 100644 --- a/scripts/kconfig/lkc.h +++ b/scripts/kconfig/lkc.h @@ -110,6 +110,7 @@ void menu_finalize(struct menu *parent); void menu_set_type(int type); /* util.c */ +char *expand_string_value(const char *in); struct file *file_lookup(const char *name); int file_write_dep(const char *name); void *xmalloc(size_t size); diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h index 9dc8abf..9884adc 100644 --- a/scripts/kconfig/lkc_proto.h +++ b/scripts/kconfig/lkc_proto.h @@ -31,7 +31,6 @@ extern struct symbol * symbol_hash[SYMBOL_HASHSIZE]; struct symbol * sym_lookup(const char *name, int flags); struct symbol * sym_find(const char *name); -char *sym_expand_string_value(const char *in); const char * sym_escape_string_value(const char *in); struct symbol ** sym_re_search(const char *pattern); const char * sym_type_name(enum symbol_type type); diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index 2220bc4..e4ccf56 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -894,59 +894,6 @@ 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. - */ -char *sym_expand_string_value(const char *in) -{ - const char *src; - char *res; - size_t reslen; - - /* - * Note: 'in' might come from a token that's about to be - * freed, so make sure to always allocate a new string - */ - reslen = strlen(in) + 1; - res = xmalloc(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) + 1; - if (newlen > reslen) { - reslen = newlen; - res = xrealloc(res, reslen); - } - - strcat(res, symval); - in = src; - } - strcat(res, in); - - return res; -} - const char *sym_escape_string_value(const char *in) { const char *p; diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c index c6f6e21..22201a4 100644 --- a/scripts/kconfig/util.c +++ b/scripts/kconfig/util.c @@ -10,11 +10,64 @@ #include #include "lkc.h" +/* + * 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. + */ +char *expand_string_value(const char *in) +{ + const char *src; + char *res; + size_t reslen; + + /* + * Note: 'in' might come from a token that's about to be + * freed, so make sure to always allocate a new string + */ + reslen = strlen(in) + 1; + res = xmalloc(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) + 1; + if (newlen > reslen) { + reslen = newlen; + res = xrealloc(res, reslen); + } + + strcat(res, symval); + in = src; + } + strcat(res, in); + + return res; +} + /* file already present in list? If not add it */ struct file *file_lookup(const char *name) { struct file *file; - char *file_name = sym_expand_string_value(name); + char *file_name = expand_string_value(name); for (file = file_list; file; file = file->next) { if (!strcmp(name, file->name)) { diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y index ad6305b..262c464 100644 --- a/scripts/kconfig/zconf.y +++ b/scripts/kconfig/zconf.y @@ -547,7 +547,7 @@ void conf_parse(const char *name) tmp = rootmenu.prompt->text; rootmenu.prompt->text = _(rootmenu.prompt->text); - rootmenu.prompt->text = sym_expand_string_value(rootmenu.prompt->text); + rootmenu.prompt->text = expand_string_value(rootmenu.prompt->text); free((char*)tmp); menu_finalize(&rootmenu); -- 2.7.4