home *** CD-ROM | disk | FTP | other *** search
Wrap
Text File | 1992-04-18 | 27.0 KB | 1,041 lines
Newsgroups: comp.sources.unix From: jpm@Logix.DE (Jan-Piet Mens) Subject: v26i018: uuhost - lookup UUCP mail and USENET information Sender: unix-sources-moderator@pa.dec.com Approved: vixie@pa.dec.com Submitted-By: jpm@Logix.DE (Jan-Piet Mens) Posting-Number: Volume 26, Issue 18 Archive-Name: uuhost-2.1 [ this package is similar but unrelated to the "uuhosts" program in volumes 2 and 3. --vix ] It is a new [and as far as I'm concerned, better :-] program. It needs not run as root, the databases are smaller (text only), and does more for me than all others have done so far :-) Uuhost reads the UUCP maps which live in a directory, and builds a smallish database, containing just enough data to read the UUCP and USENET information from the maps. jpm@Logix.DE (Jan-Piet Mens) #! /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 <file", e.g.. If this archive is complete, you # will see the following message at the end: # "End of shell archive." # Contents: README Copyright Makefile patchlevel.h uuhost.N uuhost.S # uulookup.c uusplit.c # Wrapped by vixie@cognition.pa.dec.com on Sun Apr 19 13:41:09 1992 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f 'README' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'README'\" else echo shar: Extracting \"'README'\" \(3609 characters\) sed "s/^X//" >'README' <<'END_OF_FILE' UUHOST 2.1 X========== X X This is uuhost 2.1 X X It is a new [and as far as I'm concerned, better :-] program. X It needs not run as root, the databases are smaller (text only), X and does more for me than all others have done so far :-) X X Uuhost reads the UUCP maps which live in a directory, and builds a X smallish database, containing just enough data to read the UUCP and X USENET information from the maps. X X - Edit the Makefile. Set the variables described at the top of the X Makefile to desired values. X X - Do a `make'. This should produce X uusplit executable X uulookup executable X uuhost shell-script X uuhost.1 manual page X X - Do a "make install" X This will copy the uuhost program to your LOCALBIN directory, X uusplit to your BINDIR directory, and uulookup to your X LOOKUPBINDIR directory. Note: Neither BINDIR nor LOOKUPBINDIR X need not be in the user's path. X Please install the manual page `uuhost.1' manually. X X - Run "uuhost -l" It should show you a list of contents of your X maps directory. X X - Try "uuhost -r u.usa.ca.1" or similar. That should work too. X X - Now run "uuhost -index" This will take a while. The index is X being built. (should not take much longer than five minutes) X X - Try "uuhost hostname" where hostname is a host that you know X about. X X - Set up "uuhost -index" so that it runs once a day. This can be X done via crontab: X X 00 07 * * * uuhost -index X X X - Congratulations. Finished. X X - If you have problems, bugs or suggestions, please contact me. X My name is Jan-Piet Mens, and my address is X <jpm@Logix.DE> X INTERNALS X========= X uuhost -index X============= X This program reads all files in the MAPSDIR directory. Here is the map entry from the file `u.deu.2' (line 1451) for my site: X X #N logixwi, logix.de, .logix.de X #S Tandon 486/25;SCO UNIX 3.2.2 X #O Logix GmbH X #C Jan-Piet Mens X #E postmaster@logixwi.logix.de X #T +49 611 309797 X #P Moritzstrasse 50, D-W-6200 Wiesbaden, Germany X #L X #W cs@Germany.EU.net; 910228 / bs@Germany.EU.net ; 911016 X #U unido X # X logixwi unido(HOURLY) X logixwi .logix.de X The `#N' entry contains three names (I call them hostnames, although that is not quite correct :-) The `uusplit' program gets the `#N' line passed to it, prepended by a line number (produced by grep). It will split that line into individual hostnames, producing: X X logixwi u.deu.2 1451 X logix.de u.deu.2 1451 X .logix.de u.deu.2 1451 X These lines are put into the UUHOSTINDEX database. `uuhost -index' does this for each `#N' in all files in the MAPSDIR directory. The database is then sorted by the first field. X When `uuhost' looks for a hostname, it parses (with help of `uulookup') the database, finds (or doesn't) the desired entry, and Charly 's your uncle. X Problems, Praise & Bugs X======================= X Please direct these to Jan-Piet Mens <jpm@Logix.DE> X Thanks! to ... X============== X Mon Oct 21 20:38:26 MET 1991 X From: btr.com!thad (Thaddeus P. Floryan) X Message-Id: <9110211245.AA09299@public.BTR.COM> X X One comment: on my systems (3B1, CT MightyFrame, etc.) the X "uuhost -index" would abort due to "Cannot fork: too many processes." X X Finally discovered the problem to be ksh. By using /bin/sh it X worked fine per: X X $ sh uuhost -index X X Thanks for the great program! X X Thad Floryan [ thad@btr.com (OR) {decwrl, mips, fernwood}!btr!thad ] X Tue Oct 22 18:28:27 MET 1991 X Thad Floryan [ thad@btr.com (OR) {decwrl, mips, fernwood}!btr!thad ] X Added #F expansion. X Tue Oct 22 19:15:05 MET 1991 X <pat@rwing> (Pat Myrto) X "Suggest adding option to produce mail address. " X I've added -u for doing it. Thanks. END_OF_FILE if test 3609 -ne `wc -c <'README'`; then echo shar: \"'README'\" unpacked with wrong size! fi # end of 'README' fi if test -f 'Copyright' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'Copyright'\" else echo shar: Extracting \"'Copyright'\" \(403 characters\) sed "s/^X//" >'Copyright' <<'END_OF_FILE' X/* X * UUHOST, Copyright 1992, Jan-Piet Mens [Logix GmbH, Wiesbaden, Germany] X * License to freely use and distribute this software is hereby granted X * by the author, subject to the condition that this copyright notice X * remains intact. The author retains the exclusive right to publish X * derivative works based on this work, including, but not limited X * to, revised versions of this work. X */ END_OF_FILE if test 403 -ne `wc -c <'Copyright'`; then echo shar: \"'Copyright'\" unpacked with wrong size! fi # end of 'Copyright' fi if test -f 'Makefile' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'Makefile'\" else echo shar: Extracting \"'Makefile'\" \(3730 characters\) sed "s/^X//" >'Makefile' <<'END_OF_FILE' X# UUHOST, Copyright 1991, Jan-Piet Mens [Logix GmbH, Wiesbaden, Germany] X# License to freely use and distribute this software is hereby granted X# by the author, subject to the condition that this copyright notice X# remains intact. The author retains the exclusive right to publish X# derivative works based on this work, including, but not limited X# to, revised versions of this work. X# Jan-Piet Mens <jpm@Logix.DE> X# X# Define MAPSDIR to be the directory in which your maps are kept. X# X#MAPSDIR=/usr/spool/maps MAPSDIR=/u/local/lib/uucpmaps/uucpmap X X# Define UUHOSTINDEX to the location of the UUHOST index file. X# UUHOSTINDEX=/u/local/lib/uuhostindex X X# LOCALBIN is for the `uuhost' program only. All others go into BINDIR. X# This directory *should* be in a user's path. X# LOCALBIN=/u/local/bin X X# Define BINDIR to be the directory into which targets are copied upon X# a make install. This directory need _not_ be in a user's $PATH. X# BINDIR=/u/local/lib/uucpmaps/bin X X# Define LOOKUPBINDIR to be the directory into which the `uulookup' program X# is copied. Some people like this in their path. X# LOOKUPBINDIR=$(LOCALBIN) X#LOOKUPBINDIR=$(BINDIR) X X# Define PATHALIAS to be the name of your pathalias file X# X#PATHALIAS=/usr/lib/uucp/paths.uucp PATHALIAS=/u/local/lib/pathalias X X# Define PATHLOOKUP to the the program that gets a hostname, and returns X# the uucp mail path to that host. X# PATHLOOKUP=$(LOOKUPBINDIR)/uulookup -m X X# Define CATPROG to be the program with which to view the u.* maps. If the X# maps are compressed [which I highly recommend] use `zcat'. Otherwise `cat'. X# X#CATPROG=cat CATPROG=zcat X X# LOOKPROG is a program which returns the entry from UUHOSTINDEX X# LOOKPROG=$(LOOKUPBINDIR)/uulookup -h X X# The name of your preferred pager (pg,more,less,...,cat ?) X# PAGEPROG="less" X X# Add -DNEED_STRINGS_H to CFLAGS if you have <strings.h> instead of <string.h> X# CC=cc CFLAGS=-O -s LIBS= X SRCS=uusplit.c uulookup.c SHARFILES=README Makefile Copyright uuhost.S uuhost.N HFILES= patchlevel.h X all: uusplit uulookup uuhost uuhost.1 X uuhost: uuhost.S Makefile X sed -e 's|__MAPSDIR__|$(MAPSDIR)|g' \ X -e 's|__CATPROG__|$(CATPROG)|g' \ X -e 's|__PAGEPROG__|$(PAGEPROG)|g' \ X -e 's|__PATHLOOKUP__|$(PATHLOOKUP)|g' \ X -e 's|__LOOKPROG__|$(LOOKPROG)|g' \ X -e 's|__LOOKUPBINDIR__|$(LOOKUPBINDIR)|g' \ X -e 's|__BINDIR__|$(BINDIR)|g' \ X -e 's|__UUHOSTINDEX__|$(UUHOSTINDEX)|g' uuhost.S > uuhost X chmod +x uuhost X uuhost.1: uuhost.N Makefile X rm -f uuhost.1 X sed -e 's|__MAPSDIR__|$(MAPSDIR)|g' \ X -e 's|__BINDIR__|$(BINDIR)|g' \ X -e 's|__LOOKUPBINDIR__|$(LOOKUPBINDIR)|g' \ X -e 's|__PATHALIAS__|$(PATHALIAS)|g' \ X -e 's|__UUHOSTINDEX__|$(UUHOSTINDEX)|g' uuhost.N > uuhost.1 X chmod 444 uuhost.1 X uusplit: uusplit.c Makefile $(HFILES) X $(CC) $(CFLAGS) -o uusplit uusplit.c $(LIBS) X [ -x /usr/bin/mcs ] && /usr/bin/mcs -d uusplit X uulookup: uulookup.c Makefile $(HFILES) X $(CC) $(CFLAGS) -DPATHALIAS='"$(PATHALIAS)"' -DUUHOSTINDEX='"$(UUHOSTINDEX)"' -o uulookup uulookup.c $(LIBS) X [ -x /usr/bin/mcs ] && /usr/bin/mcs -d uulookup X install: uusplit uulookup uuhost X [ -d $(BINDIR) ] || mkdir $(BINDIR) X -chmod 755 $(BINDIR) X rm -f $(BINDIR)/uusplit && cp uusplit $(BINDIR) X chmod 111 $(BINDIR)/uusplit X rm -f $(LOOKUPBINDIR)/uulookup && cp uulookup $(LOOKUPBINDIR) X chmod 111 $(LOOKUPBINDIR)/uulookup X rm -f $(LOCALBIN)/uuhost && cp uuhost $(LOCALBIN) X chmod 555 $(LOCALBIN)/uuhost X X touch $(UUHOSTINDEX) X X @echo X @echo 'Please install the manual page "uuhost.1" manually' X @echo clean: X rm -f core *.o Part.?? clobber: clean X rm -f uusplit uulookup uuhost uuhost.1 X dist: $(SRCS) $(SHARFILES) $(HFILES) X shar49 -n uuhost -a -s 'jpm@Logix.DE' -o Part -l 50 -c \ X $(SHARFILES) $(SRCS) $(HFILES) END_OF_FILE if test 3730 -ne `wc -c <'Makefile'`; then echo shar: \"'Makefile'\" unpacked with wrong size! fi # end of 'Makefile' fi if test -f 'patchlevel.h' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'patchlevel.h'\" else echo shar: Extracting \"'patchlevel.h'\" \(24 characters\) sed "s/^X//" >'patchlevel.h' <<'END_OF_FILE' X#define PATCHLEVEL 2.1 END_OF_FILE if test 24 -ne `wc -c <'patchlevel.h'`; then echo shar: \"'patchlevel.h'\" unpacked with wrong size! fi # end of 'patchlevel.h' fi if test -f 'uuhost.N' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'uuhost.N'\" else echo shar: Extracting \"'uuhost.N'\" \(4250 characters\) sed "s/^X//" >'uuhost.N' <<'END_OF_FILE' X.\" nroff -man %s X.\" UUHOST, Copyright 1992, Jan-Piet Mens [Logix GmbH, Wiesbaden, Germany] X.\" License to freely use and distribute this software is hereby granted X.\" by the author, subject to the condition that this copyright notice X.\" remains intact. The author retains the exclusive right to publish X.\" derivative works based on this work, including, but not limited X.\" to, revised versions of this work. X.\" X.\" $Log: uuhost.N,v $ X.\" Revision 1.2 1992/01/16 09:42:47 jpm X.\" Cleanup X.\" X.\" X.TH UUHOST 1 "" "Logix GmbH" "Local user commands" X.SH NAME uuhost - lookup UUCP mail and USENET information X.SH SYNOPSIS X.B uuhost X[ X.B -l X] X[ X.B -r X.I region X] X[ X.I hostname X] X.br X.B uuhost X.I -index X.br X.B uulookup X[ X.B -h X.I hostname X] X[ X.B -m X.I machine X] X[ X.B -u X.I address X] X[ X.B -v X] X.SH DESCRIPTION X.SS UUHOST X.RS 1i X.B uuhost looks up information on the named host X.I hostname in the UUCP map files and presents the information to the user to peruse. X.PP X.IP "\fBuuhost\fR \fIhostname\fR" shows information about the host X.I hostname. X.IP "\fBuuhost\fR \fI-l\fR" displays a list of uucp map regions available on this system. X.IP "\fBuuhost\fR -r \fIregion\fR" displays all the information for the specified X.I region. X.IP "\fBuuhost -index\fR" is reserved for the system administrator. This parses the needed information out of the UUCP map distribution, and creates the necessary database for X.B uuhost. This operation should be done once a night, after the maps have arrived at this site. X.B "uuhost -index" may be called from a crontab entry. X.PP X.SS UULOOKUP X.RS 1i X.B uulookup program parses the X.I UUHOSTINDEX or X.I PATHALIAS databases depending on the used option. X.IP "\fBuulookup\fR -h \fIhostname\fR" looks up information for the host X.I hostname in the X.I UUHOSTINDEX database, and presents the found X.I hostname , map-file name, and line number in the map to standard output. X.IP "\fBuulookup\fR -m \fImachine\fR" looks up information for the machine X.I machine in the X.I PATHALIAS database, and presents the shortest path to that host. X.IP "\fBuulookup\fR -u \fIaddress\fR" Will print a uucp bang address to the specified X.I address, which may be a bang address as in X.I site!user or a domain address as in X.I user@site. An X.I address like X.I user%system@site will be expanded (if possible) into X.I address!to!that!site!user%system. If only a site is specified, X.I %s is output instead of the user. Note that multiple sites are not supported yet. X.PP X.IP "\fBuulookup\fR \fI-v\fR ..." turns on verbose output. X.SH DIAGNOSTICS Many, and (hopefully) self-explanatory. X.SH FILES X.IP "\fIUUHOSTINDEX\fR" This is the main index file for X.B uuhost. It contains lines of text, with three fields each. The first field is the name of a host as in X.I logixwi followed by a tab character. The second field contains the relative pathname of the map file X.I u.deu.2 in which this host is described. The file name does not have a X.I .Z tacked on to it, even if the maps are in compressed form (this saves 24KB on our file system :-). The third field is the relative line number in the map file where the description of the host begins. The X.B uuhost index file must be sorted alphabetically. It is parsed by the X.B uulookup program with option X.I -h X.br On this system, the X.I UUHOSTINDEX file is called "\fI__UUHOSTINDEX__\fR". X.IP "\fIPATHALIAS\fR" This is the X.I PATHALIAS file as it is used by X.I smail or X.I sendmail. It is parsed by the X.B uulookup program with options X.I -m and X.I -u X.br On this system, the X.I PATHALIAS file is located at "\fI__PATHALIAS__\fR". X.IP "\fIMAPSDIR/u.*\fR" X This directory (\fI__MAPSDIR__\fR on this system) contains the maps. Either compressed (filenames ending in .Z) or uncompressed. X.SH NOTES X.B uulookup is located in the directory X.B __LOOKUPBINDIR__. X.br X.B uulookup only recognizes one-hop addresses, in other words, X.I site1!site2!user is not recognized. X.sp XFor X.I uulookup and X.I uuhost to work correctly, the X.I PATHALIAS database and the X.I UUHOSTINDEX database must be sorted with X.I sort -u -f X\. X.SH CREDITS Written by Jan-Piet Mens <jpm@Logix.DE>, based on an idea by John Quarterman <jsq@sally.utexas.edu> X.SH SEE ALSO grep(1), sendmail(1), pathalias(1) END_OF_FILE if test 4250 -ne `wc -c <'uuhost.N'`; then echo shar: \"'uuhost.N'\" unpacked with wrong size! fi # end of 'uuhost.N' fi if test -f 'uuhost.S' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'uuhost.S'\" else echo shar: Extracting \"'uuhost.S'\" \(2930 characters\) sed "s/^X//" >'uuhost.S' <<'END_OF_FILE' X#!/bin/sh X# X# UUHOST, Copyright 1992, Jan-Piet Mens [Logix GmbH, Wiesbaden, Germany] X# License to freely use and distribute this software is hereby granted X# by the author, subject to the condition that this copyright notice X# remains intact. The author retains the exclusive right to publish X# derivative works based on this work, including, but not limited X# to, revised versions of this work. X# X# $Id: uuhost.S,v 1.1 1992/01/16 09:43:40 jpm Exp $ X# $Log: uuhost.S,v $ X# Revision 1.1 1992/01/16 09:43:40 jpm X# Initial revision X# X# X# Set this to the name of the directory containing the uucp maps (u.*) MAPSDIR="__MAPSDIR__" X# This is the file where the UUHOST index lives UUHOSTINDEX="__UUHOSTINDEX__" X# X# This is the program that splits up a `#N' line into individual machines X# UUSPLITNAME="__BINDIR__/uusplit" X# X# CAT is either `cat' if maps are not compressed, or `zcat' if they *are*. X# CAT="__CATPROG__" X# X# If you don't want to use my `uulookup', you'll have to work at this script. X# LOOK="__LOOKPROG__" PATHLOOKUP="__PATHLOOKUP__" PAGER="__PAGEPROG__" X USAGE="$0 [-l] [-r region] [hostname]" X X[ $# -eq 0 ] && { echo "$USAGE" >&2 ; exit 1 ; } case "$1" in X -l) ls -C ${MAPSDIR} | sed -e 's/\.Z//g' ; exit 0 ;; X -r) [ $# -eq 2 ] || { echo "$USAGE" >&2 ; exit 2 ; } X REGION="${MAPSDIR}/$2" X [ ! -r $REGION -a ! -r ${REGION}.Z ] && X { echo "$0: region $2 non-existant"; exit ; } X ${CAT} $REGION | ${PAGER} X exit 0 ;; X -index) X [ -w ${UUHOSTINDEX} ] || { X echo "$UUHOSTINDEX is not writeable" >&2 X exit 2 ; } X X echo "Building index '${UUHOSTINDEX}'. Patience." >&2 X cd ${MAPSDIR} # Go to dir X ls u.* | while read mapname # Find all u. files X do X echo ".\c" >&2 X ${CAT} $mapname | X grep -n '^#N' | # Only `#N' entries X ${UUSPLITNAME} $mapname # Build list X done > ${UUHOSTINDEX} X echo "\n" >&2 X # X # there is a bug in my `sort'. Otherwise, I would have put X # it in the pipeline above... X # X sort -f -u ${UUHOSTINDEX} -o ${UUHOSTINDEX} X chmod 644 ${UUHOSTINDEX} X exit 0 ;; X -*) echo "$USAGE" >&2 ; exit 2 ;; esac X machine=$1 X X${LOOK} $machine ${UUHOSTINDEX} | # May give several per machine X sort -1 +2 -u | # Give unique entries for mach X while read mach map line # Get Machinename, mapfile, line X do X ${PATHLOOKUP} $mach # E-mail address ? X X echo '\n' X X ${CAT} ${MAPSDIR}/${map} | # Output file... X sed -n -e "$line,/^$/p" | # ... starting at `line' X sed -e "s/^#N/#Name /" \ X -e "s/^#S/#System-OS /" \ X -e "s/^#O/#Organisation /" \ X -e "s/^#F/#Forwarder(MX) /" \ X -e "s/^#R/#Remarks /" \ X -e "s/^#E/#Electr.Adress /" \ X -e "s/^#C/#Contact /" \ X -e "s/^#T/#Telephone /" \ X -e "s/^#P/#Postal-Address/" \ X -e "s/^#L/#Lat.-Longitude/" \ X -e "s/^#W/#Written-By: /" \ X -e "s/^#U/#Usenet links /" X echo "================== ${map} =======================" X done | ${PAGER} END_OF_FILE if test 2930 -ne `wc -c <'uuhost.S'`; then echo shar: \"'uuhost.S'\" unpacked with wrong size! fi chmod +x 'uuhost.S' # end of 'uuhost.S' fi if test -f 'uulookup.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'uulookup.c'\" else echo shar: Extracting \"'uulookup.c'\" \(5499 characters\) sed "s/^X//" >'uulookup.c' <<'END_OF_FILE' X/* X * UUHOST, Copyright 1992, Jan-Piet Mens [Logix GmbH, Wiesbaden, Germany] X * License to freely use and distribute this software is hereby granted X * by the author, subject to the condition that this copyright notice X * remains intact. The author retains the exclusive right to publish X * derivative works based on this work, including, but not limited X * to, revised versions of this work. X * X * $Id: uulookup.c,v 2.3 1992/01/16 09:40:58 jpm Exp $ X * X * $Log: uulookup.c,v $ X * Revision 2.3 1992/01/16 09:40:58 jpm X * Cleanup X * X * Revision 2.2 1991/10/22 18:14:09 jpm X * Added -u option. Thanks to Pat Myrto <pat@rwing> for suggesting it. X * X * Revision 2.1 1991/10/19 14:25:54 jpm X * *** empty log message *** X * X * X */ X X#include <stdio.h> X#include <ctype.h> X#ifdef NEED_STRINGS_H X# include <strings.h> X#else X# include <string.h> X#endif X#define MAXBUF 1024 X X#if defined(__STDC__) || defined(__cplusplus) X# define P_(s) s X#else X# define P_(s) () X#endif X int main P_((int argc, char **argv)); void splitpath P_((char *usr, char *adr)); int look P_((char *key, char *result)); int strsplit P_((register char *s, int sep, char **arg)); void usage P_((void)); int getopt(); void exit(); X X#undef P_ X#define FALSE 0 X#define TRUE 1 X#define MAXDOMS 20 X char *progname; char *database; /* For look() */ X X#ifndef lint static char rcs_id[] = "@(#)$Id: uulookup.c,v 2.3 1992/01/16 09:40:58 jpm Exp $"; X#endif void usage(); X int main(argc, argv) int argc; char **argv; X{ X char addr[100], user[100], buf[MAXBUF]; X extern char *optarg; X char *doms[MAXDOMS]; /* Each component of domain */ X int count, i, c, hf = FALSE, mf = FALSE, uf = FALSE; X int verbose = FALSE, found; X X progname = argv[0]; X (void)strcpy(user, ""); X X while ((c = getopt(argc, argv, "vh:m:u:")) != EOF) X switch (c) X { X case 'h': X database = UUHOSTINDEX; X (void)strcpy(addr, optarg); X hf = TRUE; X break; X case 'm': X database = PATHALIAS; X (void)strcpy(addr, optarg); X mf = TRUE; X break; X case 'u': X database = PATHALIAS; X (void)strcpy(user, optarg); X uf = TRUE; X break; X case 'v': X verbose = TRUE; X break; X default: X usage(); X } X X if (hf + mf + uf != 1) /* Options are exclusive */ X usage(); X X if (uf) X splitpath(user, addr); X X /* X * Split addr into a list of domains. If `addr' has foo.bar.top.level X * it will get split into X * X * foo.bar.top.level X * .bar.top.level X * .top.level X * .level X */ X X count = strsplit(addr, '.', doms); X X /* X * Forget about the top-level domains. They are not in (my) X * PATHALIAS. X */ X X --count; X X if (verbose) X (void)printf("Trying '%s'\n", addr); X X found = FALSE; X if (look(addr, buf) != 0) X { X for (i = 0; i < count; i++) X { X if (verbose) X (void)printf("Trying '%s'\n", doms[i]); X if (look(doms[i] - 1, buf) == 0 /* With dot */ X || look(doms[i] - 1, buf) == 0) /* W/o dot */ X { X found = TRUE; X break; X } X } X } X else found = TRUE; X X if (found == FALSE) X if (hf) X return fprintf(stderr, "HOST: '%s' not found\n", addr); X else X return fprintf(stderr, "Path to '%s' not found\n",addr); X X if (uf == TRUE) X { X (void)printf(buf, user); X (void)putchar('\n'); X } X else if (mf == TRUE) X (void)printf("Path to %s\n\t%s\n", addr, buf); X else X (void)printf("%s %s\n", addr, buf); X return (0); X} X void splitpath(usr, adr) char *usr; /* Contains user@site or site!user */ char *adr; /* Target will contain "site" */ X{ X char *strchr(), *ptr, a[100], u[100]; X X /* X * user@site ? X * Copy "site" into `adr' and chop `usr' at '@' X */ X X if ((ptr = strchr(usr, '@')) != (char *)0) X { X (void)strcpy(a, ptr + 1); X *(ptr) = '\0'; X (void)strcpy(u, usr); X } X else if ((ptr = strchr(usr, '!')) != (char *)0) X { X (void)strcpy(u, ptr + 1); X *(ptr) = '\0'; X (void)strcpy(a, usr); X } X else X { X (void)strcpy(a, usr); X (void)strcpy(u, "%s"); X } X X (void)strcpy(adr, a); X (void)strcpy(usr, u); X} X X/* X * From "Portable C Software by Mark Horton" X */ X int look(key, result) char *key, *result; X{ X long pos, middle, hi, lo; X static long pathlength = 0; X register char *s; X int c, flag; X static FILE *fp; X X if (!pathlength) X { X if ((fp = fopen(database,"r")) == (FILE *)0) { X (void)perror(database); X pathlength = -1; X } X else { X (void)fseek(fp, 0L, 2); X pathlength = ftell(fp); X } X } X X if (pathlength == -1) X return (-2); /* No database file */ X X lo = 0; X hi = pathlength; X (void)strcpy(result, key); X (void)strcat(result, "\t"); X X while (1) X { X pos = middle = (hi + lo + 1) /2; X (void)fseek(fp, pos, 0); /* Find midpoint */ X if (pos) /* to begin of next line */ X while ((c = getc(fp)) != EOF && c != '\n') X ; /* Nothing */ X X for (flag = 0, s = result; !flag; s++) { /* Match ? */ X if (*s == '\0') X goto solved; X c = getc(fp); X flag = tolower(c) - tolower(*s); X } X if (lo >= middle) /* Failure ? */ X return (-1); X if (c != EOF && flag < 0) /* Close window */ X lo = middle; X else X hi = middle - 1; X } solved: /* Just copy result... */ X while ((c = getc(fp)) != EOF && c != '\n') X *result++ = c; X *result = '\0'; X return (0); X} X int strsplit(s, sep, arg) register char *s; int sep; char **arg; X{ X int count = 0; X int wastoken = 0; X X for (; *s; ++s) X { X if (!wastoken) X { X ++count; X *arg++ = s; X } X wastoken = (sep != *s); X } X X if (!wastoken) X { X ++count; X *arg++ = s; X } X *arg = (char *)0; X return (count); X} X void usage() X{ X (void)fprintf(stderr, "Usage: %s [-h hostname] [-m mailname] [-u user] [-v]\n", progname); X exit(1); X} END_OF_FILE if test 5499 -ne `wc -c <'uulookup.c'`; then echo shar: \"'uulookup.c'\" unpacked with wrong size! fi # end of 'uulookup.c' fi if test -f 'uusplit.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'uusplit.c'\" else echo shar: Extracting \"'uusplit.c'\" \(2167 characters\) sed "s/^X//" >'uusplit.c' <<'END_OF_FILE' X/* X * UUHOST, Copyright 1992, Jan-Piet Mens [Logix GmbH, Wiesbaden, Germany] X * License to freely use and distribute this software is hereby granted X * by the author, subject to the condition that this copyright notice X * remains intact. The author retains the exclusive right to publish X * derivative works based on this work, including, but not limited X * to, revised versions of this work. X * X * $Id: uusplit.c,v 2.2 1992/01/16 09:40:58 jpm Exp $ X * X * $Log: uusplit.c,v $ X * Revision 2.2 1992/01/16 09:40:58 jpm X * Cleanup X * X * Revision 2.1 1991/10/19 14:27:49 jpm X * *** empty log message *** X * X * X */ X#include <stdio.h> X#define MAXBUF 1024 X X#if defined(__STDC__) || defined(__cplusplus) X# define P_(s) s X#else X# define P_(s) () X#endif X int main P_((int argc, char **argv)); void split P_((char *bp, char *fname)); void exit(); int strlen(); int atoi(); X X#undef P_ X X#ifndef lint static char rcs_id[] = "@(#)$Id: uusplit.c,v 2.2 1992/01/16 09:40:58 jpm Exp $"; X#endif X int main(argc, argv) int argc; char **argv; X{ X char buf[MAXBUF]; X char *fname = argv[1]; X int n = strlen(fname) - 1; X X if (argc != 2) X exit(fprintf(stderr,"Usage: %0 filename\n", *argv)); X X /* X * If filenames end in .Z, chop it off. We don't need that. X * Just wastes space ... X */ X X if (fname[n] == 'Z' && fname[n - 1] == '.') X fname[n - 1] = '\0'; X X while (fgets(buf, MAXBUF, stdin) != (char *)0) X split(buf, argv[1]); X return (0); X} X X/* X * `fname' is a relative path to a map: u.deu.2. X * `bp' contains an `#N' line from the map which has a line-number X * prepended to it by `grep' , as in X * X * 1245:#N logixwi, .logix.de, logix.de X * X * Split that line up into lines containing the host name, a filename, and X * the line number. X * X * logixwi u.deu.2 1245 X * .logix.de u.deu.2 1245 X * logix.de u.deu.2 1245 X */ X void split(bp, fname) char *bp, *fname; X{ X char *ptr, *strtok(); X int line; X X if ((ptr = strtok(bp, ":")) == (char *)0) X (void)fprintf(stderr, "ERROR: no line number\n"); X line = atoi(ptr); X X ptr = strtok(NULL, " \t,;\n"); X X while ((ptr = strtok(NULL, " \t,;\n")) != (char *)0) X (void)printf("%s\t%s\t%d\n", ptr, fname, line); X} END_OF_FILE if test 2167 -ne `wc -c <'uusplit.c'`; then echo shar: \"'uusplit.c'\" unpacked with wrong size! fi # end of 'uusplit.c' fi echo shar: End of shell archive. exit 0