Article View: news.software.nntp
Article #49345Re: Subset tool
From: Kai Henningsen
Date: Sat, 09 Dec 2000 17:29
Date: Sat, 09 Dec 2000 17:29
82 lines
3275 bytes
3275 bytes
rra@stanford.edu (Russ Allbery) wrote on 06.12.00 in <ylbsupdqju.fsf@windlord.stanford.edu>:
> Jeffrey M Vinocur <jeff@litech.org> writes:
> > bill@scconsult.com (Bill Cole) wrote:
>
> >> What am I missing that makes "grep <pattern> newsgroups" insufficient?
>
> > Err, grep doesn't do wildmat...
>
> A wildmat-using version of grep would actually be pretty easy to write and
> would be generally useful.
Using the INN 1.x wildmat code (I suspect latter versions would work just
as well), I wrote this rather crude tool some time ago. Consider it to be
public domain; it's not large enough to bother. I'm using it mostly in
Perl scripts associated with GUP.
Usage: wfilter <pattern file> <group list> <output group list>
#include "wildmat.c"
#include <assert.h>
#include <stdio.h>
#include <string.h>
FILE *pat, *lst, *out;
char buf[3000];
#define MAXPAT 100000
char *pats[MAXPAT];
int nxt, i, ok;
int main(int argc, char *argv[])
{
assert(argc == 4);
assert(pat = fopen(argv[1], "r"));
while (!feof(pat)) {
memset(buf, '\0', sizeof(buf));
fgets(buf, sizeof(buf) - 1, pat);
if (!*buf)
break;
if (buf[strlen(buf) - 1] == '\n')
buf[strlen(buf) - 1] = '\0';
if (!*buf)
break;
pats[nxt++] = strdup(buf);
assert(nxt < MAXPAT);
}
fclose(pat);
assert(lst = fopen(argv[2], "r"));
assert(out = fopen(argv[3], "w"));
while (!feof(lst)) {
memset(buf, '\0', sizeof(buf));
fgets(buf, sizeof(buf) - 1, lst);
if (!*buf)
break;
if (buf[strlen(buf) - 1] == '\n')
buf[strlen(buf) - 1] = '\0';
if (!*buf)
break;
ok = 0;
for (i = 0; i < nxt; i++) {
if (pats[i][0] == '!') {
if (ok)
ok = !wildmat(buf, pats[i] + 1);
} else {
if (!ok)
ok = wildmat(buf, pats[i]);
}
}
if (ok)
fprintf(out, "%s\n", buf);
}
fclose(lst);
fclose(out);
return 0;
}
Kai
--
http://www.westfalen.de/private/khms/
"... by God I *KNOW* what this network is for, and you can't have it."
- Russ Allbery (rra@stanford.edu)
Technical Details
Message-ID:
<7rZsHHd1w-B@khms.westfalen.de>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!supernews.google.com!sn-xit-02!supernews.com!isdnet!newsfeeds.belnet.be!news.belnet.be!newscore.univie.ac.at!newsmaster-01.atnet.at!atnet.at!tahina.priv.at!news.khms.westfalen.de!khms.westfalen.de!kaihReferences:
<jeff-A2896D.18035004122000@newsstand.cit.cornell.edu> <jeff-826F26.14363605122000@newsstand.cit.cornell.edu> <bill-0512001539590001@fireproof.scconsult.com> <jeff-83F69E.01272906122000@newsstand.cit.cornell.edu> <ylbsupdqju.fsf@windlord.stanford.edu>Show Full Headers
Complete Article Headers
Message-ID: <7rZsHHd1w-B@khms.westfalen.de> Subject: Re: Subset tool Date: Sat, 09 Dec 2000 17:29:00 +0000 From: kaih=7rZsHHd1w-B@khms.westfalen.de (Kai Henningsen) References: <jeff-A2896D.18035004122000@newsstand.cit.cornell.edu> <jeff-826F26.14363605122000@newsstand.cit.cornell.edu> <bill-0512001539590001@fireproof.scconsult.com> <jeff-83F69E.01272906122000@newsstand.cit.cornell.edu> <ylbsupdqju.fsf@windlord.stanford.edu> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!supernews.google.com!sn-xit-02!supernews.com!isdnet!newsfeeds.belnet.be!news.belnet.be!newscore.univie.ac.at!newsmaster-01.atnet.at!atnet.at!tahina.priv.at!news.khms.westfalen.de!khms.westfalen.de!kaih Newsgroups: news.software.nntp X-Newsreader: CrossPoint v3.12d.kh5 R/C435 Organization: Organisation? Me?! Are you kidding? Lines: 81 X-No-Junk-Mail: I do not want to get *any* junk mail. Comment: Unsolicited commercial mail will incur an US$100 handling fee per received mail. X-Fix-Your-Modem: +++ATS2=255&WO1