diff options
author | Tom Rini <trini@konsulko.com> | 2025-05-29 08:27:13 -0600 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2025-05-29 08:27:13 -0600 |
commit | 23be77e18d19ddb9c2ecdf71638bacfbc369fd13 (patch) | |
tree | 73d82f75a865be88af0e376baa0fc2980f1b4b48 /cmd/test.c | |
parent | 2f3766949bbea7aa5a472157561d387fd94205d2 (diff) | |
parent | 6990cc5257283a631a286a4321a3515c7537f636 (diff) |
Merge patch series "regex patches"
Rasmus Villemoes <ravi@prevas.dk> says:
This started as a rather simple patch, 1/12, adding the ability to
more conveniently do regex matching in shell.
But with that, it became very easy to see what the slre library can
and especially what it cannot do, and that way I found both outright
bugs and a "wow, doesn't it support that syntax" gotcha. I couldn't
find any tests ('git grep slre -- test/' was empty), so I added a
small test suite and tweaked slre.c.
Link: https://lore.kernel.org/r/20250513084034.654865-1-ravi@prevas.dk
Diffstat (limited to 'cmd/test.c')
-rw-r--r-- | cmd/test.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/cmd/test.c b/cmd/test.c index b4c3eabf9f6..a42a523d33d 100644 --- a/cmd/test.c +++ b/cmd/test.c @@ -7,6 +7,7 @@ #include <command.h> #include <fs.h> #include <log.h> +#include <slre.h> #include <vsprintf.h> #define OP_INVALID 0 @@ -26,6 +27,7 @@ #define OP_INT_GT 14 #define OP_INT_GE 15 #define OP_FILE_EXISTS 16 +#define OP_REGEX 17 const struct { int arg; @@ -49,6 +51,9 @@ const struct { {0, "-z", OP_STR_EMPTY, 2}, {0, "-n", OP_STR_NEMPTY, 2}, {0, "-e", OP_FILE_EXISTS, 4}, +#ifdef CONFIG_REGEX + {1, "=~", OP_REGEX, 3}, +#endif }; static int do_test(struct cmd_tbl *cmdtp, int flag, int argc, @@ -141,6 +146,20 @@ static int do_test(struct cmd_tbl *cmdtp, int flag, int argc, case OP_FILE_EXISTS: expr = file_exists(ap[1], ap[2], ap[3], FS_TYPE_ANY); break; +#ifdef CONFIG_REGEX + case OP_REGEX: { + struct slre slre; + + if (slre_compile(&slre, ap[2]) == 0) { + printf("Error compiling regex: %s\n", slre.err_str); + expr = 0; + break; + } + + expr = slre_match(&slre, ap[0], strlen(ap[0]), NULL); + break; + } +#endif } switch (op) { |