#!/usr/bin/perl -w 
# -*-cperl-*-
## Filename: ucsdoc
## Modified: Fri Mar  5 14:37:38 2004 (evert)   
##   Author: Stefan Evert
##  Purpose: wrapper around perldoc which adds the required include paths

use UCS;
use Pod::Perldoc;

if ((grep {$_ eq "-h" or $_ eq "--help"} @ARGV) or (@ARGV == 0)) {
  die "Usage:  ucsdoc [-tk|-ps|-t] [options] PageName | ModuleName | ProgramName\n"
    . "(type \"ucsdoc ucsdoc\" for more information)\n";
}

# select perldoc formatter if -tk / -ps / -t was specified
@formatter = ();
@ARGV = grep { not(/^--?(tk|ps|t)$/i and push @formatter, lc($1)) } @ARGV;
die "Error:  you may specify only one of -tk, -ps, and -t!\n"
  if @formatter > 1;
if (@formatter) {
  if ($formatter[0] eq "t") {			# -t
    unshift @ARGV, "-t";
  }
  elsif ($formatter[0] eq "tk") {		# -tk
    unshift @ARGV, "-o", "tk";
  }
  else {					# -ps
    unshift @ARGV, "-n", "groff -man -Tps", "-w", "center=UCS/Perl Documentation";
  }
}

# modify @INC to include UCS/Perl module library
$lc_libdir = $libdir = $UCS::PerlDir."/lib";	# path to UCS/Perl module library
$lc_libdir =~ s/Perl/perl/g; # use System/perl/lib/ so that perldoc recognises & strips the library path
@INC = grep {$_ ne $libdir} @INC;
unshift @INC, $lc_libdir;

# modify PATH environment variable to include UCS programs
$p5bin = (exists $ENV{PATH}) ? ":".$ENV{PATH} : ""; 
$ENV{PATH} = $UCS::PerlDir."/bin".$p5bin;

# now run perldoc (with command-line arguments passed to ucsdoc)
exit( Pod::Perldoc->run() )



__END__

=head1 NAME

ucsdoc - UCS front-end to perldoc


=head1 SYNOPSIS

  ucsdoc [-tk|-ps|-t] [options] PageName | ModuleName | ProgramName


=head1 DESCRIPTION

B<ucsdoc> is a front-end to the B<perldoc> program, which sets the
required library paths for the UCS/Perl manpages. Standard Perl
documentation is available through B<ucsdoc> as well.

With the C<-t> option, the manpage is formatted in plain ASCII, 
without highlighting.

With the C<-ps> option, the manpage is formatted in PostScript for printing.
The PostScript code is displayed on stdout so that it can be re-directed into
a file or piped into a print command.

With the C<-tk> option, the manpage is displayed in a Perl/Tk window,
provided that the B<Tk> and B<Tk::Pod> modules are installed.

Only one of the three formatting options may be specified.

All other command-line arguments are passed to the B<perldoc> program.  Type
C<perldoc -h> and C<perldoc perldoc> for more information on the available
options.


=head1 COPYRIGHT

Copyright 2004 Stefan Evert.

This software is provided AS IS and the author makes no warranty as to
its use and performance. You may use the software, redistribute and
modify it under the same terms as Perl itself.

=cut
