colonel@ellie.UUCP (Col. G. L. Sicherman) (05/15/86)
I got here late, but so long as you're interested, here's a fast C
program that I use to do the same thing. (BSD4, but easily ported.)
Ignores unsubscribed groups. Also ignores new groups, alas.
---------- TEAR OFF THE TOP OF YOUR HEAD AND SEND IT IN ----------
/*
* urn - which groups have unread news?
* the Colonel. 1986.
*/
#include <sys/types.h>
#include <sys/dir.h>
#include <sys/stat.h>
#include <stdio.h>
#include <ctype.h>
#define NEWSRC ".newsrc"
#define NEWSDIR "/usr/spool/news"
FILE *Tab;
DIR *Drlist;
main() {
char curdir[100], inline[150], *ip, *range, *index(), *strcat(),
*strcpy();
int k;
long max, m, lineno, atol();
struct direct *dp;
struct stat sb;
chdir(getenv("HOME"));
Tab = fopen(NEWSRC,"r");
if (!Tab) {
fprintf(stderr,"urn: cannot read %s in home directory\n",
NEWSRC);
exit(1);
}
lineno=0;
for (;;) {
for (ip=inline; '\n'!=(k=getc(Tab)); *ip++ = k)
if (EOF==k) {
if (ip!=inline) fprintf(stderr,
"urn: premature EOF\n");
fprintf(stderr,"urn: %ld lines read\n",lineno);
exit(ip!=inline);
}
*ip = '\0';
lineno+=1;
if (!index(inline,':')) continue;
for (ip=inline; ':'!= *ip; ip++) if ('.'==*ip) *ip='/';
*ip++ = '\0';
range = ip;
strcpy(curdir,NEWSDIR);
strcat(curdir,"/");
strcat(curdir,inline);
if (!(Drlist=opendir(curdir))) continue;
chdir(curdir);
max = 0;
while (dp=readdir(Drlist)) {
if (stat(dp->d_name,&sb)) continue;
if (S_IFREG != S_IFMT & sb.st_mode) continue;
m = atol(dp->d_name);
if (max<m) max=m;
}
for (ip=range; *ip; ip++) ;
--ip;
while (isdigit(*ip)) --ip;
++ip;
if (max > atol(ip)) {
for (ip=inline; *ip; ip++) if ('/'==*ip) *ip='.';
puts(inline);
}
closdir:
closedir(Drlist);
}
}
--
Col. G. L. Sicherman
UU: ...{rocksvax|decvax}!sunybcs!colonel
CS: colonel@buffalo-cs
BI: csdsicher@sunyabva