Skip to content

Commit f4f8d8b

Browse files
Roland Gaudigtrini
Roland Gaudig
authored andcommitted
cmd: setexpr: add format string handling
Add format string handling operator to the setexpr command. It allows to use C or Bash like format string expressions to be evaluated with the result being stored inside the environment variable name. setexpr <name> fmt <format> [value]... The following example setexpr foo fmt "%d, 0x%x" 0x100 ff will result in $foo being set to "256, 0xff". Signed-off-by: Roland Gaudig <[email protected]> Reviewed-by: Simon Glass <[email protected]>
1 parent 6244cda commit f4f8d8b

File tree

6 files changed

+300
-178
lines changed

6 files changed

+300
-178
lines changed

MAINTAINERS

+5
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,11 @@ F: arch/sandbox/
10501050
F: doc/arch/sandbox.rst
10511051
F: include/dt-bindings/*/sandbox*.h
10521052

1053+
SETEXPR
1054+
M: Roland Gaudig <[email protected]>
1055+
S: Maintained
1056+
F: cmd/printf.c
1057+
10531058
SH
10541059
M: Marek Vasut <[email protected]>
10551060
M: Nobuhiro Iwamatsu <[email protected]>

cmd/Kconfig

+8
Original file line numberDiff line numberDiff line change
@@ -1414,6 +1414,14 @@ config CMD_SETEXPR
14141414
Also supports loading the value at a memory location into a variable.
14151415
If CONFIG_REGEX is enabled, setexpr also supports a gsub function.
14161416

1417+
config CMD_SETEXPR_FMT
1418+
bool "setexpr_fmt"
1419+
default n
1420+
depends on CMD_SETEXPR
1421+
help
1422+
Evaluate format string expression and store result in an environment
1423+
variable.
1424+
14171425
endmenu
14181426

14191427
menu "Android support commands"

cmd/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ obj-$(CONFIG_CMD_SF) += sf.o
141141
obj-$(CONFIG_CMD_SCSI) += scsi.o disk.o
142142
obj-$(CONFIG_CMD_SHA1SUM) += sha1sum.o
143143
obj-$(CONFIG_CMD_SETEXPR) += setexpr.o
144+
obj-$(CONFIG_CMD_SETEXPR_FMT) += printf.o
144145
obj-$(CONFIG_CMD_SPI) += spi.o
145146
obj-$(CONFIG_CMD_STRINGS) += strings.o
146147
obj-$(CONFIG_CMD_SMC) += smccc.o

0 commit comments

Comments
 (0)