[alt.sources] Replacement for man

jwe@che.utexas.edu (John W. Eaton) (01/07/91)

This distribution includes man(1), apropos(1), whatis(1), and
manpath(1).  I wrote these mostly because Ultrix man(1) doesn't
understand multiple man page directory trees, and because I wanted to
be able to choose whatever pager program I wanted.  If you use these
programs, I hope you find them useful.  If you encounter bugs, please
forward reports directly to me.  I can't guarantee that I'll be able
to fix them, but I'll give it a shot :-).

This man(1) has all kinds of neat features that other versions of
man don't, including support for multiple man page directory trees,
preformatted man pages, and troff.  It is distributed under the terms
of the GNU copyleft.

If you compile with support for preformatted man pages, man(1) will
try to update the preformatted page if the man page source is newer.

If you compile with support for troff, you can say things like
`man -t foo | psdit > foo.ps' and have fabulous printed documentation
as well.

These files are also available via anonymous ftp from che.utexas.edu
(128.83.162.5).  Please limit your use of this service to off hours.

Cheers,

John W. Eaton
jwe@che.utexas.edu
Department of Chemical Engineering
The University of Texas at Austin

-------------------------------cut here-------------------------------
#! /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 archive 1 (of 2)."
# Contents:  man-1.0 man-1.0/COPYING man-1.0/Makefile man-1.0/README
#   man-1.0/TODO man-1.0/apropos.man man-1.0/apropos.sh
#   man-1.0/config.h man-1.0/gripes.c man-1.0/gripes.h
#   man-1.0/makewhatis.sh man-1.0/man.man man-1.0/manpath.c
#   man-1.0/manpath.config man-1.0/manpath.h man-1.0/manpath.man
#   man-1.0/ndir.h man-1.0/strdup.c man-1.0/util.c man-1.0/version.h
#   man-1.0/whatis.man man-1.0/whatis.sh
# Wrapped by jwe@andy.che.utexas.edu on Sun Jan  6 15:10:28 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test ! -d 'man-1.0' ; then
    echo shar: Creating directory \"'man-1.0'\"
    mkdir 'man-1.0'
fi
if test -f 'man-1.0/COPYING' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'man-1.0/COPYING'\"
else
echo shar: Extracting \"'man-1.0/COPYING'\" \(7742 characters\)
sed "s/^X//" >'man-1.0/COPYING' <<'END_OF_FILE'
X		 GNU EMACS GENERAL PUBLIC LICENSE
X		    (Clarified 11 Feb 1988)
X
X Copyright (C) 1985, 1987, 1988 Richard M. Stallman
X Everyone is permitted to copy and distribute verbatim copies
X of this license, but changing it is not allowed.  You can also
X use this wording to make the terms for other programs.
X
X  The license agreements of most software companies keep you at the
Xmercy of those companies.  By contrast, our general public license is
Xintended to give everyone the right to share GNU Emacs.  To make
Xsure that you get the rights we want you to have, we need to make
Xrestrictions that forbid anyone to deny you these rights or to ask you
Xto surrender the rights.  Hence this license agreement.
X
X  Specifically, we want to make sure that you have the right to give
Xaway copies of Emacs, that you receive source code or else can get it
Xif you want it, that you can change Emacs or use pieces of it in new
Xfree programs, and that you know you can do these things.
X
X  To make sure that everyone has such rights, we have to forbid you to
Xdeprive anyone else of these rights.  For example, if you distribute
Xcopies of Emacs, you must give the recipients all the rights that you
Xhave.  You must make sure that they, too, receive or can get the
Xsource code.  And you must tell them their rights.
X
X  Also, for our own protection, we must make certain that everyone
Xfinds out that there is no warranty for GNU Emacs.  If Emacs is
Xmodified by someone else and passed on, we want its recipients to know
Xthat what they have is not what we distributed, so that any problems
Xintroduced by others will not reflect on our reputation.
X
X  Therefore we (Richard Stallman and the Free Software Fundation,
XInc.) make the following terms which say what you must do to be
Xallowed to distribute or change GNU Emacs.
X
X			COPYING POLICIES
X
X  1. You may copy and distribute verbatim copies of GNU Emacs source code
Xas you receive it, in any medium, provided that you conspicuously and
Xappropriately publish on each copy a valid copyright notice "Copyright
X(C) 1988 Free Software Foundation, Inc." (or with whatever year is
Xappropriate); keep intact the notices on all files that refer to this
XLicense Agreement and to the absence of any warranty; and give any
Xother recipients of the GNU Emacs program a copy of this License
XAgreement along with the program.  You may charge a distribution fee
Xfor the physical act of transferring a copy.
X
X  2. You may modify your copy or copies of GNU Emacs source code or
Xany portion of it, and copy and distribute such modifications under
Xthe terms of Paragraph 1 above, provided that you also do the following:
X
X    a) cause the modified files to carry prominent notices stating
X    that you changed the files and the date of any change; and
X
X    b) cause the whole of any work that you distribute or publish,
X    that in whole or in part contains or is a derivative of GNU Emacs
X    or any part thereof, to be licensed at no charge to all third
X    parties on terms identical to those contained in this License
X    Agreement (except that you may choose to grant more extensive
X    warranty protection to some or all third parties, at your option).
X
X    c) if the modified program serves as a text editor, cause it when
X    started running in the simplest and usual way, to print an
X    announcement including a valid copyright notice "Copyright (C)
X    1988 Free Software Foundation, Inc." (or with the year that is
X    appropriate), saying that there is no warranty (or else, saying
X    that you provide a warranty) and that users may redistribute the
X    program under these conditions, and telling the user how to view a
X    copy of this License Agreement.
X
X    d) You may charge a distribution fee for the physical act of
X    transferring a copy, and you may at your option offer warranty
X    protection in exchange for a fee.
X
XMere aggregation of another unrelated program with this program (or its
Xderivative) on a volume of a storage or distribution medium does not bring
Xthe other program under the scope of these terms.
X
X  3. You may copy and distribute GNU Emacs (or a portion or derivative of it,
Xunder Paragraph 2) in object code or executable form under the terms of
XParagraphs 1 and 2 above provided that you also do one of the following:
X
X    a) accompany it with the complete corresponding machine-readable
X    source code, which must be distributed under the terms of
X    Paragraphs 1 and 2 above; or,
X
X    b) accompany it with a written offer, valid for at least three
X    years, to give any third party free (except for a nominal
X    shipping charge) a complete machine-readable copy of the
X    corresponding source code, to be distributed under the terms of
X    Paragraphs 1 and 2 above; or,
X
X    c) accompany it with the information you received as to where the
X    corresponding source code may be obtained.  (This alternative is
X    allowed only for noncommercial distribution and only if you
X    received the program in object code or executable form alone.)
X
XFor an executable file, complete source code means all the source code for
Xall modules it contains; but, as a special exception, it need not include
Xsource code for modules which are standard libraries that accompany the
Xoperating system on which the executable file runs.
X
X  4. You may not copy, sublicense, distribute or transfer GNU Emacs
Xexcept as expressly provided under this License Agreement.  Any attempt
Xotherwise to copy, sublicense, distribute or transfer GNU Emacs is void and
Xyour rights to use GNU Emacs under this License agreement shall be
Xautomatically terminated.  However, parties who have received computer
Xsoftware programs from you with this License Agreement will not have
Xtheir licenses terminated so long as such parties remain in full compliance.
X
X  5. If you wish to incorporate parts of GNU Emacs into other free programs
Xwhose distribution conditions are different, write to the Free Software
XFoundation.  We have not yet worked out a simple rule that can be stated
Xhere, but we will often permit this.  We will be guided by the two goals of
Xpreserving the free status of all derivatives of our free software and of
Xpromoting the sharing and reuse of software.
X
XYour comments and suggestions about our licensing policies and our
Xsoftware are welcome!  Please contact the Free Software Foundation, Inc.,
X675 Mass Ave, Cambridge, MA 02139, or call (617) 876-3296.
X
X			   NO WARRANTY
X
X  BECAUSE GNU EMACS IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
XNO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW.  EXCEPT
XWHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,
XRICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE GNU EMACS "AS IS"
XWITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
XBUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
XFITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY
XAND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE GNU EMACS
XPROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY
XSERVICING, REPAIR OR CORRECTION.
X
X IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL FREE SOFTWARE
XFOUNDATION, INC., RICHARD M. STALLMAN, AND/OR ANY OTHER PARTY WHO MAY
XMODIFY AND REDISTRIBUTE GNU EMACS AS PERMITTED ABOVE, BE LIABLE TO YOU
XFOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR OTHER
XSPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR
XINABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA
XBEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR A
XFAILURE OF THE PROGRAM TO OPERATE WITH PROGRAMS NOT DISTRIBUTED BY
XFREE SOFTWARE FOUNDATION, INC.) THE PROGRAM, EVEN IF YOU HAVE BEEN
XADVISED OF THE POSSIBILITY OF SUCH DAMAGES, OR FOR ANY CLAIM BY ANY
XOTHER PARTY.
END_OF_FILE
if test 7742 -ne `wc -c <'man-1.0/COPYING'`; then
    echo shar: \"'man-1.0/COPYING'\" unpacked with wrong size!
fi
# end of 'man-1.0/COPYING'
fi
if test -f 'man-1.0/Makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'man-1.0/Makefile'\"
else
echo shar: Extracting \"'man-1.0/Makefile'\" \(4084 characters\)
sed "s/^X//" >'man-1.0/Makefile' <<'END_OF_FILE'
X# Makefile for man and manpath
X#
X# Copyright (c) 1991, John W. Eaton.
X#
X# You may distribute under the terms of the GNU General Public
X# License as specified in the README file that comes with the man 1.0
X# distribution.  
X#
X# John W. Eaton
X# jwe@che.utexas.edu
X# Department of Chemical Engineering
X# The University of Texas at Austin
X# Austin, Texas  78712
X
XDISTDIR = man-1.0
X
XTOP = /usr/local
X
XBINDIR = $(TOP)/bin
XLIBDIR = $(TOP)/lib/man
XMANDIR = $(TOP)/man
XMANEXT = 1
X
XMANBINNAME = man
X
X# The file that defines the mapping of bin directories to man
X# directories.  This should match the definition of config_file[] in
X# config.h.
X
XMANPATH_CONFIG_FILE=$(LIBDIR)/manpath.config
X
X# Add these to DEFS if...
X#
X# -DHAS_TROFF		if you have troff installed
X# -DSUPPORT_CAT_DIRS	if you have directories of preformatted man pages
X# -DCHARSPRINTF		if your sprintf returns char *
X# -DSTD_HEADERS		if you have standard headers installed
X# -DALT_SYSTEMS		if you have system specific subdirectories in
X#			your manpath (i.e. /usr/man/sunos/...)
X# -DSTRDUP_MISSING	if your system lacks strdup()
X#
X# Edit and add any of the defs below if you want to override the
X# defaults in config.h.
X#
X# -DMAXPATHLEN=512	maximum number of characters in an absolute filename
X# -DBUFSIZ=1024		input buffers and some other things have this length
X# -DMAXDIRS=64		something more than the maximum number of
X#			directories in the config file 
X
XDEFS = -DSUPPORT_CAT_DIRS -DCHARSPRINTF -DHAS_TROFF -DSTRDUP_MISSING
X
XCC = gcc
XCFLAGS = -Wall -O $(DEFS)
X
Xall: man manpath apropos whatis makewhatis manpages
X
Xmanpath: manpath.c config.h manpath.h gripes.o util.o strdup.o
X	$(CC) $(CFLAGS) -DMAIN -o manpath manpath.c gripes.o util.o strdup.o
X
Xman: man.c config.h gripes.h manpath.c manpath.h gripes.o glob.o \
X	util.o strdup.o
X	$(CC) $(CFLAGS) -o man man.c manpath.c gripes.o glob.o util.o strdup.o
X
Xgripes.o: gripes.h
Xutil.o: gripes.h
X
Xapropos: apropos.sh
X	sed -e 's,LIBDIR,$(LIBDIR),' -e 's,BINDIR,$(BINDIR),' \
X		apropos.sh > apropos
X
Xwhatis: whatis.sh
X	sed -e 's,LIBDIR,$(LIBDIR),' -e 's,BINDIR,$(BINDIR),' \
X		whatis.sh > whatis
X
Xmakewhatis: makewhatis.sh
X	cp makewhatis.sh makewhatis
X
Xinstall: all install.man apropos whatis makewhatis
X	install -c -m 755 man $(BINDIR)/$(MANBINNAME)
X	install -c -m 755 manpath $(BINDIR)/manpath
X	install -c -m 755 apropos $(BINDIR)/apropos
X	install -c -m 755 whatis $(BINDIR)/whatis
X	install -c -m 754 makewhatis $(LIBDIR)/makewhatis
X	install -c -m 644 manpath.config $(LIBDIR)/manpath.config
X
Xmanpages: man.$(MANEXT) manpath.$(MANEXT) apropos.$(MANEXT) whatis.$(MANEXT) 
X
Xman.$(MANEXT): man.man
X	sed -e 's,MANPATH_CONFIG_FILE,$(MANPATH_CONFIG_FILE),' \
X	man.man > man.$(MANEXT)
X
Xmanpath.$(MANEXT): manpath.man
X	sed -e 's,MANPATH_CONFIG_FILE,$(MANPATH_CONFIG_FILE),' \
X	manpath.man > manpath.$(MANEXT)
X
Xapropos.$(MANEXT): apropos.man
X	sed -e 's,MANPATH_CONFIG_FILE,$(MANPATH_CONFIG_FILE),' \
X	apropos.man > apropos.$(MANEXT)
X
Xwhatis.$(MANEXT): whatis.man
X	sed -e 's,MANPATH_CONFIG_FILE,$(MANPATH_CONFIG_FILE),' \
X	whatis.man > whatis.$(MANEXT)
X
Xinstall.man:
X	install -c -m 644 man.$(MANEXT) \
X		$(MANDIR)/man$(MANEXT)/man.$(MANEXT)
X	install -c -m 644 manpath.$(MANEXT) \
X		$(MANDIR)/man$(MANEXT)/manpath.$(MANEXT)
X	install -c -m 644 apropos.$(MANEXT) \
X		$(MANDIR)/man$(MANEXT)/apropos.$(MANEXT)
X	install -c -m 644 whatis.$(MANEXT) \
X		$(MANDIR)/man$(MANEXT)/whatis.$(MANEXT)
X	
Xclean:
X	rm -f *.o *~ core
X
Xspotless: clean
X	rm -f manpath man apropos whatis makewhatis
X	rm -f man.$(MANEXT) manpath.$(MANEXT)
X	rm -f apropos.$(MANEXT) whatis.$(MANEXT) 
X
Xdist:
X	[ -d $(DISTDIR) ] || mkdir $(DISTDIR)
X	cp glob.c gripes.c manpath.c strdup.c util.c $(DISTDIR)
X	cp gripes.h manpath.h ndir.h version.h $(DISTDIR)
X	cp apropos.man man.man manpath.man whatis.man $(DISTDIR)
X	cp apropos.sh whatis.sh makewhatis.sh $(DISTDIR)
X	cp README COPYING TODO $(DISTDIR)
X	cp config.h.dist $(DISTDIR)/config.h
X	cp manpath.config.dist $(DISTDIR)/manpath.config
X	cp Makefile.dist $(DISTDIR)/Makefile
X	(cd $(DISTDIR) ; gawk -f ../fixdist.awk ../man.c > man.c)
X
Xtar.dist: dist
X	tar czvf $(DISTDIR).tar.Z $(DISTDIR)
END_OF_FILE
if test 4084 -ne `wc -c <'man-1.0/Makefile'`; then
    echo shar: \"'man-1.0/Makefile'\" unpacked with wrong size!
fi
# end of 'man-1.0/Makefile'
fi
if test -f 'man-1.0/README' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'man-1.0/README'\"
else
echo shar: Extracting \"'man-1.0/README'\" \(2077 characters\)
sed "s/^X//" >'man-1.0/README' <<'END_OF_FILE'
XREADME file for man(1).
X
XThis is a replacement for Un*x man(1), apropos(1), whatis(1), and
Xmanpath(1).  It has all kinds of neat features that other versions of
Xman don't, including support for multiple man page directory trees,
Xpreformatted man pages, and troff.  It is provided without any
Xwarranty whatever.  I hope you find it useful.  It is distributed
Xunder the terms of the GNU copyleft which is described in the file
XCOPYING.
X
XThere is a solution written in perl which is probably superior in
Xevery way, but, like me, you may prefer this one anyway.
X:-)
X
XIf you compile with support for preformatted man pages, man(1) will
Xtry to update the preformatted page if the man page source is newer.
X
XIf you compile with support for troff, you can say things like
X`man -t foo | psdit > foo.ps' and have fabulous printed documentation
Xas well.
X
XThe file ndir.h is included because you might need it to compile glob.c.
X
XThese programs have been tested on a VaxStation 3200 running Ultrix 3.1, 
Xand an Encore Multimax running Umax 4.3, a DEC 5810 running Ultrix 4.0, 
Xand a Convex C-220 running Convex Unix.
X
XINSTALLATION
X
X1. Edit the file config.h to match your site.
X
X2. Edit the manpath.config file.  This determines the system-wide
X   mappings for bin directories and man page directories.
X
X3. Edit the Makefile.  Make sure that all the directories you specify
X   exist -- no checks are made on this.
X
X4. Do a `make all', try it out, and then if you're happy with that, do
X   a `make install'.  You don't need to be root to use this set of
X   programs.
X
X5. Install the whatis database(s) by running makewhatis.  If you want
X   to keep things absolutely current, you'll need to run this whenever
X   you add new man pages.  You might want to add an entry in your
X   crontab. 
X
X
XBUGS
X
XIf you find one of these, please tell me about it.  If you have a fix,
Xthat's even better.  If not, I can't guarantee that I'll fix it, but I
Xwould like to know about them.
X
XJohn Eaton
Xjwe@che.utexas.edu
XDepartment of Chemical Engineering
XThe University of Texas at Austin
XAustin, Texas  78712
END_OF_FILE
if test 2077 -ne `wc -c <'man-1.0/README'`; then
    echo shar: \"'man-1.0/README'\" unpacked with wrong size!
