Signed-off-by: Peter Meerwald <pmeerw at pmeerw.net> --- src/pulsecore/cli-command.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/pulsecore/cli-command.c b/src/pulsecore/cli-command.c index 6a38dd9..6434f43 100644 --- a/src/pulsecore/cli-command.c +++ b/src/pulsecore/cli-command.c @@ -70,6 +70,7 @@ struct command { #define META_FAIL ".fail" #define META_NOFAIL ".nofail" #define META_IFEXISTS ".ifexists" +#define META_IFENV ".ifenv" #define META_ELSE ".else" #define META_ENDIF ".endif" @@ -2118,6 +2119,28 @@ int pa_cli_command_execute_line_stateful(pa_core *c, const char *s, pa_strbuf *b const char *filename = cs+l+strspn(cs+l, whitespace); *ifstate = pa_module_exists(filename) ? IFSTATE_TRUE : IFSTATE_FALSE; } + } else if (l == sizeof(META_IFENV)-1 && !strncmp(cs, META_IFENV, l)) { + if (!pa_cli_check_ifstate(buf, ifstate, cs)) + return -1; + else { + const char *e = cs+l+strspn(cs+l, whitespace); + char *envname; + + *ifstate = IFSTATE_FALSE; + l = strcspn(e, whitespace); + + if ((envname = pa_xstrndup(e, l)) != NULL) { + char *ev = getenv(envname); + if (ev) { + const char *v = e+l+strspn(e+l, whitespace); + l = strcspn(v, whitespace); + *ifstate = !l || !strncmp(ev, v, + PA_MAX(strlen(ev), l)) ? + IFSTATE_TRUE : IFSTATE_FALSE; + } + pa_xfree(envname); + } + } } else { pa_strbuf_printf(buf, "Invalid meta command: %s\n", cs); if (*fail) return -1; -- 1.9.1