v07i093: pathalias builder alternative.
Brandon S. Allbery - comp.sources.misc
allbery at uunet.UU.NET
Sat Jul 22 11:01:53 AEST 1989
Posting-number: Volume 7, Issue 93
Submitted-by: edw at wells.UUCP (Ed Wells)
Archive-name: news2path.edw
In order to create a pathalias file in a restricted space, I wrote a
few programs that keep the intermediate files smaller. I putting this
in the public domain for others that may like to do the same. See
the 'read.me' file in the shar archive for more information.
A few things that I will be adding in the future myself is the ability
to build pathalias files for several systems without having to rebuild
the intermediate file again (20/20 hind site ya' know!).
If you add anything to this, please send it back to me.
---- Cut Here and unpack ----
#!/bin/sh
# shar: Shell Archiver (v1.22)
#
# Run the following text with /bin/sh to create:
# read.me
# pa.paths
# usa.paths
# news2path.c
#
if test -f read.me; then echo "File read.me exists"; else
sed 's/^X//' << 'SHAR_EOF' > read.me &&
X
X
X
X
X
X
X
X Wells Computer Systems Corp.
X Box 343, Levittown, Pa. 19058
X (215)-943-6061
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 program also requires 3 programs from the public domain for
X processing this information to its final output. These are the
X 'pathalias', 'pathproc' and 'pathprune' programs.
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
X
X
X Enjoy,
X Ed Wells, President
X
X
X
X
X
X
X
X
X
X
X
X July 14, 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" != "2170"
then echo original size 2170, current size $Sum;fi
fi
if test -f pa.paths; then echo "File pa.paths exists"; else
sed 's/^X//' << 'SHAR_EOF' > pa.paths &&
X#
X# Program name = "pa.paths"
X# @(#)pa.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 ... 3/21/89 -- 10:19:55
X# SCCS extracted ... 7/14/89 -- 05:55:43
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.7 3/21/89\n"
XREVID="Revision 1.7 3/21/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 >$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 $LIMIT <$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 0444 pa.paths || echo "restore of pa.paths fails"
set `wc -c pa.paths`;Sum=$1
if test "$Sum" != "1975"
then echo original size 1975, current size $Sum;fi
fi
if test -f usa.paths; then echo "File usa.paths exists"; else
sed 's/^X//' << 'SHAR_EOF' > usa.paths &&
X#
X# Program name = "usa.paths"
X# @(#)usa.paths 1.9
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 ... 3/21/89 -- 12:38:26
X# SCCS extracted ... 7/14/89 -- 05:55:43
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.9 3/21/89\n"
XREVID="Revision 1.9 3/21/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=/tmp/sel.file
XTMPFILE=/tmp/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 >$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 $LIMIT <$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 0444 usa.paths || echo "restore of usa.paths fails"
set `wc -c usa.paths`;Sum=$1
if test "$Sum" != "1966"
then echo original size 1966, current size $Sum;fi
fi
if test -f news2path.c; then echo "File news2path.c exists"; else
sed 's/^X//' << 'SHAR_EOF' > news2path.c &&
X/*
X * Program name = "news2path.c"
X * @(#)news2path.c 1.3
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 ... 3/21/89 -- 11:09:09
X * SCCS extracted ... 3/21/89 -- 11:09:31
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.3 3/21/89\n";
X static char REVID[] = "Revision 1.3 3/21/89\n";
X
X#define BSIZE 256
X#define ENDSHAR "SHAR_EOF"
X#define LIMITLINE "echo shar: extracting "
X#define STR1 "echo"
X#define STR2 "shar:"
X#define STR3 "extracting"
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[BSIZE], buf[BSIZE], buf2[BSIZE], *cp, *cp1;
X char *fgets(), *strcpy(), *strtok();
X int strcmp();
X int i, j, firstline;
X
X if (ac != 2) {
X fprintf(stderr, "Usage: %s (LIMIT_STRING)\n", av[0]);
X fprintf(stderr,
X"LIMIT_STRING selects/rejects the file based on finding a matching string\n");
X fprintf(stderr, "\tUses standard in/out and error.\n\n");
X fprintf(stderr, "\tstdin - list of filename(s) to open.\n");
X fprintf(stderr, "\tstdout - data for 'pathalias'.\n");
X fprintf(stderr, "\tstderr - Status information.\n");
X fprintf(stderr,
X"Example: %s u.usa.pa\n", av[0]);
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..... ", fname);
X/*
X * Read up until the LIMITLINE is found (or EOF).
X */
X while (fgets(buf, BSIZE, fp) != NULL) {
X if (!strncmp(buf, LIMITLINE, strlen(LIMITLINE)))
X goto select;
X }
X fprintf(stderr, "ERROR: LIMIT_STRING missing.\n");
X exit(2);
X/*
X * Find out if this file should be select (in which case we continue)
X * or rejected.
X */
X select:
X cp = buf;
X while ( (cp1 = strtok(cp, " \r\n")) != NULL ) {
X strcpy(buf2, cp1);
X cp = NULL;
X if (!strcmp(buf2, STR1))
X continue;
X if (!strcmp(buf2, STR2))
X continue;
X if (!strcmp(buf2, STR3))
X continue;
X if ( instr(buf2, av[1]) >= 0 ) {
X fprintf(stderr, "\t\tSelected! Proceeding.\n");
X break; /* Quit "while" loop, and continue */
X } else {
X fprintf(stderr, "\t\tFile ignored!\n");
X goto nextfile;
X }
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, ENDSHAR, 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 }
Xnextfile: fclose(fp);
X }
X fprintf(stderr,"\n\tSelecting complete\n");
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" != "3539"
then echo original size 3539, current size $Sum;fi
fi
exit 0
--
=========================================================================
Edward E. Wells Jr., President Voice: (215)-943-6061
Wells Computer Systems Corp., Box 343, Levittown, Pa. 19058
{dsinc,francis,hotps,houxl,lgnp1,mdi386,pebco}!wells!edw
More information about the Comp.sources.misc
mailing list