#!/bin/sh
#
# Usage: roffitall [-nroff|-psroff|-groff]
#
# Authors: Tom Christiansen, Raphael Manfredi

me=roffitall
tmp=.

if test -f ../config.sh; then
	. ../config.sh
fi

mandir=$installman1dir
libdir=$installman3dir

test -d $mandir || mandir=/usr/new/man/man1
test -d $libdir || libdir=/usr/new/man/man3

case "$1" in
-nroff) cmd="nroff -man"; ext='txt';;
-psroff) cmd="psroff -t"; ext='ps';;
-groff) cmd="groff -man"; ext='ps';;
*)
	echo "Usage: roffitall [-nroff|-psroff|-groff]" >&2
	exit 1
	;;
esac

toroff=`
	echo		\
    $mandir/perl.1	\
    $mandir/perldata.1	\
    $mandir/perlsyn.1	\
    $mandir/perlop.1	\
    $mandir/perlre.1	\
    $mandir/perlrun.1	\
    $mandir/perlfunc.1	\
    $mandir/perlvar.1	\
    $mandir/perlsub.1	\
    $mandir/perlopentut.1	\
    $mandir/perlmod.1	\
    $mandir/perlmodlib.1	\
    $mandir/perlmodinstall.1	\
    $mandir/perlfork.1	\
    $mandir/perlform.1	\
    $mandir/perllocale.1	\
    $mandir/perlref.1	\
    $mandir/perlreftut.1	\
    $mandir/perldsc.1	\
    $mandir/perllol.1	\
    $mandir/perlboot.1	\
    $mandir/perltoot.1	\
    $mandir/perlobj.1	\
    $mandir/perltie.1	\
    $mandir/perlbot.1	\
    $mandir/perlipc.1	\
    $mandir/perlthrtut.1	\
    $mandir/perldebguts.1	\
    $mandir/perldebug.1	\
    $mandir/perlnumber.1	\
    $mandir/perldiag.1	\
    $mandir/perlsec.1	\
    $mandir/perltrap.1	\
    $mandir/perlport.1	\
    $mandir/perlstyle.1	\
    $mandir/perlpod.1	\
    $mandir/perlbook.1	\
    $mandir/perlembed.1	\
    $mandir/perlapio.1	\
    $mandir/perlxs.1	\
    $mandir/perlxstut.1	\
    $mandir/perlguts.1	\
    $mandir/perlcall.1	\
    $mandir/perlcompile.1	\
    $mandir/perltodo.1	\
    $mandir/perlapi.1	\
    $mandir/perlintern.1	\
    $mandir/perlhack.1	\
    $mandir/perlhist.1	\
    $mandir/perldelta.1	\
    $mandir/perl5004delta.1	\
    $mandir/perl5005delta.1	\
    $mandir/perlfaq.1	\
    $mandir/perlfaq1.1	\
    $mandir/perlfaq2.1	\
    $mandir/perlfaq3.1	\
    $mandir/perlfaq4.1	\
    $mandir/perlfaq5.1	\
    $mandir/perlfaq6.1	\
    $mandir/perlfaq7.1	\
    $mandir/perlfaq8.1	\
    $mandir/perlfaq9.1	\
	\
    $mandir/a2p.1	\
    $mandir/c2ph.1	\
    $mandir/dprofpp.1	\
    $mandir/h2ph.1	\
    $mandir/h2xs.1	\
    $mandir/perlbug.1	\
    $mandir/perldoc.1	\
    $mandir/pl2pm.1	\
    $mandir/pod2html.1	\
    $mandir/pod2man.1	\
    $mandir/s2p.1	\
    $mandir/splain.1	\
    $mandir/xsubpp.1	\
			\
    $libdir/attrs.3	\
    $libdir/autouse.3	\
    $libdir/base.3	\
    $libdir/blib.3	\
    $libdir/constant.3	\
    $libdir/diagnostics.3	\
    $libdir/fields.3	\
    $libdir/filetest.3	\
    $libdir/integer.3	\
    $libdir/less.3	\
    $libdir/lib.3	\
    $libdir/locale.3	\
    $libdir/ops.3	\
    $libdir/overload.3	\
    $libdir/re.3	\
    $libdir/sigtrap.3	\
    $libdir/strict.3	\
    $libdir/subs.3	\
    $libdir/vars.3	\
	\
    $libdir/AnyDBM_File.3	\
    $libdir/AutoLoader.3	\
    $libdir/AutoSplit.3	\
    $libdir/B.3	\
    $libdir/B::Asmdata.3	\
    $libdir/B::Assembler.3	\
    $libdir/B::Bblock.3	\
    $libdir/B::Bytecode.3	\
    $libdir/B::C.3	\
    $libdir/B::CC.3	\
    $libdir/B::Debug.3	\
    $libdir/B::Deparse.3	\
    $libdir/B::Disassembler.3	\
    $libdir/B::Lint.3	\
    $libdir/B::Showlex.3	\
    $libdir/B::Stackobj.3	\
    $libdir/B::Terse.3	\
    $libdir/B::Xref.3	\
    $libdir/Benchmark.3	\
    $libdir/Carp.3	\
    $libdir/CGI.3	\
    $libdir/CGI::Apache.3	\
    $libdir/CGI::Carp.3	\
    $libdir/CGI::Cookie.3	\
    $libdir/CGI::Fast.3	\
    $libdir/CGI::Push.3	\
    $libdir/CGI::Switch.3	\
    $libdir/Class::Struct.3	\
    $libdir/Config.3	\
    $libdir/CPAN.3	\
    $libdir/CPAN::FirstTime.3	\
    $libdir/CPAN::Nox.3	\
    $libdir/Cwd.3	\
    $libdir/Data::Dumper.3	\
    $libdir/DB_File.3	\
    $libdir/Devel::SelfStubber.3	\
    $libdir/DirHandle.3	\
    $libdir/DynaLoader.3	\
    $libdir/Dumpvalue.3	\
    $libdir/English.3	\
    $libdir/Env.3	\
    $libdir/Errno.3	\
    $libdir/Exporter.3	\
    $libdir/ExtUtils::Command.3	\
    $libdir/ExtUtils::Embed.3	\
    $libdir/ExtUtils::Install.3	\
    $libdir/ExtUtils::Installed.3	\
    $libdir/ExtUtils::Liblist.3	\
    $libdir/ExtUtils::MakeMaker.3	\
    $libdir/ExtUtils::Manifest.3	\
    $libdir/ExtUtils::Miniperl.3	\
    $libdir/ExtUtils::Mkbootstrap.3	\
    $libdir/ExtUtils::Mksymlists.3	\
    $libdir/ExtUtils::MM_OS2.3	\
    $libdir/ExtUtils::MM_Unix.3	\
    $libdir/ExtUtils::MM_VMS.3	\
    $libdir/ExtUtils::MM_Win32.3	\
    $libdir/ExtUtils::Packlist.3	\
    $libdir/ExtUtils::testlib.3	\
    $libdir/Fatal.3	\
    $libdir/Fcntl.3	\
    $libdir/File::Basename.3	\
    $libdir/File::CheckTree.3	\
    $libdir/File::Compare.3	\
    $libdir/File::Copy.3	\
    $libdir/File::DosGlob.3	\
    $libdir/File::Find.3	\
    $libdir/File::Path.3	\
    $libdir/File::Spec.3	\
    $libdir/File::Spec::Mac.3	\
    $libdir/File::Spec::OS2.3	\
    $libdir/File::Spec::Unix.3	\
    $libdir/File::Spec::VMS.3	\
    $libdir/File::Spec::Win32.3	\
    $libdir/File::stat.3	\
    $libdir/FileCache.3	\
    $libdir/FileHandle.3	\
    $libdir/FindBin.3	\
    $libdir/GDBM_File.3	\
    $libdir/Getopt::Long.3	\
    $libdir/Getopt::Std.3	\
    $libdir/I18N::Collate.3	\
    $libdir/IO.3 \
    $libdir/IO::File.3 \
    $libdir/IO::Handle.3 \
    $libdir/IO::Pipe.3 \
    $libdir/IO::Seekable.3 \
    $libdir/IO::Select.3 \
    $libdir/IO::Socket.3 \
    $libdir/IPC::Msg.3	\
    $libdir/IPC::Open2.3	\
    $libdir/IPC::Open3.3	\
    $libdir/IPC::Semaphore.3	\
    $libdir/IPC::SysV.3	\
    $libdir/Math::BigFloat.3	\
    $libdir/Math::BigInt.3	\
    $libdir/Math::Complex.3	\
    $libdir/Math::Trig.3	\
    $libdir/NDBM_File.3	\
    $libdir/Net::hostent.3	\
    $libdir/Net::netent.3	\
    $libdir/Net::Ping.3	\
    $libdir/Net::protoent.3	\
    $libdir/Net::servent.3	\
    $libdir/O.3	\
    $libdir/Opcode.3	\
    $libdir/Pod::Html.3	\
    $libdir/Pod::Text.3	\
    $libdir/POSIX.3	\
    $libdir/Safe.3	\
    $libdir/SDBM_File.3	\
    $libdir/Search::Dict.3	\
    $libdir/SelectSaver.3	\
    $libdir/SelfLoader.3	\
    $libdir/Shell.3	\
    $libdir/Socket.3	\
    $libdir/Symbol.3	\
    $libdir/Sys::Hostname.3	\
    $libdir/Sys::Syslog.3	\
    $libdir/Term::Cap.3	\
    $libdir/Term::Complete.3	\
    $libdir/Term::ReadLine.3	\
    $libdir/Test.3	\
    $libdir/Test::Harness.3	\
    $libdir/Text::Abbrev.3	\
    $libdir/Text::ParseWords.3	\
    $libdir/Text::Soundex.3	\
    $libdir/Text::Tabs.3	\
    $libdir/Text::Wrap.3	\
    $libdir/Tie::Array.3	\
    $libdir/Tie::Handle.3	\
    $libdir/Tie::Hash.3	\
    $libdir/Tie::RefHash.3	\
    $libdir/Tie::Scalar.3	\
    $libdir/Tie::SubstrHash.3	\
    $libdir/Time::gmtime.3	\
    $libdir/Time::Local.3	\
    $libdir/Time::localtime.3	\
    $libdir/Time::tm.3		\
    $libdir/UNIVERSAL.3		\
    $libdir/User::grent.3		\
    $libdir/User::pwent.3 | \
    perl -ne 'map { -r && print "$_ " } split'`

    # Bypass internal shell buffer limit -- can't use case
    if perl -e '$a = shift; exit($a =~ m|/|)' $toroff; then
	echo "$me: empty file list -- did you run install?" >&2
	exit 1
    fi

    #psroff -t -man -rC1 -rD1 -rF1 > $tmp/PerlDoc.ps 2>$tmp/PerlTOC.raw
    #nroff -man -rC1 -rD1 -rF1 > $tmp/PerlDoc.txt 2>$tmp/PerlTOC.nr.raw

    # First, create the raw data
    run="$cmd -rC1 -rD1 -rF1 >$tmp/PerlDoc.$ext 2>$tmp/PerlTOC.$ext.raw"
    echo "$me: running $run"
    eval $run $toroff

    #Now create the TOC
    echo "$me: parsing TOC"
    ./rofftoc $tmp/PerlTOC.$ext.raw > $tmp/PerlTOC.tmp.man
    run="$cmd $tmp/PerlTOC.tmp.man >$tmp/PerlTOC.$ext"
    echo "$me: running $run"
    eval $run

    # Finally, recreate the Doc, without the blank page 0
    run="$cmd -rC1 -rD1 >$tmp/PerlDoc.$ext 2>$tmp/PerlTOC.$ext.raw"
    echo "$me: running $run"
    eval $run $toroff
    rm -f $tmp/PerlTOC.tmp.man $tmp/PerlTOC.$ext.raw
    echo "$me: leaving you with $tmp/PerlDoc.$ext and $tmp/PerlTOC.$ext"

