diff options
author | Yorhel <git@yorhel.nl> | 2012-07-11 14:29:15 +0200 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2012-07-11 14:29:15 +0200 |
commit | 147e76d405d89ae494d4f52b54d85b021fb92a50 (patch) | |
tree | f7cf2237489333ccbd3c456618f8ef07d0c957bf /lib | |
parent | eb3e6cf9299abac88d3a0de09f289e30c66ca851 (diff) |
ManUtils: Fix render issues when grog detects multiple macro packages
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ManUtils/ManUtils.pm | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/lib/ManUtils/ManUtils.pm b/lib/ManUtils/ManUtils.pm index 660829c..e222343 100644 --- a/lib/ManUtils/ManUtils.pm +++ b/lib/ManUtils/ManUtils.pm @@ -52,10 +52,29 @@ sub fmt { return; } - my $groff = run_cmd [split / /, $cmd], + my $double; + @$errors = grep { + chomp; + s/^grog: grog: /grog: /; + !$double && /there are several macro packages: (.+)$/ ? ($double = $1) && 0 : 1; + } @$errors; + + my @cmd = split / /, $cmd; + if($double) { + my %double = map +($_,1), split / /, $double; + # Use the first macro package in ASCIIbetical order. (This is somewhat + # arbitrary, need to find a better conflict resolution method). + my $macros = (sort keys %double)[0]; + # Replace macro arguments with our selected one. + @cmd = grep !$double{$_}, @cmd; + @cmd = (@cmd[0..$#cmd-1], $macros, $cmd[$#cmd]); + push @$errors, "grog detected several macro packages: $double. Using $macros. (@cmd)"; + } + + my $groff = run_cmd \@cmd, '<' => \$input, '>' => \my $fmt, - '2>' => sub { $_[0] && push @$errors, "groff: $_[0]" }; + '2>' => sub { if($_[0]) { chomp(my $e = $_[0]); push @$errors, "groff: $e" } }; $groff->cb(sub { $$output = $fmt ? decode_utf8($fmt) : ''; @@ -74,7 +93,7 @@ sub fmt_block { my $c = shift; my $cv = fmt $c, \my $out, \my @err; $cv->recv; - warn $_ for @err; + warn "$_\n" for @err; $out; } |