[PATCH v3 0/6] cmd: setexpr: add fmt format string operation

Roland Gaudig roland.gaudig-oss at weidmueller.com
Fri Jul 23 14:29:17 CEST 2021


From: Roland Gaudig <roland.gaudig at weidmueller.com>


In contrast to version 2, the "fmt" operator has been made more flexible
like its Bash counterpart, as some comments to version 2 requested.
For license compatibility reasons the code for parsing the format string
has been taken from the BusyBox project and not from Bash.

The _maxags limit for setexpr has been increased to 8, which allows up
to 4 remaining arguments for the format string.

This patch adds C like format string capabilities to the setexpr
command. Here are some examples:

  => setexpr foo fmt %d 0x100
  => echo $foo
  256
  =>

  => setexpr foo fmt 0x%08x 0x63
  => echo $foo
  0x00000063
  =>

  => setexpr foo fmt %%%o 8
  => echo $foo
  %10
  =>

  => setexpr foo fmt \"0x%08x-%s-%d-%s\" $a $b $c $d
  => echo $foo
  0x00000eff-hello-99-world
  =>

Format string handling can be turned on by enabling the
CONFIG_CMD_SETEXPR_FMT option. Enabling that option will increase code
size by 2480 bytes on ARM target and 1648 bytes on ARM Thumb2 target.
Handling of float already has been removed. A further reduction is
possible by disabling the escape character handling.

Changes in v3:
 - enable Bash like format string support for the setexpr fmt operator
 - import format string parsing routines from Busybox project

Changes in v2:
 - replace the setexpr dec operator by fmt for simple format strings


(no changes since v1)

Roland Gaudig (6):
  lib: strto: add simple_strtoll function
  cmd: printf: import busybox-1.33.1 printf.c
  cmd: printf: add helper functions from busybox
  cmd: setexpr: add format string handling
  doc: usage: add description for setexpr command
  test: cmd: setexpr: add format string tests

 MAINTAINERS           |   6 +
 cmd/Kconfig           |   8 +
 cmd/Makefile          |   1 +
 cmd/printf.c          | 647 ++++++++++++++++++++++++++++++++++++++++++
 cmd/printf.h          |   8 +
 cmd/setexpr.c         |  37 ++-
 doc/usage/index.rst   |   1 +
 doc/usage/setexpr.rst | 148 ++++++++++
 include/vsprintf.h    |   1 +
 lib/strto.c           |   8 +
 test/cmd/setexpr.c    |  84 ++++++
 11 files changed, 945 insertions(+), 4 deletions(-)
 create mode 100644 cmd/printf.c
 create mode 100644 cmd/printf.h
 create mode 100644 doc/usage/setexpr.rst

-- 
2.25.1



More information about the U-Boot mailing list