home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-11-28 | 30.6 KB | 1,405 lines |
- Newsgroups: comp.sources.misc
- From: clewis@ferret.ocunix.on.ca (Chris Lewis)
- Subject: v34i002: unpackmaps - A secure comp.mail.maps unpacker, Part02/02
- Message-ID: <1992Nov29.202143.15872@sparky.imd.sterling.com>
- X-Md4-Signature: 3ad0492fa994dcb97ee9d546b2c83303
- Date: Sun, 29 Nov 1992 20:21:43 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: clewis@ferret.ocunix.on.ca (Chris Lewis)
- Posting-number: Volume 34, Issue 2
- Archive-name: unpackmaps/part02
- Environment: Pathalias, Cnews, UNIX
- Supersedes: unpackmaps: Volume 22, Issue 69
-
- #! /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: Make.proto deletelist display.c docomp.c dointer.c dopath
- # fatal.c fileinit.c getmaps.c getpath.c lock.c savestr.c unpack.h
- # uuwhere.M
- # Wrapped by clewis@ecicrl on Sat Nov 28 02:12:46 1992
- 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 2 (of 2)."'
- if test -f 'Make.proto' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'Make.proto'\"
- else
- echo shar: Extracting \"'Make.proto'\" \(1964 characters\)
- sed "s/^X//" >'Make.proto' <<'END_OF_FILE'
- X# Copyright 1992, Chris Lewis. All Rights Reserved
- X# Please see the README for the terms of the copyright.
- X# 1.2 92/06/10
- X
- X# @(#)Make.P 1.2 92/06/10 01:45:13
- X
- X# Compilation options. The defines are actually in config.proto/config.h
- XCFLAGS = -O
- X
- X# Sometimes necessary to pick up getopt:
- X# Dynix UCB universe: -lseq
- X# If you have added on directory routines, list the archive here:
- X
- XLIBS =
- X
- X# Where you want to install the binaries for unpackmaps and uuwhere
- XBINDIR = /usr/local/bin
- X
- X# Manual page directory:
- XMANDIR = /usr/man/man1
- X# Suffix. Usually 1 or 1L
- XMANEXT = 1
- X
- X# Don't touch from here on.
- X
- XPACKEROBJ = unpacker.o uncomp.o docomp.o runpath.o sortwdb.o unpack.o \
- X fatal.o savestr.o dointer.o fileinit.o lock.o getmaps.o
- XPACKERSRC = unpacker.c uncomp.c docomp.c runpath.c sortwdb.c unpack.c \
- X fatal.c savestr.c dointer.c fileinit.c lock.c getmaps.c
- XWHEREOBJ = uuwhere.o getpath.o display.o uncomp.o fileinit.o getmaps.o \
- X savestr.o
- XWHERESRC = uuwhere.c getpath.c display.c uncomp.c fileinit.c getmaps.c \
- X savestr.c
- X
- Xall: unpackmaps uuwhere
- X
- Xunpackmaps: $(PACKEROBJ)
- X $(CC) $(CFLAGS) -o unpackmaps $(PACKEROBJ) $(LIBS)
- X
- Xuuwhere: $(WHEREOBJ)
- X $(CC) $(CFLAGS) -o uuwhere $(WHEREOBJ) $(LIBS)
- X
- X$(WHEREOBJ): unpack.h config.h
- X
- X$(PACKEROBJ): unpack.h config.h
- X
- Xclean:
- X rm -fr unpackmaps uuwhere core *.o
- X
- Xlint: uuwhere.li unpackmaps.li
- X
- Xunpackmaps.li:
- X lint -Dlint $(CFLAGS) $(PACKERSRC) > unpackmaps.lin
- X
- Xuuwhere.li:
- X lint -Dlint $(CFLAGS) $(WHERESRC) > uuwhere.lin
- X
- Xmakekit:
- X makekit -m
- X
- Xinstall: all
- X rm -f $(BINDIR)/unpackmaps
- X cp unpackmaps $(BINDIR)/unpackmaps
- X chmod 755 $(BINDIR)/unpackmaps
- X rm -f $(BINDIR)/uuwhere
- X cp uuwhere $(BINDIR)/uuwhere
- X chmod 755 $(BINDIR)/uuwhere
- X
- X rm -f $(MANDIR)/unpackmaps.$(MANEXT)
- X -cp unpackmaps.M $(MANDIR)/unpackmaps.$(MANEXT)
- X -chmod 755 $(MANDIR)/unpackmaps.$(MANEXT)
- X rm -f $(MANDIR)/uuwhere.$(MANEXT)
- X -cp uuwhere.M $(MANDIR)/uuwhere.$(MANEXT)
- X -chmod 755 $(MANDIR)/uuwhere.$(MANEXT)
- X
- END_OF_FILE
- if test 1964 -ne `wc -c <'Make.proto'`; then
- echo shar: \"'Make.proto'\" unpacked with wrong size!
- fi
- # end of 'Make.proto'
- fi
- if test -f 'deletelist' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'deletelist'\"
- else
- echo shar: Extracting \"'deletelist'\" \(2310 characters\)
- sed "s/^X//" >'deletelist' <<'END_OF_FILE'
- Xu.arg.1
- Xu.arg.ba.1
- Xu.arg.ba.2
- Xu.arg.cb.1
- Xu.arg.cc.1
- Xu.arg.ch.1
- Xu.arg.cn.1
- Xu.arg.ct.1
- Xu.arg.er.1
- Xu.arg.fm.1
- Xu.arg.lr.1
- Xu.arg.mn.1
- Xu.arg.mz.1
- Xu.arg.nq.1
- Xu.arg.rn.1
- Xu.arg.sa.1
- Xu.arg.se.1
- Xu.arg.sf.1
- Xu.arg.sj.1
- Xu.arg.sl.1
- Xu.arg.tf.1
- Xu.arg.tm.1
- Xu.aus.act.1
- Xu.aus.dom.1
- Xu.aus.nsw.1
- Xu.aus.nt.1
- Xu.aus.qld.1
- Xu.aus.sa.1
- Xu.aus.tas.1
- Xu.aus.vic.1
- Xu.aus.wa.1
- Xu.aut.1
- Xu.bel.0
- Xu.bel.1
- Xu.bgr.0
- Xu.bgr.1
- Xu.bys.1
- Xu.che.0
- Xu.che.1
- Xu.che.10
- Xu.che.100
- Xu.chl.1
- Xu.col.1
- Xu.cri.1
- Xu.csk.0
- Xu.csk.1
- Xu.deu.0
- Xu.deu.1
- Xu.deu.100
- Xu.deu.101
- Xu.deu.102
- Xu.deu.2
- Xu.deu.3
- Xu.deu.4
- Xu.deu.5
- Xu.deu.6
- Xu.deu.7
- Xu.deu.8
- Xu.deu.9
- Xu.dmk.1
- Xu.dnk.0
- Xu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1
- END_OF_FILE
- if test 2310 -ne `wc -c <'deletelist'`; then
- echo shar: \"'deletelist'\" unpacked with wrong size!
- fi
- # end of 'deletelist'
- fi
- if test -f 'display.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'display.c'\"
- else
- echo shar: Extracting \"'display.c'\" \(2951 characters\)
- sed "s/^X//" >'display.c' <<'END_OF_FILE'
- X/* Copyright 1992, Chris Lewis. All Rights Reserved
- X Please see the README for the terms of the copyright.
- X 1.3 92/08/15
- X */
- X
- X#ifndef lint
- Xstatic char SCCSid[] = "@(#)display.c 1.3 92/08/15 22:31:35";
- X#endif
- X#include "unpack.h"
- X
- Xextern long pathlength;
- Xextern char *gpathdata;
- Xextern int verbose;
- X
- Xdumpmap(site)
- Xregister char *site; {
- X char buf[BUFSIZ];
- X register char *s,*e;
- X int cost;
- X
- X pathlength = 0;
- X gpathdata = wheredb;
- X
- X if (getpath(site, buf, &cost))
- X return(1);
- X
- X s = buf;
- X while(*s) {
- X e = strchr(s, ':');
- X if (e)
- X *e++ = '\0';
- X (void) dumpit(s);
- X if (e)
- X s = e;
- X else
- X break;
- X }
- X return(0);
- X}
- X
- Xdumpit(mapfn)
- Xchar *mapfn; {
- X
- X char *p, *e;
- X int offsets[20], *op = offsets;
- X
- X p = strchr(mapfn, ',');
- X if (!p)
- X return(1);
- X *p++ = '\0'; /* mapfn now is map file name */
- X while(*p) {
- X e = strchr(p, ',');
- X if (e)
- X *e = '\0';
- X *op++ = atoi(p);
- X if (e)
- X p = e + 1;
- X else
- X break;
- X }
- X *op = 0;
- X for (op = offsets; *op; op++)
- X (void) printf("%s: %d\n", mapfn, *op);
- X return(dumpfile(mapfn, offsets, 1));
- X}
- X
- Xdumpfile(mapfn, offsets, nterm)
- Xchar *mapfn;
- Xint *offsets, nterm; {
- X
- X int compressed = 0, printing = 0;
- X FILE *fin = (FILE *) NULL;
- X register int *op = offsets;
- X register int recno;
- X char *((*rdfcn)());
- X char *p;
- X extern int rc;
- X
- X extern FILE *zfopen();
- X extern char *zfgets();
- X
- X if (debug)
- X (void) fprintf(stderr, "mapfn: %s\n", mapfn);
- X
- X if ((fin = fopen(mapfn, "r")) != NULL)
- X rdfcn = fgets;
- X else {
- X (void) sprintf(tempbuf, "%s.Z", mapfn);
- X fin = zfopen(tempbuf, "r");
- X compressed = 1;
- X rdfcn = zfgets;
- X }
- X
- X if (!fin) {
- X (void) fprintf(stderr, "%s: Can't open %s\n", progname, mapfn);
- X rc |= 1;
- X return(1);
- X }
- X
- X recno = 0;
- X while(rdfcn(tempbuf, sizeof(tempbuf), fin)) {
- X recno++;
- X
- X if (!printing && recno == *op) {
- X printing = 1;
- X }
- X if (recno > *op && nterm && strncmp(tempbuf, "#N", 2) == 0) {
- X op++;
- X if (!*op)
- X break;
- X if (recno < *op)
- X printing = 0;
- X }
- X if (printing) {
- X if (verbose && tempbuf[0] == '#' &&
- X isupper(tempbuf[1]) &&
- X isspace(tempbuf[2])) {
- X register char *str;
- X str = "";
- X switch(tempbuf[1]) {
- X case 'N': str = "Name:"; break;
- X case 'S': str = "System:"; break;
- X case 'O': str = "Organization:"; break;
- X case 'C': str = "Contacts:"; break;
- X case 'E': str = "Email:"; break;
- X case 'T': str = "Telephone:"; break;
- X case 'P': str = "Postal:"; break;
- X case 'L': str = "Lat/Long:"; break;
- X case 'R': str = "Remarks:"; break;
- X case 'U': str = "USENET links:"; break;
- X case 'W': str = "Who:"; break;
- X }
- X
- X p = &tempbuf[1];
- X
- X if (!isspace(tempbuf[1]))
- X p++;
- X
- X while(*p && (*p == ' ' || *p == '\t')) p++;
- X (void) printf("#%-15s%s", str, p);
- X } else
- X (void) fputs(tempbuf, stdout);
- X }
- X }
- X
- X if (compressed)
- X (void) zfclose(fin);
- X else
- X (void) fclose(fin);
- X return(0);
- X}
- END_OF_FILE
- if test 2951 -ne `wc -c <'display.c'`; then
- echo shar: \"'display.c'\" unpacked with wrong size!
- fi
- # end of 'display.c'
- fi
- if test -f 'docomp.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'docomp.c'\"
- else
- echo shar: Extracting \"'docomp.c'\" \(2733 characters\)
- sed "s/^X//" >'docomp.c' <<'END_OF_FILE'
- X/* Copyright 1992, Chris Lewis. All Rights Reserved
- X Please see the README for the terms of the copyright.
- X 1.2 92/08/14
- X */
- X
- X#ifndef lint
- Xstatic char SCCSid[] = "@(#)docomp.c 1.2 92/08/14 20:48:28";
- X#endif
- X#define UNPACKMAPS
- X#include "unpack.h"
- X#define ARMAX 10
- X
- X#ifdef COMPFLAG
- X#define FF 2
- X#else
- X#define FF 1
- X#endif
- X
- X/* Buffers up files to compress in big chunks */
- Xdocompress(file)
- Xregister char *file; {
- X char tb[16];
- X static char *arglist[ARMAX + 3] = {"COMPRESS"
- X#ifdef COMPFLAG
- X , COMPFLAG
- X#endif
- X };
- X static char **ap = &arglist[FF];
- X
- X /* If maps are coming in two different newsgroups (not x-posted),
- X it is possible that you'll get the same name twice. If you
- X don't ignore the duplicates, compress will complain that it
- X couldn't find the subsequent instances. While this is harmless,
- X it is somewhat disturbing. We simply ignore the
- X second or subsequent mention of the same file name.
- X
- X [The scenario happens with the Canadian maps. Both Rutgers and
- X the Canadian map authority post the Canadian maps simultaneously.
- X The former in comp.mail.maps, the latter in can.uucp.maps.
- X The logic behind this is relatively sound, but too long to reproduce
- X here. They're not cross-posted because it breaks uuhosts (but not
- X unpackmaps! ;-).]
- X */
- X
- X if (file && ap > &arglist[FF]) {
- X char **p;
- X
- X for (p = &arglist[FF]; p < ap; p++)
- X if (strcmp(file, *p) == 0)
- X return;
- X }
- X
- X#if (FILELENGTH == 0) || (FILELENGTH == 1)
- X# define MAXCOMPLEN 12
- X#else
- X# define MAXCOMPLEN (FILELENGTH - 2)
- X#endif
- X
- X /* To avoid compress complaints on systems with file name restrictions */
- X if (file && strlen(file) > MAXCOMPLEN)
- X return;
- X
- X if (file) {
- X (void) strcpy(tb, file);
- X (void) strcat(tb, ".Z");
- X (void) unlink(tb);
- X }
- X
- X if (!compflag)
- X return;
- X
- X if (debug)
- X (void) fprintf(stderr, "docompress %s (%d)\n", file, ap - arglist);
- X
- X if ((!file || ap > &arglist[ARMAX]) && ap > &arglist[FF]) {
- X int pid, wpid, waitloc;
- X if (debug)
- X (void) fprintf(stderr, "Firing off compress (fc = %d)\n",
- X ap - arglist);
- X
- X if (debug)
- X for (ap = arglist; *ap; ap++)
- X (void) fprintf(stderr, "%d: %s\n", ap-arglist, *ap);
- X
- X fflush(stderr);
- X if ((pid = fork()) == 0) {
- X (void) execv(compress, arglist);
- X fatal(1, "Can't exec compress");
- X }
- X while((wpid = wait(&waitloc)) != pid && wpid > 0)
- X continue;
- X if (waitloc) {
- X (void) fprintf(stderr, "%s: compress failed, returned 0x%x (pid: %d)\n",
- X progname, waitloc, wpid);
- X }
- X for (ap = &arglist[FF]; *ap; ap++)
- X free(*ap);
- X ap = &arglist[FF];
- X }
- X if (file) {
- X *ap = (char *) malloc(strlen(file)+1);
- X (void) strcpy(*ap++, file);
- X *ap = (char *) NULL;
- X }
- X}
- END_OF_FILE
- if test 2733 -ne `wc -c <'docomp.c'`; then
- echo shar: \"'docomp.c'\" unpacked with wrong size!
- fi
- # end of 'docomp.c'
- fi
- if test -f 'dointer.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'dointer.c'\"
- else
- echo shar: Extracting \"'dointer.c'\" \(1322 characters\)
- sed "s/^X//" >'dointer.c' <<'END_OF_FILE'
- X/* Copyright 1992, Chris Lewis. All Rights Reserved
- X Please see the README for the terms of the copyright.
- X 1.2 92/11/28
- X */
- X
- X#ifndef lint
- Xstatic char SCCSid[] = "@(#)dointer.c 1.2 92/11/28 00:44:13";
- X#endif
- X#define UNPACKMAPS
- X#include "unpack.h"
- X
- Xint
- Xcountbang(path)
- Xregister char *path; {
- X register int i;
- X for (i = 0; *path; path++)
- X if (*path == '!')
- X i++;
- X return(i);
- X}
- X
- Xdointernet(site, route)
- Xregister char *site, **route; {
- X static int intbangcount = -1;
- X register char *p;
- X
- X if (intbangcount == -1)
- X intbangcount = countbang(internet);
- X
- X if (*site == '.') {
- X /* .domain longpath!%s -> .domain internet!%s */
- X if (intbangcount + 2 < countbang(*route)) {
- X (void) sprintf(tempbuf, "%s!%%s", internet);
- X *route = tempbuf;
- X }
- X } else if (strchr(site, '.')) {
- X /* domain longpath!%s -> domain internet!domain!%s */
- X if (intbangcount + 2 < countbang(*route)) {
- X (void) sprintf(tempbuf, "%s!%s!%%s", internet, site);
- X *route = tempbuf;
- X }
- X } else if (p = strrchr(*route, '.')) {
- X /* any longpath!domain!path!%s -> any internet!domain!path!%s */
- X while(p > *route && *p != '!') p--;
- X if (*p == '!') {
- X *p = '\0';
- X if (intbangcount < countbang(*route)) {
- X (void) sprintf(tempbuf, "%s!%s", internet, p+1);
- X *route = tempbuf;
- X }
- X *p = '!';
- X }
- X }
- X}
- END_OF_FILE
- if test 1322 -ne `wc -c <'dointer.c'`; then
- echo shar: \"'dointer.c'\" unpacked with wrong size!
- fi
- # end of 'dointer.c'
- fi
- if test -f 'dopath' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'dopath'\"
- else
- echo shar: Extracting \"'dopath'\" \(203 characters\)
- sed "s/^X//" >'dopath' <<'END_OF_FILE'
- XPATH=.:/usr/local/bin:$PATH export PATH
- XLD=/u/clewis/maps
- Xcd /u/clewis/src/unpackmaps
- Xunpackmaps -cup -Iuunet.ca -f $LD/path.local \
- X -f $LD/path.private -ldeletelist -U
- Xunpackmaps -cud /usr/spool/pmaps
- END_OF_FILE
- if test 203 -ne `wc -c <'dopath'`; then
- echo shar: \"'dopath'\" unpacked with wrong size!
- fi
- # end of 'dopath'
- fi
- if test -f 'fatal.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'fatal.c'\"
- else
- echo shar: Extracting \"'fatal.c'\" \(1487 characters\)
- sed "s/^X//" >'fatal.c' <<'END_OF_FILE'
- X/* Copyright 1992, Chris Lewis. All Rights Reserved
- X Please see the README for the terms of the copyright.
- X 1.3 92/08/14
- X */
- X
- X#ifndef lint
- Xstatic char SCCSid[] = "@(#)fatal.c 1.3 92/08/14 20:48:32";
- X#endif
- X#define UNPACKMAPS
- X#include "unpack.h"
- X
- Xfatal(code, msg)
- Xint code;
- Xchar *msg; {
- X
- X if (code) {
- X (void) fprintf(stderr, "%s: %s\n", progname, msg);
- X (void) myexit(code);
- X }
- X}
- X
- Xstatic char errlog[] = "/tmp/unpXXXXXX";
- Xextern char *mktemp();
- Xstartlog() {
- X if (!(freopen(mktemp(errlog), "w", stderr))) {
- X (void) printf("%s: Can't open temporary file %s for errors!\n",
- X progname, errlog);
- X exit(1);
- X }
- X}
- X
- Xmyexit(code)
- Xint code; {
- X struct stat stb;
- X FILE *diag;
- X FILE *notifyfp;
- X
- X (void) unlink(pathtmp);
- X (void) unlink(pathtmp2);
- X (void) unlink(wheretmp);
- X (void) fclose(stderr);
- X
- X if (batchlock)
- X setbatch(0);
- X
- X if (!notify)
- X exit(code);
- X
- X if (stat(errlog, &stb) == 0 && stb.st_size > 0) {
- X
- X if (!(notifyfp = popen(notify, "w"))) {
- X (void) printf("%s: Can't open mail pipeline ``%s''\n", progname, notify);
- X (void) exit(1);
- X }
- X
- X (void) fputs("Subject: Map Unpacking Report\n\n", notifyfp);
- X
- X if (!(diag = fopen(errlog, "r"))) {
- X (void) printf("%s: Can't open error log %s\n",
- X progname, errlog);
- X (void) exit(1);
- X }
- X
- X while(fgets(spooldir, sizeof(spooldir), diag)) {
- X (void) fputs(spooldir, notifyfp);
- X }
- X (void) fclose(diag);
- X (void) pclose(notifyfp);
- X }
- X (void) unlink(errlog);
- X (void) exit(code);
- X}
- END_OF_FILE
- if test 1487 -ne `wc -c <'fatal.c'`; then
- echo shar: \"'fatal.c'\" unpacked with wrong size!
- fi
- # end of 'fatal.c'
- fi
- if test -f 'fileinit.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'fileinit.c'\"
- else
- echo shar: Extracting \"'fileinit.c'\" \(634 characters\)
- sed "s/^X//" >'fileinit.c' <<'END_OF_FILE'
- X/* Copyright 1992, Chris Lewis. All Rights Reserved
- X Please see the README for the terms of the copyright.
- X 1.1 92/06/10
- X */
- X
- X#ifndef lint
- Xstatic char SCCSid[] = "@(#)fileinit.c 1.1 92/06/10 01:16:15";
- X#endif
- X
- X#include "unpack.h"
- X
- Xchar *
- Xmakepath(dir, file)
- Xchar *dir, *file; {
- X register char *p = (char *) malloc(strlen(dir) + strlen(file) + 10);
- X char numbuf[10];
- X fatal(!p, "Can't allocate temporary file names");
- X (void) strcpy(p, dir);
- X (void) strcat(p, "/");
- X if (*file == '.') {
- X (void) sprintf(numbuf, "%d", (int) getpid());
- X (void) strcat(p, numbuf);
- X }
- X (void) strcat(p, file);
- X return(p);
- X}
- END_OF_FILE
- if test 634 -ne `wc -c <'fileinit.c'`; then
- echo shar: \"'fileinit.c'\" unpacked with wrong size!
- fi
- # end of 'fileinit.c'
- fi
- if test -f 'getmaps.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'getmaps.c'\"
- else
- echo shar: Extracting \"'getmaps.c'\" \(1622 characters\)
- sed "s/^X//" >'getmaps.c' <<'END_OF_FILE'
- X/* Copyright 1992, Chris Lewis. All Rights Reserved
- X Please see the README for the terms of the copyright.
- X 1.1 92/06/10
- X */
- X
- X#ifndef lint
- Xstatic char SCCSid[] = "@(#)getmaps.c 1.1 92/06/10 01:16:16";
- X#endif
- X
- X#include "unpack.h"
- X
- X#if defined(USGDIR) || defined(BERKDIR)
- Xint
- Xfilesort(a, b)
- Xchar **a, **b; {
- X return(strcmp(*a, *b));
- X}
- X
- Xvoid
- Xgetmaps(sl, flag)
- Xint flag;
- Xstruct stringlist *sl; {
- X DIR *dirp;
- X struct dirent *dp;
- X struct stat stb;
- X
- X dirp = opendir(".");
- X while((dp = readdir(dirp)) != NULL) {
- X if (dp->d_name[0] == '.')
- X continue;
- X if (flag && ((dp->d_name[0] != 'd' && dp->d_name[0] != 'u') ||
- X dp->d_name[1] != '.'))
- X continue;
- X if (debug)
- X (void) fprintf(stderr, "Adding %s\n", dp->d_name);
- X if (stat(dp->d_name, &stb))
- X (void) fprintf(stderr, "Can't stat %s\n", dp->d_name);
- X else
- X (void) savestr(sl, dp->d_name);
- X }
- X (void) closedir(dirp);
- X (void) qsort(sl->list, sl->curptr - sl->list, sizeof(char **), filesort);
- X}
- X#else
- Xvoid
- Xgetmaps(sl, flag)
- Xstruct stringlist *sl;
- Xint flag; {
- X char buf[40];
- X register char *p;
- X FILE *list;
- X struct stat stb;
- X
- X /* first, collect the files from the directory */
- X fatal(!(list = popen("/bin/ls * 2>/dev/null", "r")), "can't popen map list");
- X
- X while(fgets(buf, sizeof(buf), list)) {
- X if ((p = strchr(buf, '\n')) != NULL)
- X *p = '\0';
- X if (flag && ((buf[0] != 'd' && buf[0] != 'u') || buf[1] != '.'))
- X continue;
- X if (stat(buf, &stb))
- X (void) fprintf(stderr, "Can't stat %s\n", buf);
- X else
- X (void) savestr(sl, buf);
- X }
- X
- X fatal(pclose(list), "Spool area ls failed");
- X}
- X#endif
- END_OF_FILE
- if test 1622 -ne `wc -c <'getmaps.c'`; then
- echo shar: \"'getmaps.c'\" unpacked with wrong size!
- fi
- # end of 'getmaps.c'
- fi
- if test -f 'getpath.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'getpath.c'\"
- else
- echo shar: Extracting \"'getpath.c'\" \(2330 characters\)
- sed "s/^X//" >'getpath.c' <<'END_OF_FILE'
- X/* taken from: *sccsid="@(#)getpath.c 2.5 (smail) 9/15/87";
- X Permission pending
- X */
- X
- X#ifndef lint
- Xstatic char SCCSid[] = "@(#)getpath.c 1.1 92/06/10 01:16:17";
- X#endif
- X
- X#include "unpack.h"
- X
- X#define DEBUG if (debug) (void) printf
- Xchar *gpathdata;
- X#define lower(x) (isupper(x)? x-'A'+'a' : x)
- X
- X/*
- X**
- X** getpath(): look up key in ascii sorted path database.
- X**
- X*/
- X
- X/* Every time reset to zero, path file is reopened */
- Xlong pathlength = 0;
- X
- Xgetpath( key, path, cost)
- Xchar *key; /* what we are looking for */
- Xchar *path; /* where the path results go */
- Xint *cost; /* where the cost results go */
- X{
- X long pos, middle, hi, lo;
- X register char *s;
- X int c;
- X int flag;
- X static FILE *file = (FILE *) NULL;
- X
- X DEBUG("getpath: looking for '%s'\n", key);
- X
- X if(pathlength == 0) { /* open file on first use */
- X if (file)
- X (void) fclose(file);
- X if((file = fopen(gpathdata, "r")) == NULL) {
- X (void) printf("Can't access %s.\n", gpathdata);
- X pathlength = -1;
- X } else {
- X (void) fseek(file, 0L, 2); /* find length */
- X pathlength = ftell(file);
- X }
- X }
- X if( pathlength == -1 )
- X return( 1 );
- X
- X lo = 0;
- X hi = pathlength;
- X (void) strcpy( path, key );
- X (void) strcat( path, "\t" );
- X/*
- X** "Binary search routines are never written right the first time around."
- X** - Robert G. Sheldon.
- X*/
- X for( ;; ) {
- X pos = middle = ( hi+lo+1 )/2;
- X (void) fseek(file, pos, 0); /* find midpoint */
- X if(pos != 0)
- X while(((c = getc(file)) != EOF) && (c != '\n'))
- X continue; /* go to beginning of next line */
- X if(c == EOF) {
- X return(1);
- X }
- X for( flag = 0, s = path; flag == 0; s++ ) { /* match??? */
- X if( *s == '\0' ) {
- X goto solved;
- X }
- X if((c = getc(file)) == EOF) {
- X return(1);
- X }
- X flag = lower(c) - lower(*s);
- X }
- X if(lo >= middle) { /* failure? */
- X return(1);
- X }
- X if((c != EOF) && (flag < 0)) { /* close window */
- X lo = middle;
- X } else {
- X hi = middle - 1;
- X }
- X }
- X/*
- X** Now just copy the result.
- X*/
- Xsolved:
- X while(((c = getc(file)) != EOF) && (c != '\t') && (c != '\n')) {
- X *path++ = c;
- X }
- X *path = '\0';
- X/*
- X** See if the next field on the line is numeric.
- X** If so, use it as the cost for the route.
- X*/
- X if(c == '\t') {
- X int tcost = -1;
- X while(((c = getc(file)) != EOF) && isdigit(c)) {
- X if(tcost < 0) tcost = 0;
- X tcost *= 10;
- X tcost += c - '0';
- X }
- X if(tcost >= 0) *cost = tcost;
- X }
- X return (0);
- X}
- X
- END_OF_FILE
- if test 2330 -ne `wc -c <'getpath.c'`; then
- echo shar: \"'getpath.c'\" unpacked with wrong size!
- fi
- # end of 'getpath.c'
- fi
- if test -f 'lock.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'lock.c'\"
- else
- echo shar: Extracting \"'lock.c'\" \(1199 characters\)
- sed "s/^X//" >'lock.c' <<'END_OF_FILE'
- X/* Copyright 1992, Chris Lewis. All Rights Reserved
- X Please see the README for the terms of the copyright.
- X 1.1 92/06/10
- X */
- X
- X#ifndef lint
- Xstatic char SCCSid[] = "@(#)lock.c 1.1 92/06/10 01:16:19";
- X#endif
- X
- X#define UNPACKMAPS
- X#include "unpack.h"
- X
- X#define TRYTIME
- X
- Xint
- Xsetbatch(on)
- Xint on; {
- X#ifdef LOCKBATCH
- X batchlock = 1;
- X return(mylock(LOCKBATCH, on));
- X#else
- X return(0);
- X#endif
- X}
- X
- X#define INTERVAL 25
- Xint
- Xmylock(lockfile, on)
- Xchar *lockfile;
- Xint on; {
- X if (!on) {
- X (void) unlink(lockfile);
- X } else {
- X register char *tempnm, *p;
- X FILE *tempfp;
- X int locktries = 10;
- X
- X fatal(!(tempnm = (char *) malloc(strlen(lockfile) + 15)),
- X "allocate temp lock");
- X (void) strcpy(tempnm, lockfile);
- X fatal(!(p = strrchr(tempnm, '/')), "Lock isn't full path");
- X *p = '\0';
- X (void) strcat(tempnm, "/LCKXXXXXX");
- X (void) mktemp(tempnm);
- X
- X fatal(!(tempfp = fopen(tempnm, "w")), "Can't create temp lock");
- X (void) fprintf(tempfp, "%d\n", getpid());
- X (void) fclose(tempfp);
- X
- X while (link(tempnm, lockfile) < 0) {
- X fatal(errno != EEXIST, "Can't link locks");
- X fatal(!(locktries--), "Couldn't get lock");
- X (void) sleep(INTERVAL);
- X }
- X (void) unlink(tempnm);
- X free(tempnm);
- X }
- X return(0);
- X}
- END_OF_FILE
- if test 1199 -ne `wc -c <'lock.c'`; then
- echo shar: \"'lock.c'\" unpacked with wrong size!
- fi
- # end of 'lock.c'
- fi
- if test -f 'savestr.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'savestr.c'\"
- else
- echo shar: Extracting \"'savestr.c'\" \(1002 characters\)
- sed "s/^X//" >'savestr.c' <<'END_OF_FILE'
- X/* Copyright 1992, Chris Lewis. All Rights Reserved
- X Please see the README for the terms of the copyright.
- X 1.2 92/08/14
- X */
- X
- X#ifndef lint
- Xstatic char SCCSid[] = "@(#)savestr.c 1.2 92/08/14 20:48:38";
- X#endif
- X#define UNPACKMAPS
- X#include "unpack.h"
- X
- X#define INCR 5
- X
- Xsavestr(l, s)
- Xstruct stringlist *l;
- Xchar *s; {
- X int count;
- X char **save;
- X
- X if (!l->list || l->curptr >= l->lastalloc) {
- X count = (l->lastalloc - l->list) + 1 + INCR;
- X save = l->list;
- X if (l->list) {
- X l->list = (char **) realloc((char *)l->list, sizeof(char **) * count);
- X l->curptr = (l->curptr - save) + l->list;
- X } else {
- X l->list = (char **) malloc(sizeof(char **) * count);
- X l->curptr = l->list;
- X }
- X fatal(!l->list, "string list allocate - out of memory");
- X l->lastalloc = l->list + count - 1;
- X }
- X
- X *l->curptr = (char *) malloc(strlen(s)+1);
- X fatal(!*l->curptr, "string list string allocate - out of memory");
- X (void) strcpy(*l->curptr, s);
- X l->curptr++;
- X *l->curptr = (char *) NULL;
- X}
- END_OF_FILE
- if test 1002 -ne `wc -c <'savestr.c'`; then
- echo shar: \"'savestr.c'\" unpacked with wrong size!
- fi
- # end of 'savestr.c'
- fi
- if test -f 'unpack.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'unpack.h'\"
- else
- echo shar: Extracting \"'unpack.h'\" \(1964 characters\)
- sed "s/^X//" >'unpack.h' <<'END_OF_FILE'
- X/* Copyright 1992, Chris Lewis. All Rights Reserved
- X Please see the README for the terms of the copyright.
- X 1.5 92/11/28
- X */
- X
- X#ifndef lint
- X#ifdef INIT
- Xstatic char head_SCCSid[] = "@(#)unpack.h 1.5 92/11/28 02:09:22";
- X#endif
- X#endif
- X
- X#define VERSION "unpackmaps 4.1"
- X
- X#include "config.h"
- X#include <stdio.h>
- X#include <errno.h>
- X
- Xextern int errno;
- X
- X
- X#ifdef NEEDTYPES_H
- X#include <sys/types.h>
- X#endif
- X
- X#include <sys/stat.h>
- X
- X#ifdef BSD
- X# include <strings.h>
- X# define strchr index
- X# define strrchr rindex
- X# include <sys/file.h>
- X
- X#else
- X# include <string.h>
- X
- X# include <unistd.h>
- X#endif
- X
- X#include <ctype.h>
- X
- X#ifndef F_OK
- X# define F_OK 0
- X# define X_OK 1
- X# define W_OK 2
- X# define R_OK 4
- X#endif
- X
- X#ifndef INIT
- X# define INIT(x)
- X# define EXTERN extern
- X#else
- X# define EXTERN
- X#endif
- X
- Xextern MALLRET *malloc();
- Xextern MALLRET *realloc();
- X
- XEXTERN char
- X tempbuf[BUFSIZ],
- X unpackdir[BUFSIZ] INIT(MAPDIR),
- X pathfile[BUFSIZ] INIT(PATHFILE),
- X *wheredb;
- X
- X#ifdef UNPACKMAPS
- XEXTERN char
- X *togofile,
- X *workfile,
- X *tempfile,
- X *wheretmp,
- X *pathtmp,
- X *pathtmp2,
- X *notify INIT((char *) NULL),
- X *pathalias INIT(PATHALIAS),
- X compress[BUFSIZ] INIT(COMPRESS),
- X spooldir[BUFSIZ] INIT(SPOOLDIR);
- X#endif /* UNPACKMAPS */
- X
- X
- Xstruct stringlist {
- X char **list;
- X char **curptr;
- X char **lastalloc;
- X};
- X
- X#ifdef UNPACKMAPS
- X
- XEXTERN struct stringlist
- X mapfiles,
- X lmapfiles,
- X localmaps;
- X
- XEXTERN char *internet INIT((char*) NULL);
- XEXTERN int verbose;
- X
- X
- X#endif /* UNPACKMAPS */
- X
- XEXTERN int
- X debug INIT(0),
- X usage INIT(0);
- X
- X#ifdef UNPACKMAPS
- XEXTERN int
- X runpath INIT(0),
- X forcepath INIT(0),
- X initialize INIT(0),
- X compflag INIT(0),
- X anyunpacked INIT(0),
- X whereonly INIT(0),
- X unlinkskip INIT(0),
- X unlinkflag INIT(0),
- X dontunpack INIT(0),
- X batchlock INIT(0);
- X#endif /* UNPACKMAPS */
- X
- Xextern FILE *popen();
- X
- XEXTERN char *progname;
- X
- XEXTERN char *makepath();
- XEXTERN int setbatch();
- X#ifdef USGDIR
- X#include <dirent.h>
- X#endif
- X
- X#ifdef BERKDIR
- X#define direct dirent
- X#include <sys/dir.h>
- X#endif
- END_OF_FILE
- if test 1964 -ne `wc -c <'unpack.h'`; then
- echo shar: \"'unpack.h'\" unpacked with wrong size!
- fi
- # end of 'unpack.h'
- fi
- if test -f 'uuwhere.M' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'uuwhere.M'\"
- else
- echo shar: Extracting \"'uuwhere.M'\" \(1536 characters\)
- sed "s/^X//" >'uuwhere.M' <<'END_OF_FILE'
- X.\"Copyright 1992 by Chris Lewis 1.1 92/06/10
- X.TH UUWHERE 1 "Chris Lewis"
- Xuuwhere \- USENET UUCP map viewer and path search
- X.SH SYNOPSIS
- X.B uuwhere
- X.RB [ \-l ]
- X.RB [ \-rregion ]
- X.RB [ \-v ]
- X.RB [ \-e ]
- X.RI [ hosts ]
- X.SH DESCRIPTION
- XWithout any options
- X.B uuwhere
- Xwill search the UUCP routing database for the sites mentioned
- Xand will display the UUCP route to them.
- X.P
- XIf the
- X.B \-e
- Xoption is also specified the map entries for the requested sites
- Xwill also be displayed.
- X.P
- XIf the
- X.B \-v
- Xoption is specified, the output of both the path search and
- Xmap entry search (if requested) will be more explanatory,
- Xand the map keywords will be expanded.
- X.P
- XThe
- X.B \-l
- Xoption merely lists all of the files in the map database.
- XIf any file has a
- X.B .Z
- Xsuffix (compressed), it is removed before display.
- XAll other options are ignored.
- X.P
- XThe
- X.BI \-r region
- Xoption displays the map file
- X.IR region .
- XIf the
- X.B \-v
- Xoption is also specified, the keywords are expanded.
- XAll other options are ignored.
- X.P
- XThere are two extra options to change the operation
- Xof
- X.BR uuwhere .
- X.BI \-d mapdir
- Xchanges the map directory to
- X.IR mapdir .
- X.BI \-m pathfile
- Xchanges the path file for searching to
- X.IR pathfile .
- X.SH FILES
- X.br
- X.if t .ta 2.5i
- X.if n .ta 3.5i
- X/usr/spool/maps Default map directory
- X"/where.db Where database
- X"/maps Where the unpacked maps are kept
- X/usr/lib/uucp/paths Default paths file
- X.SH AUTHOR
- X.B Uuwhere
- Xwas written by Chris Lewis.
- XThe binary search algorithm used for searching the path file
- Xand
- X.B uuwhere
- Xdatabase is borrowed from Smail 2.5.
- END_OF_FILE
- if test 1536 -ne `wc -c <'uuwhere.M'`; then
- echo shar: \"'uuwhere.M'\" unpacked with wrong size!
- fi
- # end of 'uuwhere.M'
- fi
- echo shar: End of archive 2 \(of 2\).
- cp /dev/null ark2isdone
- MISSING=""
- for I in 1 2 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked both archives.
- rm -f ark[1-9]isdone
- else
- echo You still must unpack the following archives:
- echo " " ${MISSING}
- fi
- exit 0
-
- --
- Chris Lewis; clewis@ferret.ocunix.on.ca; Phone: Canada 613 832-0541
- Psroff 3.0 info: psroff-request@ferret.ocunix.on.ca
- Ferret list: ferret-request@ferret.ocunix.on.ca
-
- exit 0 # Just in case...
-