[comp.sources.unix] v22i111: Pathalias, version 10, Part03/03

rsalz@uunet.uu.net (Rich Salz) (06/08/90)

Submitted-by: peter honeyman <honey@citi.umich.edu>
Posting-number: Volume 22, Issue 111
Archive-name: pathalias10/part03

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then feed it
# into a shell via "sh file" or similar.  To overwrite existing files,
# type "sh file -c".
# The tool that generated this appeared in the comp.sources.unix newsgroup;
# send mail to comp-sources-unix@uunet.uu.net if you want that tool.
# Contents:  CHANGES Makefile config.h def.h local.c main.c make.honey
#   makedb.c
# Wrapped by rsalz@litchi.bbn.com on Fri Jun  8 09:25:22 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
echo If this archive is complete, you will see the following message:
echo '          "shar: End of archive 3 (of 3)."'
if test -f 'CHANGES' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'CHANGES'\"
else
  echo shar: Extracting \"'CHANGES'\" \(1202 characters\)
  sed "s/^X//" >'CHANGES' <<'END_OF_FILE'
XNets without names.
XAllow negative cost components; prohibit negative costs.
XNew input syntax: adjust {host, ...}; kill -a option.
XNew input syntax: file {filename}.
XNew input syntax: delete {host, host!neighbor}.
XTerminal nets.
XPrevent back links to domains.
X
X-- mod.sources, 10/87 -- version 9
XTerminal edges and domains (<host> syntax and -D option).
XDead hosts and edges in the input stream.
XEmpty private list ends scope of privates.
XFirst hop cost in output (-f option).
XPenalize deprecated hosts (-a option).
X
X-- mod.sources, 4.3bsd, 1/86 -- version 8
XImproved alias treatment.
XRoutes to domain gateways.
XLeading dot in name implies domain.
XLink/host tracing (-t option).
XUse getopt().
X
X-- mod.sources, 8/85 -- version 7
XPrivate hosts documented.
XHomegrown scanner -- it was true what they said about lex.
XMakedb.
XDomains and gateways.
XDEAD back link.
X
X-- net.sources, 1/85 -- version 6
XNo ! in dbm key.
XNetwork character must be one of !@%: -- dot is dead.
XPrivate hosts.
XDiscourage hybrid addresses.  
XMagic @ <-> % rule.
X
X-- 1983-1984 -- version 5
XReverse sense of the -c (cost) flag.
XUse cheapest among duplicate links.
XElide network names in output.
X
X-- epoch (smb version) -- versions 1-4
END_OF_FILE
  if test 1202 -ne `wc -c <'CHANGES'`; then
    echo shar: \"'CHANGES'\" unpacked with wrong size!
  fi
  # end of 'CHANGES'
fi
if test -f 'Makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Makefile'\"
else
  echo shar: Extracting \"'Makefile'\" \(1354 characters\)
  sed "s/^X//" >'Makefile' <<'END_OF_FILE'
