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: J Naman
Subject: Re: fix getopt.awk first long option parsing
Date: Fri, 6 Jan 2023 14:51:57 -0500

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]