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: Andrew J. Schorr
Subject: Re: difference in RS handling for equivalent regexps with unending input stream
Date: Wed, 3 Jul 2024 13:22:49 -0400
User-agent: Mutt/1.5.21 (2010-09-15)

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]