X#!/bin/make -f
X# pathalias -- by steve bellovin, as told to peter honeyman
X
X### begin configuration section
X###
X# if you can't or don't intend to use dbm files,
X# don't bother with DBM or makedb
XDBM = -ldbm
X# or if you roll your own ...
X# DBM = dbm.o
X###
X# where is getopt (if not in the c library)?
X# GETOPT = getopt.o
X### end of configuration section 
X
X
XCC = cc
XCFLAGS = -O
XLDFLAGS = -s $(GETOPT)
XYFLAGS = -d
X
XOBJ = addlink.o addnode.o local.o main.o mapit.o mapaux.o mem.o parse.o printit.o
XHDRS = def.h config.h
XCSRC = addlink.c addnode.c local.c main.c mapit.c mapaux.c mem.c printit.c
XLSRC = $(CSRC) parse.c
XSRC = $(CSRC) parse.y makedb.c arpatxt.c
X
Xpathalias: $(OBJ)
X	$(CC) $(OBJ) $(LDFLAGS) -o pathalias
X
Xall: pathalias makedb arpatxt
X
X$(OBJ):	$(HDRS)
X
Xparse.c: parse.y $(HDRS)
X	$(YACC) $(YFLAGS) parse.y
X	mv y.tab.c parse.c
X
Xmakedb: makedb.o
X	$(CC) makedb.o $(LDFLAGS) $(DBM) -o makedb
X
Xmakedb.o: config.h
X
Xarpatxt: arpatxt.o
X	$(CC) arpatxt.o $(LDFLAGS) -o arpatxt
X
Xclean:
X	rm -f *.o y.tab.? parse.c
X
Xclobber: clean
X	rm -f pathalias makedb arpatxt
X
Xtags: $(SRC) $(HDRS)
X	ctags -w $(HDRS) $(SRC)
X
Xbundle:
X	@bundle README CHANGES pathalias.1 Makefile ${HDRS} ${SRC}
X
Xlint:	$(LSRC)
X	lint $(CFLAGS) $(LSRC)
X	lint makedb.c
X	lint arpatxt.c
X
Xinstall:
X	@echo "install pathalias, makedb, arpatxt, and pathalias.1"
X	@echo "according to local conventions"
END_OF_FILE
  if test 1354 -ne `wc -c <'Makefile'`; then
    echo shar: \"'Makefile'\" unpacked with wrong size!
  fi
  # end of 'Makefile'
fi
if test -f 'config.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'config.h'\"
else
  echo shar: Extracting \"'config.h'\" \(2426 characters\)
  sed "s/^X//" >'config.h' <<'END_OF_FILE'
X/* pathalias -- by steve bellovin, as told to peter honeyman */
X
X/**************************************************************************
X * +--------------------------------------------------------------------+ *
X * |                    begin configuration section                     | *
X * +--------------------------------------------------------------------+ *
X **************************************************************************/
X
X#undef STRCHR		/* have strchr -- system v and many others */
X
X#undef UNAME		/* have uname() -- probably system v or 8th ed. */
X#undef MEMSET		/* have memset() -- probably system v or 8th ed. */
X
X#define GETHOSTNAME	/* have gethostname() -- probably bsd */
X#define BZERO		/* have bzero() -- probably bsd */
X
X/* default place for dbm output of makedb (or use -o at run-time) */
X#define	ALIASDB	"/usr/local/lib/palias"
X
X/**************************************************************************
X * +--------------------------------------------------------------------+ *
X * |                    end of configuration section                    | *
X * +--------------------------------------------------------------------+ *
X **************************************************************************/
X
X
X
X#ifdef MAIN
X#ifndef lint
Xstatic char	*c_sccsid = "@(#)config.h	9.2 89/03/03";
X#endif /*lint*/
X#endif /*MAIN*/
X
X/*
X * malloc/free fine tuned for pathalias.
X *
X * MYMALLOC should work everwhere, so it's not a configuration
X * option (anymore).  nonetheless, if you're getting strange
X * core dumps (or panics!), comment out the following manifest,
X * and use the inferior C library malloc/free.
X */
X#define MYMALLOC	/**/
X
X#ifdef MYMALLOC
X#define malloc mymalloc
X#define calloc(n, s) malloc ((n)*(s))
X#define free(s)
X#define cfree(s)
Xextern char *memget();
X#else /* !MYMALLOC */
Xextern char *calloc();
X#endif /* MYMALLOC */
X
X#ifdef STRCHR
X#define index strchr
X#define rindex strrchr
X#else
X#define strchr index
X#define strrchr rindex
X#endif
X
X#ifdef BZERO
X#define strclear(s, n)	((void) bzero((s), (n)))
X#else /*!BZERO*/
X
X#ifdef MEMSET
Xextern char	*memset();
X#define strclear(s, n)	((void) memset((s), 0, (n)))
X#else /*!MEMSET*/
Xextern void	strclear();
X#endif /*MEMSET*/
X
X#endif /*BZERO*/
X
Xextern char	*malloc();
Xextern char	*strcpy(), *index(), *rindex();
X
X#ifndef STATIC
X
X#ifdef DEBUG
X#define STATIC extern
X#else /*DEBUG*/
X#define STATIC static
X#endif /*DEBUG*/
X
X#endif /*STATIC*/
END_OF_FILE
  if test 2426 -ne `wc -c <'config.h'`; then
    echo shar: \"'config.h'\" unpacked with wrong size!
  fi
  # end of 'config.h'
