v06i018: Program to build paths file directly from news///maps
Brandon S. Allbery - comp.sources.misc
allbery at uunet.UU.NET
Mon Jan 30 06:45:07 AEST 1989
Posting-number: Volume 6, Issue 18
Submitted-by: edw at wells.UUCP (Ed Wells)
Archive-name: news2path
[Beware of this "shar" format... ++bsa]
---- Cut Here and unpack ----
#!/bin/sh
# shar: Shell Archiver (v1.22)
#
# Run the following text with /bin/sh to create:
# read.me
# usa.paths
# pa.paths
# news2path.c
#
echo "x - extracting read.me (Text)"
sed 's/^X//' << 'SHAR_EOF' > read.me &&
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X Here's a little program that I wrote to use the information stored
X in /usr/spool/news/comp/mail/maps/* directly without having to build a
X second set of files nearly totaling the same size.
X
X This program extracts only the information that is needed to
X rebuild a pathalias file. It extracts from whatever files are present
X removing the headers, shar information and all lines that start with a
X '#' sign. This leaves only the minimal amount of information needed to
X start building a paths file.
X
X I also have two shell scripts that I have provided. Both of these
X shell programs accept one argument which is the target system name.
X Each shell is used to filter the listing down to either just 'usa' list-
X ings or 'usa.pa' (Pennsylvania) listings. I also have the program look
X for a file named 'local.$1' where $1 gets replaced with the target name
X I am building a file for. It's in this file that I normally put all of
X the unlisted/private/local connections to each system that I am building
X a paths file for. I also list the 'smart-host' system here also for
X each system.
X
X When I'm done, I just take the file named 'paths.$1' (where $1 is
X replaced with the target name) and install it in my /usr/lib/uucp/paths
X file or send it to the remote site requiring a path.
X
X This source code is the property of Wells Computer Systems Corp.
X and is being released to the Usenet community for any not-for-profit
X use.
X
X If you add anything to this, please submit it back to me.
X Enjoy.
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X January 17, 1989
X
X
SHAR_EOF
chmod 0640 read.me || echo "restore of read.me fails"
set `wc -c read.me`;Sum=$1
if test "$Sum" != "1724"
then echo original size 1724, current size $Sum;fi
echo "x - extracting usa.paths (Text)"
sed 's/^X//' << 'SHAR_EOF' > usa.paths &&
X#
X# Program name = "usa.paths"
X# @(#)usa.paths 1.7
X# Written by: Ed Wells, President, Wells Computer Systems Corp.
X# Wells Computer Systems Corp., Box 343, Levittown, Pa. 19058
X# (215)-943-6061, Voice
X# (215)-943-0435, (Data Telebit 19200-1200)
X# Usenet: wells!edw / edw at wells
X# UNIX System V 3.1 / SCO Xenix V
X#
X# Original date ..... Sat Jan 14 13:47:16 EST 1989
X# Last update ..... Sat Jan 14 13:47:16 EST 1989 (before SCCS)
X# SCCS delta date ... 1/15/89 -- 19:59:37
X# SCCS extracted ... 1/15/89 -- 19:59:47
X#
X# Program description : Used to generate paths for USA only.
X# Inputs : target system name from standard input.
X# Outputs : paths.{target_name}
X# Status/Errors : Standard error
X# Files accessed : See program
X# NOTE : A filename called "local.{target_name} must exist
X# with a list of locally known systems.
X#
Xsccsid="@(#)usa.paths 1.7 1/15/89\n"
XREVID="Revision 1.7 1/15/89\n"
X#
Xif [ $# -ne 1 ]
X then echo "Usage: $0 target_system_name" ; exit 1
Xfi
X#
XNEWS=/usr/spool/news
XLIMIT='.\.usa\.'
XLOCAL="local.$1 ../mail/MY.USENET.REG"
XSELFILE=/ram/sel.file
XTMPFILE=/ram/d.paths
Xtrap "rm -f pp paths $SELFILE $TMPFILE ; exit" 0 1 2 3 15
X#
Xecho "Creating a list of filename to use."
Xfind $NEWS/comp/mail/maps -type f -print | while read fname
Xdo
X # ***** LIMIT TO ONLY "$LIMIT" NAMES *****
X head -23 $fname | grep -l "echo shar: extracting $LIMIT" >/dev/null
X if [ $? -eq 0 ]
X then echo $fname
X fi
Xdone | tee $SELFILE
X#
X# Now create one merged file from the list in $SELFILE.
X#
Xecho "Creating a combined list from the \"$NEWS/comp/mail/maps\" directory"
Xecho "All news/shar headers will be extracted leaving only the file."
Xnews2path <$SELFILE >$TMPFILE
Xrm $SELFILE
X#
Xecho "Using \"pathalias\" to process the combined file."
Xpathalias -fv -l $1 $TMPFILE $LOCAL > paths
X#
Xecho "Using \"pathproc\" to sort/order the file."
Xpathproc < paths > pp
Xif [ ! -s pp ]
Xthen
X echo pathproc error
X mv paths pp
Xfi
Xecho "Delete entries not needed with \"pathprune\"."
Xpathprune -v < pp > paths
Xif [ -s paths ]
Xthen
X rm -f pp
Xelse
X echo pathprune error
X mv pp paths
Xfi
X
Xmv paths paths.$1
Xecho "Your completed file is in \"paths.$1\"."
Xexit 0
SHAR_EOF
chmod 0550 usa.paths || echo "restore of usa.paths fails"
set `wc -c usa.paths`;Sum=$1
if test "$Sum" != "2149"
then echo original size 2149, current size $Sum;fi
echo "x - extracting pa.paths (Text)"
sed 's/^X//' << 'SHAR_EOF' > pa.paths &&
X#
X# Program name = "pa.paths"
X# @(#)pa.paths 1.6
X# Written by: Ed Wells, President, Wells Computer Systems Corp.
X# Wells Computer Systems Corp., Box 343, Levittown, Pa. 19058
X# (215)-943-6061, Voice
X# (215)-943-0435, (Data Telebit 19200-1200)
X# Usenet: wells!edw / edw at wells
X# UNIX System V 3.1 / SCO Xenix V
X#
X# Original date ..... Sat Jan 14 13:47:16 EST 1989
X# Last update ..... Sat Jan 14 13:47:16 EST 1989 (before SCCS)
X# SCCS delta date ... 1/15/89 -- 19:59:35
X# SCCS extracted ... 1/15/89 -- 19:59:47
X#
X# Program description : Used to generate paths for Pennsylvania only.
X# Inputs : target system name from standard input.
X# Outputs : paths.{target_name}
X# Status/Errors : Standard error
X# Files accessed : See program
X# NOTE : A filename called "local.{target_name} must exist
X# with a list of locally known systems.
X#
Xsccsid="@(#)pa.paths 1.6 1/15/89\n"
XREVID="Revision 1.6 1/15/89\n"
X#
Xif [ $# -ne 1 ]
X then echo "Usage: $0 target_system_name" ; exit 1
Xfi
X#
XNEWS=/usr/spool/news
XLIMIT='.\.usa\.pa\.'
XLOCAL="local.$1 ../mail/MY.USENET.REG"
XSELFILE=/ram/sel.file
XTMPFILE=/ram/d.paths
Xtrap "rm -f pp paths $SELFILE $TMPFILE ; exit" 0 1 2 3 15
X#
Xecho "Creating a list of filename to use."
Xfind $NEWS/comp/mail/maps -type f -print | while read fname
Xdo
X # ***** LIMIT TO ONLY "$LIMIT" NAMES *****
X head -23 $fname | grep -l "echo shar: extracting $LIMIT" >/dev/null
X if [ $? -eq 0 ]
X then echo $fname
X fi
Xdone | tee $SELFILE
X#
X# Now create one merged file from the list in $SELFILE.
X#
Xecho "Creating a combined list from the \"$NEWS/comp/mail/maps\" directory"
Xecho "All news/shar headers will be extracted leaving only the file."
Xnews2path <$SELFILE >$TMPFILE
Xrm $SELFILE
X#
Xecho "Using \"pathalias\" to process the combined file."
Xpathalias -fv -l $1 $TMPFILE $LOCAL > paths
X#
Xecho "Using \"pathproc\" to sort/order the file."
Xpathproc < paths > pp
Xif [ ! -s pp ]
Xthen
X echo pathproc error
X mv paths pp
Xfi
Xecho "Delete entries not needed with \"pathprune\"."
Xpathprune -v < pp > paths
Xif [ -s paths ]
Xthen
X rm -f pp
Xelse
X echo pathprune error
X mv pp paths
Xfi
X
Xmv paths paths.$1
Xecho "Your completed file is in \"paths.$1\"."
Xexit 0
SHAR_EOF
chmod 0550 pa.paths || echo "restore of pa.paths fails"
set `wc -c pa.paths`;Sum=$1
if test "$Sum" != "2159"
then echo original size 2159, current size $Sum;fi
echo "x - extracting news2path.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > news2path.c &&
X/*
X * Program name = "news2path.c"
X * @(#)news2path.c 1.1
X * Written by: Ed Wells, President, Wells Computer Systems Corp.
X * Wells Computer Systems Corp., Box 343, Levittown, Pa. 19058
X * (215)-943-6061, Voice
X * (215)-943-0435, (Data Telebit 19200-1200)
X * Usenet: wells!edw / edw at wells
X * UNIX System V 3.1 / SCO Xenix V
X *
X * Original date ..... Fri Jan 13 09:18:25 EST 1989
X * Last update ..... Fri Jan 13 09:18:25 EST 1989 (before SCCS)
X * SCCS delta date ... 1/14/89 -- 13:24:00
X * SCCS extracted ... 1/14/89 -- 13:32:56
X *
X * Program description : Used to extract header information off of files in
X * : the /usr/spool/news/comp/mail/maps directory
X * : and provide a processed file for 'pathalias'.
X * Inputs : a list of filename(s) on stdin.
X * Outputs : stdout
X * Errors : stderr
X */
X
X static char sccsid[] = "@(#)news2path.c 1.1 1/14/89\n";
X static char REVID[] = "Revision 1.1 1/14/89\n";
X
X#define BSIZE 256
X
X#ifndef FALSE
X#define FALSE 0
X#endif
X
X#ifndef TRUE
X#define TRUE !FALSE
X#endif
X
X#include <stdio.h>
X#include <ctype.h>
X
Xmain(ac, av)
X int ac;
X char *av[];
X{
X FILE *fp, *fopen();
X char fname[15], buf[BSIZE];
X int i, j, firstline;
X
X if (ac != 1) {
X fprintf(stderr, "Usage: %s (NO ARGUMENTS ALLOWED)\n", av[0]);
X fprintf(stderr, "\tUses standard in/out and error.\n\n");
X fprintf(stderr, "\tstdin - list of filename(s).\n");
X fprintf(stderr, "\tstdout - data for 'pathalias'.\n");
X fprintf(stderr, "\tstderr - any format differences.\n");
X exit(1);
X }
X/*
X * Read while filenames are available on stdin.
X */
X while ( fscanf(stdin, "%s", fname) > 0) {
X if ( (fp=fopen(fname, "r")) == NULL) {
X fprintf(stderr, "ERROR: Can open file (%s)\n", fname);
X exit(2);
X }
X fprintf(stderr, "\"%s\" opened for processing.\n", fname);
X
X/*
X * Read until the first understandable line shows up.
X */
X firstline = FALSE;
X while( fgets(buf, BSIZE, fp) != NULL ) {
X if (buf[0] == '#' && isalpha(buf[1]) &&
X (buf[2] == ' ' || buf[2] == '\t') ) {
X firstline = TRUE;
X break;
X }
X }
X
X while ( fgets(buf, BSIZE, fp) != NULL ) {
X if ( !strncmp(buf, "SHAR_EOF", 8) )
X goto nextfile; /* We are done with this file */
X if (!strlen(buf))
X continue; /* This one is blank */
X if (buf[0] == '#')
X continue; /* This isn't for us */
X fputs(buf, stdout);
X }
X nextfile: ;
X fclose(fp);
X }
X exit(0);
X}
SHAR_EOF
chmod 0440 news2path.c || echo "restore of news2path.c fails"
set `wc -c news2path.c`;Sum=$1
if test "$Sum" != "2348"
then echo original size 2348, current size $Sum;fi
exit 0
More information about the Comp.sources.misc
mailing list