Received: by 10.192.165.156 with SMTP id m28csp2451916imm; Sun, 15 Apr 2018 00:59:17 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/peEqRdY314sZEM+XePg7O61SPLsItWHDxUvMIvL4+4PNsdnVhtICLH9jriZ1cpigIEAXu X-Received: by 2002:a17:902:4464:: with SMTP id k91-v6mr10617087pld.219.1523779157357; Sun, 15 Apr 2018 00:59:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523779157; cv=none; d=google.com; s=arc-20160816; b=JE5jNPKyhM62p7+fruhbv9d61exARZjFY0IFCBrNeqEui5YU4DzO3sT7WmA/5wmV7u v5tMYR+YFHvhofVRtv1I75aN8Mz7JrF2GL4TyDmEaUAFKo5AST/uTEl+eoCaXMI5Pjei n+DnSM6oSvBTBwmUUdXTM/nYswaFXE14cxj26UcmryIe2Bd0cVTmscBUq5bw5vrl8lgp wOtusVB8Y0X+QIVlIW0jYKbf/N6b0xvD9VaxeWFUhap19I5ChE+qT9yA50fzISWsAtJm fgLdQcdfjMXjLZk/Oi6viGsX0br7wlivYhkGvD//d83UJ8EJN82+fidhqnk0n1PnXWCj QFYg== 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 :arc-authentication-results; bh=RAnnXfNoNmjRNo1vsgmjz9/9MX1+bkFMIa5zn7xcXbs=; b=hPlQM4amxAHXLwv3ZVrPd+8J3wgfE3k//EFfKTHtU5hLHJmrBj/jrZ952XFS+c0kLh 9uxad5ygcO5vDpc9V0nYn0GcdR+CWl3zJ3CVDLFf7uIemRQszqKh3zA15xkyynO9vyMX YaGWurQqXPoWmZ8D3i9XPlXjxR1VRncZICat2+haCA0wHwyXUA48J/wKJ6T5XziZHMA0 6Qj/5swfEktuBUi9xLRfrtePNcpgyJ3ClfHcqufDVN4+XbIIIqYxN1nEv0pMyIZ4P2f7 hMJjQwsVt/HNF3KyLDa16sNvPyTuMG8YrCePRqJ6DIqCpHjmv2JxRZmdMB+PwJwWA8ZA +LxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=kJ9UPlM8; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e9si7501329pgn.17.2018.04.15.00.59.01; Sun, 15 Apr 2018 00:59:17 -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=@gmail.com header.s=20161025 header.b=kJ9UPlM8; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751224AbeDOH5q (ORCPT + 99 others); Sun, 15 Apr 2018 03:57:46 -0400 Received: from mail-vk0-f67.google.com ([209.85.213.67]:39479 "EHLO mail-vk0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750871AbeDOH5p (ORCPT ); Sun, 15 Apr 2018 03:57:45 -0400 Received: by mail-vk0-f67.google.com with SMTP id n124so7723267vkd.6; Sun, 15 Apr 2018 00:57:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=RAnnXfNoNmjRNo1vsgmjz9/9MX1+bkFMIa5zn7xcXbs=; b=kJ9UPlM8eYQiPbGgKqyx/aybkmN4NPKpfpqV44Yy30wOrdRWw+T0mVPCy5thH9WH5m Bg2TKTLVu9CzUZuzL6BDo9lBzgg3D1HDtxqLAK1ya2xCooQdK2J4Mlzv6AmNvh88WV3v F1VYbrIGXx19CvAgJxdXeDTpr05m1IL6FB4SQf2t9buuZ2SDAvH9ym9NC/Gn+RTyfbvv NR0Vje5Gijy+HZT8hZ/uP9pSfr482xIIDHmwF4oBjzmURRQajoT1YaEHeDr8XEYQKlc2 bZArIHp1PG1m+gsyKjrTutd02Rc8boVB63JSNXQMpo5zS5CNqvUQiFY5LDHgeGeT4liP mOGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=RAnnXfNoNmjRNo1vsgmjz9/9MX1+bkFMIa5zn7xcXbs=; b=govDmnn1HWg2A2UbmjQNhZrwqSw1l2xpn6Bvy28YMf3QxcIq/nv/nwNtQcB7DAhmMJ nqFZqQpM2gCMcXtsxxczVsu3YLVyjoFWP6Fhj5ru3sz2ViX/mmNUcBMTMXww5QC+1AUh BLwSbEoAihhgGZy21s2XrolDIEYg1dE+ePn57xu8/ymC9G95l9nNH6J9TsemyDBXJ6l+ BfWpbCRyp3KB9v4di3mRs1OhFfFYwkyV88ZYdmyqfHAMz1LkbGi8w/CDWuKkr2Pz8w8T wi3V64vK0j/LobPcFUb3rfnbPdwDFGd8y7pHoLZ4sooteurnLXrDktZ/pXsu+WMv3jGk w1hQ== X-Gm-Message-State: ALQs6tCDBv0lYxSuHpO4m1yoTKzuObGAuGM3B4O2Bz68iD3UipcNy/pT e2B7cltcupbvQdql9zCJ0H1Kd/oTlHoBQHX6/dg= X-Received: by 10.31.55.11 with SMTP id e11mr7893726vka.192.1523779064242; Sun, 15 Apr 2018 00:57:44 -0700 (PDT) MIME-Version: 1.0 Received: by 10.103.222.15 with HTTP; Sun, 15 Apr 2018 00:57:43 -0700 (PDT) In-Reply-To: <1523595999-27433-9-git-send-email-yamada.masahiro@socionext.com> References: <1523595999-27433-1-git-send-email-yamada.masahiro@socionext.com> <1523595999-27433-9-git-send-email-yamada.masahiro@socionext.com> From: Ulf Magnusson Date: Sun, 15 Apr 2018 09:57:43 +0200 Message-ID: Subject: Re: [PATCH 08/30] kconfig: add built-in function support To: Masahiro Yamada 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 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. Cheers, Ulf