diff options
author | Yorhel <git@yorhel.nl> | 2020-10-16 12:23:38 +0200 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2020-10-16 12:23:41 +0200 |
commit | eecc8e798cc89cdb5ba884efdbe87b5dd587d207 (patch) | |
tree | 6f1164dbeb95c00d67e704262d54260f10ce687d | |
parent | 2ee9a5b6b0e0f82b8a326e5fc5afdb6f0693b0b5 (diff) |
Workaround grog using -ms for pod2man generated sources
When I have time I'll do a search for man pages that actually *need*
-ms, as I'm getting the impression that it's never used for man pages
and all of grog's guesses for it are wrong.
-rw-r--r-- | lib/ManUtils/ManUtils.pm | 54 |
1 files changed, 32 insertions, 22 deletions
diff --git a/lib/ManUtils/ManUtils.pm b/lib/ManUtils/ManUtils.pm index 84f573b..a325d17 100644 --- a/lib/ManUtils/ManUtils.pm +++ b/lib/ManUtils/ManUtils.pm @@ -13,6 +13,33 @@ require XSLoader; XSLoader::load('ManUtils', $VERSION); +sub _groff { + my($input, $output, $errors, $cv, @cmd) = @_; + + # $MANWIDTH works by using the following groff options: -rLL=100n -rLT=100n + splice @cmd, 1, 0, qw|-Tutf8 -DUTF-8 -P-c -rLL=80n -rLT=80n|; + + $input = + # Disable hyphenation, since that screws up man page references. :-( + ".hy 0\n.de hy\n..\n" + # Emulate man-db's --nj option + .".na\n.de ad\n..\n" + .$input; + + my $groff = run_cmd \@cmd, + '<' => \$input, + '>' => \my $fmt, + '2>' => sub { if($_[0]) { chomp(my $e = $_[0]); push @$errors, "groff: $e" } }; + + $groff->cb(sub { + $$output = $fmt ? decode_utf8($fmt) : ''; + $$output =~ s/[\t\s\r\n]+$//; + $cv->send; + }); + $cv +} + + # Usage: $cv = fmt($input, \$output, \@errors) # $cv = AnyEvent condition variable, fired when done. # $input = UTF-8 encoded manual page source @@ -26,9 +53,11 @@ sub fmt { $input = encode_utf8($input); + # grog has a tendency to recognize pod2man generated pages as -ms, let's just work around that by enforcing -man + return _groff $input, $output, $errors, $cv, 'groff', '-man' if $input =~ /^.\\" Automatically generated by Pod::Man/; + # Call grog to figure out which preprocessors to use. - # $MANWIDTH works by using the following groff options: -rLL=100n -rLT=100n - my $grog = run_cmd [qw|grog -Tutf8 -P-c -DUTF-8 -rLL=80n -rLT=80n -|], + my $grog = run_cmd [qw|grog -Tutf8 -DUTF-8 -|], '<' => \$input, '>' => \my $cmd, '2>' => sub { $_[0] && push @$errors, "grog: $_[0]" }; @@ -60,26 +89,7 @@ sub fmt { push @$errors, "grog detected several macro packages: $double. Using $macros. (@cmd)"; } - # grog 1.22.3 somehow loses the -P-c argument, let's make sure it's in the list. - splice @cmd, 1, 0, '-P-c'; - - $input = - # Disable hyphenation, since that screws up man page references. :-( - ".hy 0\n.de hy\n..\n" - # Emulate man-db's --nj option - .".na\n.de ad\n..\n" - .$input; - - my $groff = run_cmd \@cmd, - '<' => \$input, - '>' => \my $fmt, - '2>' => sub { if($_[0]) { chomp(my $e = $_[0]); push @$errors, "groff: $e" } }; - - $groff->cb(sub { - $$output = $fmt ? decode_utf8($fmt) : ''; - $$output =~ s/[\t\s\r\n]+$//; - $cv->send; - }); + _groff $input, $output, $errors, $cv, @cmd; }); $cv; |