From 2115c8f6a7b45de1f8a073ab207eb28a0784b149 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Sun, 20 Mar 2016 10:03:43 +0000 Subject: Stylistic cleanups for s6-test, document the -v expression, credit Aranea --- AUTHORS | 3 +++ doc/s6-test.html | 7 +++++++ src/skaembutils/s6-test.c | 19 +++++++++---------- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/AUTHORS b/AUTHORS index d2df44b..10b43e0 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,6 +1,9 @@ Main author: Laurent Bercot +Contributors: + Luis Ressel + Thanks to: Dan J. Bernstein Jean Marot diff --git a/doc/s6-test.html b/doc/s6-test.html index d256cdf..6b48d42 100644 --- a/doc/s6-test.html +++ b/doc/s6-test.html @@ -50,5 +50,12 @@ program; however, if your arguments never start with a backslash, it exhibits th exact same behaviour.

+

Non-standard expressions

+ +
    +
  • -v VAR : tests whether the +VAR variable is defined in the current environment.
  • +
+ diff --git a/src/skaembutils/s6-test.c b/src/skaembutils/s6-test.c index 9ee11e0..36b7b15 100644 --- a/src/skaembutils/s6-test.c +++ b/src/skaembutils/s6-test.c @@ -7,9 +7,10 @@ #include #include #include +#include #include -#define USAGE "s6-test expression or [ expression ]" +#define USAGE "s6-test expression... or [ expression... ]" enum opnum { @@ -276,16 +277,16 @@ static unsigned int parse (struct node *tree, unsigned int n) return stack[1] ; } -static int run (struct node const *tree, unsigned int root, char const *const *envp) +static int run (struct node const *tree, unsigned int root) { switch (tree[root].op) { case T_NOT : - return !run(tree, tree[root].arg1, envp) ; + return !run(tree, tree[root].arg1) ; case T_AND : - return run(tree, tree[root].arg1, envp) && run(tree, tree[root].arg2, envp) ; + return run(tree, tree[root].arg1) && run(tree, tree[root].arg2) ; case T_OR : - return run(tree, tree[root].arg1, envp) || run(tree, tree[root].arg2, envp) ; + return run(tree, tree[root].arg1) || run(tree, tree[root].arg2) ; case T_EXIST : { struct stat st ; @@ -492,9 +493,7 @@ static int run (struct node const *tree, unsigned int root, char const *const *e return n1 <= n2 ; } case T_ENV : - { - return env_get2(envp, tree[tree[root].arg1].data) ? 1 : 0 ; - } + return !!env_get(tree[tree[root].arg1].data) ; default: strerr_dief1x(111, "operation not implemented") ; } @@ -503,7 +502,7 @@ errorint: strerr_dief2x(100, tree[root].data, " requires integer arguments") ; } -int main (int argc, char const *const *argv, char const *const *envp) +int main (int argc, char const *const *argv) { PROG = "s6-test" ; if (argc <= 1) return 1 ; @@ -516,6 +515,6 @@ int main (int argc, char const *const *argv, char const *const *envp) n-- ; else strerr_dief1x(100, "parse error: missing closing bracket") ; } - return !run(tree, parse(tree, n), envp) ; + return !run(tree, parse(tree, n)) ; } } -- cgit v1.2.3