diff options
Diffstat (limited to 'debian/pod2rst-fix')
-rwxr-xr-x | debian/pod2rst-fix | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/debian/pod2rst-fix b/debian/pod2rst-fix new file mode 100755 index 0000000..ab40f51 --- /dev/null +++ b/debian/pod2rst-fix @@ -0,0 +1,113 @@ +#!/usr/bin/perl + +# Copyright (C) 2007-2022 Ole Tange, http://ole.tange.dk and Free +# Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, see <https://www.gnu.org/licenses/> +# or write to the Free Software Foundation, Inc., 51 Franklin St, +# Fifth Floor, Boston, MA 02110-1301 USA +# +# SPDX-FileCopyrightText: 2021-2022 Ole Tange, http://ole.tange.dk and Free Software and Foundation, Inc. +# SPDX-License-Identifier: GPL-3.0-or-later + +# This fixes problems in pod2rst conversion + +# Conversion errors: + +# B<foo `bar` baz> + +# Fixed: +# ... B<foo> +# bar + +# Fixed: +# =item - - a + +# Fixed: +# \\` => \` + +# Not fixed (RST does not support Bold-Italic): +# B<cat | xargs -d "\n" -n1 I<command>> + +sub pipefunc { + # Emulate a shell pipe but between Perl functions + # stdin | func1 | func2 | ... | funcN + # pipefunc(*func1, *func2, ..., *funcN); + my $func = pop; + + my $pid = open(my $kid_to_read, "-|"); + defined($pid) || die "can't fork: $!"; + if ($pid) { + open STDIN, "<&", $kid_to_read or die; + &$func(); + } else { # child + close $kid_to_read; + if($_[1]) { + # More than one function remaining: Recurse + pipefunc(@_); + } else { + # Only one function remaining: Run it + $func = pop; + &$func(); + } + exit 0; + } +} + +sub pre1 { + while(<STDIN>) { + # Remove comments + /^\#/ and next; + # quote - + s/^=item -/=item \001/; + + if(/^ /) { + # ignore source blocks + } else { + # \\ => \ + s/\\/\\\\/g; + } + print; + } +} + +sub pre2 { + $/="\n\n"; + while(<STDIN>) { + # join lines in each paragraph + s/(\S)\n(\S)/$1 $2/g; + print; + } +} + +sub pod2rst { + exec "pod2rst"; +} + +sub post { + while(<STDIN>) { + # =item in =item + s/- \\[*]/- /; + # B<*.log> + s/\\\\[*]/\\*/g; + # - - + s/^-(\s+)\001/-$1\\-/g; + # \\` => \` + s/\\\\`/\\`/g; + print; + } +} + +# stdin | pre1() | pre2() | pod2rst() | post() +pipefunc(*pre1,*pre2,*pod2rst,*post); |