bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: fix getopt.awk first long option parsing


From: arnold
Subject: Re: fix getopt.awk first long option parsing
Date: Sun, 08 Jan 2023 00:42:59 -0700
User-agent: Heirloom mailx 12.5 7/5/10

Thanks.

I'm not that worried about running this code with --posix. BWK awk
and mawk both have /dev/stderr built-in, as does gawk in non-POSIX
mode, so it's good enough.

Arnold

J Naman <jnaman2@gmail.com> wrote:

> When I tested getopt() with the RLENGTH fix, in *--posix mode*, getopt has
> a fatal
>    error:
> gawk: getopt.awk:42: fatal: cannot redirect to `/dev/stderr': No such file
> or
>    directory
> command line was: gawk --posix -f "%AWKRUN%" -- -x --qqq
>
> My *proposed* "portable" solution is a small change to the code and two
> small functions.
>
> #   fatal error in --posix mode:
> #   printf("%s -- invalid option\n", thisopt) > "/dev/stderr"
>     printerr(sprintf("%s -- invalid option\n", thisopt))
> ...
>
> #  print to stderr in either --posix mode OR gawk mode
> #    on mingw(win32) or unix
> #  note: special characters must be quoted differently in different shells
>
> #  Portable software can be excruciating ... use this portable library
> function
>
> function printerr(str)
> {
>    if (isPOSIX()) {
>       #   print str | "cat 1>&2"    # does NOT work on mingw(win32) platform
>       system("echo " str " 1>&2")   # should work all platforms
>    } else {
>       print(str) > "/dev/stderr"
>    }
> }
>
> function isPOSIX()
> {
>    # returns number: 1 = Posix mode; 0 = Gawk specific mode
>    return (length(FUNCTAB) < 22)
>    # 22 = number of awk funcs in traditional awk; could be ' == 0'
> }
>
> #========
> The full alt_getopt.awk code is freely available at:
> https://sourceforge.net/projects/gawk-apps-library/files/
> Hope this is useful, J Naman



reply via email to

[Prev in Thread] Current Thread [Next in Thread]