From patchwork Fri Feb 16 18:38:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 128623 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp869617ljc; Fri, 16 Feb 2018 10:48:16 -0800 (PST) X-Google-Smtp-Source: AH8x225+C17WUht6+ubqHYusSbnsPr53UcDgb1INae/8FftQSdQciE2/Hm6xWjR8mlZOmOmVePT5 X-Received: by 2002:a17:902:848b:: with SMTP id c11-v6mr3143484plo.372.1518806896661; Fri, 16 Feb 2018 10:48:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518806896; cv=none; d=google.com; s=arc-20160816; b=ZQ+AIsrhhNpZP8Q/ygjyz6ECLEwXSqwy6uwD4MHYbm4VX8mvHBBOQbGto2TYczz6uO 7SHjf9S7iU+vcRcQWKRdtwco5TwFZllT9GgQa8IYDdRmbuEmZ984qOXtEk8OH4hWHkBG DCOuF2/UOMkgk3Ep0V0Nzc/0xKixtpxCTiQHhAr4NYcqJiQzZHYu2Ury3kNL7UCHp+RZ NsORWjIarb6FmPZCXaDg/oBR/cDIj11GDggguaFzKChkAEvgkRDRS5SEshFFYoCZvgHi qslvbWhgbZKZbiimFCn2Q/h64Ip4hKuvQC9C4wZdat80h6tXcr771/77npp3S/nxHQ7I pUdg== 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 p33-v6si2408561pld.310.2018.02.16.10.48.16; Fri, 16 Feb 2018 10:48:16 -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 S1752517AbeBPSsM (ORCPT + 28 others); Fri, 16 Feb 2018 13:48:12 -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(-) -- 2.7.4 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);