home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Source Code 1992 March
/
Source_Code_CD-ROM_Walnut_Creek_March_1992.iso
/
usenet
/
altsrcs
/
1
/
1013
< prev
next >
Wrap
Internet Message Format
|
1990-12-28
|
14KB
From: chip@chinacat.Lonestar.ORG (Chip Rosenthal)
Newsgroups: news.software.b,alt.sources
Subject: program to check sys file entries
Message-ID: <1066@chinacat.Lonestar.ORG>
Date: 12 Mar 90 20:28:18 GMT
The "chksys" script verifies USENET B2.11 "sys" file entries. This utility
is extremely helpful for sites which receive a partial news feed. It
examines sys files (both yours and from your feeding site) and verifies
that it is passing the newsgroups you want, but not those newsgroups you
don't.
#! /bin/sh
# this is a "shar" archive - run through "/bin/sh" to extract 4 files:
# README chksys ngmatch.c Makefile
# Wrapped by chip@chinacat on Mon Mar 12 14:22:50 CST 1990
# Unpacking this archive requires: sed test wc (possibly mkdir)
# Existing files will not be clobbered unless "-c" is specified on the cmd line.
if test -f README -a "$1" != "-c" ; then
echo "README: file exists - will not be overwritten"
else
echo "x - README (file 1 of 4, 2485 chars)"
sed -e 's/^X//' << 'END_OF_FILE_README' > README
XThe "chksys" script verifies USENET B2.11 "sys" file entries. This utility
Xis extremely helpful for sites which receive a partial news feed. It
Xexamines sys files (both yours and from your feeding site) and verifies
Xthat it is passing the newsgroups you want, but not those newsgroups you
Xdon't.
X
XYou will need to edit the following configurations in the "chksys" script:
X
Xactive_file Point this to your active file (e.g. /usr/lib/news/active).
X
Xng_file Point this to a list of all the known newsgroups. You
X will probably need to go to a site which receives a full
X news feed to get a file for this purpose. I snarfed
X "/usr/spool/ftp/news/newsgroups" from uunet to use here.
X Note that your own "newsgroups" file is not usable for
X this because it is only supposed to contain the locally
X valid groups.
X
XThen say something like:
X
X chksys /usr/lib/news/sys
X
XAs an example, this is the output I obtained when I ran "chksys" on the
Xsys file from one of my feeding sites:
X
X +-----
X | The following desired groups are not being transmitted:
X | control local.test to.sequoia
X | junk to.balkan to.ssbn
X | local.general to.rpp386 to.texbell
X | local.news
X |
X | The following unwanted groups are being transmitted:
X | alt.cyberpunk.movement rec.arts.anime sci.electronics
X | alt.cyberpunk.tech rec.arts.comics sci.environment
X | austin.announce rec.arts.tv.soaps
X +-----
X
XThe top section lists those newsgroups which are valid on the local system,
Xbut are not matched by the "sys" file entry on the feeding system. Note
Xthat this is all fine -- that system shouldn't be feeding me any of these
Xgroups. The bottom section, on the other hand, does list some newsgroups
Xwhich are being fed to me which I don't want.
X
XA couple of notes:
X
X(1) The "chksys" script uses some awk features which are not available in
X older versions of awk (namely the sub() function and the ability to
X create user-defined functions).
X
X(2) If you use the "ME" pseudo-sitename in your local sys file entry to
X describe what you receive, you will have to use the "-s ME" option
X on the command line when you check your local sys file.
X
XChip Rosenthal
X12 Mar 90
X<chip@chinacat.Unicom.COM>
X
END_OF_FILE_README
size="`wc -c < README`"
if test 2485 -ne "$size" ; then
echo "README: extraction error - got $size chars"
fi
fi
if test -f chksys -a "$1" != "-c" ; then
echo "chksys: file exists - will not be overwritten"
else
echo "x - chksys (file 2 of 4, 4707 chars)"
sed -e 's/^X//' << 'END_OF_FILE_chksys' > chksys
X:
X# chksys - Program to check sys file entries.
X#
X# This program scans a USENET B2.11 sys file, and determines whether it
X# correctly lists the desired newsgroups. That is, it verifies that all
X# the groups will be matched by a sys file entry, and no undesired groups
X# will be matched. This program is very useful for sites which receive a
X# partial news feed - it may be used to verify that both your sys file and
X# your connecting site's sys file are correct with respect to the newsgroups
X# you want.
X#
X# Three files are required to perform these checks: sys_file, active_file,
X# and ng_file. You need to specify "sys_file" on the command line. You
X# will need to edit the definitions of "active_file" and "ng_file" for your
X# local site. The purpose of these files is:
X#
X# sys_file The USENET sys file to scan - specified on the command line.
X#
X# active_file File containing a list of all the newsgroups valid on this
X# machine. The file is organized with one newsgroup per line,
X# with the newsgroup name at the beginning of the line, and any
X# subsequent text on the line ignored. This should be configured
X# to point to your "active" file.
X#
X# ng_file File containing a list of all the newsgroups known, again one
X# newsgroup per line with the newsgroup name at the beginning of
X# the line. I snarfed "/usr/spool/ftp/news/newsgroups" from
X# uunet to use for this file.
X#
X# In addition, "ngmatch" must point to the "ngmatch" command.
X#
X# The following temporary files are used:
X#
X# $TMP.valid All newsgroups valid on this system.
X# $TMP.known All newsgroups known throughout the entire universe.
X# $TMP.syspat Newsgroup patterns from sys file for specified system.
X# $TMP.m-valid The subset of valid groups matched by this sys entry.
X# $TMP.m-known The subset of valid groups matched by this sys entry.
X# $TMP.out Scratch output file.
X#
X# Mon Mar 12 13:35:53 1990 - Chip Rosenthal <chip@chinacat.Unicom.COM>
X# Original composition.
X
XUSAGE="usage: $0 [-s sitename] [sys_file]"
XTMP=/tmp/ng$$
X
Xsys_name=`uuname -l` # Default name if '-s' not specified.
Xsys_file= # Will be specified on command line.
Xactive_file=/usenet/lib/news/active # List of newsgroups valid locally.
Xng_file=/usenet/lib/news/newsgr-uunet # List of all possible newsgroups.
Xngmatch=./ngmatch # The "ngmatch" command.
X
X# Crack command line.
Xif set -- `getopt 's:' $*` ; then
X : getopt worked
Xelse
X echo "$USAGE" 1>&2
X exit 1
Xfi
Xwhile : ; do
X case "$1" in
X -s) shift ; sys_name="$1" ; shift ;;
X --) shift ; break ;;
X *) echo "$USAGE" 1>&2 ; exit 1 ;;
X esac
Xdone
Xcase $# in
X 0) sys_file= ;;
X 1) sys_file=$1 ;;
X *) echo "$USAGE" 1>&2 ; exit 1 ;;
Xesac
X
X# Make sure files exist.
Xfor f in $sys_file $active_file $ng_file ; do
X if [ ! -r $f ] ; then
X echo "$0: file '$f' not found or unreadable" 1>&2
X exit 1
X fi
Xdone
X
X# Set cleanup trap.
Xtrap 'rm -f $TMP.* ; exit 1' 1 2 3
X
X# Create the lists of valid and known newsgroups.
Xsed -e 's/[ ].*//' $active_file | sort -u > $TMP.valid
Xsed -e 's/[ ].*//' $ng_file | sort -u > $TMP.known
X
X# Go through sys file and select the records which match this system.
Xawk '
X
XBEGIN { line = "" }
X
Xfunction print_line(line)
X{
X split(line,field,":")
X gsub("[ ]","",field[1])
X gsub("[ ]","",field[2])
X printf("%s %s\n",field[1],field[2])
X}
X
X{
X sub("#.*","",$0) # trim comments
X if ( length($0) == 0 ) # skip empty lines
X next
X line = line $0 # append line to buffer
X len = length(line) # check for backslash at end of line
X if ( substr(line,len,1) == "\\" ) {
X line = substr(line,1,len-1)
X next
X }
X print_line(line) # cleanup and output the line
X line = ""
X}
X
XEND {
X if ( line != "" )
X print_line(line)
X}
X
X' $sys_file | sed -n -e "s/^$sys_name //p" > $TMP.syspat
X
X# Select groups from the valid and known lists which match a sys file pattern.
X>$TMP.m-valid
X>$TMP.m-known
Xcat $TMP.syspat | while read pat ; do
X $ngmatch "$pat" $TMP.valid >> $TMP.m-valid
X $ngmatch "$pat" $TMP.known >> $TMP.m-known
Xdone
Xsort -u -o $TMP.m-valid $TMP.m-valid
Xsort -u -o $TMP.m-known $TMP.m-known
X
X# Find the valid groups which aren't being transmitted.
Xecho ""
Xcomm -23 $TMP.valid $TMP.m-valid > $TMP.out
Xif [ -s $TMP.out ] ; then
X echo "The following desired groups are not being transmitted:"
X pr -3 -t -l0 -w80 -o4 $TMP.out
Xelse
X echo "All desired groups are being transmitted."
Xfi
X
X# Find the transmitted groups which aren't valid.
Xecho ""
Xcomm -23 $TMP.m-known $TMP.valid > $TMP.out
Xif [ -s $TMP.out ] ; then
X echo "The following unwanted groups are being transmitted:"
X pr -3 -t -l0 -w80 -o4 $TMP.out
Xelse
X echo "No unwanted groups are being transmitted."
Xfi
X
Xrm $TMP.*
Xexit 0
X
END_OF_FILE_chksys
size="`wc -c < chksys`"
if test 4707 -ne "$size" ; then
echo "chksys: extraction error - got $size chars"
fi
fi
if test -f ngmatch.c -a "$1" != "-c" ; then
echo "ngmatch.c: file exists - will not be overwritten"
else
echo "x - ngmatch.c (file 3 of 4, 2584 chars)"
sed -e 's/^X//' << 'END_OF_FILE_ngmatch.c' > ngmatch.c
X/*
X * ngmatch - Select newsgroups from a file which match a newsgroup pattern.
X * The file must contain the newsgroups one per line. The ngmatch() procedure
X * was lifted from the USENET B2.11 funcs.c file.
X *
X * Mon Mar 12 13:39:35 1990 - Chip Rosenthal <chip@chinacat.Unicom.COM>
X * Original composition.
X */
X
X#include <stdio.h>
X
X#define USAGE "usage: %s pattern [ file ... ]\n"
X
X#define NGDELIM ','
X#define NEGCHAR '!'
X#define BUFLEN 256
X#define TRUE 1
X#define FALSE 0
X
Xmain(argc,argv)
Xint argc;
Xchar *argv[];
X{
X int status, i;
X char *pattern;
X FILE *fp;
X
X if ( argc < 2 ) {
X fprintf(stderr,USAGE,argv[0]);
X exit(1);
X }
X pattern = argv[1];
X
X status = 0;
X if ( argc == 2 ) {
X status = dofile(pattern,stdin);
X } else {
X status = 0;
X for ( i = 2 ; i < argc ; ++i ) {
X if ( (fp=fopen(argv[i],"r")) == NULL ) {
X perror(argv[i]);
X exit(2);
X }
X status |= dofile(pattern,fp);
X (void) fclose(fp);
X }
X }
X
X exit ( status == 0 ? 0 : 1 );
X /*NOTREACHED*/
X}
X
X
Xint dofile(pat,fp)
Xchar *pat;
XFILE *fp;
X{
X static char buf[BUFLEN];
X int status;
X
X status = -1;
X while ( fgets(buf,sizeof(buf),fp) != NULL ) {
X buf[strlen(buf)-1] = '\0';
X if ( ngmatch(buf,pat) ) {
X status = 0;
X puts(buf);
X }
X }
X return status;
X}
X
X
X/*
X * News group matching.
X *
X * nglist is a list of newsgroups.
X * sublist is a list of subscriptions.
X * sublist may have "meta newsgroups" in it.
X * All fields are NGDELIM separated,
X * and there is an NGDELIM at the end of each argument.
X *
X * Currently implemented glitches:
X * sublist uses 'all' like shell uses '*', and '.' like shell '/'.
X * If subscription X matches Y, it also matches Y.anything.
X */
Xngmatch(nglist, sublist)
Xregister char *nglist, *sublist;
X{
X register char *n, *s;
X register int rc;
X
X rc = FALSE;
X for (n = nglist; *n != '\0' && rc == FALSE;) {
X for (s = sublist; *s != '\0';) {
X if (*s != NEGCHAR)
X rc = rc || ptrncmp(s, n);
X else
X rc = rc && !ptrncmp(s+1, n);
X while (*s++ != NGDELIM && *s != '\0')
X ;
X }
X while (*n++ != NGDELIM && *n != '\0')
X ;
X }
X return rc;
X}
X
X/*
X * Compare two newsgroups for equality.
X * The first one may be a "meta" newsgroup.
X */
Xptrncmp(ng1, ng2)
Xregister char *ng1, *ng2;
X{
X while (*ng1 != NGDELIM && *ng1 != '\0') {
X if (ng1[0]=='a' && ng1[1]=='l' && ng1[2]=='l') {
X ng1 += 3;
X while (*ng2 != NGDELIM && *ng2 != '.' && *ng2 != '\0')
X if (ptrncmp(ng1, ng2++))
X return(TRUE);
X return ptrncmp(ng1, ng2);
X } else if (*ng1++ != *ng2++)
X return FALSE;
X }
X return *ng2 == '.' || *ng2 == NGDELIM || *ng2 == '\0';
X}
X
END_OF_FILE_ngmatch.c
size="`wc -c < ngmatch.c`"
if test 2584 -ne "$size" ; then
echo "ngmatch.c: extraction error - got $size chars"
fi
fi
if test -f Makefile -a "$1" != "-c" ; then
echo "Makefile: file exists - will not be overwritten"
else
echo "x - Makefile (file 4 of 4, 1290 chars)"
sed -e 's/^X//' << 'END_OF_FILE_Makefile' > Makefile
X
X# %Z% %M% %I% %E% %U%
X# Makefile for "ngmatch" (generated by makemake version 1.00.09)
X# Created by chip@chinacat on Mon Mar 12 14:20:49 CST 1990
X
XSHELL = /bin/sh
XCC = cc
XDEFS =
XCOPTS = -O
XLOPTS =
XLIBS =
XDEBUG = -g -DDEBUG
XLINTFLAGS = -DLINT
X
XTARG = ngmatch
XOTHERS =
X
XSRCS = ngmatch.c
X
XOBJS = ngmatch.o
X
X# Any edits below this line will be lost if "makemake" is rerun!
X# Commands may be inserted after the '#%custom' line at the end of this file.
X
XCFLAGS = $(COPTS) $(DEFS) # $(DEBUG)
XLFLAGS = $(LOPTS) # $(DEBUG)
X
Xall: $(TARG) $(OTHERS)
Xinstall: all ; inst Install
Xclean: ; rm -f $(TARG) $(OBJS) a.out core $(TARG).lint
Xclobber: clean ; inst -u Install
Xlint: $(TARG).lint
X
X$(TARG): $(OBJS)
X $(CC) $(LFLAGS) -o $@ $(OBJS) $(LIBS)
X
X$(TARG).lint: $(TARG)
X lint $(LINTFLAGS) $(DEFS) $(SRCS) $(LIBS) > $@
X
Xngmatch.o: ngmatch.c
X
Xmake: ;
X makemake -i -v1.00.09 -aMakefile \
X -DSHELL='$(SHELL)' -DCC='$(CC)' -DDEFS='$(DEFS)' \
X -DCOPTS='$(COPTS)' -DLOPTS='$(LOPTS)' -DLIBS='$(LIBS)' \
X -DDEBUG='$(DEBUG)' -DLINTFLAGS='$(LINTFLAGS)' \
X -DOTHERS='$(OTHERS)' $(TARG) $(SRCS)
X
X#%custom - commands below this line will be maintained if 'makemake' is rerun
X
XARLIST = README chksys ngmatch.c Makefile
X
Xshar: chksys.shar
Xchksys.shar: $(ARLIST) ; shar $(ARLIST) > $@
X
END_OF_FILE_Makefile
size="`wc -c < Makefile`"
if test 1290 -ne "$size" ; then
echo "Makefile: extraction error - got $size chars"
fi
fi
echo "done - 4 files extracted"
exit 0
--
Chip Rosenthal | Yes, you're a happy man and you're
chip@chinacat.Lonestar.ORG | a lucky man, but are you a smart
Unicom Systems Development, 512-482-8260 | man? -David Bromberg