MINOR: cli: add two general purpose pointers and integers in the CLI struct
Most of the keywords don't need to have their own entry in the appctx
union, they just need to reuse some generic pointers like we've been
used to do in the appctx with st{0,1,2}. This patch adds p0, p1, i0, i1
and initializes them to zero before calling the parser. This way some
of the simplest existing keywords will be able to disappear from the
union.
It's worth noting that this is an extension to what was initially
attempted via the "private" member that I removed a few patches ago by
not understanding how it was supposed to be used. Here the fact that
we share the same union will force us to be stricter: the code either
uses the general purpose variables or it uses its own fields but not
both.
diff --git a/include/types/applet.h b/include/types/applet.h
index 82e4781..672f9db 100644
--- a/include/types/applet.h
+++ b/include/types/applet.h
@@ -93,6 +93,8 @@
struct {
const char *msg; /* pointer to a persistent message to be returned in CLI_ST_PRINT state */
char *err; /* pointer to a 'must free' message to be returned in CLI_ST_PRINT_FREE state */
+ void *p0, *p1; /* general purpose pointers and integers for registered commands, initialized */
+ int i0, i1; /* to 0 by the CLI before first invocation of the keyword parser. */
} cli; /* context used by the CLI */
/* all entries below are used by various CLI commands, please
diff --git a/src/cli.c b/src/cli.c
index 82c1bf7..adb2dd6 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -455,6 +455,7 @@
}
appctx->st2 = 0;
+ memset(&appctx->ctx.cli, 0, sizeof(appctx->ctx.cli));
kw = cli_find_kw(args);
if (!kw)