🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: demon.tech.amiga
Article #536

Re: Arexx Again

#536
From: Terrance Richard Boyes
Date: Wed, 08 Mar 2000 00:00
139 lines
6511 bytes
Stephen Bridges <newsreply@bh01.demon.co.uk> wrote:

[snip]

> If anyone is interested, the whole script scans NewsRog (or Yam)
> postings and extracts the ICQ UINs and asks if you want to add them to
> your contact list in StrICQ. Because my posts contain my UIN twice, and I
> was using my posts to test the script I thought it might be a nice idea
> for the script to identify repeats and ignore them. Thanks again Tez.

No problem, but now I know what you're doing you will definitely
be interested in using the other syntax I suggested (which I 
first encountered in the OS/2 Rexx nntpclient, and have been
using ever since - mainly in awk scripts :)

The concept is known as "associative indexing" and is really
quite a clever piece of implementation (technically it appears
to be using a hash'ing algorithm, but who cares how it works...).
It's only of use if you need exact string matching (so it's
of little use for killfiles as they normally involve pattern matches),
and is mostly of use only with unique strings.

Here's a simple pseudo-code example of the idea as it works for
message-id checking...

/* open a file containing a list of message-ids */
err=open(hist_io,newshistory,'R')
do until eof(hist_io)
/* read each line */
  messageid = readln(hist_io)
/* and use the clever trick */
  messageids.messageid = 1     /* [1] */
end

/* open a file containing a list of newsgroups and timestamps */
err=open(groups_io,newsgroups,'R')
newsgroups.0 = 0
do until eof(groups_io)
/* read each line */
  newsgroup_num = newsgroups.0 + 1
  line = readln(groups_io)
  newsgroup = word(line,1)
  datestamp = word(line,2)
  timestamp = word(line,3)
  /* be slightly clever */
  newsgroups.newsgroup_num.GROUP = newsgroup     /* [2] */
  newsgroups.newsgroup_num.DATES = datestamp
  newsgroups.newsgroup_num.TIMES = timestamp
  newsgroups.0 = newsgroup_num
end
err = close(group_io)

/* NB this won't actually work as I'm missing out some responses */
/* plus it'll do a couple of dodgy things with the '.' */
/* and it has no error checking */

err=open(nntp_io,'TCP:'newsserver'/nntp','R')
/* read and throwaway the welcome */
err=readln(nntp_io)

err=open(batch_io,newsbatch,'W')
/* command that will get a list of message-ids for my.group */
do newsgroup_num = 1 to newsgroups.0
  newsgroup = newsgroups.newsgroup_num.GROUP
  datestamp = newsgroups.newsgroup_num.DATES
  timestamp = newsgroups.newsgroup_num.TIMES
  nntpcommand='NEWNEWS 'newsgroup' 'datestamp' 'timestamp
  err=writeln(nntp_io,nntpcommand)
  /* read and throwaway the response code */
  err=readln(nntp_io)
  
  /* if it's a '.' then end of message-ids */
  do until messageid == '.'    /* use == to keep AP happy :) */
    /* get the next message-id */
    messageid=readln(nntp_io)
    /* use the clever bit :) */
    if messageids.messageid = 1 then dupes = dupes + 1     /* [3] */
    else do
      newarts = newarts + 1
      /* do something cos it's a new article */
      /* may want to add a killfile in here */
      err=open(temp_io,tempfile,'W')
      nntpcommand = 'ARTICLE 'messageid
      err=writeln(nntp_io,nntpcommand)
      /* read and throwaway the response code */
      err=readln(nntp_io)
      /* if it's a '.' then end of article */
      artsize = 0
      do until line == '.'    /* use == to keep AP happy :) */
        line = readln(nntp_io)
        artsize = artsize + length(line)
        err=writeln(temp_io,line)
      end
      err=close(temp_io)
      err=writeln(batch_io,'#!rnews 'artsize)
      err=open(temp_io,tempfile,'R')
      do until eof(temp_io)
        line=readln(temp_io)
        err=writeln(batch_io,line)
      end
      err=close(temp_io)
      /* use of clever bit to ensure we don't download dupe messages */
      messageids.messageid = 1     /* [4] */
      /* and write it to the newshistory for next time */
      err=writeln(hist_io,messageid)
    end
  end
