Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 13 Sep 1998 09:51:13 -0500 (CDT)
From:      Conrad Sabatier <conrads@neosoft.com>
To:        freebsd-stable@FreeBSD.ORG
Subject:   Awk problem (bug?)
Message-ID:  <XFMail.980913095113.conrads@neosoft.com>

next in thread | raw e-mail | index | archive | help
If this would be better posted to another list, please let me know, and I'll
remail it.

Background:

FreeBSD 2.2.7-STABLE, cvsup/make world/kernel build done on Aug 28, 1998.

I recently decided to try writing an external filtering program for "suck".
Here's the mechanism as described in the suck man page:

              1. suck will write a 8 byte long string, which rep-
              resents the length of the header record on stdin of
              the external program.  Then length is in ascii,  is
              left-aligned, and ends in a newline (example: "1234
              \n").
              2. suck will then write the header on stdin of  the
              external program.
              3.  suck  will wait for a 2 character response code
              on stdout.  This response code is either  "0\n"  or
              "1\n"  (NOT BINARY ZERO OR ONE, ASCII ZERO OR ONE).
              If the return code is zero, suck will download  the
              article, if it is one, suck won't.
              4.  When  there  are  no  more articles, the length
              written down (for step 1) will be  zero  (again  in
              ascii  "0        \n").  Suck will then wait for the
              external program to exit before continuing on.  The
              external program can do any clean up it needs, then
              exit.  Note:  suck  will  not  continue  processing
              until the external program exits.

Unfortunately, my awk script would not communicate properly with suck using the
standard /usr/bin/awk.  For some reason, the result string my script was
writing to stdout was not being read by suck, and both the script and suck
would simply hang in a piperd state.

So, I installed kawk from the ports collection, and it worked!

Here's the script.  So far, it just checks the Newsgroups: header against the
active file and rejects the article if any group is not found:


#!/usr/local/bin/kawk -f

BEGIN   {
                active = "/usr/local/news/lib/active"
                logfile = "/usr/local/news/suck.kill.log"
                stdin = "/dev/stdin"
                stdout = "/dev/stdout"
        }

# size of header?

/^[0-9]+ *$/ \
{
        FS = " "
        if ($1 == "0")
        {
                print "===== NO MORE ARTICLES =====" >> logfile
                exit
        }
        headsize = int($1)
        size = 0
        next
}

# All other header lines

{
        print $0 >> logfile
        FS = " "
        size += (length + 1)
        if ($1 == "Newsgroups:")
        {
                NGS = $2
                FS = ","
                n = split ($2, group)
                FS = " "
                act_groups = 0

                for (i = 1; i <= n; i++)
                {
                        while (getline <active)
                        {
                                if ($1 == group[i])
                                {
                                        act_groups++
                                        break
                                }
                        }
                        close (active)
                        if (act_groups < i)
                        {
                                break
                        }
                }

        }
        if (size >= headsize)
        {
                if (act_groups < n)
                {
                        print "===== ARTICLE REJECTED =====" >> logfile
                        print "1" >stdout
                }
                else
                {
                        print "===== ARTICLE ACCEPTED =====" >> logfile
                        print "0" >stdout
                }
        next
        }
}



----------------------------------
E-Mail: Conrad Sabatier <conrads@neosoft.com>
Date: 13-Sep-98
Time: 09:38:11

This message was sent by XFMail
----------------------------------

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-stable" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?XFMail.980913095113.conrads>