Mercurial > octave
changeset 24955:005120381e78 stable
maint: rename mk-qthelp.pl for consistency with other build scripts
* doc/interpreter/mk-qthelp.pl: Rename from mk_qthelp.pl. Strip trailing
whitespace.
* doc/interpreter/module.mk: Update references to script name.
author | Mike Miller <mtmiller@octave.org> |
---|---|
date | Wed, 21 Mar 2018 14:50:08 -0700 |
parents | a600838cb1c9 |
children | 1a5ae7526c1e |
files | doc/interpreter/mk-qthelp.pl doc/interpreter/mk_qthelp.pl doc/interpreter/module.mk |
diffstat | 3 files changed, 198 insertions(+), 198 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/doc/interpreter/mk-qthelp.pl Wed Mar 21 14:50:08 2018 -0700 @@ -0,0 +1,195 @@ +#!/usr/bin/env perl + +################################################################################ +# File : mk-qthelp.pl +# Purpose : Transform Octave HTML documentation into intermediate formats +# for Qt Help Project (.qhp) and Qt Help Collection Project (.qhcp). +# Usage : mk-qthelp.pl input_htmldir output_filename +################################################################################ +use warnings; # report warnings for questionable run-time code +use strict qw(refs subs); # check at compile-time for bad programming style +use File::Basename; # For splitting paths between dir and file +use File::Spec; # For combining dirs and filenames into paths + +################################################################################ +# Extract command line arguments +if ($#ARGV != 1) +{ die "USAGE: %0 input_htmldir output_filename"; } + +$htmldir = basename ($ARGV[0]); +$basedir = File::Spec->rel2abs (dirname ($ARGV[1])); +$fname = File::Spec->catfile ($basedir, basename ($ARGV[1])); + +################################################################################ +# Parse index.html to retrieve the table of contents +$htmlfname = File::Spec->catfile ($basedir, $htmldir, "index.html"); +open (my $HTML, "<", $htmlfname) or die "Unable to open $htmlfname"; + +# Skip through preamble of file to find start of list +while (($_ = <$HTML>) !~ /^<div class="contents">/ ) {;} +while (($_ = <$HTML>) !~ /^<ul class="no-bullet">/ ) {;} + +$level = 0; +while (<$HTML>) +{ + if (/^\s*<li>/) + { + ($href, $text) = m|href="([^"]*)">(.*)</a>|; + # Sanitize text + $text =~ s/<[^>]*>//g; # remove xml-looking blocks like <code> + $text =~ s/’/’/g; # Code for apostrophe + + push (@toc, { "href" => $href, "text" => $text, + "level" => $level, "sectionstart" => 0 }); + } + elsif (/^\s+<ul /) + { + $level++; + # Get last node and amend it to have a section start + %node = %{ $toc[-1] }; + $node{sectionstart} = 1; + $toc[-1] = { %node }; + } + elsif (m|^\s+</ul>|) + { $level--; } + elsif (m|^</ul>$|) + { last; } + else + { die "error:unrecognized input:$htmlfname:$.:$_"; } +} + +close ($HTML); + +die "Failed to parse index.html" if ($level != 0); + +################################################################################ +# Parse Function-Index.html to retrieve the function reference +$htmlfname = File::Spec->catfile ($basedir, $htmldir, "Function-Index.html"); +open ($HTML, "<", $htmlfname) or die "Unable to open $htmlfname"; + +# Skip through preamble of file to find start of list +while (($_ = <$HTML>) !~ /^<table class="index-fn/ ) {;} + +while (<$HTML>) +{ + if (m|<a href="([^"]*)"><code>(.*)</code>|) + { + $href = $1, $name = $2; + # Keep only the first link for each entry + if (! $kword{$name}) + { $kword{$name} = $href; } + } + elsif (m|^</table>$|) + { last; } +} + +close ($HTML); + +die "Failed to parse Function-Index.html" if (! m|^</table>$|); + +################################################################################ +# Prepare Qt Help Project document (.qhp file) +open (my $FH, ">", "$fname.qhp") or die "Unable to open $fname.qhcp"; + +$htmlfname = File::Spec->catfile ($htmldir, "index.html"); + +# Add header to file +print $FH <<__EOT1__; +<?xml version="1.0" encoding="UTF-8"?> +<!--DO NOT EDIT! Generated automatically by $0--> +<QtHelpProject version="1.0"> + <namespace>org.octave.interpreter-1.0</namespace> + <virtualFolder>doc</virtualFolder> + <customFilter name="Octave Manual"> + <filterAttribute>core</filterAttribute> + <filterAttribute>manual</filterAttribute> + </customFilter> + <customFilter name="Octave C++ API"> + <filterAttribute>core</filterAttribute> + <filterAttribute>cpp</filterAttribute> + </customFilter> + <filterSection> + <filterAttribute>core</filterAttribute> + <filterAttribute>manual</filterAttribute> + <toc> + <section title="GNU Octave Manual" ref="$htmlfname"> +__EOT1__ + +# Print out an XML block for each TOC section +$level = 0; +$indent = 4; +foreach $hashref (@toc) +{ + %node = %{$hashref}; + while ($node{level} < $level) + { + # Unindent and close section + $level--; + print $FH " " x ($indent + $level); + print $FH "</section>\n"; + } + $level = $node{level}; + + print $FH " " x ($indent + $node{level}); + print $FH qq|<section title="$node{text}" |; + print $FH qq|ref="|, File::Spec->catfile ($htmldir, $node{href}); + print $FH ($node{sectionstart} ? qq|">\n| : qq|"/>\n|); +} + +# Spacer between TOC and Keywords +print $FH <<__EOT2__; + </section> + </toc> + <keywords> +__EOT2__ + +# Print out sorted keywords +foreach $kw (sort {lc($a) cmp lc($b)} (keys (%kword))) +{ + print $FH qq| <keyword name="$kw" id="$kw" |; + print $FH qq|ref="|, File::Spec->catfile ($htmldir, $kword{$kw}), qq|"/>\n|; +} + +# Footer of file +$htmlfiles = File::Spec->catfile ($htmldir, "*.html"); +$pngfiles = File::Spec->catfile ($htmldir, "*.png"); +$cssfiles = File::Spec->catfile ($htmldir, "*.css"); +print $FH <<__EOT3__; + </keywords> + <files> + <file>$htmlfiles</file> + <file>$pngfiles</file> + <file>$cssfiles</file> + </files> + </filterSection> +</QtHelpProject> +__EOT3__ + +close ($FH); + +################################################################################ +# Prepare Qt Help Collection Project document (.qhcp file) +open ($FH, ">", "$fname.qhcp") or die "Unable to open $fname.qhcp"; + +$qhpfile = basename ($fname) . ".qhp"; +$qchfile = basename ($fname) . ".qch"; + +# This is the entire file +print $FH <<__EOT4__; +<?xml version="1.0" encoding="UTF-8"?> +<!--DO NOT EDIT! Generated automatically by $0--> +<QHelpCollectionProject version="1.0"> + <docFiles> + <generate> + <file> + <input>$qhpfile</input> + <output>$qchfile</output> + </file> + </generate> + <register> + <file>$qchfile</file> + </register> + </docFiles> +</QHelpCollectionProject> +__EOT4__ +
--- a/doc/interpreter/mk_qthelp.pl Wed Mar 21 14:47:58 2018 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,195 +0,0 @@ -#!/usr/bin/env perl - -################################################################################ -# File : mk_qthelp.pl -# Purpose : Transform Octave HTML documentation into intermediate formats -# for Qt Help Project (.qhp) and Qt Help Collection Project (.qhcp). -# Usage : mk_qthelp.pl input_htmldir output_filename -################################################################################ -use warnings; # report warnings for questionable run-time code -use strict qw(refs subs); # check at compile-time for bad programming style -use File::Basename; # For splitting paths between dir and file -use File::Spec; # For combining dirs and filenames into paths - -################################################################################ -# Extract command line arguments -if ($#ARGV != 1) -{ die "USAGE: %0 input_htmldir output_filename"; } - -$htmldir = basename ($ARGV[0]); -$basedir = File::Spec->rel2abs (dirname ($ARGV[1])); -$fname = File::Spec->catfile ($basedir, basename ($ARGV[1])); - -################################################################################ -# Parse index.html to retrieve the table of contents -$htmlfname = File::Spec->catfile ($basedir, $htmldir, "index.html"); -open (my $HTML, "<", $htmlfname) or die "Unable to open $htmlfname"; - -# Skip through preamble of file to find start of list -while (($_ = <$HTML>) !~ /^<div class="contents">/ ) {;} -while (($_ = <$HTML>) !~ /^<ul class="no-bullet">/ ) {;} - -$level = 0; -while (<$HTML>) -{ - if (/^\s*<li>/) - { - ($href, $text) = m|href="([^"]*)">(.*)</a>|; - # Sanitize text - $text =~ s/<[^>]*>//g; # remove xml-looking blocks like <code> - $text =~ s/’/’/g; # Code for apostrophe - - push (@toc, { "href" => $href, "text" => $text, - "level" => $level, "sectionstart" => 0 }); - } - elsif (/^\s+<ul /) - { - $level++; - # Get last node and amend it to have a section start - %node = %{ $toc[-1] }; - $node{sectionstart} = 1; - $toc[-1] = { %node }; - } - elsif (m|^\s+</ul>|) - { $level--; } - elsif (m|^</ul>$|) - { last; } - else - { die "error:unrecognized input:$htmlfname:$.:$_"; } -} - -close ($HTML); - -die "Failed to parse index.html" if ($level != 0); - -################################################################################ -# Parse Function-Index.html to retrieve the function reference -$htmlfname = File::Spec->catfile ($basedir, $htmldir, "Function-Index.html"); -open ($HTML, "<", $htmlfname) or die "Unable to open $htmlfname"; - -# Skip through preamble of file to find start of list -while (($_ = <$HTML>) !~ /^<table class="index-fn/ ) {;} - -while (<$HTML>) -{ - if (m|<a href="([^"]*)"><code>(.*)</code>|) - { - $href = $1, $name = $2; - # Keep only the first link for each entry - if (! $kword{$name}) - { $kword{$name} = $href; } - } - elsif (m|^</table>$|) - { last; } -} - -close ($HTML); - -die "Failed to parse Function-Index.html" if (! m|^</table>$|); - -################################################################################ -# Prepare Qt Help Project document (.qhp file) -open (my $FH, ">", "$fname.qhp") or die "Unable to open $fname.qhcp"; - -$htmlfname = File::Spec->catfile ($htmldir, "index.html"); - -# Add header to file -print $FH <<__EOT1__; -<?xml version="1.0" encoding="UTF-8"?> -<!--DO NOT EDIT! Generated automatically by $0--> -<QtHelpProject version="1.0"> - <namespace>org.octave.interpreter-1.0</namespace> - <virtualFolder>doc</virtualFolder> - <customFilter name="Octave Manual"> - <filterAttribute>core</filterAttribute> - <filterAttribute>manual</filterAttribute> - </customFilter> - <customFilter name="Octave C++ API"> - <filterAttribute>core</filterAttribute> - <filterAttribute>cpp</filterAttribute> - </customFilter> - <filterSection> - <filterAttribute>core</filterAttribute> - <filterAttribute>manual</filterAttribute> - <toc> - <section title="GNU Octave Manual" ref="$htmlfname"> -__EOT1__ - -# Print out an XML block for each TOC section -$level = 0; -$indent = 4; -foreach $hashref (@toc) -{ - %node = %{$hashref}; - while ($node{level} < $level) - { - # Unindent and close section - $level--; - print $FH " " x ($indent + $level); - print $FH "</section>\n"; - } - $level = $node{level}; - - print $FH " " x ($indent + $node{level}); - print $FH qq|<section title="$node{text}" |; - print $FH qq|ref="|, File::Spec->catfile ($htmldir, $node{href}); - print $FH ($node{sectionstart} ? qq|">\n| : qq|"/>\n|); -} - -# Spacer between TOC and Keywords -print $FH <<__EOT2__; - </section> - </toc> - <keywords> -__EOT2__ - -# Print out sorted keywords -foreach $kw (sort {lc($a) cmp lc($b)} (keys (%kword))) -{ - print $FH qq| <keyword name="$kw" id="$kw" |; - print $FH qq|ref="|, File::Spec->catfile ($htmldir, $kword{$kw}), qq|"/>\n|; -} - -# Footer of file -$htmlfiles = File::Spec->catfile ($htmldir, "*.html"); -$pngfiles = File::Spec->catfile ($htmldir, "*.png"); -$cssfiles = File::Spec->catfile ($htmldir, "*.css"); -print $FH <<__EOT3__; - </keywords> - <files> - <file>$htmlfiles</file> - <file>$pngfiles</file> - <file>$cssfiles</file> - </files> - </filterSection> -</QtHelpProject> -__EOT3__ - -close ($FH); - -################################################################################ -# Prepare Qt Help Collection Project document (.qhcp file) -open ($FH, ">", "$fname.qhcp") or die "Unable to open $fname.qhcp"; - -$qhpfile = basename ($fname) . ".qhp"; -$qchfile = basename ($fname) . ".qch"; - -# This is the entire file -print $FH <<__EOT4__; -<?xml version="1.0" encoding="UTF-8"?> -<!--DO NOT EDIT! Generated automatically by $0--> -<QHelpCollectionProject version="1.0"> - <docFiles> - <generate> - <file> - <input>$qhpfile</input> - <output>$qchfile</output> - </file> - </generate> - <register> - <file>$qchfile</file> - </register> - </docFiles> -</QHelpCollectionProject> -__EOT4__ -
--- a/doc/interpreter/module.mk Wed Mar 21 14:47:58 2018 -0700 +++ b/doc/interpreter/module.mk Wed Mar 21 14:50:08 2018 -0700 @@ -204,9 +204,9 @@ octdoc_DATA += \ $(OCTAVE_QTHELP_FILES) -$(OCTAVE_QTHELP_FILES): $(OCTAVE_HTML_STAMP) $(srcdir)/%reldir%/mk_qthelp.pl +$(OCTAVE_QTHELP_FILES): $(OCTAVE_HTML_STAMP) %reldir%/mk-qthelp.pl $(AM_V_GEN)rm -f $(OCTAVE_QTHELP_FILES) && \ - $(PERL) $(srcdir)/%reldir%/mk_qthelp.pl octave.html %reldir%/octave_interpreter && \ + $(PERL) $(srcdir)/%reldir%/mk-qthelp.pl octave.html %reldir%/octave_interpreter && \ $(QCOLLECTIONGENERATOR) $(QCOLLECTIONGENERATORFLAGS) %reldir%/octave_interpreter.qhcp -o %reldir%/octave_interpreter.qhc >/dev/null && \ rm -f %reldir%/octave_interpreter.qhcp %reldir%/octave_interpreter.qhp @@ -356,7 +356,7 @@ %reldir%/images.mk \ %reldir%/macros.texi \ %reldir%/mk-doc-cache.pl \ - %reldir%/mk_qthelp.pl \ + %reldir%/mk-qthelp.pl \ %reldir%/mkcontrib.awk \ %reldir%/munge-texi.pl \ $(DOC_IMAGES) \