Path: utzoo!attcan!uunet!unisoft!cander From: cander@unisoft.UUCP (Charles Anderson) Newsgroups: comp.lang.perl Subject: Re: uucp map browser? Message-ID: <3208@unisoft.UUCP> Date: 6 Nov 90 01:17:25 GMT References: <1990Nov3.162853.19637@pegasus.com> Lines: 114 From article <1990Nov3.162853.19637@pegasus.com>, by richard@pegasus.com (Richard Foulk): > Before someone goes and reinvents another wheel... does anyone have > any perl scripts for searching or browsing the Uucp maps? > Richard Foulk richard@pegasus.com Below is my entry. It relies on a pre-compiled database (built by grep) that really should be a DBM file, but when I wrote this, DBM files and assoc arrays seemed to have problems. Someday I'll finish it. ---cut here--- #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh 'descsite' <<'END_OF_FILE' X#!/usr/local/bin/perl X# X# Synopsis: descsite [-i] sitename X# prints out the map entry for a uucp site X# -i causes the site database to be initialized. X# X# Author: Charles Anderson (cander@unisoft.com) X# X X$USAGE="Usage: descsite [-i] sitename"; X$MAPDIR="/usr/spool/maps/comp.mail.maps"; X$SITENAMES="site_names"; chdir $MAPDIR || die "Cannot chdir to mapdir: $MAPDIR"; X if ($ARGV[0] eq "-i") { X print "Initializing site database. Please wait...\n"; X system("grep ^#N [du]*. > $SITENAMES"); X print "Done\n"; X exit 0 if ($#ARGV == 0); X shift; X} X if ($#ARGV != 0) { X print "$USAGE \n"; X exit 1; X} X$site=$ARGV[0]; X open (IN, $SITENAMES) || die "Cannot open $SITENAMES\n"; while () { X if (/^(\S+):#N\s+$site[\s,\$]/o) { X $FILE=$1; X last; X } X} close(IN); X die "Unable to locate site $site in file site name database\n" X unless defined($FILE); X print "Map information for $site in $MAPDIR/$FILE\n"; X open (MAP, $FILE) || die "Cannot open $FILE"; X while () { X last if /^#N\s+$site[,\s\$]/o; X} X die "Unable to locate map info for site $site in file $FILE\n" if eof(MAP); X X$pager = $ENV{'PAGER'} || 'more'; X open(OUT, "| $pager"); print OUT $_; X while () { X last if /^#N/o; X print OUT $_; X} X close(OUT); END_OF_FILE if test 1271 -ne `wc -c <'descsite'`; then echo shar: \"'descsite'\" unpacked with wrong size! fi chmod +x 'descsite' # end of 'descsite' fi echo shar: End of archive 1 \(of 1\). cp /dev/null ark1isdone MISSING="" for I in 1 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have the archive. rm -f ark[1-9]isdone else echo You still need to unpack the following archives: echo " " ${MISSING} fi ## End of shell archive. exit 0 -- Unix is the Winchester Mystery | Charles Anderson, UniSoft Corp. House of software design. | {sun, ucbvax, uunet}!unisoft!cander