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 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 3B637C2B9F4 for ; Wed, 23 Jun 2021 00:10:15 +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 15E3961351 for ; Wed, 23 Jun 2021 00:10:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 15E3961351 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 726E3829BE; Wed, 23 Jun 2021 02:10:11 +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="JybLTiK2"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8E26C829C0; Wed, 23 Jun 2021 02:10:09 +0200 (CEST) Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) (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 4D0D5829BA for ; Wed, 23 Jun 2021 02:10:06 +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-wr1-x42c.google.com with SMTP id d11so629440wrm.0 for ; Tue, 22 Jun 2021 17:10:06 -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=yFZ+lYefL4lUrWKExY1jsotEZQsOl0VFb5I9nXI0weo=; b=JybLTiK2LRtfQ+RwJcMXwj1dnxMLbjc97IDqHnzZUrlb6rkEgz2jZI7eykwCYRFBM5 2wtikAReDNCAjhRmMe54iBKe3E451VKx68Hq1WepnzNTQnmgCjrJTkTyacQrBgHMqqfl Gl0YM8xWOYflNhjuzKwrkhV5AKxmBTCTX/ERU= 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=yFZ+lYefL4lUrWKExY1jsotEZQsOl0VFb5I9nXI0weo=; b=XViE/1KpdzKx1JVyB7UwmLoPuScLVBYw+4bQ4R12Lo2ScfIDWD91xyzg2sdns5wtf+ xiG0+jsQNiLYssrwTXpzjSgxVmWziswT+bRfJmEy/5gud+3rh2bL7oYIloh/aF16Cmha 7gr0RRgreo8uGh3N3L2w1QzDBLEjjAw6pP/f5k1nHbfctv92Sgyolt7CK3+Lzx4h11/Z V5my4/WT7t5oScMSs2qN2vKsqAiQDKKWnoZTWmUfDQPyhzDa5IpkP668xGtI/vkeuk9n zT3htjNdfL30mWao60vIFkLSuWcvruWmJ+If+fCF2YzwTSXCVGDe3FB4EF6j8Wv55AIf fhdQ== X-Gm-Message-State: AOAM533NM9kIJj86IsfhrPnTAn4XYfKhIGDqFXb5nl9Rwd5X52TII0Hz 9/JkAFQ7Jp+6VPVhraK0FFoXCuoDr0By1EV6Uy9M0w== X-Google-Smtp-Source: ABdhPJxyvr1ePuXRF5Y4LcuZnAhhOOrvbtAQWgggZQI35JV8pFch3sRdHTaRpNi7UIyPBGlaWFPzG7diqkZEgXR9Wj4= X-Received: by 2002:a5d:64ee:: with SMTP id g14mr8390135wri.66.1624407005640; Tue, 22 Jun 2021 17:10:05 -0700 (PDT) MIME-Version: 1.0 References: <20210622135042.133904-1-roland.gaudig-oss@weidmueller.com> <20210622135042.133904-2-roland.gaudig-oss@weidmueller.com> <573f7c82-985c-cf55-ac75-b55dc408e3e4@seco.com> In-Reply-To: <573f7c82-985c-cf55-ac75-b55dc408e3e4@seco.com> From: Simon Glass Date: Tue, 22 Jun 2021 18:09:54 -0600 Message-ID: Subject: Re: [PATCH v1 1/1] cmd: setexpr: add dec operation for converting variable to decimal To: Sean Anderson Cc: roland.gaudig-oss@weidmueller.com, 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 Sean, On Tue, 22 Jun 2021 at 13:30, Sean Anderson wrote: > > > > On 6/22/21 3:25 PM, Simon Glass wrote: > > 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). > > Perhaps 0d123? Though I would prefer to remove many of the implicit > assumptions of hex input. Right, we can't use 'd' because it is valid hex. I believe hex is the right default. We just need an easy way to use decimal. - Simon > > --Sean > > > > > Can you please add a test for this in test//cmd/setexpr.c and also, > > how about adding something in doc/usage? > > > > Regards, > > Simon > >