fi
# end of 'man-1.0/README'
fi
if test -f 'man-1.0/TODO' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'man-1.0/TODO'\"
else
echo shar: Extracting \"'man-1.0/TODO'\" \(823 characters\)
sed "s/^X//" >'man-1.0/TODO' <<'END_OF_FILE'
XThings that would be nice but aren't really necessary:
X
X0.  Update the documentation.
X
X1.  Properly handle commands like `man 3f intro' when the name of the
X    file we want is something like .../man3/intro.3f.  The way this is
X    done right now seems sort of kludgey but it mostly works.  See
X    man.c for details.
X
X2.  Malloc everything instead of having fixed limits... Or at least
X    check the limits everywhere.  If you're paranoid about this, make
X    the limits big (famous last words: really, there aren't that many
X    things that could go wrong :-).
X
X3.  Try to do a little better job of memory management.  There are a
X    lot of little temporary strings that are malloc'd and never freed.
X    This is probably ok for a standalone program but not so good if
X    you wanted to call man() from another program.
END_OF_FILE
if test 823 -ne `wc -c <'man-1.0/TODO'`; then
    echo shar: \"'man-1.0/TODO'\" unpacked with wrong size!
fi
# end of 'man-1.0/TODO'
fi
if test -f 'man-1.0/apropos.man' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'man-1.0/apropos.man'\"
else
echo shar: Extracting \"'man-1.0/apropos.man'\" \(712 characters\)
sed "s/^X//" >'man-1.0/apropos.man' <<'END_OF_FILE'
X.\" Man page for apropos
X.\"
X.\" Copyright (c) 1991, John W. Eaton.
X.\"
X.\" You may distribute under the terms of the GNU General Public
X.\" License as specified in the README file that comes with the man 1.0
X.\" distribution.  
X.\"
X.\" John W. Eaton
X.\" jwe@che.utexas.edu
X.\" Department of Chemical Engineering
X.\" The University of Texas at Austin
X.\" Austin, Texas  78712
X.\"
X.TH apropos 1 "Jan 15, 1991"
X.LO 1
X.SH NAME
Xapropos \- search the whatis database for strings
X.SH SYNOPSIS
X.BI apropos
Xkeyword ...
X.SH DESCRIPTION
Xapropos searches a set of database files containing short descriptions
Xof system commands for keywords and displays the result on the
Xstandard output.
X.SH "SEE ALSO"
Xwhatis(1), man(1).
END_OF_FILE
if test 712 -ne `wc -c <'man-1.0/apropos.man'`; then
    echo shar: \"'man-1.0/apropos.man'\" unpacked with wrong size!
fi
# end of 'man-1.0/apropos.man'
fi
if test -f 'man-1.0/apropos.sh' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'man-1.0/apropos.sh'\"
else
echo shar: Extracting \"'man-1.0/apropos.sh'\" \(1103 characters\)
sed "s/^X//" >'man-1.0/apropos.sh' <<'END_OF_FILE'
X#!/bin/sh
X#
X# apropos -- search the whatis database for keywords.
X#
X# Copyright (c) 1991, John W. Eaton.
X#
X# You may distribute under the terms of the GNU General Public
X# License as specified in the README file that comes with the man 1.0
X# distribution.  
X#
X# John W. Eaton
X# jwe@che.utexas.edu
X# Department of Chemical Engineering
X# The University of Texas at Austin
X# Austin, Texas  78712
X
XPATH=/usr/local/bin:/bin:/usr/ucb:/usr/bin
X
Xlibdir=LIBDIR
X
Xif [ $# = 0 ]
Xthen
X    echo "usage: `basename $0` keyword ..."
X    exit 1
Xfi
X
Xmanpath=`BINDIR/manpath -q | tr : '\040'`
X
Xif [ "$manpath" = "" ]
Xthen
X    echo "whatis: manpath is null"
X    exit 1
Xfi
X
Xwhile [ $1 ]
Xdo
X        found=0
X        for d in $manpath /usr/lib
X        do
X            if [ -f $d/whatis ]
X            then
X                grep -i "$1" $d/whatis
X                status=$?
X                if [ "$status" = "0" ]
X                then
X                    found=1
X                fi
X            fi
X        done
X
X        if [ "$found" = "0" ]
X        then
X            echo "$1: nothing appropriate"
X        fi
X
X        shift
Xdone
X
Xexit
END_OF_FILE
if test 1103 -ne `wc -c <'man-1.0/apropos.sh'`; then
    echo shar: \"'man-1.0/apropos.sh'\" unpacked with wrong size!
fi
# end of 'man-1.0/apropos.sh'
fi
if test -f 'man-1.0/config.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'man-1.0/config.h'\"
else
echo shar: Extracting \"'man-1.0/config.h'\" \(2981 characters\)
sed "s/^X//" >'man-1.0/config.h' <<'END_OF_FILE'
X/*
X * config.h
X *
X * Edit this file to match your site.
X *
X * Copyright (c) 1991, John W. Eaton.
X *
X * You may distribute under the terms of the GNU General Public
X * License as specified in the README file that comes with the man 1.0
X * distribution.  
X *
X * John W. Eaton
X * jwe@che.utexas.edu
X * Department of Chemical Engineering
X * The University of Texas at Austin
X * Austin, Texas  78712
X */
X
X#ifndef BUFSIZ
X#define BUFSIZ 1024
X#endif
X
X#ifndef MAXPATHLEN
X#define MAXPATHLEN 512
X#endif
X
X#ifndef MAXDIRS
X#define MAXDIRS 64
X#endif
X
X/*
X * These are the programs man(1) execs with the -k and -f options.
X */
X
X#define APROPOS "/usr/local/bin/apropos"
X#define WHATIS  "/usr/local/bin/whatis"
X
X/*
X * This might also be "/usr/ucb/more -s", though I prefer less(1)
X * because it allows one to backup even when reading from pipes.
X */
X
X#define PAGER   "/usr/local/bin/less -sC"
X
Xstatic char config_file[] = "/usr/local/lib/man/manpath.config";
X
X/*
X * These might also be something like
X *
X *  nroff_command[] = "/usr/local/bin/groff -Tascii -man"
X *  troff_command[] = "/usr/local/bin/groff -Tps -man"
X */
X
Xstatic char nroff_command[] = "/usr/bin/nroff -man";
X
X#ifdef HAS_TROFF
Xstatic char troff_command[] = "/usr/bin/troff -man";
X#endif
X
X/*
X * Define the valid manual sections.  For example, if your man
X * directory tree has subdirectories man1, man2, man3, mann,
X * and man3foo, valid_sections[] would have "1", "2", "3", "n", and
X * "3foo".  Directories are searched in the order they appear.  Having
X * extras isn't fatal, it just slows things down a bit.
X *
X * Note that this is just for directories to search.  If you have
X * files like .../man3/foobar.3Xtc, you don't need to have "3Xtc" in
X * the list below -- this is handled separately, so that `man 3Xtc foobar',
X * `man 3 foobar', and `man foobar' should find the file .../man3/foo.3Xtc,
X * (assuming, of course, that there isn't a .../man1/foo.1 or somesuch
X * that we would find first).
X *
X * Note that this list should be in the order that you want the
X * directories to be searched.  Is there a standard for this?  What is
X * the normal order?  If anyone knows, please tell me!
X */
X
Xstatic char *valid_sections[] = 
X{
X  "1",  "2",  "3",  "4",  "5",  "6",  "7",  "8",  NULL
X};
X
X/*
X * Not all systems define these in stat.h.
X */
X
X#ifndef S_IRUSR
X#define	S_IRUSR	00400		/*  read permission: owner */
X#endif
X#ifndef S_IWUSR
X#define	S_IWUSR	00200		/*  write permission: owner */
X#endif
X#ifndef S_IRGRP
X#define	S_IRGRP	00040		/*  read permission: group */
X#endif
X#ifndef S_IWGRP
X#define	S_IWGRP	00020		/*  write permission: group */
X#endif
X#ifndef S_IROTH
X#define	S_IROTH	00004		/*  read permission: other */
X#endif
X#ifndef S_IWOTH
X#define	S_IWOTH	00002		/*  write permission: other */
X#endif
X
X/*
X * This is the mode used for formatted pages that we create.
X */
X
X#ifndef CATMODE
X#define CATMODE S_IRUSR | S_IRGRP | S_IROTH
X#endif
X
X#ifdef SUPPORT_CAT_DIRS
Xstatic int cat_support = 1;
X#else
Xstatic int cat_support = 0;
X#endif
END_OF_FILE
if test 2981 -ne `wc -c <'man-1.0/config.h'`; then
    echo shar: \"'man-1.0/config.h'\" unpacked with wrong size!