fi
if test -f 'def.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'def.h'\"
else
  echo shar: Extracting \"'def.h'\" \(4496 characters\)
  sed "s/^X//" >'def.h' <<'END_OF_FILE'
X/* pathalias -- by steve bellovin, as told to peter honeyman */
X
X#ifndef lint
X#ifdef MAIN
Xstatic char	*h_sccsid = "@(#)def.h	9.5 88/05/09";
X#endif /*MAIN*/
X#endif /*lint*/
X
X#include <stdio.h>
X#include <ctype.h>
X#include "config.h"
X
Xtypedef	long Cost;
Xtypedef struct node node;
Xtypedef struct link link;
X
X#ifdef lint
X#define vprintf fprintf
X#else /*!lint -- this gives null effect warning*/
X/* because it's there ... */
X#define vprintf		!Vflag ? 0 : fprintf
X#endif /*lint*/
X
X#define NTRACE	16	/* can trace up to NTRACE hosts/links */
X
X/* flags for n_flag */
X#define ISPRIVATE  0x0001 /* invisible outside its definition file */
X#define NALIAS	   0x0002 /* heaped as an alias */
X#define ATSIGN	   0x0004 /* seen an at sign?  used for magic @/% rules */
X#define MAPPED	   0x0008 /* extracted from heap */
X#define	NDEAD	   0x0010 /* out links are dead */
X#define HASLEFT	   0x0020 /* has a left side net character */
X#define HASRIGHT   0x0040 /* route has a right side net character */
X#define	NNET	   0x0080 /* network pseudo-host */
X#define INDFS	   0x0100 /* used when removing net cycles (for -g) */
X#define DUMP	   0x0200 /* we have dumped this net's edges (for -g) */
X#define PRINTED	   0x0400 /* this host has been printed */
X#define NTERMINAL  0x0800 /* heaped as terminal edge (or alias thereto) */
X#define NREF	   0x1000 /* node has an "interesting" reference */
X
X#define ISADOMAIN(n)	 ((n)->n_name[0] == '.')
X#define ISANET(n)	 (((n)->n_flag & NNET) || ISADOMAIN(n))
X#define ALTEREGO(n1, n2) ((n1)->n_name == (n2)->n_name)
X#define DEADHOST(n)	 (((n)->n_flag & (NDEAD | NTERMINAL)) && !ISANET(n))
X#define DEADLINK(l)	 ((l)->l_flag & LDEAD)
X#define DEADNET(n)	 (((n)->n_flag & (NNET | NDEAD)) == (NNET | NDEAD))
X#define GATEWAYED(n)	 (DEADNET(n) || ISADOMAIN(n))
X
X#ifndef DEBUG
X/*
X * save some space in nodes -- there are > 10,000 allocated!
X */
X
X#define n_root un1.nu_root
X#define n_net un1.nu_net
X#define n_copy un1.nu_copy
X
X#define n_private un2.nu_priv
X#define n_parent  un2.nu_par
X
X/* WARNING: if > 2^16 nodes, type of n_tloc must change */
Xstruct node {
X	char	*n_name;	/* host name */
X	link	*n_link;	/* adjacency list */
X	Cost	n_cost;		/* cost to this host */
X	union {
X		node *nu_net;	/* others in this network (parsing) */
X		node *nu_root;	/* root of net cycle (graph dumping) */
X		node *nu_copy;	/* circular copy list (mapping) */
X	} un1;
X	union {
X		node *nu_priv;	/* other privates in this file (parsing) */
X		node *nu_par;	/* parent in shortest path tree (mapping) */
X	} un2;
X	unsigned short n_tloc;	/* back ptr to heap/hash table */
X	unsigned short n_flag;		/* see manifests above */
X};
X
X#endif /*DEBUG*/
X
X#define MILLION (1000L * 1000L)
X#define	DEFNET	'!'			/* default network operator */
X#define	DEFDIR	LLEFT			/* host on left is default */
X#define	DEFCOST	((Cost) 4000)		/* default cost of a link */
X#define	INF	((Cost) 100 * MILLION)	/* infinitely expensive link */
X#define DEFPENALTY ((Cost) 200)		/* default avoidance cost */
X
X/* data structure for adjacency list representation */
X
X/* flags for l_dir */
X
X#define NETDIR(l)	((l)->l_flag & LDIR)
X#define NETCHAR(l)	((l)->l_netop)
X
X#define LDIR	  0x0008	/* 0 for left, 1 for right */
X#define LRIGHT	  0x0000	/* user@host style */
X#define LLEFT	  0x0008	/* host!user style */
X
X#define LDEAD	  0x0010	/* this link is dead */
X#define LALIAS	  0x0020	/* this link is an alias */
X#define LTREE	  0x0040	/* member of shortest path tree */
X#define LGATEWAY  0x0080	/* this link is a gateway */
X#define LTERMINAL 0x0100	/* this link is terminal */
X
X#ifndef DEBUG
X/*
X * borrow a field for link/node tracing.  there's a shitload of
X * edges -- every word counts.  only so much squishing is possible:
X * alignment dictates that the size be a multiple of four.
X */
X
X#define l_next un.lu_next
X#define l_from un.lu_from
X
Xstruct link {
X	node	*l_to;		/* adjacent node */
X	Cost	l_cost;		/* edge cost */
X	union {
X		link *lu_next;	/* rest of adjacency list (not tracing) */
X		node *lu_from;	/* source node (tracing) */
X	} un;
X	short	l_flag;		/* right/left syntax, flags */
X	char	l_netop;	/* network operator */
X};
X
X#endif /*DEBUG*/
X
X#ifdef DEBUG
X/*
X * flattening out the unions makes it easier
X * to debug (when pi is unavailable).
X */
Xstruct node {
X	char	*n_name;
X	link	*n_link;
X	Cost	n_cost;
X	node	*n_net;
X	node	*n_root;
X	node	*n_copy;
X	node	*n_private;
X	node	*n_parent;
X	unsigned short n_tloc;
X	unsigned short n_flag;
X};
Xstruct link {
X	node	*l_to;
X	Cost	l_cost;
X	link	*l_next;
X	node	*l_from;
X	short	l_flag;
X	char	l_netop;
X};
X#endif /*DEBUG*/
END_OF_FILE
  if test 4496 -ne `wc -c <'def.h'`; then
    echo shar: \"'def.h'\" unpacked with wrong size!
  fi
  # end of 'def.h'
