3
# man-page-table-check - workaround for go-md2man bug that screws up tables
5
package Podman::ManPage::TableCheck;
13
(our $ME = $0) =~ s|.*/||;
15
###############################################################################
16
# BEGIN boilerplate args checking, usage messages
22
$ME checks man pages (the *roff files produced
23
by go-md2man) for empty table cells. Reason: go-md2man cannot handle
24
markdown characters (e.g. asterisk) in tables. It produces horribly
25
broken *roff which in turn makes unreadable man pages.
27
If $ME finds broken tables, it will highlight them
28
and display hints on how to resolve the problem.
31
--help display this message
37
# Command-line options. Note that this operates directly on @ARGV !
41
our $NOT = ''; # print "blahing the blah$NOT\n" if $debug
48
) or die "Try `$ME --help' for help\n";
51
# END boilerplate args checking, usage messages
52
###############################################################################
54
############################## CODE BEGINS HERE ###############################
56
# The term is "modulino".
57
__PACKAGE__->main() unless caller();
61
# Note that we operate directly on @ARGV, not on function parameters.
62
# This is deliberate: it's because Getopt::Long only operates on @ARGV
63
# and there's no clean way to make it use @_.
64
handle_opts(); # will set package globals
66
die "$ME: Too many arguments; try $ME --help\n" if @ARGV;
68
my $manpage_dir = 'docs/build/man'; # FIXME-hardcoding
69
opendir my $dir_fh, $manpage_dir
70
or die "$ME: Cannot opendir $manpage_dir: $!\n";
72
for my $ent (sort readdir $dir_fh) {
73
next unless $ent =~ /^[a-z].*\.[1-8][a-z]?$/; # groff files only
74
next if -l "$manpage_dir/$ent"; # skip links
80
or die "$ME: did not find any .[1-8] files under $manpage_dir\n";
83
for my $file (@manpages) {
84
$errs += check_tables("$manpage_dir/$file");
88
die "\n$ME: found empty cells in the above man page(s)
90
This is a bug in go-md2man: it gets really confused when it sees
91
misaligned vertical-bar signs ('|') in tables, or a left-hand
92
column with more than 31 characters.
94
WORKAROUND: find the above line(s) in the docs/source/markdown file,
95
then fix the issue (left as exercise for the reader). Keep regenerating
98
\$ make -C docs clean;make docs;$0
108
my @cmd = ('man', '-l', '--no-hyphenation', '-Tlatin1', '-');
109
pipe my $fh_read, my $fh_write;
111
if ($kidpid) { # we are the parent
114
elsif (defined $kidpid) { # we are the child
117
open my $fh_in, '<:utf8', $path
118
or die "$ME: Could not read $path: $!\n";
119
# groff spits out nasty useless warnings
121
open STDOUT, '>&', $fh_write;
122
open my $fh_man, '|-', @cmd
123
or die "$ME: Could not fork: $! (message will never be seen)\n";
125
while (my $line = <$fh_in>) {
127
print { $fh_man } $line;
130
close $fh_man or die;
134
die "$ME: could not fork: $!";
139
while (my $line = <$fh_read>) {
143
# Table borders (+----------+------------+)
144
if ($line =~ /^\s*\+-+\+-+/) {
149
# Row immediately after table borders
152
# *Two* blank cells is OK, go-md2man always does this
153
# on the last row of each table.
154
if ($line !~ /^\s*\|\s+\|\s+\|/) {
155
if ($line =~ /\|\s+\|/) {
156
warn "\n$ME: $path:\n" if $status == 0;
165
die "$ME: $path: command failed: @cmd\n" if $?;
168
if ($linecount < 10) {
169
die "$ME: $path: nothing seen!\n";