From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85676C2B9F4 for ; Tue, 22 Jun 2021 19:25:56 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 61CF46128E for ; Tue, 22 Jun 2021 19:25:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 61CF46128E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0131B829C4; Tue, 22 Jun 2021 21:25:44 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="dxsJZxbM"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C86FF829BC; Tue, 22 Jun 2021 21:25:38 +0200 (CEST) Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 9B2B5829BC for ; Tue, 22 Jun 2021 21:25:33 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@google.com Received: by mail-wm1-x335.google.com with SMTP id n23so47557wms.2 for ; Tue, 22 Jun 2021 12:25:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=1Qv9t+LGB7zjMquiPvoxVZbnsj/djgoKEcBAeI85D7w=; b=dxsJZxbMYZsj+G6TImnny7yHFe41wiqmq+CPwr4xQ6cZ+es1O89Es/9i/RJtTTGZnJ eDA+zWGO4cSpA7ZdX/j4yXNP+kwSTXIgUcHhrZjixSkKWwGwu9qetUKVYuBn61kbZtdc sw19LPPKsAQgFYvbuSs0zzHCF+yscEqgUvmug= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=1Qv9t+LGB7zjMquiPvoxVZbnsj/djgoKEcBAeI85D7w=; b=dumAiM9yV9HaZh7NAz7ZkO+G/xMQi0PVQ2Pa8k9+bcUtvGu0FtQzYBZmp83GkFOYmX K1HUUTW32EDrLX5EoWUQ19zU8kYJujnYxwrss6znSC4bZE9dwg6PCaFmGa6c/RgQ54zB Zx4zZS9ahRgBM80K+bEiXyPNc5rjf8IeaQ91aYZYKdXG8y1jMaW29mh7jLoBHnytcj0r BcR2x+BG67c/H8mTBwT6HUxSiuKVCY1HpduWnLaKnJJ44s5e7DcestZTgkoGPw5nETc5 tEWiWhI836JleGKiEjJo7SAdaTkYdYQOgvyvtdxc5Yi6bDTyhvtiQ4LfbtCJBUvIrgjE PIVw== X-Gm-Message-State: AOAM533wGJ3uxqxoG+iBpn8phe/LBoIPyDYexe+KD09g8K0Eqg6hOwVN 54FTZuU+2RhCeN4mPmk/hrU5WjbKcId4Y22PnfYI3A== X-Google-Smtp-Source: ABdhPJzcIPyoYCTUzA7WiGI1Ykmu2/qBR0HRLKdEsR2ityhH/uiLCGEeiTiM6FNCxXkKjQj/RknXreVU76+1CzzgnSY= X-Received: by 2002:a05:600c:1c87:: with SMTP id k7mr6264805wms.168.1624389932813; Tue, 22 Jun 2021 12:25:32 -0700 (PDT) MIME-Version: 1.0 References: <20210622135042.133904-1-roland.gaudig-oss@weidmueller.com> <20210622135042.133904-2-roland.gaudig-oss@weidmueller.com> In-Reply-To: <20210622135042.133904-2-roland.gaudig-oss@weidmueller.com> From: Simon Glass Date: Tue, 22 Jun 2021 13:25:20 -0600 Message-ID: Subject: Re: [PATCH v1 1/1] cmd: setexpr: add dec operation for converting variable to decimal To: roland.gaudig-oss@weidmueller.com Cc: U-Boot Mailing List , Roland Gaudig , =?UTF-8?B?TWFyZWsgQmVow7pu?= Content-Type: text/plain; charset="UTF-8" X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean Hi Roland, On Tue, 22 Jun 2021 at 07:51, wrote: > > From: Roland Gaudig > > This patch extends the setexpr command with a dec operator to > convert an input value to decimal. > > Signed-off-by: Roland Gaudig > --- > > cmd/setexpr.c | 16 ++++++++++++++-- > 1 file changed, 14 insertions(+), 2 deletions(-) > > diff --git a/cmd/setexpr.c b/cmd/setexpr.c > index e828be3970..2d4bee2182 100644 > --- a/cmd/setexpr.c > +++ b/cmd/setexpr.c > @@ -370,15 +370,16 @@ static int do_setexpr(struct cmd_tbl *cmdtp, int flag, int argc, > int w; > > /* > - * We take 3, 5, or 6 arguments: > + * We take 3, 4, 5, or 6 arguments: > * 3 : setexpr name value > + * 4 : setexpr name dec value > * 5 : setexpr name val1 op val2 > * setexpr name [g]sub r s > * 6 : setexpr name [g]sub r s t > */ > > /* > 6 already tested by max command args */ > - if ((argc < 3) || (argc == 4)) > + if (argc < 3) > return CMD_RET_USAGE; > > w = cmd_get_data_size(argv[0], 4); > @@ -398,6 +399,13 @@ static int do_setexpr(struct cmd_tbl *cmdtp, int flag, int argc, > return ret; > } > > + /* hexadecimal to decimal conversion: "setexpr name dec value" */ > + if (argc == 4 && (strcmp(argv[2], "dec") == 0)) { > + w = cmd_get_data_size(argv[3], 4); > + a = get_arg(argv[3], w); > + return env_set_ulong(argv[1], a); > + } > + > /* 5 or 6 args (6 args only with [g]sub) */ > #ifdef CONFIG_REGEX > /* > @@ -515,4 +523,8 @@ U_BOOT_CMD( > "setexpr name sub r s [t]\n" > " - Just like gsub(), but replace only the first matching substring" > #endif > + "\n" > + "setexpr name dec [*]value\n" > + " - set environment variable 'name' to the result of the decimal\n" > + " conversion of [*]value.\n" > ); > -- > 2.25.1 > This seems reasonable to me. I have been thinking of introducing a prefix for decimal, perhaps 0m123 ? ('m' for deciMal). Can you please add a test for this in test//cmd/setexpr.c and also, how about adding something in doc/usage? Regards, Simon