fi
if test -f 'local.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'local.c'\"
else
  echo shar: Extracting \"'local.c'\" \(1554 characters\)
  sed "s/^X//" >'local.c' <<'END_OF_FILE'
X/* pathalias -- by steve bellovin, as told to peter honeyman */
X#ifndef lint
Xstatic char	*sccsid = "@(#)local.c	9.2 88/06/10";
X#endif /* lint */
X
X#include <stdio.h>
X#include "config.h"
X
X#ifdef	UNAME
X#include <sys/utsname.h>
X
Xchar	*
Xlocal()
X{
X	static struct utsname utsname;
X	extern int uname();
X
X	(void) uname(&utsname);
X	return(utsname.nodename);
X}
X
X#else /* !UNAME */
X
Xchar	*
Xlocal()
X{
X	static char lname[64];
X	extern int gethostname();
X
X	(void) gethostname(lname, (int) sizeof(lname));
X	lname[sizeof(lname)] = 0;
X	return(lname);
X}
X
X#ifndef GETHOSTNAME
X
XSTATIC int
Xgethostname(name, len)
X	char *name;
X	int len;
X{	FILE *whoami;
X	char *ptr;
X	extern int pclose();
X	extern FILE *fopen(), *popen();
X
X	*name = '\0';
X
X	/* try /etc/whoami */
X	if ((whoami = fopen("/etc/whoami", "r")) != 0) {
X		(void) fgets(name, len, whoami);
X		(void) fclose(whoami);
X		if ((ptr = index(name, '\n')) != 0)
X			*ptr = '\0';
X	}
X	if (*name)
X		return 0;
X
X	/* try /usr/include/whoami.h */
X	if ((whoami = fopen("/usr/include/whoami.h", "r")) != 0) {
X		while (!feof(whoami)) {
X			char	buf[100];
X
X			if (fgets(buf, 100, whoami) == 0)
X				break;
X			if (sscanf(buf, "#define sysname \"%[^\"]\"", name))
X				break;
X		}
X		(void) fclose(whoami);
X		if (*name)
X			return 0;
X	}
X
X	/* ask uucp */
X	if ((whoami = popen("uuname -l", "r")) != 0) {
X		(void) fgets(name, len, whoami);
X		(void) pclose(whoami);
X		if ((ptr = index(name, '\n')) != 0)
X			*ptr = '\0';
X	}
X	if (*name)
X		return 0;
X	
X	/* aw hell, i give up!  is this really unix? */
X	return -1;
X}
X#endif /* GETHOSTNAME */
X#endif /* UNAME */
END_OF_FILE
  if test 1554 -ne `wc -c <'local.c'`; then
    echo shar: \"'local.c'\" unpacked with wrong size!
  fi
  # end of 'local.c'
