Received: by 10.192.165.156 with SMTP id m28csp2751047imm; Sun, 15 Apr 2018 08:14:18 -0700 (PDT) X-Google-Smtp-Source: AIpwx48tdpO1S2YYBZ2qOEuBe/PpzNoS6+vWqs4MQsnkhL5nKxDv27YEsCmNhFCCiCPOrKN4NQvw X-Received: by 10.101.77.145 with SMTP id p17mr10206258pgq.275.1523805258150; Sun, 15 Apr 2018 08:14:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523805258; cv=none; d=google.com; s=arc-20160816; b=DwroeiiLnvNHRGb1WscADt/H3tYwCK96j5kJOhrFpoGSOY9ocEOMQm6C1HE/F61irt dxXaWZH+WlHYacNsURt/60wvXDsQRXMVjdfElSyeATHgaV9K81t7q5lv6xMeWREFvQ5p C7/Y3tlGIL8aoLjkj64Fwp5I72mSvX2BNCkzDpTdLDOOdR+pDH9pswZjBd3hWcO7Fqvw gHXRAC+y6MdTP5Jh1umsSDT92F5j8km1wzGuOKMjaimHOzJuk+WB/6vKqxeiWwSYI1JH zW+dU716n/cU8ucVHPEZVhMliCYNV14uQKzgb8BH4+cQ0zQdQbZnhCK+WFTYgVXORQzi T3xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature:dkim-filter :arc-authentication-results; bh=ZQNaR6fV4vBl7gEo7V8muOnVomRpUQQ1BBvpDQ6Hu10=; b=KxhCEKbuBSQDwgYVhQy/YgNw781FH/CKZUZwliXPfy+tO8K9zhXA9IHd15PAW9Ggex HJ2m9cE/otA9BvCYtnEq2mKLCZ58s3xIIr5e9G2g6Ldmbc5h6tsQsN4wMH4ggnMt0XWG rv0LMKmgh0e2RFcF6W0lfcsOyLJmJK6CSS7h6VB9wStN9UoNraqg58TxhhU+SiVzX+HR EKd0LGjdqUGi7iQ8Y4mQ+ctNAf0HrE1sWuf4Xi+NswI+v5qeMH33Ae/UPH3EcWmDlcgd 09HoSxNVny0iFyPrvNGSVgGnhVD/d/lx2DatRqCUXr+GqvU+Wl8xdyaY/jI0eJb/R0ZV OC1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=Jn0oJ8fW; 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 v14si7973040pgq.266.2018.04.15.08.14.03; Sun, 15 Apr 2018 08:14:18 -0700 (PDT) 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=Jn0oJ8fW; 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 S1752552AbeDOPM4 (ORCPT + 99 others); Sun, 15 Apr 2018 11:12:56 -0400 Received: from conssluserg-03.nifty.com ([210.131.2.82]:41416 "EHLO conssluserg-03.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751890AbeDOPMy (ORCPT ); Sun, 15 Apr 2018 11:12:54 -0400 Received: from mail-ua0-f172.google.com (mail-ua0-f172.google.com [209.85.217.172]) (authenticated) by conssluserg-03.nifty.com with ESMTP id w3FFClZg013312; Mon, 16 Apr 2018 00:12:47 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-03.nifty.com w3FFClZg013312 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1523805168; bh=ZQNaR6fV4vBl7gEo7V8muOnVomRpUQQ1BBvpDQ6Hu10=; h=In-Reply-To:References:From:Date:Subject:To:Cc:From; b=Jn0oJ8fWGME7eBPLmRXBuEponih92YSEOlp0zE+hmSQuRNFd4dCPmd7UJl3A0wG0Z LTN8tiORxuo9uzC920TI/lq6G7AXtwd1Vi9kXUNkge0xLphZ4/W6gArws9zmMAoSqL Hv43jsMr2EzhiIbY4SdHOqLW7oK7FsntrNwvq1T0holBih7axCnDOmV6GY3HoCJQwU hYzTfe21EUcEyiv2H1WpHQh28bOs7mWSuDT0Ad9Q5x0POOz2SLtzdBg1sVtH3CeOie 5EvRlRY7AlNSJGsDmItlsfTUqboh5zR/kXZJ0BggxtfxAgYBQmxCO8ihDSi7RvjZGf P30VwSHfLlDhQ== X-Nifty-SrcIP: [209.85.217.172] Received: by mail-ua0-f172.google.com with SMTP id d3so8248828uae.4; Sun, 15 Apr 2018 08:12:47 -0700 (PDT) X-Gm-Message-State: ALQs6tA+OGvL18kX39yxnrbDCmEBIILp4eEED7FHA84aJKB8tY25fVrn ASGsK+k5cTC4Y9BIWlvOkCva3aMD86UNkKQKYy4= X-Received: by 10.176.22.3 with SMTP id k3mr5079463uae.52.1523805166359; Sun, 15 Apr 2018 08:12:46 -0700 (PDT) MIME-Version: 1.0 Received: by 10.176.85.216 with HTTP; Sun, 15 Apr 2018 08:12:06 -0700 (PDT) In-Reply-To: References: <1523595999-27433-1-git-send-email-yamada.masahiro@socionext.com> <1523595999-27433-9-git-send-email-yamada.masahiro@socionext.com> From: Masahiro Yamada Date: Mon, 16 Apr 2018 00:12:06 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 08/30] kconfig: add built-in function support To: Ulf Magnusson Cc: Linux Kbuild mailing list , Linus Torvalds , Sam Ravnborg , Nicholas Piggin , Kees Cook , Emese Revfy , X86 ML , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2018-04-15 16:57 GMT+09:00 Ulf Magnusson : > On Fri, Apr 13, 2018 at 7:06 AM, Masahiro Yamada > wrote: >> This commit adds a new concept 'function' to do more text processing >> in Kconfig. >> >> A function call looks like this: >> >> $(function arg1, arg2, arg3, ...) >> >> This commit adds the basic infrastructure to expand functions. >> Change the text expansion helpers to take arguments. >> >> Signed-off-by: Masahiro Yamada >> --- >> >> Changes in v3: >> - Split base infrastructure and 'shell' function >> into separate patches. >> >> Changes in v2: >> - Use 'shell' for getting stdout from the comment. >> It was 'shell-stdout' in the previous version. >> - Symplify the implementation since the expansion has been moved to >> lexer. >> >> scripts/kconfig/preprocess.c | 142 +++++++++++++++++++++++++++++++++++++++---- >> 1 file changed, 130 insertions(+), 12 deletions(-) >> >> diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c >> index fa4abc8..e77cf7c 100644 >> --- a/scripts/kconfig/preprocess.c >> +++ b/scripts/kconfig/preprocess.c >> @@ -8,6 +8,10 @@ >> >> #include "list.h" >> >> +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) >> + >> +static char *expand_string_with_args(const char *in, int argc, char *argv[]); >> + >> /* >> * Environment variables >> */ >> @@ -74,9 +78,47 @@ void env_write_dep(FILE *f, const char *autoconfig_name) >> } >> } >> >> -static char *eval_clause(const char *in) >> +/* >> + * Built-in Functions >> + */ >> +struct function { >> + char *name; >> + char *(*func)(int argc, char *argv[]); >> +}; >> + >> +static const struct function function_table[] = { >> +}; >> + >> +static char *function_call(const char *name, int argc, char *argv[]) >> { >> - char *res, *name; >> + const struct function *f; >> + int i; >> + >> + for (i = 0; i < ARRAY_SIZE(function_table); i++) { >> + f = &function_table[i]; >> + if (!strcmp(f->name, name)) >> + return f->func(argc, argv); >> + } >> + >> + return NULL; >> +} >> + >> +#define FUNCTION_MAX_ARGS 16 >> + >> +/* >> + * Evaluate a clause with arguments. argc/argv are arguments from the upper >> + * function call. >> + * >> + * Returned string must be freed when done >> + */ >> +static char *eval_clause(const char *in, int argc, char *argv[]) >> +{ >> + char *tmp, *prev, *p, *res, *name; >> + char delim = ' '; >> + int new_argc = 0; >> + char *new_argv[FUNCTION_MAX_ARGS]; >> + int nest = 0; >> + int i; >> >> /* >> * Returns an empty string because '$()' should be evaluated >> @@ -85,10 +127,73 @@ static char *eval_clause(const char *in) >> if (!*in) >> return xstrdup(""); >> >> - name = expand_string(in); >> + tmp = xstrdup(in); >> + >> + prev = p = tmp; >> >> - res = env_expand(name); >> + /* >> + * Split into tokens >> + * The function name and the first argument are separated by a space. >> + * Arguments are separated by a comma. >> + * For example, if the function call is like this: >> + * $(foo abc,$(x),$(y)) >> + * >> + * The input string for this helper should be: >> + * foo abc,$(x),$(y) >> + * >> + * and split into: >> + * new_argv[0]: foo >> + * new_argv[1]: abc >> + * new_argv[2]: $(x) >> + * new_argv[3]: $(y) >> + */ >> + while (*p) { >> + if (nest == 0 && *p == delim) { >> + *p = 0; >> + new_argv[new_argc++] = prev; > > Erroring out would be nicer than overflowing the array. OK, will do. -- Best Regards Masahiro Yamada