gbranden pushed a commit to branch master
in repository groff.

commit 22d1cb611ffce531e627155ad00af6ab6deb0176
Author: G. Branden Robinson <[email protected]>
AuthorDate: Wed May 20 12:25:17 2026 -0500

    src/roff/troff/div.cpp: Refactor.
    
    ...to rationalize and parallelize vertical position trap request
    handlers.
    
    * src/roff/troff/div.cpp (when_request): Check for presence of
      arguments; if none, throw warning in category "missing".
    
      (diversion_trap_request): Clear any existing diversion trap if given a
      valid vertical position argument but no second argument, analogously
      to `ch` request.
---
 ChangeLog              | 10 ++++++++++
 src/roff/troff/div.cpp | 38 +++++++++++++++++++++-----------------
 2 files changed, 31 insertions(+), 17 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 3d6185201..fbcd3fc27 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2026-05-20  G. Branden Robinson <[email protected]>
+
+       * src/roff/troff/div.cpp: Refactor to rationalize and
+       parallelize vertical position trap request handlers.
+       (when_request): Check for presence of arguments; if none, throw
+       warning in category "missing".
+       (diversion_trap_request): Clear any existing diversion trap if
+       given a valid vertical position argument but no second argument,
+       analogously to `ch` request.
+
 2026-05-19  G. Branden Robinson <[email protected]>
 
        * src/roff/troff/div.h (class diversion): Declare new pure
diff --git a/src/roff/troff/div.cpp b/src/roff/troff/div.cpp
index 555e1be22..e862b3884 100644
--- a/src/roff/troff/div.cpp
+++ b/src/roff/troff/div.cpp
@@ -780,13 +780,18 @@ static void configure_page_length_request() // .pl
 static void when_request() // .wh
 {
   vunits n;
-  if (read_vunits(&n, 'v')) {
-    symbol s = read_identifier();
-    if (s.is_null())
-      topdiv->remove_trap_at(n);
-    else
-      topdiv->add_trap(s, n);
+  if (has_arg()) {
+    if (read_vunits(&n, 'v')) {
+      symbol s = read_identifier();
+      if (s.is_null())
+       topdiv->remove_trap_at(n);
+      else
+       topdiv->add_trap(s, n);
+    }
   }
+  else
+    warning(WARN_MISSING, "page trap location configuration request"
+           " expects arguments");
   skip_line();
 }
 
@@ -1007,20 +1012,17 @@ static void diversion_trap_request() // .dt
   if (!has_arg())
     curdiv->clear_diversion_trap();
   else if (read_vunits(&n, 'v')) {
-    if (has_arg()) {
       symbol s = read_identifier();
-      if (!s.is_null())
+      if (s.is_null())
+       curdiv->clear_diversion_trap();
+      else
        curdiv->set_diversion_trap(s, n);
-    }
-    else
-      warning(WARN_MISSING, "diversion trap request expects macro"
-             " identifier argument after vertical position argument");
   }
-  // We have no `else` branch here; `read_vunits()` already threw an
-  // error diagnostic.  Historically, GNU troff, like other troffs,
-  // treated botched `dt` arguments the same as no arguments at all,
-  // removing the trap.  That behavior was inconsistent with other
-  // request handling.
+  // We have no `else` branch here; `read_vunits()` may have already
+  // thrown an error diagnostic.  ("May have"?  See Savannah #68375.)
+  // Historically, GNU troff, like other troffs, treated botched `dt`
+  // arguments the same as no arguments at all, removing the trap.  That
+  // behavior was inconsistent with other request handling.
   skip_line();
 }
 
@@ -1034,6 +1036,8 @@ static void change_trap_request() // .ch
     else
       topdiv->remove_trap(s);
   }
+  // We have no `else` branch here; `read_vunits()` may have already
+  // thrown an error diagnostic.  ("May have"?  See Savannah #68375.)
   skip_line();
 }
 

_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit

Reply via email to