#1076660 po4a: Fail to parse .ie in groff man pages

Package:
po4a
Source:
po4a
Submitter:
Petter Reinholdtsen
Date:
2024-08-06 16:57:04 UTC
Severity:
normal
#1076660#5
Date:
2024-07-21 08:00:25 UTC
From:
To:
We ran into a problem with po4a on LinuxCNC,
<URL: https://github.com/linuxcnc/linuxcnc/ >. The issue is po4a going
into a seemingly endless loop print lines like these:

  Use of uninitialized value $line in scalar chomp at
    /usr/share/perl5/Locale/Po4a/Man.pm line 2344.
  Use of uninitialized value $line in concatenation (.) or string at
    /usr/share/perl5/Locale/Po4a/Man.pm line 2345.
  Use of uninitialized value $line in pattern match (m//) at
    /usr/share/perl5/Locale/Po4a/Man.pm line 2346.
  Use of uninitialized value $line in pattern match (m//) at
    /usr/share/perl5/Locale/Po4a/Man.pm line 2347.

It was triggered by adding .ie to some generated groff files in
<URL: https://github.com/LinuxCNC/linuxcnc/commit/d1414e63eb19f2ebb6c300ea40b4404869c516a3 >,
causing docs/man/man9/toggle.9 and docs/man/man9/toggle2nist.9 to
confuse po4a.
We have applied a fix by commenting out the files in docs/po4a.cfg.

To trigger the error, just uncomment the lines, touch one of the adoc
files in docs/src/ (for example docs/src/config/ini-config.adoc) and run
'debuild'.

One of the problematic files, toggle.9, look like this:

==========================================================================
.\" -*- mode: troff; coding: utf-8 -*-
.\"*******************************************************************
.\"
.\" This file was extracted from hal/components/toggle.comp using halcompile.g.
.\" Modify the source file.
.\"
.\"*******************************************************************

.TH TOGGLE "9" "2024-07-21" "LinuxCNC Documentation" "HAL Component"
.SH NAME

toggle \- 'push-on, push-off' from momentary pushbuttons
.SH SYNOPSIS
.HP
.B loadrt toggle [count=\fIN\fB|names=\fIname1\fB[,\fIname2...\fB]]
.SH DESCRIPTION


.ie '\*[.T]'html' \{ .HTML <tt> \}
\[u00A0]\[u00A0]\[u00A0]\[u00A0]\[u00A0]\[u2510]\[u00A0]\[u00A0]\[u00A0]\[u00A0]\[u00A0]\[u250C]\[u2500]\[u2500]\[u2510]\[u00A0]\[u00A0]\[u00A0]\[u00A0]\[u00A0]\[u00A0]\[u00A0]\[u00A0]\[u250C]\[u2500]\[u2500]\[u2510]
.br
in\[u00A0]:\[u00A0]\[u2514]\[u2500]\[u2500]\[u2500]\[u2500]\[u2500]\[u2518]\[u00A0]\[u00A0]\[u2514]\[u2500]\[u2500]\[u2500]\[u2500]\[u2500]\[u2500]\[u2500]\[u2500]\[u2518]\[u00A0]\[u00A0]\[u2514]\[u2500]\[u2500]
.br
\[u00A0]\[u00A0]\[u00A0]\[u00A0]\[u00A0]\[u2510]\[u00A0]\[u00A0]\[u00A0]\[u00A0]\[u00A0]\[u250C]\[u2500]\[u2500]\[u2500]\[u2500]\[u2500]\[u2500]\[u2500]\[u2500]\[u2500]\[u2500]\[u2500]\[u2510]
.br
out:\[u00A0]\[u2514]\[u2500]\[u2500]\[u2500]\[u2500]\[u2500]\[u2518]\[u00A0]\[u00A0]\[u00A0]\[u00A0]\[u00A0]\[u00A0]\[u00A0]\[u00A0]\[u00A0]\[u00A0]\[u00A0]\[u2514]\[u2500]\[u2500]\[u2500]\[u2500]\[u2500]
.ie '\*[.T]'html' \{ .HTML </tt> \}

.SH FUNCTIONS
.TP
\fBtoggle.\fIN\fB\fR

.SH PINS
.TP
.B toggle.\fIN\fB.in\fR bit in \fR
button input
.TP
.B toggle.\fIN\fB.out\fR bit io \fR
on/off output
.SH PARAMETERS
.TP
.B toggle.\fIN\fB.debounce\fR u32 rw \fR(default: \fI2\fR)
debounce delay in periods
.SH AUTHOR

John Kasunich
.SH LICENSE

GPL
==========================================================================

#1076660#10
Date:
2024-07-24 07:13:09 UTC
From:
To:
Hello,

a first quick check on the provided file raises a proper error:

$ PERL5LIB=lib/ ./po4a-normalize -f man /tmp/toggle.9
po4a-normalize is mostly useful to debug po4a itself. Users are advised to use the po4a(1) program instead.
/tmp/toggle.9:19: (po4a::man)
               This page uses conditionals with '.ie'. Since po4a is not a real groff parser, this is not supported by default. The option
               'groff_code=verbatim' gets these macros copied verbatim in the translated file, but it's not very robust. 'groff_code=translate'
               shows these macros to the translators, but groff macros are not user-friendly for translators.

The file used in this test is the one you provide in your bug report. The po4a
version used is the git one, but there was not change since 0.73 on the Man
module. The difference between 0.69 and 0.73 wtr seems to be
https://github.com/mquinson/po4a/issues/361

Could you please check whether your problem is "fixed" with the 0.73 version?
If not, I'll try to find the time to dig into your repository properly. 

In any case, I'm rather reluctant to implement a proper support for
conditionals in po4a, as it would request to implement a complete groff
interpreter. Of course, I'd accept proper patches going in that direction.

Sorry about that, and thanks for your interest,
Mt

Le dimanche 21 juillet 2024 à 10:00 +0200, Petter Reinholdtsen a écrit :

#1076660#15
Date:
2024-07-24 08:08:40 UTC
From:
To:
[Martin Quinson]

I retried the LinuxCNC master branch on trixie with 0.73, and the
problem exist there too.

Note, the LinuxCNC master repository has worked around this issue by
dropping the problematic change, so I reapplied it for my test using
'git cherry-pick d1414e63eb19f2ebb6c300ea40b4404869c516a3'.

I would be happy with po4a not going into a endless loop printing
errors, do not believe there is a need for a complete groff
interpreter. :)

#1076660#22
Date:
2024-08-06 10:04:53 UTC
From:
To:
Hello Petter,

could you please give me the sequence of commands I should give to reproduce
the bugs? I've tried `make -C src translateddocs` from the docs directory as
advised by the README (IIUC), and I get an error that the Make target does not
exist. I fail to find the Makefile to fix it myself.

Thanks in advance,
Mt

Le mercredi 24 juillet 2024 à 10:08 +0200, Petter Reinholdtsen a écrit :

#1076660#27
Date:
2024-08-06 16:53:06 UTC
From:
To:
[Martin Quinson]

Sure.

I believe the following sequence of commands would allow you to
reproduce it.  It is untested, as it take an hour or more on my test
machine, but is running as I write.  The commit is one picked where the
issue introduced in d1414e63eb19f2ebb6c300ea40b4404869c516a3 is present
in the master branch.

  git clone https://github.com/LinuxCNC/linuxcnc.git && \
    cd linuxcnc && \
    git checkout ab12165cd8b5ad3782d462cc0459242a8cb7087a && \
    debian/configure && \
    debuild

To avoid triggering the problem with po4a, we have reverted the
problematic groff notation for now.

Note, there are probably other sequences that might work, and normally I
restart the build using 'make -C src translateddocs' when the debuilt
has succeeded or been interrupted, but as a start just letting the
debian build run its cause is the easiest path.