########################################################################## # HelpDocupdate.pl # # # # Update the new style Windows Help that is distributed with ActiverPerl # # # # Requires: Windows, MS HTML Help WorkShop, ActivePerl build 630 or # # higher # # # # Author: Simon Flack, perl@simonflack.com # # Version: 0.1 21 December 2001 # ########################################################################## use strict; use File::Find; use Config; my $HTML_Compiler = Win32::GetShortPathName('c:\Program Files\HTML Help Workshop\HHC.EXE'); my $OutFilenames = "ActivePerl"; #---------------------------------------------------------- # Main #---------------------------------------------------------- my @perl_help_files; my %perl_help_docs; my $perl_prefix = $Config{installprefix}; # Find all the Activeperl html files... find(\&AddHTMLFiles, $Config{installhtmldir}); # Write the Help Project File MakeHHP("$Config{installhtmldir}/$OutFilenames.hhp", @perl_help_files); # Write the Table of Contents MakeHHC("$Config{installhtmldir}/$OutFilenames.hhc", \%perl_help_docs); # Compile the project MakeHelp("$Config{installhtmldir}/$OutFilenames.hhp"); #---------------------------------------------------------- # Subroutines #---------------------------------------------------------- sub AddHTMLFiles { # This is the File::Find callback. # Adds to an array of files, and builds a hash for the module docs next unless $File::Find::name =~ /\.html?$/i; (my $file = $File::Find::name) =~ s[/][\\]g; push @perl_help_files, $file; #return unless it's @INC (lib, site\lib, etc) $file =~ s#^\Q$Config{installhtmldir}\E\\?##; return unless $file =~ /^(lib\\site|lib|site\\lib)\\(.*)/i; my $module_doc_path = $2 or return; my $module_root = $1; my @module_doc_path_split = split /\\/, "modules\\$module_doc_path"; shift @module_doc_path_split; PopulateHashTree(\%perl_help_docs, $module_root, @module_doc_path_split); } sub PopulateHashTree { my ($hash_ref, $mod_root, @path) = @_; # This is really dirty, will fix... # Just populates a hash, it should be a recursive func probably. my $dirty_eval = '%{$hash_ref}'; my $page = $path[-1]; my $full_path = join '\\', $Config{installhtmldir}, $mod_root, @path; $path[-1] =~ s[\.html?$][]i; $dirty_eval .= qq[->{'$_'}] foreach @path; $dirty_eval .= qq[ = '$full_path']; eval $dirty_eval; } sub MakeHelp { my $project_file = shift; print "Writing Help File... $perl_prefix\\Docs\\$OutFilenames.chm...\n"; system ($HTML_Compiler, $project_file) == 0 or die "There were errors compiling the Help file"; } sub MakeHHP { # Generate the Help Project File my ($output_file, @doc_files) = @_; print "Writing Project File: $output_file...\n"; my $hhp = <", $output_file or die "can't write Project file"; print HPP $hhp; close HPP; } sub MakeHHC { my ($hhc_file, $perl_docs) = @_; print "Building Table of Contents: $hhc_file...\n"; ########################################################### # ActiveState Documentation ########################################################### my $contents = <