diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2016-03-20 10:03:43 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2016-03-20 10:03:43 +0000 |
commit | 2115c8f6a7b45de1f8a073ab207eb28a0784b149 (patch) | |
tree | 947722a5798cc708da0feca21c499456fa082a4d | |
parent | c2edfe05b05ad2f19c659dda994641c2d958aeab (diff) | |
download | s6-portable-utils-2115c8f6a7b45de1f8a073ab207eb28a0784b149.tar.gz s6-portable-utils-2115c8f6a7b45de1f8a073ab207eb28a0784b149.tar.xz s6-portable-utils-2115c8f6a7b45de1f8a073ab207eb28a0784b149.zip |
Stylistic cleanups for s6-test, document the -v expression, credit Aranea
-rw-r--r-- | AUTHORS | 3 | ||||
-rw-r--r-- | doc/s6-test.html | 7 | ||||
-rw-r--r-- | 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 <ska-skaware@skarnet.org> +Contributors: + Luis Ressel <aranea@aixah.de> + Thanks to: Dan J. Bernstein <djb@cr.yp.to> Jean Marot <jean.marot@salle-s.org> 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. </p> +<h2> Non-standard expressions </h2> + +<ul> + <li> <tt>-v <em>VAR</em></tt> : tests whether the +<em>VAR</em> variable is defined in the current environment. </li> +</ul> + </body> </html> 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 <skalibs/bytestr.h> #include <skalibs/fmtscan.h> #include <skalibs/strerr2.h> +#include <skalibs/env.h> #include <skalibs/djbunix.h> -#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)) ; } } |