3 # Post-process the translated texinfo page to add the correct path for
4 # install-info, and to correct the alignment of the main menu.
8 use open qw(:std :utf8); # assume utf8 encoding
11 $Text::Wrap::columns = 72;
14 if (@ARGV and $ARGV[0] =~ /^-o(.*)/)
17 my $out = $1 || shift || die "$0: missing output file\n";
18 open OUT, '>', $out or die "$0: can't open $out ($!)\n";
22 my $encoding = 'none';
26 $/ = ''; # read paragraphs
29 if (!$lang and /^This is help2man-(.*)\.info\b/)
35 if (!$fixed{menu} and $last =~ /^\* Menu:\n*$/)
41 if (/^\* (.*)::\s+(.*)/)
44 push @entries, [$w, $1, $2];
45 # Stash the largest width (within limits) to use when
46 # calculating the indent.
47 $width = $w if $w > $width and $w < 40;
51 # Append to previous entry.
53 $entries[-1][-1] .= $_;
57 $_ = join "\n", (map {
58 my ($w, $node, $description) = @$_;
59 my $prefix = "* ${node}::";
60 # 6 for leading *, trailing ::, and spaces.
61 my $indent = ' ' x ($width + 6);
70 $first = sprintf "%-*s", length $indent, $prefix;
74 $prefix . wrap $first, " $indent", $description;
81 if (!$fixed{info_dir} and /^START-INFO-DIR-ENTRY/m and $lang)
83 my $first = "* help2man-$lang: (help2man-$lang). ";
84 my $indent = ' ' x ((length $first) + 2);
85 s/^\* help2man: \(help2man\)\.\s*(.*)\nEND-INFO-DIR-ENTRY/
86 (my $t = $1) =~ s#\s+# #g; # normalise spaces
87 (wrap $first, $indent, $t) . "\nEND-INFO-DIR-ENTRY"/mse or next;
93 if (/^Local Variables:/m and /^coding: (\S+)/m)
105 warn "$0: didn't find menu to correct\n" unless $fixed{menu};
106 warn "$0: didn't find info dir entry to correct\n" unless $fixed{info_dir};
107 warn "$0: expected utf-8 encoding, found $encoding\n"
108 unless $encoding eq 'utf-8';