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 >
Internet Message Format  |  1990-12-28  |  14KB

  1. From: chip@chinacat.Lonestar.ORG (Chip Rosenthal)
  2. Newsgroups: news.software.b,alt.sources
  3. Subject: program to check sys file entries
  4. Message-ID: <1066@chinacat.Lonestar.ORG>
  5. Date: 12 Mar 90 20:28:18 GMT
  6.  
  7. The "chksys" script verifies USENET B2.11 "sys" file entries.  This utility
  8. is extremely helpful for sites which receive a partial news feed.  It
  9. examines sys files (both yours and from your feeding site) and verifies
  10. that it is passing the newsgroups you want, but not those newsgroups you
  11. don't.
  12.  
  13. #! /bin/sh
  14. # this is a "shar" archive - run through "/bin/sh" to extract 4 files:
  15. #   README chksys ngmatch.c Makefile
  16. # Wrapped by chip@chinacat on Mon Mar 12 14:22:50 CST 1990
  17. # Unpacking this archive requires:  sed test wc (possibly mkdir)
  18. # Existing files will not be clobbered unless "-c" is specified on the cmd line.
  19. if test -f README -a "$1" != "-c" ; then
  20.     echo "README: file exists - will not be overwritten"
  21. else
  22.     echo "x - README (file 1 of 4, 2485 chars)"
  23.     sed -e 's/^X//' << 'END_OF_FILE_README' > README
  24. XThe "chksys" script verifies USENET B2.11 "sys" file entries.  This utility
  25. Xis extremely helpful for sites which receive a partial news feed.  It
  26. Xexamines sys files (both yours and from your feeding site) and verifies
  27. Xthat it is passing the newsgroups you want, but not those newsgroups you
  28. Xdon't.
  29. X
  30. XYou will need to edit the following configurations in the "chksys" script:
  31. X
  32. Xactive_file    Point this to your active file (e.g. /usr/lib/news/active).
  33. X
  34. Xng_file        Point this to a list of all the known newsgroups.  You
  35. X                will probably need to go to a site which receives a full
  36. X                news feed to get a file for this purpose.  I snarfed
  37. X                "/usr/spool/ftp/news/newsgroups" from uunet to use here.
  38. X                Note that your own "newsgroups" file is not usable for
  39. X                this because it is only supposed to contain the locally
  40. X                valid groups.
  41. X
  42. XThen say something like:
  43. X
  44. X    chksys /usr/lib/news/sys
  45. X
  46. XAs an example, this is the output I obtained when I ran "chksys" on the
  47. Xsys file from one of my feeding sites:
  48. X
  49. X    +-----
  50. X    | The following desired groups are not being transmitted:
  51. X    |     control                    local.test                 to.sequoia
  52. X    |     junk                       to.balkan                  to.ssbn
  53. X    |     local.general              to.rpp386                  to.texbell
  54. X    |     local.news
  55. X    | 
  56. X    | The following unwanted groups are being transmitted:
  57. X    |     alt.cyberpunk.movement     rec.arts.anime             sci.electronics
  58. X    |     alt.cyberpunk.tech         rec.arts.comics            sci.environment
  59. X    |     austin.announce            rec.arts.tv.soaps
  60. X    +-----
  61. X
  62. XThe top section lists those newsgroups which are valid on the local system,
  63. Xbut are not matched by the "sys" file entry on the feeding system.  Note
  64. Xthat this is all fine -- that system shouldn't be feeding me any of these
  65. Xgroups.  The bottom section, on the other hand, does list some newsgroups
  66. Xwhich are being fed to me which I don't want.
  67. X
  68. XA couple of notes:
  69. X
  70. X(1)  The "chksys" script uses some awk features which are not available in
  71. X     older versions of awk (namely the sub() function and the ability to
  72. X     create user-defined functions).
  73. X
  74. X(2)  If you use the "ME" pseudo-sitename in your local sys file entry to
  75. X     describe what you receive, you will have to use the "-s ME" option
  76. X     on the command line when you check your local sys file.
  77. X
  78. XChip Rosenthal
  79. X12 Mar 90
  80. X<chip@chinacat.Unicom.COM>
  81. X
  82. END_OF_FILE_README
  83.     size="`wc -c < README`"
  84.     if test 2485 -ne "$size" ; then
  85.     echo "README: extraction error - got $size chars"
  86.     fi
  87. fi
  88. if test -f chksys -a "$1" != "-c" ; then
  89.     echo "chksys: file exists - will not be overwritten"
  90. else
  91.     echo "x - chksys (file 2 of 4, 4707 chars)"
  92.     sed -e 's/^X//' << 'END_OF_FILE_chksys' > chksys
  93. X:
  94. X# chksys - Program to check sys file entries.
  95. X#
  96. X# This program scans a USENET B2.11 sys file, and determines whether it
  97. X# correctly lists the desired newsgroups.  That is, it verifies that all
  98. X# the groups will be matched by a sys file entry, and no undesired groups
  99. X# will be matched.  This program is very useful for sites which receive a
  100. X# partial news feed - it may be used to verify that both your sys file and
  101. X# your connecting site's sys file are correct with respect to the newsgroups
  102. X# you want.
  103. X#
  104. X# Three files are required to perform these checks:  sys_file, active_file,
  105. X# and ng_file.  You need to specify "sys_file" on the command line.  You
  106. X# will need to edit the definitions of "active_file" and "ng_file" for your
  107. X# local site.  The purpose of these files is:
  108. X#
  109. X# sys_file    The USENET sys file to scan - specified on the command line.
  110. X#
  111. X# active_file    File containing a list of all the newsgroups valid on this
  112. X#        machine.  The file is organized with one newsgroup per line,
  113. X#        with the newsgroup name at the beginning of the line, and any
  114. X#        subsequent text on the line ignored.  This should be configured
  115. X#        to point to your "active" file.
  116. X#
  117. X# ng_file    File containing a list of all the newsgroups known, again one
  118. X#        newsgroup per line with the newsgroup name at the beginning of
  119. X#        the line.  I snarfed "/usr/spool/ftp/news/newsgroups" from
  120. X#        uunet to use for this file.
  121. X#
  122. X# In addition, "ngmatch" must point to the "ngmatch" command.
  123. X#
  124. X# The following temporary files are used:
  125. X#
  126. X#   $TMP.valid        All newsgroups valid on this system.
  127. X#   $TMP.known        All newsgroups known throughout the entire universe.
  128. X#   $TMP.syspat        Newsgroup patterns from sys file for specified system.
  129. X#   $TMP.m-valid    The subset of valid groups matched by this sys entry.
  130. X#   $TMP.m-known    The subset of valid groups matched by this sys entry.
  131. X#   $TMP.out        Scratch output file.
  132. X#
  133. X# Mon Mar 12 13:35:53 1990 - Chip Rosenthal <chip@chinacat.Unicom.COM>
  134. X#    Original composition.
  135. X
  136. XUSAGE="usage: $0 [-s sitename] [sys_file]"
  137. XTMP=/tmp/ng$$
  138. X
  139. Xsys_name=`uuname -l`            # Default name if '-s' not specified.
  140. Xsys_file=                # Will be specified on command line.    
  141. Xactive_file=/usenet/lib/news/active    # List of newsgroups valid locally.
  142. Xng_file=/usenet/lib/news/newsgr-uunet    # List of all possible newsgroups.
  143. Xngmatch=./ngmatch            # The "ngmatch" command.
  144. X
  145. X# Crack command line.
  146. Xif set -- `getopt 's:' $*` ; then
  147. X    : getopt worked
  148. Xelse
  149. X    echo "$USAGE" 1>&2
  150. X    exit 1
  151. Xfi
  152. Xwhile : ; do
  153. X    case "$1" in
  154. X    -s)    shift ; sys_name="$1" ; shift ;;
  155. X    --)    shift ; break ;;
  156. X    *)    echo "$USAGE" 1>&2 ; exit 1 ;;
  157. X    esac
  158. Xdone
  159. Xcase $# in
  160. X    0)    sys_file= ;;
  161. X    1)    sys_file=$1 ;;
  162. X    *)    echo "$USAGE" 1>&2 ; exit 1 ;;
  163. Xesac
  164. X
  165. X# Make sure files exist.
  166. Xfor f in $sys_file $active_file $ng_file ; do
  167. X    if [ ! -r $f ] ; then
  168. X    echo "$0: file '$f' not found or unreadable" 1>&2
  169. X    exit 1
  170. X    fi
  171. Xdone
  172. X
  173. X# Set cleanup trap.
  174. Xtrap 'rm -f $TMP.* ; exit 1' 1 2 3
  175. X
  176. X# Create the lists of valid and known newsgroups.
  177. Xsed -e 's/[     ].*//' $active_file | sort -u > $TMP.valid
  178. Xsed -e 's/[     ].*//' $ng_file | sort -u > $TMP.known
  179. X
  180. X# Go through sys file and select the records which match this system.
  181. Xawk '
  182. X
  183. XBEGIN { line = "" }
  184. X
  185. Xfunction print_line(line)
  186. X{
  187. X    split(line,field,":")
  188. X    gsub("[     ]","",field[1])
  189. X    gsub("[     ]","",field[2])
  190. X    printf("%s    %s\n",field[1],field[2])
  191. X}
  192. X
  193. X{
  194. X    sub("#.*","",$0)            # trim comments
  195. X    if ( length($0) == 0 )        # skip empty lines
  196. X    next
  197. X    line = line $0            # append line to buffer
  198. X    len = length(line)            # check for backslash at end of line
  199. X    if ( substr(line,len,1) == "\\" ) {
  200. X    line = substr(line,1,len-1)
  201. X    next
  202. X    }
  203. X    print_line(line)            # cleanup and output the line
  204. X    line = ""
  205. X}
  206. X
  207. XEND {
  208. X    if ( line != "" )
  209. X    print_line(line)
  210. X}
  211. X
  212. X' $sys_file | sed -n -e "s/^$sys_name    //p" > $TMP.syspat
  213. X
  214. X# Select groups from the valid and known lists which match a sys file pattern.
  215. X>$TMP.m-valid
  216. X>$TMP.m-known
  217. Xcat $TMP.syspat | while read pat ; do
  218. X    $ngmatch "$pat" $TMP.valid >> $TMP.m-valid
  219. X    $ngmatch "$pat" $TMP.known >> $TMP.m-known
  220. Xdone
  221. Xsort -u -o $TMP.m-valid $TMP.m-valid
  222. Xsort -u -o $TMP.m-known $TMP.m-known
  223. X
  224. X# Find the valid groups which aren't being transmitted.
  225. Xecho ""
  226. Xcomm -23 $TMP.valid $TMP.m-valid > $TMP.out
  227. Xif [ -s $TMP.out ] ; then
  228. X    echo "The following desired groups are not being transmitted:"
  229. X    pr -3 -t -l0 -w80 -o4 $TMP.out
  230. Xelse
  231. X    echo "All desired groups are being transmitted."
  232. Xfi
  233. X
  234. X# Find the transmitted groups which aren't valid.
  235. Xecho ""
  236. Xcomm -23 $TMP.m-known $TMP.valid > $TMP.out
  237. Xif [ -s $TMP.out ] ; then
  238. X    echo "The following unwanted groups are being transmitted:"
  239. X    pr -3 -t -l0 -w80 -o4 $TMP.out
  240. Xelse
  241. X    echo "No unwanted groups are being transmitted."
  242. Xfi
  243. X
  244. Xrm $TMP.*
  245. Xexit 0
  246. X
  247. END_OF_FILE_chksys
  248.     size="`wc -c < chksys`"
  249.     if test 4707 -ne "$size" ; then
  250.     echo "chksys: extraction error - got $size chars"
  251.     fi
  252. fi
  253. if test -f ngmatch.c -a "$1" != "-c" ; then
  254.     echo "ngmatch.c: file exists - will not be overwritten"
  255. else
  256.     echo "x - ngmatch.c (file 3 of 4, 2584 chars)"
  257.     sed -e 's/^X//' << 'END_OF_FILE_ngmatch.c' > ngmatch.c
  258. X/*
  259. X * ngmatch - Select newsgroups from a file which match a newsgroup pattern.
  260. X * The file must contain the newsgroups one per line.  The ngmatch() procedure
  261. X * was lifted from the USENET B2.11 funcs.c file.
  262. X *
  263. X * Mon Mar 12 13:39:35 1990 - Chip Rosenthal <chip@chinacat.Unicom.COM>
  264. X *    Original composition.
  265. X */
  266. X
  267. X#include <stdio.h>
  268. X
  269. X#define USAGE    "usage: %s pattern [ file ... ]\n"
  270. X
  271. X#define NGDELIM    ','
  272. X#define NEGCHAR    '!'
  273. X#define BUFLEN    256
  274. X#define TRUE    1
  275. X#define FALSE    0
  276. X
  277. Xmain(argc,argv)
  278. Xint argc;
  279. Xchar *argv[];
  280. X{
  281. X    int status, i;
  282. X    char *pattern;
  283. X    FILE *fp;
  284. X
  285. X    if ( argc < 2 ) {
  286. X    fprintf(stderr,USAGE,argv[0]);
  287. X    exit(1);
  288. X    }
  289. X    pattern = argv[1];
  290. X
  291. X    status = 0;
  292. X    if ( argc == 2 ) {
  293. X    status = dofile(pattern,stdin);
  294. X    } else {
  295. X    status = 0;
  296. X    for ( i = 2 ; i < argc ; ++i ) {
  297. X        if ( (fp=fopen(argv[i],"r")) == NULL ) {
  298. X        perror(argv[i]);
  299. X        exit(2);
  300. X        }
  301. X        status |= dofile(pattern,fp);
  302. X        (void) fclose(fp);
  303. X    }
  304. X    }
  305. X
  306. X    exit ( status == 0 ? 0 : 1 );
  307. X    /*NOTREACHED*/
  308. X}
  309. X
  310. X
  311. Xint dofile(pat,fp)
  312. Xchar *pat;
  313. XFILE *fp;
  314. X{
  315. X    static char buf[BUFLEN];
  316. X    int status;
  317. X
  318. X    status = -1;
  319. X    while ( fgets(buf,sizeof(buf),fp) != NULL ) {
  320. X    buf[strlen(buf)-1] = '\0';
  321. X    if ( ngmatch(buf,pat) ) {
  322. X        status = 0;
  323. X        puts(buf);
  324. X    }
  325. X    }
  326. X    return status;
  327. X}
  328. X
  329. X
  330. X/*
  331. X * News group matching.
  332. X *
  333. X * nglist is a list of newsgroups.
  334. X * sublist is a list of subscriptions.
  335. X * sublist may have "meta newsgroups" in it.
  336. X * All fields are NGDELIM separated,
  337. X * and there is an NGDELIM at the end of each argument.
  338. X *
  339. X * Currently implemented glitches:
  340. X * sublist uses 'all' like shell uses '*', and '.' like shell '/'.
  341. X * If subscription X matches Y, it also matches Y.anything.
  342. X */
  343. Xngmatch(nglist, sublist)
  344. Xregister char *nglist, *sublist;
  345. X{
  346. X    register char *n, *s;
  347. X    register int rc;
  348. X
  349. X    rc = FALSE;
  350. X    for (n = nglist; *n != '\0' && rc == FALSE;) {
  351. X        for (s = sublist; *s != '\0';) {
  352. X            if (*s != NEGCHAR)
  353. X                rc = rc || ptrncmp(s, n);
  354. X            else
  355. X                rc = rc && !ptrncmp(s+1, n);
  356. X            while (*s++ != NGDELIM && *s != '\0')
  357. X                ;
  358. X        }
  359. X        while (*n++ != NGDELIM && *n != '\0')
  360. X            ;
  361. X    }
  362. X    return rc;
  363. X}
  364. X
  365. X/*
  366. X * Compare two newsgroups for equality.
  367. X * The first one may be a "meta" newsgroup.
  368. X */
  369. Xptrncmp(ng1, ng2)
  370. Xregister char *ng1, *ng2;
  371. X{
  372. X    while (*ng1 != NGDELIM && *ng1 != '\0') {
  373. X        if (ng1[0]=='a' && ng1[1]=='l' && ng1[2]=='l') {
  374. X            ng1 += 3;
  375. X            while (*ng2 != NGDELIM && *ng2 != '.' && *ng2 != '\0')
  376. X                if (ptrncmp(ng1, ng2++))
  377. X                    return(TRUE);
  378. X            return ptrncmp(ng1, ng2);
  379. X        } else if (*ng1++ != *ng2++)
  380. X            return FALSE;
  381. X    }
  382. X    return *ng2 == '.' || *ng2 == NGDELIM || *ng2 == '\0';
  383. X}
  384. X
  385. END_OF_FILE_ngmatch.c
  386.     size="`wc -c < ngmatch.c`"
  387.     if test 2584 -ne "$size" ; then
  388.     echo "ngmatch.c: extraction error - got $size chars"
  389.     fi
  390. fi
  391. if test -f Makefile -a "$1" != "-c" ; then
  392.     echo "Makefile: file exists - will not be overwritten"
  393. else
  394.     echo "x - Makefile (file 4 of 4, 1290 chars)"
  395.     sed -e 's/^X//' << 'END_OF_FILE_Makefile' > Makefile
  396. X
  397. X# %Z% %M% %I% %E% %U%
  398. X# Makefile for "ngmatch" (generated by makemake version 1.00.09)
  399. X# Created by chip@chinacat on Mon Mar 12 14:20:49 CST 1990
  400. X
  401. XSHELL = /bin/sh
  402. XCC = cc
  403. XDEFS = 
  404. XCOPTS = -O
  405. XLOPTS = 
  406. XLIBS = 
  407. XDEBUG = -g -DDEBUG
  408. XLINTFLAGS = -DLINT
  409. X
  410. XTARG = ngmatch
  411. XOTHERS = 
  412. X
  413. XSRCS = ngmatch.c
  414. X
  415. XOBJS = ngmatch.o
  416. X
  417. X# Any edits below this line will be lost if "makemake" is rerun!
  418. X# Commands may be inserted after the '#%custom' line at the end of this file.
  419. X
  420. XCFLAGS = $(COPTS) $(DEFS) # $(DEBUG)
  421. XLFLAGS = $(LOPTS) # $(DEBUG)
  422. X
  423. Xall:        $(TARG) $(OTHERS)
  424. Xinstall:    all        ; inst Install
  425. Xclean:                ; rm -f $(TARG) $(OBJS) a.out core $(TARG).lint
  426. Xclobber:    clean        ; inst -u Install
  427. Xlint:        $(TARG).lint
  428. X
  429. X$(TARG):        $(OBJS)
  430. X        $(CC) $(LFLAGS) -o $@ $(OBJS) $(LIBS)
  431. X
  432. X$(TARG).lint:    $(TARG)
  433. X        lint $(LINTFLAGS) $(DEFS) $(SRCS) $(LIBS) > $@
  434. X
  435. Xngmatch.o: ngmatch.c
  436. X
  437. Xmake:        ;
  438. X        makemake -i -v1.00.09 -aMakefile \
  439. X            -DSHELL='$(SHELL)' -DCC='$(CC)' -DDEFS='$(DEFS)' \
  440. X            -DCOPTS='$(COPTS)' -DLOPTS='$(LOPTS)' -DLIBS='$(LIBS)' \
  441. X            -DDEBUG='$(DEBUG)' -DLINTFLAGS='$(LINTFLAGS)' \
  442. X            -DOTHERS='$(OTHERS)' $(TARG) $(SRCS)
  443. X
  444. X#%custom - commands below this line will be maintained if 'makemake' is rerun
  445. X
  446. XARLIST = README chksys ngmatch.c Makefile
  447. X
  448. Xshar:        chksys.shar
  449. Xchksys.shar:    $(ARLIST)    ; shar $(ARLIST) > $@
  450. X
  451. END_OF_FILE_Makefile
  452.     size="`wc -c < Makefile`"
  453.     if test 1290 -ne "$size" ; then
  454.     echo "Makefile: extraction error - got $size chars"
  455.     fi
  456. fi
  457. echo "done - 4 files extracted"
  458. exit 0
  459.  
  460. -- 
  461. Chip Rosenthal                            |  Yes, you're a happy man and you're
  462. chip@chinacat.Lonestar.ORG                |  a lucky man, but are you a smart
  463. Unicom Systems Development, 512-482-8260  |  man?  -David Bromberg
  464.