fi
if test -f 'main.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'main.c'\"
else
  echo shar: Extracting \"'main.c'\" \(3827 characters\)
  sed "s/^X//" >'main.c' <<'END_OF_FILE'
X/* pathalias -- by steve bellovin, as told to peter honeyman */
X#ifndef lint
Xstatic char	*sccsid = "@(#)main.c	9.5 88/06/10";
X#endif
X
X#define MAIN	/* for sccsid in header files */
X
X#include "def.h"
X
X/* exports */
Xchar *Cfile;	/* current input file */
Xchar *Graphout;	/* file for dumping edges (-g option) */
Xchar *Linkout;	/* file for dumping shortest path tree */
Xchar **Argv;	/* external copy of argv (for input files) */
Xnode *Home;	/* node for local host */
Xint Cflag;	/* print costs (-c option) */
Xint Dflag;	/* penalize routes beyond domains (-D option) */
Xint Iflag;	/* ignore case (-i option) */
Xint Tflag;	/* trace links (-t option) */
Xint Vflag;	/* verbose (-v option) */
Xint Fflag;	/* print cost of first hop */
Xint Lineno = 1;	/* line number within current input file */
Xint Argc;	/* external copy of argc (for input files) */
Xextern void die();
Xextern int tracelink();
X
X/* imports */
Xextern char *optarg;
Xextern int optind;
Xextern long Lcount, Ncount;
Xextern long allocation();
Xextern void wasted(), mapit(), hashanalyze(), deadlink();
Xextern char *local();
Xextern node *addnode();
Xextern int getopt(), yyparse();
Xextern void printit();
X
X#define USAGE "usage: %s [-vciDf] [-l localname] [-d deadlink] [-t tracelink] [-g edgeout] [-s treeout] [-a avoid] [files ...]\n"
X
Xmain(argc, argv) 
X	register int argc; 
X	register char **argv;
X{	char *locname = 0, *bang;
X	register int c;
X	int errflg = 0;
X
X	setbuf(stderr, (char *) 0);
X	(void) allocation();	/* initialize data space monitoring */
X	Cfile = "[deadlinks]";	/* for tracing dead links */
X	Argv = argv;
X	Argc = argc;
X
X	while ((c = getopt(argc, argv, "cd:Dfg:il:s:t:v")) != EOF)
X		switch(c) {
X		case 'c':	/* print cost info */
X			Cflag++;
X			break;
X		case 'd':	/* dead host or link */
X			if ((bang = index(optarg, '!')) != 0) {
X				*bang++ = 0;
X				deadlink(addnode(optarg), addnode(bang));
X			} else
X				deadlink(addnode(optarg), (node *) 0);
X			break;
X		case 'D':	/* penalize routes beyond domains */
X			Dflag++;
X			break;
X		case 'f':	/* print cost of first hop */
X			Cflag++;
X			Fflag++;
X			break;
X		case 'g':	/* graph output file */
X			Graphout = optarg;
X			break;
X		case 'i':	/* ignore case */
X			Iflag++;
X			break;
X		case 'l':	/* local name */
X			locname = optarg;
X			break;
X		case 's':	/* show shortest path tree */
X			Linkout = optarg;
X			break;
X		case 't':	/* trace this link */
X			if (tracelink(optarg) < 0) {
X				fprintf(stderr, "%s: can trace only %d links\n", Argv[0], NTRACE);
X				exit(1);
X			}
X			Tflag = 1;
X			break;
X		case 'v':	/* verbose stderr, mixed blessing */
X			Vflag++;
X			break;
X		default:
X			errflg++;
X		}
X
X	if (errflg) {
X		fprintf(stderr, USAGE, Argv[0]);
X		exit(1);
X	}
X	argv += optind;		/* kludge for yywrap() */
X
X	if (*argv)
X		freopen("/dev/null", "r", stdin);
X	else
X		Cfile = "[stdin]";
X
X	if (!locname) 
X		locname = local();
X	if (*locname == 0) {
X		locname = "lostinspace";
X		fprintf(stderr, "%s: using \"%s\" for local name\n",
X				Argv[0], locname);
X	}
X
X	Home = addnode(locname);	/* add home node */
X	Home->n_cost = 0;		/* doesn't cost to get here */
X
X	(void) yyparse();			/* read in link info */
X
X	if (Vflag > 1)
X		hashanalyze();
X	vprintf(stderr, "%d nodes, %d links, alloc %ldk\n", 
X				Ncount, Lcount, allocation());
X
X	Cfile = "[backlinks]";	/* for tracing back links */
X	Lineno = 0;
X
X	/* compute shortest path tree */
X	mapit();
X	vprintf(stderr, "allocation is %ldk after mapping\n", allocation());
X
X	/* traverse tree and print paths */
X	printit();
X	vprintf(stderr, "allocation is %ldk after printing\n", allocation());
X
X	wasted();	/* how much was wasted in memory allocation? */
X
X	return 0;
X}
X
Xvoid
Xdie(s)
X	char *s;
X{
X#ifdef DEBUG
X	extern int abort();
X
X	fprintf(stderr, "%s: %s\n", Argv[0], s);
X	fflush(stdout);
X	fflush(stderr);
X	abort();
X#else
X	fprintf(stderr, "%s: %s; notify the authorities\n", Argv[0], s);
X	exit(-1);
X#endif
X}
END_OF_FILE
  if test 3827 -ne `wc -c <'main.c'`; then
    echo shar: \"'main.c'\" unpacked with wrong size!
  fi
  # end of 'main.c'