fi
# end of 'man-1.0/config.h'
fi
if test -f 'man-1.0/gripes.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'man-1.0/gripes.c'\"
else
echo shar: Extracting \"'man-1.0/gripes.c'\" \(2590 characters\)
sed "s/^X//" >'man-1.0/gripes.c' <<'END_OF_FILE'
X/*
X * gripes.c
X *
X * Copyright (c) 1991, John W. Eaton.
X *
X * You may distribute under the terms of the GNU General Public
X * License as specified in the README file that comes with the man 1.0
X * distribution.  
X *
X * John W. Eaton
X * jwe@che.utexas.edu
X * Department of Chemical Engineering
X * The University of Texas at Austin
X * Austin, Texas  78712
X */
X
X#include <stdio.h>
X#include "gripes.h"
X
X#ifndef __STDH__
Xextern int fprintf ();
Xextern int fflush ();
Xextern int exit ();
X#endif
X
Xextern char *prognam;
X
Xvoid
Xgripe_no_name (section)
X     char *section;
X{
X  if (section)
X    fprintf (stderr, "What manual page do you want from section %s?\n",
X	     section);
X  else
X    fprintf (stderr, "What manual page do you want?\n");
X
X  fflush (stderr);
X}
X
Xvoid
Xgripe_reading_man_file (name)
X     char *name;
X{
X  fprintf (stderr, "Read access denied for file %s\n", name);
X
X  fflush (stderr);
X}
X
Xvoid
Xgripe_converting_name (name, to_cat)
X     char *name;
X     int to_cat;
X{
X  if (to_cat)
X    fprintf (stderr, "Error converting %s to cat name\n", name);
X  else
X    fprintf (stderr, "Error converting %s to man name\n", name);
X
X  fflush (stderr);
X
X  exit (1);
X}
X
Xvoid
Xgripe_system_command (status)
X     int status;
X{
X  fprintf (stderr, "Error executing formatting or display command.\n");
X  fprintf (stderr, "system command exited with status %d\n", status);
X
X  fflush (stderr);
X}
X
Xvoid
Xgripe_not_found (name, section)
X     char *name, *section;
X{
X  if (section)
X    fprintf (stderr, "No entry for %s in section %s of the manual\n",
X	     name, section);
X  else
X    fprintf (stderr, "No manual entry for %s\n", name);
X
X  fflush (stderr);
X}
X
Xvoid
Xgripe_incompatible (s)
X     char *s;
X{
X  fprintf (stderr, "%s: incompatible options %s\n", prognam, s);
X
X  fflush (stderr);
X
X  exit (1);
X}
X
Xvoid
Xgripe_getting_mp_config (file)
X     char *file;
X{
X  fprintf (stderr, "%s: unable to find the file %s\n", prognam, file);
X
X  fflush (stderr);
X
X  exit (1);
X}
X
Xvoid
Xgripe_reading_mp_config (file)
X     char *file;
X{
X  fprintf (stderr, "%s: unable to make sense of the file %s\n", prognam, file);
X
X  fflush (stderr);
X
X  exit (1);
X}
X
Xvoid
Xgripe_invalid_section (section)
X     char *section;
X{
X  fprintf (stderr, "%s: invalid section (%s) selected\n", prognam, section);
X
X  fflush (stderr);
X
X  exit (1);
X}
X
Xvoid
Xgripe_manpath ()
X{
X  fprintf (stderr, "%s: manpath is null\n", prognam);
X
X  fflush (stderr);
X
X  exit (1);
X}
X
Xvoid
Xgripe_alloc (bytes, object)
X     int bytes;
X     char *object;
X{
X  fprintf (stderr, "%s: can't malloc %d bytes for %s\n",
X	   prognam, bytes, object);
X
X  fflush (stderr);
X
X  exit (1);
X}
END_OF_FILE
if test 2590 -ne `wc -c <'man-1.0/gripes.c'`; then
    echo shar: \"'man-1.0/gripes.c'\" unpacked with wrong size!
fi
# end of 'man-1.0/gripes.c'
fi
if test -f 'man-1.0/gripes.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'man-1.0/gripes.h'\"
else
echo shar: Extracting \"'man-1.0/gripes.h'\" \(746 characters\)
sed "s/^X//" >'man-1.0/gripes.h' <<'END_OF_FILE'
X/*
X * gripes.h
X *
X * Copyright (c) 1991, John W. Eaton.
X *
X * You may distribute under the terms of the GNU General Public
X * License as specified in the README file that comes with the man 1.0
X * distribution.  
X *
X * John W. Eaton
X * jwe@che.utexas.edu
X * Department of Chemical Engineering
X * The University of Texas at Austin
X * Austin, Texas  78712
X */
X
Xextern void gripe_no_name ();
Xextern void gripe_converting_name ();
Xextern void gripe_system_command ();
Xextern void gripe_reading_man_file ();
Xextern void gripe_not_found ();
Xextern void gripe_invalid_section ();
Xextern void gripe_manpath ();
Xextern void gripe_alloc ();
Xextern void gripe_incompatible ();
Xextern void gripe_getting_mp_config ();
Xextern void gripe_reading_mp_config ();
END_OF_FILE
if test 746 -ne `wc -c <'man-1.0/gripes.h'`; then
    echo shar: \"'man-1.0/gripes.h'\" unpacked with wrong size!
