bug-groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug #45502] [troff] .if, .ie, .el parsing incompatible with Unix V7, DW


From: G. Branden Robinson
Subject: [bug #45502] [troff] .if, .ie, .el parsing incompatible with Unix V7, DWB, and Heirloom Doctools troff
Date: Fri, 5 Apr 2024 01:20:28 -0400 (EDT)

Follow-up Comment #6, bug #45502 (group groff):

I think I have it.


$ git log --patch src/roff
commit 06c4b5704193d4a3afc03132eb552c897f0ae029 (HEAD -> master)
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
Date:   Thu Apr 4 23:51:56 2024 -0500

    [troff]: Fix Savannah #45502.
    
    * src/roff/troff/input.cpp: Alter handling of degenerate or ambiguous
      control flow requests.
    
      (skip_alternative, begin_alternative): If an `el` request or the
      conditional expression of an `if` or `ie` request is followed
      immediately by a newline, then (A) if in AT&T compatibility mode,
      ignore the newline character as AT&T troff did (but issue an error
      message regarding the ambiguity); (B) otherwise, emit a warning in
      category `el` and ignore the _request_.
    
    Fixes <https://savannah.gnu.org/bugs/?45502>.  Thanks to Carsten Kunze
    for the report.
    
    GNU troff treats a newline and EOF equivalently in this case.  This
    detail is not specified by CSTR #54.
    
    "Any spaces between the condition and the beginning of anything are
    skipped over."
    
    DWB 3.3 and Heirloom Doctools troff handle EOF here differently from GNU
    troff and from each other.
    
    ANNOUNCE: Acknowledge Carsten.

diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 2d5dc4980..30db343b9 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -5880,6 +5880,17 @@ static void troff_request()
 
 static void skip_alternative()
 {
+  if (tok.is_newline()) {
+    if (compatible_flag) {
+      error("ambiguous branch in control flow; rewrite to append"
+           " control or text line, or end line with escape character");
+      return;
+    }
+    else {
+      warning(WARN_EL, "ignoring empty branch in control flow");
+      tok.next();
+    }
+  }
   int level = 0;
   // ensure that ".if 0\{" works as expected
   if (tok.is_left_brace())
@@ -5922,6 +5933,17 @@ static void skip_alternative()
 
 static void begin_alternative()
 {
+  if (tok.is_newline()) {
+    if (compatible_flag) {
+      error("ambiguous branch in control flow; rewrite to append"
+           " control or text line, or end line with escape character");
+      tok.next();
+    }
+    else {
+      warning(WARN_EL, "ignoring empty branch in control flow");
+      return;
+    }
+  }
   while (tok.is_space() || tok.is_left_brace())
     tok.next();
 }
diff --git a/src/roff/troff/troff.1.man b/src/roff/troff/troff.1.man
index 3d81f980c..f0d36f1ea 100644
--- a/src/roff/troff/troff.1.man
+++ b/src/roff/troff/troff.1.man
@@ -606,11 +606,19 @@ .SH Warnings
 .
 .TP
 .BR el "\t16"
-The
+An
 .B el
 request was encountered with no prior corresponding
 .B ie
-request.
+request;
+or an
+.B el
+request or the conditional expression of an
+.B if
+of
+.B ie
+request was followed immediately by a newline,
+making the control flow ambiguous.
 .
 .
 .TP

commit 5d5834a8dfefe363805617f4e5e1e18626058b83
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
Date:   Thu Apr 4 23:54:17 2024 -0500

    [troff]: Regression-test Savannah #45502.
    
    Test fails at this commit.

diff --git a/src/roff/groff/groff.am b/src/roff/groff/groff.am
index 5c7ed2f3b..0ce7601eb 100644
--- a/src/roff/groff/groff.am
+++ b/src/roff/groff/groff.am
@@ -42,6 +42,7 @@ groff_TESTS = \
   src/roff/groff/tests/backslash-exclamation-early-does-not-fail.sh \
   src/roff/groff/tests/break_zero-length_output_line_sanely.sh \
   src/roff/groff/tests/cf-request-early-does-not-fail.sh \
+  src/roff/groff/tests/degenerate-control-flow-works.sh \
   src/roff/groff/tests/detect-evil-link-time-optimizer.sh \
   src/roff/groff/tests/device-request-works.sh \
   src/roff/groff/tests/device_control_escapes_express_basic_latin.sh \
diff --git a/src/roff/groff/tests/degenerate-control-flow-works.sh
b/src/roff/groff/tests/degenerate-control-flow-works.sh
new file mode 100755
index 000000000..8eb0881e2
--- /dev/null
+++ b/src/roff/groff/tests/degenerate-control-flow-works.sh
@@ -0,0 +1,59 @@
+#!/bin/sh
+#
+# Copyright (C) 2024 Free Software Foundation, Inc.
+#
+# This file is part of groff.
+#
+# groff 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.
+#
+# groff 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 <http://www.gnu.org/licenses/>.
+#
+
+groff="${abs_top_builddir:-.}/test-groff"
+
+fail=
+
+wail () {
+  echo ...FAILED >&2
+  fail=YES
+}
+
+input='.if 1
+.tm true
+.if !0
+.tm also true
+.ie 0
+.tm startlingly, but AT&T compatibly, true
+.el
+.tm unsurprisingly false'
+
+output=$(echo "$input" | "$groff" -W el -T ascii 2>&1)
+echo "$output"
+
+echo "checking GNU troff truncated control flow request semantics" >&2
+echo "$output" | sed -n 1p | grep -qx 'true' || wail
+echo "$output" | sed -n 2p | grep -q 'also true' || wail
+echo "$output" | sed -n 3p | grep -q 'unsurprisingly' || wail
+! echo "$output" | grep -q 'startlingly' || wail
+
+output=$(echo "$input" | "$groff" -CE -T ascii 2>&1)
+echo "$output"
+
+echo "checking AT&T troff truncated control flow request semantics" >&2
+echo "$output" | sed -n 1p | grep -qx 'true' || wail
+echo "$output" | sed -n 2p | grep -q 'also true' || wail
+echo "$output" | sed -n 3p | grep -q 'startlingly' || wail
+echo "$output" | sed -n 4p | grep -q 'unsurprisingly' || wail
+
+test -z "$fail"
+
+# vim:set autoindent expandtab shiftwidth=2 tabstop=2 textwidth=72:




    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?45502>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]