    eval 'exec perl -S $0 "$@"'
        if 0;
#
# pod2hlb 1-MAY-1999 pvhp@best.com
#

=head1 NAME

pod2hlb - pod library to VMS help library converter.

=head1 SYNOPSIS

    edit pod2hlb.
    perl pod2hlb

=head1 DESCRIPTION

This is an extremely simple program that merely
converts the PERL_ROOT:[lib.pod]*.pod,*.pm files into
*.hlp files using the Pod::Hlp module.  It then 
adds all the resultant .hlp files to a PERL.HLB 
library in the DEFAULT directory.  You are strongly
encouraged to modify the code to suit your personal
preferences and/or local pod locations.

Since this program invokes the LIBRARIAN it
is unlikely to work on non-VMS systems.  For that
reason is uses RMS style file specifications internally.

=head2 Installation

The resultant *.HLP files could be added directly to the
system default help file (usually SYS$HELP:HELPLIB.HLB).
Alternatively, you may retain PERL.HLB as a separate 
library and install it via either copying to SYS$HELP 
and invoking help via:

    HELP/LIBRARY=PERL

or by defining a HLP$LIBRARY logical name such as one 
of the following:

    define HLP$LIBRARY PERL_ROOT:[lib.pod]perl

or, if HLP$LIBRARY is already defined add an underscore 
and integer _n such as:

    define HLP$LIBRARY_1 PERL_ROOT:[lib.pod]perl

see HELP HELP and HELP LIBRARY for further details.

=head1 AUTHOR

Copyright (c) 1999 Peter Prymmer.  This program
may be used under the same terms as Perl.
Peter Prymmer pvhp@best.com 1-MAY-1999.
First released with Pod2Hlp1.00 Aug 19 1996.

=cut

use Pod::Hlp;  # this module should be in perl_root:[lib.pod]Hlp.pm

my(@podlib,$hlp_file);

#
# You might want to add or remove files from the @podlib list.
# You might want to wander through @INC looking for pod files.
# Beware that not all *.pm files contain pod, and some files
# that contain pod are not .pm type (e.g. README.vms - on the 
# other hand you might not want README.vms in your PERL.HLB, 
# you'd probably do well to have perlvms.pod converted and in 
# PERL.HLB though).
#

@podlib = <perl_root:[lib.pod]*.pod>;
push(@podlib,<perl_root:[lib.pod]*.pm>);

#
# If you want to experiment before actually building PERL.HLB,
# then ncomment the next two statements:
#

#print join("\n",@podlib,"");
#exit;

system("library/create/help", "perl.hlb");
for (@podlib) { 
    $hlp_file = &pod2hlp($_);
    print "$hlp_file\n";
    system("library/help/replace", "perl.hlb", "$hlp_file");
}

sub pod2hlp {

    my($infile, $tmp, $pod, $hlp_level);
    $tmp = $infile = $_[0];
#
# Note the following regexp may need modification if you've added
# to @podlib
#
    $tmp =~ s/perl\_root\:\[lib\.pod\]//;
    $tmp =~ s/\..*//i;
    $pod = $tmp;
    $tmp = $tmp . ".hlp";

    if ($_[1]) { $hlp_level = $_[1]; } else { $hlp_level = '1'; }

    open(TMP,">$tmp");
    print TMP "$hlp_level $pod\n$pod\n";
    Pod::Hlp::pod2hlp($infile,$hlp_level,*TMP);
    close(TMP);

    # print "output is in file $tmp\n";
    return $tmp;
}