fi
if test -f 'make.honey' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'make.honey'\"
else
  echo shar: Extracting \"'make.honey'\" \(3090 characters\)
  sed "s/^X//" >'make.honey' <<'END_OF_FILE'
X#!/bin/make -f
X# pathalias -- by steve bellovin, as told to peter honeyman
X
X### configuration section
X###
X# if you can't or don't intend to use dbm files,
X# don't bother with DBM or makedb
XDBM = -ldbm
X# or if you roll your own ...
X# DBM = dbm.o
X###
X# where is getopt (if not in the c library)?
X# GETOPT = -lgetopt
X### end of configuration section 
X
XCC = cc -g
XCFLAGS =  -DDEBUG
XLDFLAGS =
XYFLAGS = -dD
XYYDEBUG=0
X
XOBJ = addlink.o addnode.o local.o main.o mapit.o mapaux.o mem.o parse.o printit.o
XOFILES = addlink.O addnode.O local.O main.O mapit.O mapaux.O mem.O parse.O printit.O
XHDRS = def.h config.h
XCSRC = addlink.c addnode.c local.c main.c mapit.c mapaux.c mem.c printit.c
XLSRC = $(CSRC) parse.c
XSRC = $(CSRC) parse.y makedb.c arpatxt.c
X
Xpathalias: & $(OBJ)
X	$(CC) $(OBJ) $(LDFLAGS) -o pathalias
X
Xall: pathalias makedb arpatxt
X
X$(OBJ):	$(HDRS)
X
Xparse.c: parse.y $(HDRS)
X	$(YACC) $(YFLAGS) parse.y
X	echo '#define YYDEBUG' > parse.c
X	sed -e '/^# line/d' -e 's/yydebug = 0/yydebug = $(YYDEBUG)/' y.tab.c >> parse.c
X
Xmakedb: makedb.o
X	$(CC) makedb.o $(LDFLAGS) $(DBM) -o makedb
X
Xmakedb.o: config.h
X
Xarpatxt: arpatxt.o
X	$(CC) arpatxt.o $(LDFLAGS) -o arpatxt
X
Xclean:
X	rm -f *.o y.tab.? parse.c
X
Xtags: $(SRC) $(HDRS)
X	ctags -w $(SRC) $(HDRS)
X
Xbundle: README CHANGES pathalias.8 Makefile ${HDRS} ${SRC} arpa-privates make.honey
X	@bundle README CHANGES pathalias.8 Makefile ${HDRS} ${SRC} arpa-privates make.honey
X
Xbundle1: README CHANGES pathalias.8 Makefile ${HDRS}
X	@bundle README CHANGES pathalias.8 Makefile ${HDRS}
X
Xbundle2: addlink.c addnode.c local.c main.c
X	@bundle addlink.c addnode.c local.c main.c
X
Xbundle3: mapit.c mapaux.c
X	@bundle mapit.c mapaux.c
X
Xbundle4: mem.c printit.c parse.y
X	@bundle mem.c printit.c parse.y makedb.c
X
Xbundle5: makedb.c arpatxt.c arpa-privates make.honey
X	@bundle  makedb.c arpatxt.c arpa-privates make.honey
X
Xftp:
X	@make -s bundle | compress > /usr/ftp/pub/honey/pathalias.Z
X
Xmake.honey: makefile
X	@cp makefile make.honey
X
Xlint:	$(LSRC)
X	lint -hbu $(CFLAGS) $(LSRC)
X	lint makedb.c
X
X
X# the remainder is site specific.
X
XLOCAL = paths/citi paths/internet
XFILES = pp/* $(LOCAL)
X
Xpaths/internet: hosts.txt arpa-privates local.hosts arpatxt
X	arpatxt -vfi -g citi -g umix -g mailrus -p arpa-privates local.hosts hosts.txt > paths/internet
X
XAVOID =
X
X# map output (input, really) to lower case; verbose; terminal domains
XARGS = -iD
X
XPARGS=$(ARGS) $(AVOID) $(FILES)
X# desperation debugging -- examine the costs.
Xcosts:
X	pathalias -icvvD ${PARGS} 2>error.costs | awk '{printf("%s\t%s\t%s\n", $$2, $$1, $$3)}' | sort -o pa.costs 
X
X# make one BIG file.  a BIG bad idea.
Xcat:
X	for i in $(FILES); do echo "file {$$i}"; cat $$i; echo 'private {}'; done > CAT
X
X# make a pathparse database.  -g is undocumented.
Xedges:
X	pathalias -g edges $(PARGS) 2>ERRORS > edges.hosts
X#	makedb edges pa
X
X# kill bogus domains with mr. grep, then sort
XPOSTPROC = egrep -v '(\.(com|edu|mil|gov|net|org|arpa|[a-z][a-z])	.*!.*!)|(.\.(com|edu|mil|gov|net|org|arpa|[a-z][a-z])	)' | sort
X
X# round up the usual suspects
Xciti dwon umix mailrus:	$(LOCAL)
X	pathalias -l $@ $(PARGS) | $(POSTPROC) > $@
END_OF_FILE
  if test 3090 -ne `wc -c <'make.honey'`; then
    echo shar: \"'make.honey'\" unpacked with wrong size!
  fi
  # end of 'make.honey'
fi
if test -f 'makedb.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'makedb.c'\"
else
  echo shar: Extracting \"'makedb.c'\" \(2342 characters\)
  sed "s/^X//" >'makedb.c' <<'END_OF_FILE'
X/* pathalias -- by steve bellovin, as told to peter honeyman */
X#ifndef lint
Xstatic char	*sccsid = "@(#)makedb.c	9.1 87/10/04";
X#endif /* lint */
X
X#include <stdio.h>
X#include "config.h"
X
Xtypedef struct {
X	char *dptr;
X	int dsize;
X} datum;
X
Xchar *Ofile = ALIASDB, *ProgName;
X
X#define USAGE "%s [-o dbmname] [-a] [file ...]\n"
X
Xmain(argc, argv)
X	char *argv[];
X{	char *ofptr;
X	int c, append = 0;
X	extern int optind;
X	extern char *optarg;
X
X	ProgName = argv[0];
X	while ((c = getopt(argc, argv, "o:a")) != EOF)
X		switch(c) {
X		case 'o':	/* dbm output file */
X			Ofile = optarg;
X			break;
X
X		case 'a':	/* append mode */
X			append++;
X			break;
X
X		default:
X			fprintf(stderr, USAGE, ProgName);
X			exit(1);
X			break;
X		}
X
X
X	if ((ofptr = rindex(Ofile, '/')) != 0)
X		ofptr++;
X	else
X		ofptr = Ofile;
X	if (strlen(ofptr) > 10) {
X		ofptr[10] = 0;
X		fprintf(stderr, "%s: using %s for dbm output\n", ProgName, Ofile);
X	}
X
X	if (append == 0 && dbfile(Ofile) != 0) {
X		perror_(Ofile);
X		exit(1);
X	}
X
X	if (dbminit(Ofile) < 0) {
X		perror_(Ofile);
X		exit(1);
X	}
X
X	if (optind == argc)
X		makedb((char *) 0);
X	else for ( ; optind < argc; optind++)
X		makedb(argv[optind]);
X	exit(0);
X}
X
Xdbfile(dbf)
X	char *dbf;
X{
X	return (dbcreat(dbf, "dir") != 0 || dbcreat(dbf, "pag") != 0);
X}
X
Xdbcreat(dbf, suffix)
X	char *dbf, *suffix;
X{	char buf[BUFSIZ];
X	int fd;
X
X	(void) sprintf(buf, "%s.%s", dbf, suffix);
X	if ((fd = creat(buf, 0666)) < 0)
X		return(-1);
X	(void) close(fd);
X	return(0);
X}
X
X
Xmakedb(ifile)
X	char *ifile;
X{	char line[BUFSIZ];
X	datum key, val;
X
X	if (ifile && (freopen(ifile, "r", stdin) == NULL)) {
X		perror_(ifile);
X		return;
X	}
X
X	/*
X	 * keys and values are 0 terminated.  this wastes time and (disk) space,
X	 * but does lend simplicity and backwards compatibility.
X	 */
X	key.dptr = line;
X	while (fgets(line, sizeof(line), stdin) != NULL) {
X		char *op, *end;
X
X		end = line + strlen(line);
X		end[-1] = 0;	/* kill newline, stuff null terminator */
X		op = index(line, '\t');
X		if (op != 0) {
X			*op++ = 0;
X			key.dsize = op - line;		/* 0 terminated */
X			val.dptr = op;
X			val.dsize = end - op;		/* 0 terminated */
X		} else {
X			key.dsize = end - line;		/* 0 terminated */
X			val.dptr = "\0";		/* why must i do this? */
X			val.dsize = 1;
X		}
X		if (store(key, val) < 0)
X			perror_(Ofile);
X	}
X}
X
Xperror_(str)
X	char	*str;
X{
X	fprintf(stderr, "%s: ", ProgName);
X	perror(str);
X}
END_OF_FILE
  if test 2342 -ne `wc -c <'makedb.c'`; then
    echo shar: \"'makedb.c'\" unpacked with wrong size!
  fi
  # end of 'makedb.c'
fi
echo shar: End of archive 3 \(of 3\).
cp /dev/null ark3isdone
MISSING=""
for I in 1 2 3 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 3 archives.
    rm -f ark[1-9]isdone
else
    echo You still must unpack the following archives:
    echo "        " ${MISSING}
fi
exit 0
exit 0 # Just in case...
-- 
Please send comp.sources.unix-related mail to rsalz@uunet.uu.net.
Use a domain-based address or give alternate paths, or you may lose out.