bug-gawk
[Top][All Lists]
Advanced

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

Re: difference in RS handling for equivalent regexps with unending input


From: Ed Morton
Subject: Re: difference in RS handling for equivalent regexps with unending input stream
Date: Fri, 5 Jul 2024 13:48:54 -0500
User-agent: Mozilla Thunderbird

Andy - done, see https://stackoverflow.com/a/78712922/1745001.

    Ed.

On 7/5/2024 9:42 AM, Andrew J. Schorr wrote:
Hi Ed,

OK, fair enough. Having wasted all of this time on this solution, I'm
wondering if it should be posted in response to the stackoverflow question,
but for some reason, Stackoverflow won't let me create an account. Perhaps
you could share there.

Regards,
Andy

On Thu, Jul 04, 2024 at 05:03:01AM -0500, Ed Morton wrote:
Thanks Andy but unfortunately I'm not able to install any extensions such as
the "select" library that don't just come with the gawk installation on my work
computer (where I most need to develop/use solutions to problems) and so I
avoid doing so on my personal one too to keep the tools I use on both as
similar as possible. So I won't be able to try your suggestion.

     Ed.

On 7/3/2024 12:22 PM, Andrew J. Schorr wrote:

     On Wed, Jul 03, 2024 at 06:58:27AM -0500, Ed Morton wrote:

         I'd be interested to hear if you or anyone else reading this knows
         of a way to read the input 1 char at a time in a case like this
         where the input is unending and we can't rely on a regexp match for
         RS to find each character.

     Have you considered trying to use the select extension and its
     nonblocking feature?

     Something like this sort of seems to work:

     (echo "A;B;C;D;"; cat -) | gawk -v 'RS=[;=]' -lselect -ltime '
     BEGIN {
        fd = input_fd("")
        set_non_blocking(fd)
        PROCINFO[FILENAME, "RETRY"] = 1
        while (1) {
           delete readfds
           readfds[fd] = ""
           select(readfds, writefds, exceptfds)
           while ((rc = getline x) > 0) {
              if (rc > 0)
                 printf "%d [%s]\n", ++n, x
              else if (rc != 2) {
                 print "Error: non-retry error"
                 exit 1
              }
           }
        }
     }'

     Regards,
     Andy





reply via email to

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