#!/usr/bin/perl -sw

$pod_dir = './';      # directory where core pod files are
@extra_pods = ('/usr/lib/perl5/5.00503/pod',
               '/usr/lib/perl5/site_perl/5.005/i386-linux',
               '/usr/lib/perl5/site_perl/5.005',
               '/usr/lib/perl5/5.00503/i386-linux'
               );     # directories where other pod files are

#
# copyright 1998 $Bill Luebkert - you may use/modify freely
#
# make perl manual from pods into single text file
# Usage: perl perlman.pl >perl.man
#

$| = 1;

print <<EOD and exit 0 if $h or $help;

Usage: $0 [-s] [<pod-dir>] >perl.man
   -s      silent (no progress lines)
   pod-dir      optional directory in which to find pod files

Combines all of the Perl man pages into a single file for searching
and reference.  Should generate a lot of format errors.

EOD

# core sections

%sections = (
  "01perl" => "Perl overview (this section)",
  "02perldelta" => "Perl changes since previous version",
  "03perl5004delta" => "Perl changes in version 5.004",
  "04perlfaq" => "Perl frequently asked questions",
  "05perldata" => "Perl data structures",
  "06perlsyn" => "Perl syntax",
  "07perlop" => "Perl operators and precedence",
  "08perlre" => "Perl regular expressions",
  "09perlrun" => "Perl execution and options",
  "10perlfunc" => "Perl builtin functions",
  "11perlopentut" => "Perl open() tutorial",
  "12perlvar" => "Perl predefined variables",
  "13perlsub" => "Perl subroutines",
  "14perlmod" => "Perl modules: how they work",
  "15perlmodlib" => "Perl modules: how to write and use",
  "16perlmodinstall" => "Perl modules: how to install from CPAN",
  "17perlform" => "Perl formats",
  "18perllocale" => "Perl locale support",
  "19perlref" => "Perl references",
  "20perlreftut" => "Perl references short introduction",
  "21perldsc" => "Perl data structures intro",
  "22perllol" => "Perl data structures: lists of lists",
  "23perltoot" => "Perl OO tutorial",
  "24perlobj" => "Perl objects",
  "25perltie" => "Perl objects hidden behind simple variables",
  "26perlbot" => "Perl OO tricks and examples",
  "27perlipc" => "Perl interprocess communication",
  "28perlthrtut" => "Perl threads tutorial",
  "29perldebug" => "Perl debugging",
  "30perldiag" => "Perl diagnostic messages",
  "31perlsec" => "Perl security",
  "32perltrap" => "Perl traps for the unwary",
  "33perlport" => "Perl portability guide",
  "34perlstyle" => "Perl style guide",
  "35perlpod" => "Perl plain old documentation",
  "36perlbook" => "Perl book information",
  "37perlembed" => "Perl ways to embed perl in your C or C++ application",
  "38perlapio" => "Perl internal IO abstraction interface",
  "39perlxs" => "Perl XS application programming interface",
  "40perlxstut" => "Perl XS tutorial",
  "41perlguts" => "Perl internal functions for those doing extensions",
  "42perlcall" => "Perl calling conventions from C",
  "43perlhist" => "Perl history records",
  "44perlwin32" => "Perl under Win32",
  "45Win32" => "Interfaces to some Win32 API functions",
  "46perlfaq1" => "Perl frequently asked questions 1",
  "47perlfaq2" => "Perl frequently asked questions 2",
  "48perlfaq3" => "Perl frequently asked questions 3",
  "49perlfaq4" => "Perl frequently asked questions 4",
  "50perlfaq5" => "Perl frequently asked questions 5",
  "51perlfaq6" => "Perl frequently asked questions 6",
  "52perlfaq7" => "Perl frequently asked questions 7",
  "53perlfaq8" => "Perl frequently asked questions 8",
  "54perlfaq9" => "Perl frequently asked questions 9",
  "55perltoc" => "Perl documentation table of contents",
);

&main;

exit 0;

#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

sub main {
   my ($ii, $key);
   my ($sect_hdr) = "\tSection of Perl Manual";
   use Pod::Text;

opendir DIR, $pod_dir or die "Error on opendir $pod_dir: $!\n";
while (defined ($_ = readdir DIR)) {
   next if !/\.pod/;
   s/\.pod$//io;
   $pods{$_} = 1;
}
closedir DIR;

# get the core sections in order

foreach $key (sort keys %sections) {

   $key =~ /^(\d{2})(.*)$/;
   $ii = $1; $section = $2;
   print STDERR "$ii: $section\n" if !$s;

   if (not (exists $pods{$section})) {
      print STDERR "$ii: $section section missing\n";
      next;
   }

   print "$section $sect_hdr\n\n";
   &pod2text ("-80", "$pod_dir/$section.pod");
   delete $pods{$section};
}

# handle any extra sections

foreach $key (sort keys %pods) {

   print STDERR "$ii: $pods{$key}\n" if !$s;
   print "$key Section\n\n";
   &pod2text ("-80", "$pod_dir/$key.pod");
   $ii++;
}

# handle any extra directories of pods

foreach $dir (@extra_pods) {

   opendir DIR, $dir or die "Error on opendir $dir: $!\n";
   while (defined ($_ = readdir DIR)) {

      next if !/\.pod/;
      s/\.pod$//io;
      print STDERR "$ii: $_ extra section\n" if !$s;
      print "$_ section\n\n";
      &pod2text ("-80", "$dir/$_.pod");
      $ii++;
   }
   closedir DIR;

}

}

#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

1 if ($s or $h or $help);   # single refs

__END__