Re: [hackers] [sbase] expr: Don't interpret any arguments || sin

From: Evan Gates <evan.gates_AT_gmail.com>
Date: Tue, 21 Apr 2015 10:21:46 -0700

If you want to allow a negative number to come first and not be
treated as an option that is fine, but you still need to accept -- as
an end to options. From the last paragraph of the "APPLICATION USAGE"
section of expr(1p)[0]:

Therefore, the conforming application must employ the "--" construct
of Guideline 10 of the Base Definitions volumne of POSIX.1-2008,
Section 12.2, Utility Syntax Guidelines to protect its operands if
there is any chance the first operand might be a negative integer (or
any string with a leading minus).

We need to accept then ignore -- as a first argument. We can accept a
first argument with a leading - as a non-option if we want as an
extension.

-emg

[0] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/expr.html

On Tue, Apr 21, 2015 at 9:09 AM, <git_AT_suckless.org> wrote:
> commit 504855ff96389b02fd92197792a7b26069cde593
> Author: sin <sin_AT_2f30.org>
> Date: Tue Apr 21 17:08:14 2015 +0100
>
> expr: Don't interpret any arguments
>
> expr -1 '<' 1 failed previously.
>
> There is no need to have usage at all, any errors will be flagged
> up as necessary further down.
>
> diff --git a/expr.c b/expr.c
> index 5e4f19d..608d9a8 100644
> --- a/expr.c
> +++ b/expr.c
> _AT_@ -252,22 +252,12 @@ parse(char *expr[], int numexpr)
> return (valp->str && *valp->str) || valp->num;
> }
>
> -static void
> -usage(void)
> -{
> - enprintf(3, "usage: %s expression\n", argv0);
> -}
> -
> int
> main(int argc, char *argv[])
> {
> int ret;
>
> - ARGBEGIN {
> - default:
> - usage();
> - } ARGEND;
> -
> + argv0 = argv[0], argc--, argv++;
> ret = !parse(argv, argc);
> enfshut(3, stdout, "<stdout>");
>
>
Received on Tue Apr 21 2015 - 19:21:46 CEST

This archive was generated by hypermail 2.3.0 : Tue Apr 21 2015 - 19:24:16 CEST