From owner-freebsd-stable Sun Sep 13 07:54:02 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id HAA08003 for freebsd-stable-outgoing; Sun, 13 Sep 1998 07:54:02 -0700 (PDT) (envelope-from owner-freebsd-stable@FreeBSD.ORG) Received: from as5200-port-254.no.neosoft.com (as5200-01-254.no.neosoft.com [206.27.167.254]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id HAA07957 for ; Sun, 13 Sep 1998 07:53:56 -0700 (PDT) (envelope-from conrads@as5200-port-254.no.neosoft.com) Received: (from conrads@localhost) by as5200-port-254.no.neosoft.com (8.8.8/8.8.7) id JAA25144 for freebsd-stable@FreeBSD.ORG; Sun, 13 Sep 1998 09:51:13 -0500 (CDT) (envelope-from conrads) Message-ID: X-Mailer: XFMail 1.3 [p0] on FreeBSD X-Priority: 3 (Normal) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit MIME-Version: 1.0 Date: Sun, 13 Sep 1998 09:51:13 -0500 (CDT) Reply-To: conrads@neosoft.com Organization: NeoSoft, Inc. From: Conrad Sabatier To: freebsd-stable@FreeBSD.ORG Subject: Awk problem (bug?) Sender: owner-freebsd-stable@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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 = 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 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