fi
# end of 'man-1.0/gripes.h'
fi
if test -f 'man-1.0/makewhatis.sh' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'man-1.0/makewhatis.sh'\"
else
echo shar: Extracting \"'man-1.0/makewhatis.sh'\" \(2412 characters\)
sed "s/^X//" >'man-1.0/makewhatis.sh' <<'END_OF_FILE'
X#!/bin/sh
X#
X# makewhatis -- update the whatis database in the man directories.
X#
X# Copyright (c) 1991, John W. Eaton.
X#
X# You may distribute under the terms of the GNU General Public
X# License as specified in the README file that comes with the man 1.0
X# distribution.  
X#
X# John W. Eaton
X# jwe@che.utexas.edu
X# Department of Chemical Engineering
X# The University of Texas at Austin
X# Austin, Texas  78712
X
XPATH=/bin:/usr/local/bin:/usr/ucb:/usr/bin
X
Xif [ $# = 0 ]
Xthen
X    echo "usage: makewhatis directory [...]"
X    exit 1
Xfi
X
Xfor dir in $*
Xdo
X    cd $dir
X    for subdir in man*
X    do
X        if [ -d $subdir ]
X        then
X            for f in `find . -name '*' -print`
X            do
X                sed -n '/^\.TH.*$/p
X                        /^\.SH[         ]*NAME/,/^\.SH/p' $f |\
X                sed -e 's/\\[   ]*\-/-/
X                        s/^.PP.*$//
X                        s/\\(em//
X                        s/\\fI//
X                        s/\\fR//' |\
X                awk 'BEGIN {insh = 0} {
X                     if ($1 == ".TH")
X                       sect = $3
X                     else if ($1 == ".SH" && insh == 1) {
X                       if (i > 0 && name != NULL) {
X                         namesect = sprintf("%s (%s)", name, sect)
X                         printf("%-20.20s", namesect)
X                         printf(" - ")
X                         for (j = 0; j < i-1; j++)
X                           printf("%s ", desc[j])
X                         printf("%s\n", desc[i-1])
X                       }
X                     } else if ($1 == ".SH" && insh == 0) {
X                       insh = 1
X                       count = 0
X                       i = 0
X                     } else if (insh == 1) {
X                       count++
X                       if (count == 1 && NF > 2) {
X                         start = 2
X                         if ($2 == "-") start = 3
X                         if (NF > start + 1)
X                           for (j = start; j <= NF; j++)
X                             desc[i++] = $j
X                           name = $1
X                       } else {
X                         for (j = 1; j <= NF; j++)
X                           desc[i++] = $j
X                       }
X                     }
X                }'
X            done
X            cd ..
X        fi
X    done | sort | colrm 80 > $dir/whatis.db.tmp
X    mv $dir/whatis.db.tmp $dir/whatis
Xdone
X
Xexit
END_OF_FILE
if test 2412 -ne `wc -c <'man-1.0/makewhatis.sh'`; then
    echo shar: \"'man-1.0/makewhatis.sh'\" unpacked with wrong size!
fi
# end of 'man-1.0/makewhatis.sh'
fi
if test -f 'man-1.0/man.man' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'man-1.0/man.man'\"
else
echo shar: Extracting \"'man-1.0/man.man'\" \(2323 characters\)
sed "s/^X//" >'man-1.0/man.man' <<'END_OF_FILE'
X.\" Man page for man
X.\"
X.\" Copyright (c) 1991, John W. Eaton.
X.\"
X.\" You may distribute under the terms of the GNU General Public
X.\" License as specified in the README file that comes with the man 1.0
X.\" distribution.  
X.\"
X.\" John W. Eaton
X.\" jwe@che.utexas.edu
X.\" Department of Chemical Engineering
X.\" The University of Texas at Austin
X.\" Austin, Texas  78712
X.\"
X.TH man 1 "Jan 5, 1991"
X.LO 1
X.SH NAME
Xman \- format and display the on-line manual pages
X.SH SYNOPSIS
Xman [\-afhkt] [\-M path] [\-P pager] [\-S system] [section] name ...
X.SH DESCRIPTION
Xman formats and displays the on-line manual pages.  This version knows
Xabout the MANPATH and PAGER environment variables, so you can have
Xyour own set(s) of personal man pages and choose whatever program you
Xlike to display the formatted pages.  If section is specified, man
Xonly looks in that section of the manual.
X.SH OPTIONS
X.TP
X.B \-\^P " pager"
XSpecify which pager to use.  By default,
X.B man
Xuses
X.B less,
Xwhich has the ability to backup on files and pipes, so you can go
Xbackwards while reading the manual.  This option overrides the
X.B PAGER
Xenvironment variable.
X.TP
X.B \-\^M " path"
XSpecify an alternate manpath.  By default, man uses
X.B manpath
Xto determine the path to search.  This option overrides the
X.B MANPATH
Xenvironment variable.
X.TP
X.B \-\^a
XBy default,
X.B man
Xwill exit after displaying the first manual page it finds.  Using this
Xoption forces
X.B man
Xto display all the manual pages that match
X.B name, 
Xnot just the first.  
X.TP
X.B \-\^f
XEquivalent to
X.B whatis.
X.TP
X.B \-\^h
XPrint a one line help message and exit.
X.TP
X.B \-\^k
XEquivalent to
X.B apropos.
X.TP
X.B \-\^t
XUse
X.B troff
Xto format the manual page, passing the output to 
X.B stdout.
XNormally the output from
X.B troff
Xwill need to be passed through some filter or another before being
Xprinted.
X.SH ENVIRONMENT
X.TP \w'MANPATH\ \ 'u
X.B MANPATH
XIf
X.B MANPATH
Xis set,
X.B man
Xuses its value as the path to search for manual pages.
X.TP
X.B PAGER
XIf
X.B PAGER
Xis set,
X.B man
Xuses its value as the name of the program to use to display the man
Xpage.  By default,
X.B less
Xis used.
X.SH "SEE ALSO"
Xapropos(1), whatis(1), manpath(1), less(1), nroff(1), troff(1), psdit(1).
X.SH BUGS
XThe
X.B \-t
Xoption only works if
X.B troff
Xis installed.
X.PP
X.B less
Xis sometimes confused by underlined text.
END_OF_FILE
if test 2323 -ne `wc -c <'man-1.0/man.man'`; then
    echo shar: \"'man-1.0/man.man'\" unpacked with wrong size!
fi
# end of 'man-1.0/man.man'
fi
if test -f 'man-1.0/manpath.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'man-1.0/manpath.c'\"
else
echo shar: Extracting \"'man-1.0/manpath.c'\" \(9441 characters\)
sed "s/^X//" >'man-1.0/manpath.c' <<'END_OF_FILE'
X/*
X * manpath.c
X *
X * Copyright (c) 1991, John W. Eaton.
X *
X * You may distribute under the terms of the GNU General Public
X * License as specified in the README file that comes with the man 1.0
X * distribution.  
X *
X * John W. Eaton
X * jwe@che.utexas.edu
X * Department of Chemical Engineering
X * The University of Texas at Austin
X * Austin, Texas  78712
X */
X
X#include <stdio.h>
X#include <string.h>
X#include <sys/types.h>
X#include <sys/stat.h>
X#include "config.h"
X#include "manpath.h"
X#include "gripes.h"
X
X#ifdef STD_HEADERS
X#include <stdlib.h>
X#else
Xextern int fprintf ();
Xextern int strcmp ();
Xextern int strncmp ();
Xextern char *getenv();
Xextern char *malloc();
Xextern void free ();
Xextern int exit ();
X#endif
X
Xextern char *strdup ();
X
X#ifndef MAIN
Xextern int debug;
X#endif
X
X#ifdef MAIN
X
X#ifndef __ANSI__
Xextern char *strcpy ();
Xextern int fflush ();
X#endif
X
Xchar *prognam;
Xint debug;
X
X/*
X * Examine user's PATH and print a reasonable MANPATH.
X */
Xint
Xmain(argc, argv)
X     int argc;
X     char **argv;
X{
X  int c;
X  int quiet;
X  char *mp;
X  extern int getopt ();
X  extern char *mkprogname ();
X  void usage ();
X  char *manpath ();
X
X  quiet = 1;
X
X  prognam = mkprogname (argv[0]);
X
X  while ((c = getopt (argc, argv, "dhq?")) != EOF)
X    {
X      switch (c)
X	{
X	case 'd':
X	  debug++;
X	  break;
X	case 'q':
X	  quiet = 0;
X	  break;
X	case '?':
X	case 'h':
X	default:
X	  usage();
X          break;
X	}
X    }
X
X  mp = manpath (quiet);
X
X  fprintf (stdout, "%s\n", mp);
X  fflush (stdout);
X
X  return 0;
X}
X
Xvoid
Xusage ()
X{
X  fprintf (stderr, "usage: %s [-q]\n", prognam);
X  exit (1);
X}
X#endif /* MAIN */
X
X/*
X * If the environment variable MANPATH is set, return it.
X * If the environment variable PATH is set and has a nonzero length,
X * try to determine the corresponding manpath, otherwise, return the
X * default manpath.
X *
X * The manpath.config file is used to map system wide /bin directories
X * to top level man page directories.
X *
X * For directories which are in the user's path but not in the
X * manpath.config file, see if there is a subdirectory `man' or `MAN'.
X * If so, add that directory to the path.  Example:  user has
X * $HOME/bin in his path and the directory $HOME/bin/man exists -- the
X * directory $HOME/bin/man will be added to the manpath.
X */
Xchar *
Xmanpath (perrs)
X     register int perrs;
X{
X  register int len;
X  register char *manpathlist;
X  register char *path;
X  int  get_dirlist ();
X  char *def_path ();
X  char *get_manpath ();
X
X  if (get_dirlist ())
X      gripe_reading_mp_config ();
X
X  if ((manpathlist = getenv ("MANPATH")) != NULL)
X    /*
X     * This must be it.
X     */
X    {
X      if (perrs)
X	fprintf (stderr, "(Warning: MANPATH environment variable set)\n");
X      return manpathlist;
X    }
X  else if ((path = getenv ("PATH")) == NULL)
X    /*
X     * Things aren't going to work well, but hey...
X     */
X    {
X      if (perrs)
X	fprintf (stderr, "Warning: path not set\n");
X      return def_path (perrs);
X    }
X  else
X    {
X      if ((len = strlen (path)) == 0)
X	/*
X	 * Things aren't going to work well here either...
X	 */
X	{
X	  if (perrs)
X	    fprintf (stderr, "Warning: path set but has zero length\n");
X	  return def_path (perrs);
X	}
X      return get_manpath (perrs, path);
X    }
X}
X
X/*
X * Get the list of bin directories and the corresponding man
X * directories from the manpath.config file.
X *
X * This is ugly.
X */
Xint
Xget_dirlist ()
X{
X  int i;
X  char *bp;
X  char *p;
X  char buf[BUFSIZ];
X  DIRLIST *dlp = list;
X  FILE *config;
X
X  if ((config = fopen (config_file, "r")) == NULL)
X    gripe_getting_mp_config (config_file);
X
X  while ((bp = fgets (buf, BUFSIZ, config)) != NULL)
X    {
X      while (*bp && (*bp == ' ' || *bp == '\t'))
X	bp++;
X
X      if (*bp == '#' || *bp == '\n')
X	continue;
X
X      if (!strncmp ("MANBIN", bp, 6))
X	continue;
X
X      if (!strncmp ("MANDATORY_MANPATH", bp, 17))
X	{
X	  if ((p = strchr (bp, ' ')) == NULL)
X	    if ((p = strchr (bp, '\t')) == NULL)
X	      return -1;
X
X	  bp = p;
X
X	  dlp->mandatory = 1;
X
X	  while (*bp && *bp != '\n' && (*bp == ' ' || *bp == '\t'))
X	    bp++;
X
X	  i = 0;
X	  while (*bp && *bp != '\n' && *bp != ' ' && *bp != '\t')
X	    dlp->mandir[i++] = *bp++;
X	  dlp->mandir[i] = '\0';
X
X	  if (debug)
X	    fprintf (stderr, "found mandatory man directory %s\n",
X		     dlp->mandir);
X	}
X      else if (!strncmp ("MANPATH_MAP", bp, 11))
X	{
X	  if ((p = strchr (bp, ' ')) == NULL)
X	    if ((p = strchr (bp, '\t')) == NULL)
X	      return -1;
X
X	  bp = p;
X
X	  dlp->mandatory = 0;
X
X	  while (*bp && *bp != '\n' && (*bp == ' ' || *bp == '\t'))
X	    bp++;
X
X	  i = 0;
X	  while (*bp && *bp != '\n' && *bp != ' ' && *bp != '\t')
X	    dlp->bin[i++] = *bp++;
X	  dlp->bin[i] = '\0';
X
X	  while (*bp && *bp != '\n' && (*bp == ' ' || *bp == '\t'))
X	    bp++;
X
X	  i = 0;
X	  while (*bp && *bp != '\n' && *bp != ' ' && *bp != '\t')
X	    dlp->mandir[i++] = *bp++;
X	  dlp->mandir[i] = '\0';
X
X	  if (debug)
X	    fprintf (stderr, "found manpath map %s --> %s\n",
X		     dlp->bin, dlp->mandir);
X	}
X      else
X	{
X	  gripe_reading_mp_config ();
X	}
X      dlp++;
X    }
X
X  dlp->bin[0] = NULL;
X  dlp->mandir[0] = NULL;
X  dlp->mandatory = 0;
X
X  return 0;
X}
X
X/*
X * Construct the default manpath.  This picks up mandatory manpaths
X * only.
X */
Xchar *
Xdef_path (perrs)
X     int perrs;
X{
X  register int len;
X  register char *manpathlist;
X  register DIRLIST *dlp;
X
X  len = 0;
X  dlp = list;
X  while (dlp->mandatory != 0)
X    {
X      len += strlen (dlp->mandir) + 1;
X      dlp++;
X    }
X
X  if ((manpathlist = malloc (len)) == NULL)
X    {
X      fprintf (stderr, "Fatal: can't malloc %d bytes for manpathlist\n", len);
X      exit (1);
X    }
X  *manpathlist = '\0';
X
X  dlp = list;
X  while (dlp->mandatory != 0)
X    {
X      strcat (manpathlist, dlp->mandir);
X      strcat (manpathlist, ":");
X      dlp++;
X    }
X
X  manpathlist[len-1] = '\0';
X
X  return manpathlist;
X}
X
X/*
X * For each directory in the user's path, see if it is one of the
X * directories listed in the manpath.config file.  If so, and it is
X * not already in the manpath, add it.  If the directory is not listed
X * in the manpath.config file, see if there is a subdirectory `man' or
X * `MAN'.  If so, and it is not already in the manpath, add it.
X * Example:  user has $HOME/bin in his path and the directory
X * $HOME/bin/man exists -- the directory $HOME/bin/man will be added
X * to the manpath.
X */
Xchar *
Xget_manpath (perrs, path)
X     register int perrs;
X     register char *path;
X{
X  register int len;
X  register char *tmppath;
X  register char *t;
X  register char *p;
X  register char **lp;
X  register char *end;
X  register char *manpathlist;
X  register DIRLIST *dlp;
X  void add_dir_to_list ();
X  char *has_subdirs ();
X
X  tmppath = strdup (path);
X
X  for (p = tmppath; ; p = end+1)
X    {
X      if (end = strchr(p, ':'))
X	*end = '\0';
X
X      if (debug)
X	fprintf (stderr, "\npath directory %s ", p);
X
X      for (dlp = list; dlp->mandir[0] != NULL; dlp++)
X	if (dlp->bin[0] != NULL && !strcmp (p, dlp->bin))
X	  {
X	    /*
X	     * The directory we're working on is in the config file.
X	     * If we haven't added it to the list yet, do.
X	     */
X	    if (debug)
X	      fprintf (stderr, "is in the config file\n");
X
X	    add_dir_to_list (tmplist, dlp->mandir);
X	    goto found;
X	  }
X      /*
X       * The directory we're working on isn't in the config file.  See
X       * if it has man or MAN subdirectories.  If so, and it hasn't
X       * been added to the list, do.
X       */
X      if (debug)
X	fprintf (stderr, "is not in the config file\n");
X
X      t = has_subdirs (p);
X      if (t != NULL)
X	{
X	  if (debug)
X	    fprintf (stderr, "but it does have a man or MAN subdirectory\n");
X
X	  add_dir_to_list (tmplist, t);
X	  free (t);
X	}
X      else
X	{
X	  if (debug)
X	    fprintf (stderr, "and doesn't have man or MAN subdirectories\n");
X	}
X
X    found:
X
X      if (!end)
X	break;
X    }
X
X  if (debug)
X    fprintf (stderr, "\nadding mandatory man directories\n\n");
X
X  dlp = list;
X  while (dlp->mandatory != 0)
X    {
X      add_dir_to_list (tmplist, dlp->mandir);
X      dlp++;
X    }
X
X  len = 0;
X  lp = tmplist;
X  while (*lp != NULL)
X    {
X      len += strlen (*lp) + 1;
X      lp++;
X    }
X
X  if ((manpathlist = malloc (len)) == NULL)
X    {
X      fprintf (stderr, "Fatal: can't malloc %d bytes for manpathlist\n", len);
X      exit (1);
X    }
X  *manpathlist = '\0';
X
X  lp = tmplist;
X  while (*lp != NULL)
X    {
X      strcat (manpathlist, *lp);
X      strcat (manpathlist, ":");
X      lp++;
X    }
X
X  manpathlist[len-1] = '\0';
X
X  return manpathlist;
X}
X
X/*
X * Add a directory to the manpath list if it isn't already there.
X */
Xvoid
Xadd_dir_to_list (lp, dir)
X     char **lp;
X     char *dir;
X{
X  extern char *strdup ();
X
X  while (*lp != NULL)
X    {
X      if (!strcmp (*lp, dir))
X	{
X	  if (debug)
X	    fprintf (stderr, "%s is already in the manpath\n", dir);
X	  return;
X	}
X      lp++;
X    }
X  /*
X   * Not found -- add it.
X   */
X  if (debug)
X    fprintf (stderr, "adding %s to manpath\n", dir);
X
X  *lp = strdup (dir);
X}
X
X/*
X * Check to see if the current directory has man or MAN
X * subdirectories. 
X */
Xchar *
Xhas_subdirs (p)
X     register char *p;
X{
X  int len;
X  register char *t;
X  register struct stat sb;
X  extern int stat ();
X
X  len = strlen (p);
X
X  t = malloc ((unsigned) len + 5);
X
X  if (t == 0)
X    gripe_alloc (len, "p\n");
X
X  strcpy (t, p);
X  strcat (t, "/man");
X
X  if (stat (t, &sb) == 0 && (sb.st_mode & S_IFDIR) == S_IFDIR)
X    return t;
X
X  strcpy (t, p);
X  strcat (t, "/MAN");
X  
X  if (stat (t, &sb) == 0 && (sb.st_mode & S_IFDIR) == S_IFDIR)
X    return t;
X
X  return NULL;
X}
END_OF_FILE
if test 9441 -ne `wc -c <'man-1.0/manpath.c'`; then
    echo shar: \"'man-1.0/manpath.c'\" unpacked with wrong size!
fi
# end of 'man-1.0/manpath.c'
fi
if test -f 'man-1.0/manpath.config' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'man-1.0/manpath.config'\"
else
echo shar: Extracting \"'man-1.0/manpath.config'\" \(1159 characters\)
sed "s/^X//" >'man-1.0/manpath.config' <<'END_OF_FILE'
X# manpath.config
X#
X# Edit this file to match your site.
X#
X# Copyright (c) 1991, John W. Eaton.
X#
X# You may distribute under the terms of the GNU General Public
X# License as specified in the README file that comes with the man 1.0
X# distribution.  
X#
X# John W. Eaton
X# jwe@che.utexas.edu
X# Department of Chemical Engineering
X# The University of Texas at Austin
X# Austin, Texas  78712
X#
X# This file is read by manpath to configure the mandatory manpath, to
X# map each path element to a manpath element and to determine where the
X# "man" binary lives.  The format is:
X#
X# MANBIN				pathname
X# MANDATORY_MANPATH			manpath_element
X# MANPATH_MAP		path_element	manpath_element
X#
X# MANBIN is optional.
X#
X#MANBIN		/usr/local/lib/man
X#
X# every automatically generated MANPATH includes these fields
X#
XMANDATORY_MANPATH	/usr/man
XMANDATORY_MANPATH	/usr/local/man
XMANDATORY_MANPATH	/usr/local/X11/man
X#
X# set up PATH to MANPATH mapping
X#
XMANPATH_MAP	/bin			/usr/man
XMANPATH_MAP	/usr/bin		/usr/man
XMANPATH_MAP	/usr/ucb		/usr/man
XMANPATH_MAP	/usr/local/bin		/usr/local/man
XMANPATH_MAP	/usr/local/bin/X11	/usr/local/X11/man
XMANPATH_MAP	/usr/local/bin/X11R4	/usr/local/X11/man
END_OF_FILE
if test 1159 -ne `wc -c <'man-1.0/manpath.config'`; then
    echo shar: \"'man-1.0/manpath.config'\" unpacked with wrong size!
fi
# end of 'man-1.0/manpath.config'
fi
if test -f 'man-1.0/manpath.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'man-1.0/manpath.h'\"
else
echo shar: Extracting \"'man-1.0/manpath.h'\" \(505 characters\)
sed "s/^X//" >'man-1.0/manpath.h' <<'END_OF_FILE'
X/*
X * manpath.h
X *
X * Copyright (c) 1991, John W. Eaton.
X *
X * You may distribute under the terms of the GNU General Public
X * License as specified in the README file that comes with the man 1.0
X * distribution.  
X *
X * John W. Eaton
X * jwe@che.utexas.edu
X * Department of Chemical Engineering
X * The University of Texas at Austin
X * Austin, Texas  78712
X */
X
Xtypedef struct
X{
X  char mandir[MAXPATHLEN];
X  char bin[MAXPATHLEN];
X  int mandatory;
X} DIRLIST;
X
XDIRLIST list[MAXDIRS];
X
Xchar *tmplist[MAXDIRS];
END_OF_FILE
if test 505 -ne `wc -c <'man-1.0/manpath.h'`; then
    echo shar: \"'man-1.0/manpath.h'\" unpacked with wrong size!
fi
# end of 'man-1.0/manpath.h'
fi
if test -f 'man-1.0/manpath.man' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'man-1.0/manpath.man'\"
else
echo shar: Extracting \"'man-1.0/manpath.man'\" \(1436 characters\)
sed "s/^X//" >'man-1.0/manpath.man' <<'END_OF_FILE'
X.\" Man page for manpath
X.\"
X.\" Copyright (c) 1991, John W. Eaton.
X.\"
X.\" You may distribute under the terms of the GNU General Public
X.\" License as specified in the README file that comes with the man 1.0
X.\" distribution.  
X.\"
X.\" John W. Eaton
X.\" jwe@che.utexas.edu
X.\" Department of Chemical Engineering
X.\" The University of Texas at Austin
X.\" Austin, Texas  78712
X.\"
X.TH manpath 1 "Jan 5, 1991"
X.LO 1
X.SH NAME
Xmanpath \- determine user's search path for man pages
X.SH SYNOPSIS
Xmanpath [\-q]
X.SH DESCRIPTION
Xmanpath tries to determine the user's manpath from a set of system
Xdefaults and the user's
X.B PATH ,
Xechoing the result to the standard output.  Warnings and errors are
Xwritten to the standard error.
XIf a directory in the user's path is not listed in the manpath.config
Xfile, manpath looks for the subdirectories man or MAN.  If they exist,
Xthey are added to the search path.
X.PP
Xmanpath is used by
X.B man
Xto determine the search path, so user's normally don't need to set the
X.B MANPATH
Xenvironment variable directly.
X.SH OPTIONS
X.TP
X.B \-\^q
XOperate quietly.  Only echo the final manpath.
X.SH ENVIRONMENT
X.TP \w'MANPATH\ \ 'u
X.B MANPATH
XIf
X.B MANPATH
Xis set,
X.B manpath
Xechoes its value on the standard output and issues a warning on the
Xstandard error.
X.SH FILES
X.TP \w'MANPATH_CONFIG_FILE'u+2n
X.BI MANPATH_CONFIG_FILE
XSystem configuration file.
X.SH "SEE ALSO"
Xapropos(1), whatis(1), man(1).
X.SH BUGS
XNone known.
END_OF_FILE
if test 1436 -ne `wc -c <'man-1.0/manpath.man'`; then
    echo shar: \"'man-1.0/manpath.man'\" unpacked with wrong size!
fi
# end of 'man-1.0/manpath.man'
fi
if test -f 'man-1.0/ndir.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'man-1.0/ndir.h'\"
else
echo shar: Extracting \"'man-1.0/ndir.h'\" \(1262 characters\)
sed "s/^X//" >'man-1.0/ndir.h' <<'END_OF_FILE'
X/*
X	<dir.h> -- definitions for 4.2BSD-compatible directory access
X
X	last edit:	09-Jul-1983	D A Gwyn
X*/
X
X#ifdef VMS
X#ifndef FAB$C_BID
X#include <fab.h>
X#endif
X#ifndef NAM$C_BID
X#include <nam.h>
X#endif
X#ifndef RMS$_SUC
X#include <rmsdef.h>
X#endif
X#include "dir.h"
X#endif /* VMS */
X
X#define DIRBLKSIZ	512		/* size of directory block */
X#ifdef VMS
X#define MAXNAMLEN	(DIR$S_NAME + 7) /* 80 plus room for version #.  */
X#define MAXFULLSPEC	NAM$C_MAXRSS /* Maximum full spec */
X#else
X#define MAXNAMLEN	15		/* maximum filename length */
X#endif /* VMS */
X	/* NOTE:  MAXNAMLEN must be one less than a multiple of 4 */
X
Xstruct direct				/* data from readdir() */
X	{
X	long		d_ino;		/* inode number of entry */
X	unsigned short	d_reclen;	/* length of this record */
X	unsigned short	d_namlen;	/* length of string in d_name */
X	char		d_name[MAXNAMLEN+1];	/* name of file */
X	};
X
Xtypedef struct
X	{
X	int	dd_fd;			/* file descriptor */
X	int	dd_loc;			/* offset in block */
X	int	dd_size;		/* amount of valid data */
X	char	dd_buf[DIRBLKSIZ];	/* directory block */
X	}	DIR;			/* stream data from opendir() */
X
Xextern DIR		*opendir();
Xextern struct direct	*readdir();
Xextern long		telldir();
Xextern void		seekdir();
Xextern void		closedir();
X
X#define rewinddir( dirp )	seekdir( dirp, 0L )
END_OF_FILE
if test 1262 -ne `wc -c <'man-1.0/ndir.h'`; then
    echo shar: \"'man-1.0/ndir.h'\" unpacked with wrong size!
fi
# end of 'man-1.0/ndir.h'
fi
if test -f 'man-1.0/strdup.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'man-1.0/strdup.c'\"
else
echo shar: Extracting \"'man-1.0/strdup.c'\" \(1141 characters\)
sed "s/^X//" >'man-1.0/strdup.c' <<'END_OF_FILE'
X/* strdup.c -- return a newly allocated copy of a string
X   Copyright (C) 1989, 1990 Free Software Foundation, Inc.
X
X   This program is free software; you can redistribute it and/or modify
X   it under the terms of the GNU General Public License as published by
X   the Free Software Foundation; either version 1, or (at your option)
X   any later version.
X
X   This program is distributed in the hope that it will be useful,
X   but WITHOUT ANY WARRANTY; without even the implied warranty of
X   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
X   GNU General Public License for more details.
X
X   You should have received a copy of the GNU General Public License
X   along with this program; if not, write to the Free Software
X   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
X
X#ifdef STRDUP_MISSING
X/* If you have the STDC headers, you surely have strdup, too. */
Xchar *malloc ();
Xchar *strcpy ();
X
X/* Return a newly allocated copy of string S;
X   return 0 if out of memory. */
X
Xchar *
Xstrdup (s)
X     char *s;
X{
X  char *p;
X
X  p = malloc ((unsigned) (strlen (s) + 1));
X  if (p)
X    strcpy (p, s);
X  return p;
X}
X#endif
END_OF_FILE
if test 1141 -ne `wc -c <'man-1.0/strdup.c'`; then
    echo shar: \"'man-1.0/strdup.c'\" unpacked with wrong size!
fi
# end of 'man-1.0/strdup.c'
fi
if test -f 'man-1.0/util.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'man-1.0/util.c'\"
else
echo shar: Extracting \"'man-1.0/util.c'\" \(723 characters\)
sed "s/^X//" >'man-1.0/util.c' <<'END_OF_FILE'
X/*
X * util.c
X *
X * Copyright (c) 1991, John W. Eaton.
X *
X * You may distribute under the terms of the GNU General Public
X * License as specified in the README file that comes with the man 1.0
X * distribution.  
X *
X * John W. Eaton
X * jwe@che.utexas.edu
X * Department of Chemical Engineering
X * The University of Texas at Austin
X * Austin, Texas  78712
X */
X
X#ifdef STD_HEADERS
X#include <stdio.h>
X#include <string.h>
X#include <stdlib.h>
X#else
X#include <stdio.h>
X#include <string.h>
Xextern char *strdup ();
X#endif
X
X/*
X * Extract last element of a name like /foo/bar/baz.
X */
Xchar *
Xmkprogname (s)
X     register char *s;
X{
X  char *t;
X
X  t = strrchr (s, '/');
X  if (t == NULL)
X    t = s;
X  else
X    t++;
X
X  return strdup (t);
X}
END_OF_FILE
if test 723 -ne `wc -c <'man-1.0/util.c'`; then
    echo shar: \"'man-1.0/util.c'\" unpacked with wrong size!
fi
# end of 'man-1.0/util.c'
fi
if test -f 'man-1.0/version.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'man-1.0/version.h'\"
else
echo shar: Extracting \"'man-1.0/version.h'\" \(391 characters\)
sed "s/^X//" >'man-1.0/version.h' <<'END_OF_FILE'
X/*
X * version.h
X *
X * Copyright (c) 1991, John W. Eaton.
X *
X * You may distribute under the terms of the GNU General Public
X * License as specified in the README file that comes with the man 1.0
X * distribution.  
X *
X * John W. Eaton
X * jwe@che.utexas.edu
X * Department of Chemical Engineering
X * The University of Texas at Austin
X * Austin, Texas  78712
X */
X
Xstatic char version[] = "1.0";
END_OF_FILE
if test 391 -ne `wc -c <'man-1.0/version.h'`; then
    echo shar: \"'man-1.0/version.h'\" unpacked with wrong size!
fi
# end of 'man-1.0/version.h'
fi
if test -f 'man-1.0/whatis.man' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'man-1.0/whatis.man'\"
else
echo shar: Extracting \"'man-1.0/whatis.man'\" \(758 characters\)
sed "s/^X//" >'man-1.0/whatis.man' <<'END_OF_FILE'
X.\" Man page for whatis
X.\"
X.\" Copyright (c) 1991, John W. Eaton.
X.\"
X.\" You may distribute under the terms of the GNU General Public
X.\" License as specified in the README file that comes with the man 1.0
X.\" distribution.  
X.\"
X.\" John W. Eaton
X.\" jwe@che.utexas.edu
X.\" Department of Chemical Engineering
X.\" The University of Texas at Austin
X.\" Austin, Texas  78712
X.\"
X.TH whatis 1 "Jan 5, 1991"
X.LO 1
X.SH NAME
Xwhatis \- search the whatis database for complete words.
X.SH SYNOPSIS
X.BI whatis
Xkeyword ...
X.SH DESCRIPTION
Xwhatis searches a set of database files containing short descriptions
Xof system commands for keywords and displays the result on the
Xstandard output.  Only complete word matches are displayed.
X.SH "SEE ALSO"
Xapropos(1), man(1).
END_OF_FILE
if test 758 -ne `wc -c <'man-1.0/whatis.man'`; then
    echo shar: \"'man-1.0/whatis.man'\" unpacked with wrong size!
fi
# end of 'man-1.0/whatis.man'
fi
if test -f 'man-1.0/whatis.sh' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'man-1.0/whatis.sh'\"
else
echo shar: Extracting \"'man-1.0/whatis.sh'\" \(1190 characters\)
sed "s/^X//" >'man-1.0/whatis.sh' <<'END_OF_FILE'
X#!/bin/sh
X#
X# whatis -- search the whatis database for keywords.  Like apropos,
X#           but match only commands (as whole words).
X#
X# Copyright (c) 1991, John W. Eaton.
X#
X# You may distribute under the terms of the GNU General Public
X# License as specified in the README file that comes with the man 1.0
X# distribution.  
X#
X# John W. Eaton
X# jwe@che.utexas.edu
X# Department of Chemical Engineering
X# The University of Texas at Austin
X# Austin, Texas  78712
X
XPATH=/usr/local/bin:/bin:/usr/ucb:/usr/bin
X
Xlibdir=LIBDIR
X
Xif [ $# = 0 ]
Xthen
X    echo "usage: `basename $0` name ..."
X    exit 1
Xfi
X
Xmanpath=`BINDIR/manpath -q | tr : '\040'`
X
Xif [ "$manpath" = "" ]
Xthen
X    echo "whatis: manpath is null"
X    exit 1
Xfi
X
Xwhile [ $1 ]
Xdo
X        found=0
X        for d in $manpath /usr/lib
X        do
X            if [ -f $d/whatis ]
X            then
X                grep -iw "^$1" $d/whatis
X                status=$?
X                if [ "$status" = "0" ]
X                then
X                    found=1
X		    export found;
X                fi
X            fi
X        done
X
X        if [ "$found" = "0" ]
X        then
X            echo "$1: nothing appropriate"
X        fi
X
X        shift
Xdone
X
Xexit
END_OF_FILE
if test 1190 -ne `wc -c <'man-1.0/whatis.sh'`; then
    echo shar: \"'man-1.0/whatis.sh'\" unpacked with wrong size!
fi
# end of 'man-1.0/whatis.sh'
fi
echo shar: End of archive 1 \(of 2\).
cp /dev/null ark1isdone
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 need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0

jwe@che.utexas.edu (John W. Eaton) (01/07/91)

-------------------------------cut here-------------------------------
#! /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 archive 2 (of 2)."
# Contents:  man-1.0/glob.c man-1.0/man.c
# Wrapped by jwe@andy.che.utexas.edu on Sun Jan  6 15:10:31 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'man-1.0/glob.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'man-1.0/glob.c'\"
else
echo shar: Extracting \"'man-1.0/glob.c'\" \(12628 characters\)
sed "s/^X//" >'man-1.0/glob.c' <<'END_OF_FILE'
X/* File-name wildcard pattern matching for GNU.
X   Copyright (C) 1985, 1988, 1989 Free Software Foundation, Inc.
X
X   This program is free software; you can redistribute it and/or modify
X   it under the terms of the GNU General Public License as published by
X   the Free Software Foundation; either version 1, or (at your option)
X   any later version.
X
X   This program is distributed in the hope that it will be useful,
X   but WITHOUT ANY WARRANTY; without even the implied warranty of
X   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
X   GNU General Public License for more details.
X
X   You should have received a copy of the GNU General Public License
X   along with this program; if not, write to the Free Software
X   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
X
X/* To whomever it may concern: I have never seen the code which most
X   Unix programs use to perform this function.  I wrote this from scratch
X   based on specifications for the pattern matching.  --RMS.  */
X
X#if defined (SYSV) && !defined (Xenix)
X#  define SYSVr3
X#endif
X
X#include <sys/types.h>
X
X#if defined (SYSVr3) || defined (DIRENT)
X#  include <dirent.h>
X#  define direct dirent
X#  define	D_NAMLEN(d) strlen((d)->d_name)
X#else
X#  define D_NAMLEN(d) ((d)->d_namlen)
X#  if defined (xenix)
X#    include <sys/ndir.h>
X#  else
X#    if defined (SYSV)
X#      include "ndir.h"
X#     else
X#      include <sys/dir.h>
X#    endif
X#  endif
X#endif	/* SYSVr3 or DIRENT.  */
X
X#if defined (NeXT)
X#include <string.h>
X#else
X#if defined (SYSV)
X#include <memory.h>
X#include <string.h>
X#define bcopy(s, d, n) ((void) memcpy ((d), (s), (n)))
X#define rindex	strrchr
X
X#else /* not SYSV */
X#include <strings.h>
X
Xextern void bcopy ();
X#endif /* not SYSV */
X#endif /* not NeXT */
X
Xextern char *malloc (), *realloc ();
Xextern void free ();
X
X#ifndef NULL
X#define NULL 0
X#endif
X
X/* Global variable which controls whether or not * matches .*.
X   Non-zero means don't match .*.  */
Xint noglob_dot_filenames = 1;
X
X
Xstatic int glob_match_after_star ();
X
X/* Return nonzero if PATTERN has any special globbing chars in it.  */
Xint
Xglob_pattern_p (pattern)
X     char *pattern;
X{
X  register char *p = pattern;
X  register char c;
X
X  while ((c = *p++) != '\0')
X    switch (c)
X      {
X      case '?':
X      case '[':
X      case '*':
X	return 1;
X
X      case '\\':
X	if (*p++ == '\0')
X	  return 0;
X      }
X
X  return 0;
X}
X
X/* Match the pattern PATTERN against the string TEXT;
X   return 1 if it matches, 0 otherwise.
X
X   A match means the entire string TEXT is used up in matching.
X
X   In the pattern string, `*' matches any sequence of characters,
X   `?' matches any character, [SET] matches any character in the specified set,
X   [!SET] matches any character not in the specified set.
X
X   A set is composed of characters or ranges; a range looks like
X   character hyphen character (as in 0-9 or A-Z).
X   [0-9a-zA-Z_] is the set of characters allowed in C identifiers.
X   Any other character in the pattern must be matched exactly.
X
X   To suppress the special syntactic significance of any of `[]*?!-\',
X   and match the character exactly, precede it with a `\'.
X
X   If DOT_SPECIAL is nonzero,
X   `*' and `?' do not match `.' at the beginning of TEXT.  */
X
Xint
Xglob_match (pattern, text, dot_special)
X     char *pattern, *text;
X     int dot_special;
X{
X  register char *p = pattern, *t = text;
X  register char c;
X
X  while ((c = *p++) != '\0')
X    switch (c)
X      {
X      case '?':
X	if (*t == '\0' || (dot_special && t == text && *t == '.'))
X	  return 0;
X	else
X	  ++t;
X	break;
X
X      case '\\':
X	if (*p++ != *t++)
X	  return 0;
X	break;
X
X      case '*':
X	if (dot_special && t == text && *t == '.')
X	  return 0;
X	return glob_match_after_star (p, t);
X
X      case '[':
X	{
X	  register char c1 = *t++;
X	  int invert;
X
X	  if (!c1)
X	    return (0);
X
X	  invert = ((*p == '!') || (*p == '^'));
X	  if (invert)
X	    p++;
X
X	  c = *p++;
X	  while (1)
X	    {
X	      register char cstart = c, cend = c;
X
X	      if (c == '\\')
X		{
X		  cstart = *p++;
X		  cend = cstart;
X		}
X
X	      if (c == '\0')
X		return 0;
X
X	      c = *p++;
X	      if (c == '-')
X		{
X		  cend = *p++;
X		  if (cend == '\\')
X		    cend = *p++;
X		  if (cend == '\0')
X		    return 0;
X		  c = *p++;
X		}
X	      if (c1 >= cstart && c1 <= cend)
X		goto match;
X	      if (c == ']')
X		break;
X	    }
X	  if (!invert)
X	    return 0;
X	  break;
X
X	match:
X	  /* Skip the rest of the [...] construct that already matched.  */
X	  while (c != ']')
X	    { 
X	      if (c == '\0')
X		return 0;
X	      c = *p++;
X	      if (c == '\0')
X		return 0;
X	      else if (c == '\\')
X		++p;
X	    }
X	  if (invert)
X	    return 0;
X	  break;
X	}
X
X      default:
X	if (c != *t++)
X	  return 0;
X      }
X
X  return *t == '\0';
X}
X
X/* Like glob_match, but match PATTERN against any final segment of TEXT.  */
X
Xstatic int
Xglob_match_after_star (pattern, text)
X     char *pattern, *text;
X{
X  register char *p = pattern, *t = text;
X  register char c, c1;
X
X  while ((c = *p++) == '?' || c == '*')
X    if (c == '?' && *t++ == '\0')
X      return 0;
X
X  if (c == '\0')
X    return 1;
X
X  if (c == '\\')
X    c1 = *p;
X  else
X    c1 = c;
X
X  while (1)
X    {
X      if ((c == '[' || *t == c1) && glob_match (p - 1, t, 0))
X	return 1;
X      if (*t++ == '\0')
X	return 0;
X    }
X}
X
X/* Return a vector of names of files in directory DIR
X   whose names match glob pattern PAT.
X   The names are not in any particular order.
X   Wildcards at the beginning of PAT do not match an initial period.
X
X   The vector is terminated by an element that is a null pointer.
X
X   To free the space allocated, first free the vector's elements,
X   then free the vector.
X
X   Return 0 if cannot get enough memory to hold the pointer
X   and the names.
X
X   Return -1 if cannot access directory DIR.
X   Look in errno for more information.  */
X
Xchar **
Xglob_vector (pat, dir)
X     char *pat;
X     char *dir;
X{
X  struct globval
X    {
X      struct globval *next;
X      char *name;
X    };
X
X  DIR *d;
X  register struct direct *dp;
X  struct globval *lastlink;
X  register struct globval *nextlink;
X  register char *nextname;
X  unsigned int count;
X  int lose;
X  register char **name_vector;
X  register unsigned int i;
X
X  d = opendir (dir);
X  if (d == NULL)
X    return (char **) -1;
X
X  lastlink = 0;
X  count = 0;
X  lose = 0;
X
X  /* Scan the directory, finding all names that match.
X     For each name that matches, allocate a struct globval
X     on the stack and store the name in it.
X     Chain those structs together; lastlink is the front of the chain.  */
X  while (1)
X    {
X      dp = readdir (d);
X      if (dp == NULL)
X	break;
X      if (dp->d_ino != 0
X	  && glob_match (pat, dp->d_name, noglob_dot_filenames))
X	{
X	  nextlink = (struct globval *) alloca (sizeof (struct globval));
X	  nextlink->next = lastlink;
X	  nextname = (char *) malloc (D_NAMLEN(dp) + 1);
X	  if (nextname == NULL)
X	    {
X	      lose = 1;
X	      break;
X	    }
X	  lastlink = nextlink;
X	  nextlink->name = nextname;
X	  bcopy (dp->d_name, nextname, D_NAMLEN(dp) + 1);
X	  ++count;
X	}
X    }
X  (void) closedir (d);
X
X  if (!lose)
X    {
X      name_vector = (char **) malloc ((count + 1) * sizeof (char *));
X      lose |= name_vector == NULL;
X    }
X
X  /* Have we run out of memory?  */
X  if (lose)
X    {
X      /* Here free the strings we have got.  */
X      while (lastlink)
X	{
X	  free (lastlink->name);
X	  lastlink = lastlink->next;
X	}
X      return NULL;
X    }
X
X  /* Copy the name pointers from the linked list into the vector.  */
X  for (i = 0; i < count; ++i)
X    {
X      name_vector[i] = lastlink->name;
X      lastlink = lastlink->next;
X    }
X
X  name_vector[count] = NULL;
X  return name_vector;
X}
X
X/* Return a new array which is the concatenation
X   of each string in ARRAY to DIR. */
X
Xstatic char **
Xglob_dir_to_array (dir, array)
X     char *dir, **array;
X{
X  register unsigned int i, l;
X  int add_slash;
X  char **result;
X
X  l = strlen (dir);
X  if (l == 0)
X    return array;
X
X  add_slash = dir[l - 1] != '/';
X
X  i = 0;
X  while (array[i] != NULL)
X    ++i;
X
X  result = (char **) malloc ((i + 1) * sizeof (char *));
X  if (result == NULL)
X    return NULL;
X
X  for (i = 0; array[i] != NULL; i++)
X    {
X      result[i] = (char *) malloc (l + (add_slash ? 1 : 0)
X				   + strlen (array[i]) + 1);
X      if (result[i] == NULL)
X	return NULL;
X      sprintf (result[i], "%s%s%s", dir, add_slash ? "/" : "", array[i]);
X    }
X  result[i] = NULL;
X
X  /* Free the input array.  */
X  for (i = 0; array[i] != NULL; i++)
X    free (array[i]);
X  free ((char *) array);
X
X  return result;
X}
X
X/* Do globbing on PATHNAME.  Return an array of pathnames that match,
X   marking the end of the array with a null-pointer as an element.
X   If no pathnames match, then the array is empty (first element is null).
X   If there isn't enough memory, then return NULL.
X   If a file system error occurs, return -1; `errno' has the error code.  */
Xchar **
Xglob_filename (pathname)
X     char *pathname;
X{
X  char **result;
X  unsigned int result_size;
X  char *directory_name, *filename;
X  unsigned int directory_len;
X
X  result = (char **) malloc (sizeof (char *));
X  result_size = 1;
X  if (result == NULL)
X    return NULL;
X
X  result[0] = NULL;
X
X  /* Find the filename.  */
X  filename = rindex (pathname, '/');
X  if (filename == NULL)
X    {
X      filename = pathname;
X      directory_name = "";
X      directory_len = 0;
X    }
X  else
X    {
X      directory_len = (filename - pathname) + 1;
X      directory_name = (char *) alloca (directory_len + 1);
X
X      bcopy (pathname, directory_name, directory_len);
X      directory_name[directory_len] = '\0';
X      ++filename;
X    }
X
X  /* If directory_name contains globbing characters, then we
X     have to expand the previous levels.  Just recurse. */
X  if (glob_pattern_p (directory_name))
X    {
X      char **directories;
X      register unsigned int i;
X
X      if (directory_name[directory_len - 1] == '/')
X	directory_name[directory_len - 1] = '\0';
X
X      directories = glob_filename (directory_name);
X
X      if (directories == NULL)
X	goto memory_error;
X      else if ((int) directories == -1)
X	return (char **) -1;
X      else if (*directories == NULL)
X	{
X	  free ((char *) directories);
X	  return (char **) -1;
X	}
X
X      /* We have successfully globbed the preceding directory name.
X	 For each name in DIRECTORIES, call glob_vector on it and
X	 FILENAME.  Concatenate the results together.  */
X      for (i = 0; directories[i] != NULL; ++i)
X	{
X	  char **temp_results = glob_vector (filename, directories[i]);
X
X	  /* Handle error cases. */
X	  if (temp_results == NULL)
X	    goto memory_error;
X	  else if (temp_results == (char **)-1)
X	    /* This filename is probably not a directory.  Ignore it.  */
X	    ;
X	  else
X	    {
X	      char **array = glob_dir_to_array (directories[i], temp_results);
X	      register unsigned int l;
X
X	      l = 0;
X	      while (array[l] != NULL)
X		++l;
X
X	      result =
X		(char **)realloc (result, (result_size + l) * sizeof (char *));
X
X	      if (result == NULL)
X		goto memory_error;
X
X	      for (l = 0; array[l] != NULL; ++l)
X		result[result_size++ - 1] = array[l];
X
X	      result[result_size - 1] = NULL;
X
X	      /* Note that the elements of ARRAY are not freed.  */
X	      free ((char *) array);
X	    }
X	}
X      /* Free the directories.  */
X      for (i = 0; directories[i]; i++)
X	free (directories[i]);
X
X      free ((char *) directories);
X
X      return result;
X    }
X
X  /* If there is only a directory name, return it. */
X  if (*filename == '\0')
X    {
X      result = (char **) realloc ((char *) result, 2 * sizeof (char *));
X      if (result == NULL)
X	return NULL;
X      result[0] = (char *) malloc (directory_len + 1);
X      if (result[0] == NULL)
X	goto memory_error;
X      bcopy (directory_name, result[0], directory_len + 1);
X      result[1] = NULL;
X      return result;
X    }
X  else
X    {
X      /* Otherwise, just return what glob_vector
X	 returns appended to the directory name. */
X      char **temp_results = glob_vector (filename,
X					 (directory_len == 0
X					  ? "." : directory_name));
X
X      if (temp_results == NULL || temp_results == (char **)-1)
X	return temp_results;
X
X      return glob_dir_to_array (directory_name, temp_results);
X    }
X
X memory_error:;
X  if (result != NULL)
X    {
X      register unsigned int i;
X      for (i = 0; result[i] != NULL; ++i)
X	free (result[i]);
X      free ((char *) result);
X    }
X  return NULL;
X}
X
X#ifdef TEST
X
Xmain (argc, argv)
X     int argc;
X     char **argv;
X{
X  unsigned int i;
X
X  for (i = 1; i < argc; ++i)
X    {
X      char **value = glob_filename (argv[i]);
X      if (value == NULL)
X	puts ("Out of memory.");
X      else if ((int) value == -1)
X	perror (argv[i]);
X      else
X	for (i = 0; value[i] != NULL; i++)
X	  puts (value[i]);
X    }
X
X  exit (0);
X}
X#endif	/* TEST.  */
X
X
END_OF_FILE
if test 12628 -ne `wc -c <'man-1.0/glob.c'`; then
    echo shar: \"'man-1.0/glob.c'\" unpacked with wrong size!
fi
# end of 'man-1.0/glob.c'
fi
if test -f 'man-1.0/man.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'man-1.0/man.c'\"
else
echo shar: Extracting \"'man-1.0/man.c'\" \(19322 characters\)
sed "s/^X//" >'man-1.0/man.c' <<'END_OF_FILE'
X/*
X * man.c
X *
X * Copyright (c) 1991, John W. Eaton.
X *
X * You may distribute under the terms of the GNU General Public
X * License as specified in the README file that comes with the man 1.0
X * distribution.  
X *
X * John W. Eaton
X * jwe@che.utexas.edu
X * Department of Chemical Engineering
X * The University of Texas at Austin
X * Austin, Texas  78712
X */
X
X#include <stdio.h>
X#include <ctype.h>
X#include <string.h>
X#include <sys/types.h>
X#include <sys/stat.h>
X#include <sys/file.h>
X#include <signal.h>
X#include "config.h"
X#include "gripes.h"
X#include "version.h"
X
X#ifdef STD_HEADERS
X#include <stdlib.h>
X#else
Xextern char *malloc ();
Xextern char *getenv ();
Xextern void free ();
Xextern int system ();
Xextern int strcmp ();
Xextern int strncmp ();
Xextern int exit ();
Xextern int fflush ();
Xextern int fprintf ();
Xextern FILE *fopen ();
Xextern int fclose ();
X#ifdef CHARSPRINTF
Xextern char *sprintf ();
X#else
Xextern int sprintf ();
X#endif
X#endif
X
Xextern char *strdup ();
X
Xextern char **glob_vector ();
Xextern int access ();
Xextern int unlink ();
Xextern int system ();
Xextern int stat ();
X
Xchar *prognam;
Xstatic char *pager;
Xstatic char *manp;
Xstatic char *manpathlist[MAXDIRS];
Xstatic char *section;
Xstatic int apropos;
Xstatic int whatis;
Xstatic int findall;
X
X#ifdef ALT_SYSTEMS
Xstatic int alt_system;
Xstatic char *alt_system_name;
X#endif
X
X#ifdef HAS_TROFF
Xstatic int troff;
X#endif
X
Xint debug;
X
Xint
Xmain (argc, argv)
X     int argc;
X     char **argv;
X{
X  int status = 0;
X  char *nextarg;
X  char *tmp;
X  extern int optind;
X  extern char *mkprogname ();
X  char *is_section ();
X  void man_getopt ();
X  void do_apropos ();
X  void do_whatis ();
X  int man ();
X
X  prognam = mkprogname (argv[0]);
X
X  man_getopt (argc, argv);
X
X  if (optind == argc)
X    gripe_no_name (NULL);
X
X  if (optind == argc - 1)
X    {
X      tmp = is_section (argv[optind]);
X
X      if (tmp != NULL)
X	gripe_no_name (tmp);
X    }
X
X  while (optind < argc)
X    {
X      nextarg = argv[optind++];
X
X      /*
X       * See if this argument is a valid section name.  If not,
X       * is_section returns NULL.
X       */
X      tmp = is_section (nextarg);
X
X      if (tmp != NULL)
X	{
X	  section = tmp;
X
X	  if (debug)
X	    fprintf (stderr, "\nsection: %s\n", section);
X
X	  continue;
X	}
X
X      if (apropos)
X	do_apropos (nextarg);
X      else if (whatis)
X	do_whatis (nextarg);
X      else
X	{
X	  status = man (nextarg);
X
X	  if (status == 0)
X	    gripe_not_found (nextarg, section);
X	}
X    }
X  return status;
X}
X
X/*
X * Get options from the command line and user environment.
X */
Xvoid
Xman_getopt (argc, argv)
X     register int argc;
X     register char **argv;
X{
X  register int c;
X  register char *p;
X  register char *end;
X  register char **mp;
X  extern char *optarg;
X  extern int getopt ();
X  extern void downcase ();
X  extern char *manpath ();
X  void usage ();
X
X#ifdef HAS_TROFF
X#ifdef ALT_SYSTEMS
X  while ((c = getopt (argc, argv, "M:P:S:adfhkt?")) != EOF)
X#else
X  while ((c = getopt (argc, argv, "M:P:adfhkt?")) != EOF)
X#endif
X#else
X#ifdef ALT_SYSTEMS
X  while ((c = getopt (argc, argv, "M:P:S:adfhk?")) != EOF)
X#else
X  while ((c = getopt (argc, argv, "M:P:adfhk?")) != EOF)
X#endif
X#endif
X    {
X      switch (c)
X	{
X	case 'M':
X	  manp = strdup (optarg);
X	  break;
X	case 'P':
X	  pager = strdup (optarg);
X	  break;
X#ifdef ALT_SYSTEMS
X	case 'S':
X	  alt_system++;
X	  alt_system_name = strdup (optarg);
X	  break;
X#endif
X	case 'a':
X	  findall++;
X	  break;
X	case 'd':
X	  debug++;
X	  break;
X	case 'f':
X#ifdef HAS_TROFF
X	  if (troff)
X	    gripe_incompatible ("-f and -t");
X#endif
X	  if (apropos)
X	    gripe_incompatible ("-f and -k");
X	  whatis++;
X	  break;
X	case 'k':
X#ifdef HAS_TROFF
X	  if (troff)
X	    gripe_incompatible ("-t and -k");
X#endif
X	  if (whatis)
X	    gripe_incompatible ("-f and -k");
X	  apropos++;
X	  break;
X#ifdef HAS_TROFF
X	case 't':
X	  if (apropos)
X	    gripe_incompatible ("-t and -k");
X	  if (whatis)
X	    gripe_incompatible ("-t and -f");
X	  troff++;
X	  break;
X#endif
X	case 'h':
X	case '?':
X	default:
X	  usage();
X	  break;
X	}
X    }
X
X  if (pager == NULL || *pager == NULL)
X    if ((pager = getenv ("PAGER")) == NULL)
X      pager = strdup (PAGER);
X
X  if (debug)
X    fprintf (stderr, "\nusing %s as pager\n", pager);
X
X  if (manp == NULL)
X    {
X      if ((manp = manpath (0)) == NULL)
X	gripe_manpath ();
X
X      if (debug)
X	fprintf (stderr,
X		 "\nsearch path for pages determined by manpath is\n%s\n\n",
X		 manp);
X    }
X
X#ifdef ALT_SYSTEMS
X  if (alt_system_name == NULL || *alt_system_name == NULL)
X    if ((alt_system_name = getenv ("SYSTEM")) == NULL)
X      alt_system_name = strdup (alt_system_name);
X
X  downcase (alt_system_name);
X#endif
X
X  /*
X   * Expand the manpath into a list for easier handling.
X   */
X  mp = manpathlist;
X  for (p = manp ; ; p = end+1)
X    {
X      if ((end = strchr (p, ':')) != NULL)
X	*end = '\0';
X
X      if (debug)
X	fprintf (stderr, "adding %s to manpathlist\n", p);
X
X#ifdef ALT_SYSTEMS
X      if (alt_system)
X	{
X	  char buf[BUFSIZ];
X
X	  strcpy (buf, p);
X	  strcat (buf, "/");
X	  strcat (buf, alt_system_name);
X
X	  *mp++ = strdup (buf);
X	}
X#else
X      *mp++ = strdup (p);
X#endif
X
X      if (end == NULL)
X	break;
X    }
X  *mp = NULL;
X
X}
X
Xvoid
Xusage ()
X{
X  static char usage_string[1024] = "%s, version %s\n\n";
X
X#ifdef HAS_TROFF
X#ifdef ALT_SYSTEMS
X  static char s1[] =  "usage: %s [-afhkt] [section] [-M path] [-P pager] [-S system] name ...\n\n";
X#else
X  static char s1[] =  "usage: %s [-afhkt] [section] [-M path] [-P pager] name ...\n\n";
X#endif
X#else
X#ifdef ALT_SYSTEMS
X  static char s1[] =  "usage: %s [-afhk] [section] [-M path] [-P pager] [-S system] name ...\n\n";
X#else
X  static char s1[] =  "usage: %s [-afhk] [section] [-M path] [-P pager] name ...\n\n";
X#endif
X#endif
X
Xstatic char s2[] = "  a : find all matching entries\n\
X  d : print gobs of debugging information\n\
X  f : same as whatis(1)\n\
X  h : print this help message\n\
X  k : same as apropos(1)\n";
X
X#ifdef HAS_TROFF
X  static char s3[] = "  t : use troff to format pages for printing\n";
X#endif
X
X  static char s4[] = "\n  M path   : set search path for manual pages to `path'\n\
X  P pager  : use program `pager' to display pages\n";
X
X#ifdef ALT_SYSTEMS
X  static char s5[] = "  S system : search for alternate system's man pages\n";
X#endif
X
X  strcat (usage_string, s1);
X  strcat (usage_string, s2);
X
X#ifdef HAS_TROFF
X  strcat (usage_string, s3);
X#endif
X
X  strcat (usage_string, s4);
X
X#ifdef ALT_SYSTEMS
X  strcat (usage_string, s5);
X#endif
X
X  fprintf (stderr, usage_string, prognam, version, prognam);
X  exit(1);
X}
X
X/*
X * Check to see if the argument is a valid section number.  If the
X * first character of name is a numeral, or the name matches one of
X * the sections listed in config.h, we'll assume that it's a section.
X * The list of sections in config.h simply allows us to specify oddly
X * named directories like .../man3f.  Yuk. 
X */
Xchar *
Xis_section (name)
X     register char *name;
X{
X  register char **vs;
X
X  for (vs = valid_sections; *vs != NULL; vs++)
X    if ((strcmp (*vs, name) == NULL) || (isdigit (name[0])))
X      return strdup (name);
X
X  return NULL;
X}
X
X/*
X * Handle the apropos option.  Cheat by using another program.
X */
Xvoid
Xdo_apropos (name)
X     register char *name;
X{
X  int status;
X  register int len;
X  register char *command;
X
X  len = strlen (APROPOS) + strlen (name) + 2;
X
X  if ((command = malloc(len)) == NULL)
X    gripe_alloc (len, "command");
X
X  sprintf (command, "%s %s", APROPOS, name);
X
X  status = 0;
X  if (debug)
X    fprintf (stderr, "\ntrying command: %s\n", command);
X  else
X    status = system (command);
X
X  if (status == 127)
X    gripe_system_command (status);
X
X  free (command);
X}
X
X/*
X * Handle the whatis option.  Cheat by using another program.
X */
Xvoid
Xdo_whatis (name)
X     register char *name;
X{
X  int status;
X  register int len;
X  register char *command;
X
X  len = strlen (WHATIS) + strlen (name) + 2;
X
X  if ((command = malloc(len)) == NULL)
X    gripe_alloc (len, "command");
X
X  sprintf (command, "%s %s", WHATIS, name);
X
X  status = 0;
X  if (debug)
X    fprintf (stderr, "\ntrying command: %s\n", command);
X  else
X    status = system (command);
X
X  if (status == 127)
X    gripe_system_command (status);
X
X  free (command);
X}
X
X/*
X * Search for manual pages.
X *
X * If preformatted manual pages are supported, look for the formatted
X * file first, then the man page source file.  If they both exist and
X * the man page source file is newer, or only the source file exists,
X * try to reformat it and write the results in the cat directory.  If
X * it is not possible to write the cat file, simply format and display
X * the man file.
X *
X * If preformatted pages are not supported, or the troff option is
X * being used, only look for the man page source file.
X *
X */
Xint
Xman (name)
X     char *name;
X{
X  register int found;
X  register int glob;
X  register char **mp;
X  register char **sp;
X  int try_section ();
X
X  found = 0;
X
X  fflush (stdout);
X  if (section != NULL)
X    {
X      for (mp = manpathlist; *mp != NULL; mp++)
X	{
X	  if (debug)
X	    fprintf (stderr, "\nsearching in %s\n", *mp);
X
X	  glob = 0;
X
X	  found += try_section (*mp, section, name, glob);
X
X	  if (found && !findall)   /* i.e. only do this section... */
X	    return found;
X	}
X    }
X  else
X    {
X      for (sp = valid_sections; *sp != NULL; sp++)
X	{
X	  for (mp = manpathlist; *mp != NULL; mp++)
X	    {
X	      if (debug)
X		fprintf (stderr, "\nsearching in %s\n", *mp);
X
X	      glob = 1;
X
X	      found += try_section (*mp, *sp, name, glob);
X
X	      if (found && !findall)   /* i.e. only do this section... */
X		return found;
X
X	    }
X	}
X    }
X  return found;
X}
X
X/*
X * See if the preformatted man page or the source exists in the given
X * section.
X */
Xint
Xtry_section (path, section, name, glob)
X     register char *path;
X     register char *section;
X     register char *name;
X     register int glob;
X{
X  register int found = 0;
X  register int to_cat;
X  register int cat;
X  register char **names;
X  register char **np;
X  char **glob_for_file ();
X  char **make_name ();
X  char *convert_name ();
X  char *ultimate_source ();
X  int display_cat_file ();
X  int format_and_display ();
X
X  if (debug)
X    {
X      if (glob)
X	fprintf (stderr, "trying section %s with globbing\n", section);
X      else
X	fprintf (stderr, "trying section %s without globbing\n", section);
X    }
X
X  /*
X   * Look for man page source files.
X   */
X  cat = 0;
X  if (glob)
X    names = glob_for_file (path, section, name, cat);
X  else
X    names = make_name (path, section, name, cat);
X
X  if ((int) names == -1 || *names == NULL)
X    /*
X     * No files match.  If we're not using troff and we're supporting
X     * preformatted pages, see if there's one around that we can
X     * display. 
X     */
X    {
X#ifdef HAS_TROFF
X      if (cat_support && !troff)
X#else
X      if (cat_support)
X#endif
X	{
X	  cat = 1;
X	  if (glob)
X	    names = glob_for_file (path, section, name, cat);
X	  else
X	    names = make_name (path, section, name, cat);
X
X	  if ((int) names != -1 && *names != NULL)
X	    {
X	      for (np = names; *np != NULL; np++)
X		found+= display_cat_file (*np);
X	    }
X	}
X    }
X  else
X    {
X      for (np = names; *np != NULL; np++)
X	{
X	  register char *cat_file = NULL;
X	  register char *man_file;
X
X	  man_file = ultimate_source (*np, path);
X
X#ifdef HAS_TROFF
X	  if (cat_support && !troff)
X#else
X	  if (cat_support)
X#endif
X	    {
X	      to_cat = 1;
X
X	      cat_file = convert_name (man_file, to_cat);
X	      if (debug)
X		fprintf (stderr, "will try to write %s if needed\n", cat_file);
X	    }
X
X	  found += format_and_display (path, man_file, cat_file);
X	}
X    }
X
X  return found;
X}
X
X/*
X * Change a name of the form ...man/man1/name.1 to ...man/cat1/name.1
X * or a name of the form ...man/cat1/name.1 to ...man/man1/name.1
X */
Xchar *
Xconvert_name (name, to_cat)
X     register char *name;
X     register int to_cat;
X{
X  register char *to_name;
X  register char *t1;
X  register char *t2 = NULL;
X
X  to_name = strdup (name);
X
X  t1 = strrchr (to_name, '/');
X  if (t1 != NULL)
X    {
X      *t1 = NULL;
X      t2 = strrchr (to_name, '/');
X      *t1 = '/';
X    }
X
X  if (t2 == NULL)
X    gripe_converting_name (name, to_cat);
X
X  if (to_cat)
X    {
X      *(++t2) = 'c';
X      *(t2+2) = 't';
X    }
X  else
X    {
X      *(++t2) = 'm';
X      *(t2+2) = 'n';
X    }
X
X  return to_name;
X}
X
X
X/*
X * Try to find the man page corresponding to the given name.  The
X * reason we do this with globbing is because some systems have man
X * page directories named man3 which contain files with names like
X * XtPopup.3Xt.  Rather than requiring that this program know about
X * all those possible names, we simply try to match things like
X * .../man[sect]/name[sect]*.  This is *much* easier.
X *
X * Note that globbing is only done when the section is unspecified.
X */
Xchar **
Xglob_for_file (path, section, name, cat)
X     register char *path;
X     register char *section;
X     register char *name;
X     register int cat;
X{
X  char pathname[BUFSIZ];
X  char **glob_filename ();
X  char **gf;
X
X  if (cat)
X    sprintf (pathname, "%s/cat%s/%s.%s*", path, section, name, section);
X  else
X    sprintf (pathname, "%s/man%s/%s.%s*", path, section, name, section);
X
X  if (debug)
X    fprintf (stderr, "globbing %s\n", pathname);
X
X  gf = glob_filename (pathname);
X
X  if (((int) gf == -1 || *gf == NULL) && isdigit (*section))
X    {
X      if (cat)
X	sprintf (pathname, "%s/cat%s/%s.%c*", path, section, name, *section);
X      else
X	sprintf (pathname, "%s/man%s/%s.%c*", path, section, name, *section);
X
X      gf = glob_filename (pathname);
X    }
X  return gf;
X}
X
X/*
X * Return an un-globbed name in the same form as if we were doing
X * globbing. 
X */
Xchar **
Xmake_name (path, section, name, cat)
X     register char *path;
X     register char *section;
X     register char *name;
X     register int cat;
X{
X  register int i = 0;
X  static char *names[3];
X  char buf[BUFSIZ];
X
X  if (cat)
X    sprintf (buf, "%s/cat%s/%s.%s", path, section, name, section);
X  else
X    sprintf (buf, "%s/man%s/%s.%s", path, section, name, section);
X
X  if (access (buf, R_OK) == 0)
X    names[i++] = strdup (buf);
X
X  /*
X   * If we're given a section that looks like `3f', we may want to try
X   * file names like .../man3/foo.3f as well.  This seems a bit
X   * kludgey to me, but what the hey...
X   */
X  if (section[1] != '\0')
X    {
X      if (cat)
X	sprintf (buf, "%s/cat%c/%s.%s", path, section[0], name, section);
X      else
X	sprintf (buf, "%s/man%c/%s.%s", path, section[0], name, section);
X
X      if (access (buf, R_OK) == 0)
X	names[i++] = strdup (buf);
X    }
X
X  names[i] = NULL;
X
X  return &names[0];
X}
X
X/*
X * Simply display the preformmated page.
X */
Xint
Xdisplay_cat_file (file)
X     register char *file;
X{
X  int status;
X  register int found;
X  char command[BUFSIZ];
X
X  found = 0;
X
X  if (access (file, R_OK) == NULL)
X    {
X      sprintf (command, "%s %s", pager, file);
X
X      status = 0;
X      if (debug)
X	fprintf (stderr, "\ntrying command: %s\n", command);
X      else
X	status = system (command);
X
X      if (status == 127)
X	gripe_system_command (status);
X      else
X	found++;
X    }
X  return found;
X}
X
X/*
X * Try to find the ultimate source file.  If the first line of the
X * current file is not of the form
X *
X *      .so man3/printf.3s
X *
X * the input file name is returned.
X */
Xchar *
Xultimate_source (name, path)
X     char *name;
X     char *path;
X{
X  FILE *fp;
X  char buf[BUFSIZ];
X  char ult[BUFSIZ];
X  char *beg;
X  char *end;
X
X  strcpy (ult, name);
X  strcpy (buf, name);
X
X next:
X
X  if ((fp = fopen (ult, "r")) == NULL)
X    return buf;
X
X  if (fgets (buf, BUFSIZ, fp) == NULL)
X    return ult;
X
X  if (strlen (buf) < 5)
X    return ult;
X
X  beg = buf;
X  if (*beg++ == '.' && *beg++ == 's' && *beg++ == 'o')
X    {
X      while ((*beg == ' ' || *beg == '\t') && *beg != '\0')
X	beg++;
X
X      end = beg;
X      while (*end != ' ' && *end != '\t' && *end != '\n' && *end != '\0')
X	end++;
X
X      *end = '\0';
X
X      strcpy (ult, path);
X      strcat (ult, "/");
X      strcat (ult, beg);
X
X      strcpy (buf, ult);
X
X      goto next;
X    }
X
X  if (debug)
X    fprintf (stderr, "found ultimate source file %s\n", ult);
X
X  return ult;
X}
X
X/*
X * Try to format the man page source and save it, then display it.  If
X * that's not possible, try to format the man page source and display
X * it directly.
X *
X * Note that in the commands below, the cd is necessary because some
X * man pages are one liners like my version of sprintf.3s:
X *
X *      .so man3/printf.3s
X */
Xint
Xformat_and_display (path, man_file, cat_file)
X     register char *path;
X     register char *man_file;
X     register char *cat_file;
X{
X  int status;
X  int mode;
X  register int found;
X  FILE *fp;
X  char command[BUFSIZ];
X  int is_newer ();
X
X  found = 0;
X
X  if (access (man_file, R_OK) != 0)
X    return found;
X  
X#ifdef HAS_TROFF
X  if (troff || !cat_support)
X    {
X      if (troff)
X	sprintf (command, "(cd %s ; %s %s)", path, troff_command, man_file);
X      else
X	sprintf (command, "(cd %s ; %s %s | %s)", path, nroff_command,
X		 man_file, pager); 
X#else
X  if (!cat_support)
X    {
X      sprintf (command, "(cd %s ; %s %s | %s)", path, nroff_command,
X	       man_file, pager); 
X#endif
X      status = 0;
X      if (debug)
X	fprintf (stderr, "\ntrying command: %s\n", command);
X      else
X	status = system (command);
X
X      if (status == 127)
X	gripe_system_command (status);
X      else
X	found++;
X    }
X  else
X    {
X      if ((status = is_newer (man_file, cat_file)) == 1 || status == -2)
X	{
X	  if ((fp = fopen (cat_file, "w")) != NULL)
X	    {
X	      fclose (fp);
X	      unlink (cat_file);
X
X	      fprintf (stderr, "Formatting page, please wait...\n");
X
X	      sprintf (command, "(cd %s ; %s %s > %s)", path,
X		       nroff_command, man_file, cat_file);
X
X	      signal (SIGINT, SIG_IGN);
X
X	      status = 0;
X	      if (debug)
X		fprintf (stderr, "\ntrying command: %s\n", command);
X	      else
X		status = system (command);
X
X	      if (status == 127)
X		gripe_system_command (status);
X	      else
X		found++;
X	      
X	      mode = CATMODE;
X	      chmod (cat_file, mode);
X
X	      if (debug)
X		fprintf (stderr, "mode of %s is now %o\n", cat_file, mode);
X
X	      signal (SIGINT, SIG_DFL);
X
X	      found = display_cat_file (cat_file);
X	    }
X	  else
X	    {
X	      sprintf (command, "(cd %s ; %s %s | %s)", path, nroff_command,
X		       man_file, pager); 
X
X	      status = 0;
X	      if (debug)
X		fprintf (stderr, "\ntrying command: %s\n", command);
X	      else
X		status = system (command);
X
X	      if (status == 127)
X		gripe_system_command (status);
X	      else
X		found++;
X	    }
X	}
X      else if (access (cat_file, R_OK) == 0)
X	{
X	  found = display_cat_file (cat_file);
X	}
X    }
X  return found;
X}
X
X/*
X * Is file a newer than file b?
X *
X * case:
X *
X *   a newer than b         returns    1
X *   a older than b         returns    0
X *   stat on a fails        returns   -1
X *   stat on b fails        returns   -2
X *   stat on a and b fails  returns   -3
X */
Xint
Xis_newer (fa, fb)
X  register char *fa;
X  register char *fb;
X{
X  struct stat fa_sb;
X  struct stat fb_sb;
X  register int fa_stat;
X  register int fb_stat;
X  register int status = 0;
X
X  fa_stat = stat (fa, &fa_sb);
X  if (fa_stat != 0)
X    status = 1;
X
X  fb_stat = stat (fb, &fb_sb);
X  if (fb_stat != 0)
X    status |= 2;
X
X  if (status != 0)
X    return -status;
X
X  if (fa_sb.st_mtime > fb_sb.st_mtime)
X    {
X      status = 1;
X
X      if (debug)
X	fprintf (stderr, "%s is newer than %s\n", fa, fb);
X    }
X  else
X    {
X      status = 0;
X
X      if (debug)
X	fprintf (stderr, "%s is older than %s\n", fa, fb);
X    }
X  return status;
X}
END_OF_FILE
if test 19322 -ne `wc -c <'man-1.0/man.c'`; then
    echo shar: \"'man-1.0/man.c'\" unpacked with wrong size!
fi
# end of 'man-1.0/man.c'
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 need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0