All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Roland Gaudig (OSS)" <roland.gaudig-oss@weidmueller.com>
To: u-boot@lists.denx.de
Cc: "Simon Glass" <sjg@chromium.org>, "Marek Behún" <marek.behun@nic.cz>
Subject: Re: [PATCH v1 1/1] cmd: setexpr: add dec operation for converting variable to decimal
Date: Wed, 23 Jun 2021 08:20:01 +0000	[thread overview]
Message-ID: <6d081f17-3ae3-6e24-fa09-dc6c703d5f8e@weidmueller.com> (raw)

Hi Simon,

On Tue, 22. Jun 2021 at 21:25, Simon Glass <sjg@chromium.org> wrote:
>
> Hi Roland,
> 
> On Tue, 22 Jun 2021 at 07:51, <roland.gaudig-oss@weidmueller.com> wrote:
>>
>> From: Roland Gaudig <roland.gaudig@weidmueller.com>
>>
>> This patch extends the setexpr command with a dec operator to
>> convert an input value to decimal.
>>
>> Signed-off-by: Roland Gaudig <roland.gaudig@weidmueller.com>
>> ---
>>
>>  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).

This 0x prefix would then also be parsed by get_arg(), as it does currently
with the 0x prefix?

For my application as input to the Linux bootargs it is important, that the
resulting text stored in the variable after running setexpr has no prefix
at all.

> Can you please add a test for this in test//cmd/setexpr.c and also,
> how about adding something in doc/usage?

Yes, I will add a test and a description to doc/usage.

Regards,
Roland

             reply	other threads:[~2021-06-23  8:20 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-23  8:20 Roland Gaudig (OSS) [this message]
  -- strict thread matches above, loose matches on Subject: below --
2021-06-23  8:53 [PATCH v1 1/1] cmd: setexpr: add dec operation for converting variable to decimal Roland Gaudig (OSS)
2021-06-23  9:43 ` Wolfgang Denk
2021-06-22 13:50 [PATCH v1 0/1] " roland.gaudig-oss
2021-06-22 13:50 ` [PATCH v1 1/1] " roland.gaudig-oss
2021-06-22 19:25   ` Simon Glass
2021-06-22 19:30     ` Sean Anderson
2021-06-23  0:09       ` Simon Glass
2021-06-23  6:08         ` Wolfgang Denk
2021-06-25 12:57           ` Tom Rini
2021-06-23  6:03   ` Wolfgang Denk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6d081f17-3ae3-6e24-fa09-dc6c703d5f8e@weidmueller.com \
    --to=roland.gaudig-oss@weidmueller.com \
    --cc=marek.behun@nic.cz \
    --cc=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.