end

/* be tidy */
nntpcommand='QUIT'
err=writeln(nntp_io,nntpcommand)
err=close(nntp_io)
err=close(batch_io)
err=close(hist_io)

/* */

[1] rather than have a number for each message-id and having to later
scan through that list for each message-id in a big do/while loop
with some sort of break when we hit a match, we actually create a
new variable whose name is the message-id
[2] unrelated, but uses a similar feature
[3] here we directly look up the message-id, if the value is 1 then
we know it's been read from our history file
[4] similar to [1] but done on an ongoing basis

NB all usage of these "stem variables" (variablename.) in ARexx
uses a fair bit of RAM, doing it with strings rather than numbers
doesn't use much more though.

You should be able to do a similar thing for your UINs, meaning
you can take out the inelegant loops :)

PS this article started out as a little code-sample...

-- 
<URL:http://www.pierrot.co.uk/>                                  Team AMIGA
Parallel lines never meet, unless you bend one or both of them.
Technical Details
Message-ID: <20000308.192817.C2984023.yTaa@pierrot.co.uk>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <mC.4C.c62nI4QdY64528955.NR@bh01.demon.co.uk> <20000305.195739.C2984023.koaa@pierrot.co.uk> <0A.Y0.d62gK7BJwV25wYb45.NR@bh01.demon.co.uk> <20000306.234340.0AA80202.qAaa@pierrot.co.uk> <s0.H1.f62KKnF8Ir35Gq155.NR@bh01.demon.co.uk>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1160fd,370c0c3eb2c4a678
X-Google-Attributes: gid1160fd,public
From: tez@pierrot.co.uk (Terrance Richard Boyes)
Subject: Re: Arexx Again
Date: 2000/03/08
Message-ID: <20000308.192817.C2984023.yTaa@pierrot.co.uk>
X-Deja-AN: 594829203
X-PGP-Fingerprint: 20 66 0F E8 85 64 9C 2C  6F 82 6F 19 6C 2F 6A 1D
X-Cancel-Lock: TEZT:b972ad2bf02152ad8c6de0c2468f0586 f46d894af866f5f07165e4c36e6625c0
X-PGP-Keyfile: <URL:http://www.pierrot.co.uk/pgpauth/>
References: <mC.4C.c62nI4QdY64528955.NR@bh01.demon.co.uk>   <20000305.195739.C2984023.koaa@pierrot.co.uk> <0A.Y0.d62gK7BJwV25wYb45.NR@bh01.demon.co.uk> <20000306.234340.0AA80202.qAaa@pierrot.co.uk> <s0.H1.f62KKnF8Ir35Gq155.NR@bh01.demon.co.uk>
X-PGP-Auth: pub   512/3A14C4B9 1999/04/22 Tez Boyes <tez@pierrot.co.uk>    iQBVAwUBOMap1kXush46FMS5AQGIowH/YhWTwhy6vgMtmNzdFMIlNneLw0mSxO2U    Kg4GvHQ6OEleO++Ls+HmDuwgQEOVEeYx0QPQuXgP34w1cIHBPRnZtQ==    =JMpl
X-NaMLServ: $VER: v0.9b <tez@pierrot.co.uk>
X-Complaints-To: abuse@demon.net
X-Mail2News-Path: news.demon.net!tungsten.btinternet.com!host213-1-169-163.btinternet.com!pierrot.co.uk!tez@pierrot.co.uk
X-Trace: mail2news.demon.co.uk 952543711 mail2news:5948 mail2news mail2news.demon.co.uk
Organization: ECL.Net
User-Agent: tin/pre-1.4-980618 (AMIGA)
X-Lan-Trace: news.pierrot.lan 20000308.192817 news:yTaa IDENT tez@btinternet.com
Newsgroups: demon.tech.amiga