Hi all,

I have another language change proposal.  I suspect impact will be low,
but it is strictly speaking a behavior change.

o The `color`, `cp`, `linetabs`, and `vpt` requests now interpret
  arguments with negative values as instructions to disable the
  corresponding feature, using the *roff integer-to-Boolean conversion
  idiom instead of the C/C++ one.  Thus, if you invoke these requests
  with a register interpolation, the outcome agrees with an `if` test of
  the register's value.

Here is a motivating example.

.nr i-want-compatibility-mode -1
.if \n[i-want-compatibility-mode] .tm I want compatibility mode!
.cp \n[i-want-compatibility-mode]
.ie \n(.C .tm I'm in compatibility mode now.
.el       .tm I am NOT in compatibility mode.

groff 1.22.4, 1.23.0, and Git HEAD:

I'm in compatibility mode now.

groff with this patch:

I am NOT in compatibility mode.

Patch attached.

Regards,
Branden
diff --git a/NEWS b/NEWS
index 77570e9b8..f66982810 100644
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,13 @@ VERSION next
 troff
 -----
 
+o The `color`, `cp`, `linetabs`, and `vpt` requests now interpret
+  arguments with negative values as instructions to disable the
+  corresponding feature, using the *roff integer-to-Boolean conversion
+  idiom instead of the C/C++ one.  Thus, if you invoke these requests
+  with a register interpolation, the outcome agrees with an `if` test of
+  the register's value.
+
 o In nroff mode (in other words, when producing output for devices that
   claim to be terminals), the formatter now reports warning diagnostics
   regarding certain output problems using units of lines instead of
diff --git a/doc/groff.texi b/doc/groff.texi
index a5563d103..3f6640856 100644
--- a/doc/groff.texi
+++ b/doc/groff.texi
@@ -9382,11 +9382,11 @@ @node Tabs and Fields
 @cindex tab, line-tabs mode
 @cindex line-tabs mode
 @cindex mode, line-tabs
-Activate line-tabs in the environment if the expression @var{b} is
-non-zero; deactivate them otherwise.  They are inactive by default, and
-activated if @var{b} is omitted.  When line-tabs are active, tab stops
-are computed relative to the start of the pending output line instead of
-the drawing position corresponding to the start of the input line.
+Activate or deactivate line-tabs in the environment per Boolean
+expression @var{b}.  They are inactive by default, and activated if
+@var{b} is omitted.  When line-tabs are active, tab stops are computed
+relative to the start of the pending output line instead of the drawing
+position corresponding to the start of the input line.
 
 @Example
 .ta 1i 3i
@@ -12323,11 +12323,10 @@ @node Colors
 
 @DefreqList {color, [@Var{b}]}
 @DefregListEndx {.color}
-Enable output of color-related device-independent output commands if the
-expression @var{b} is non-zero; disable it otherwise.  It is enabled by
-default, and if @var{b} is omitted.  This request modifies the
-formatter's internal state; it does not produce a
-token (@pxref{Gtroff Internals}).
+Enable or disable output of color-related device-independent output
+commands per Boolean expression @var{b}.  It is enabled by default, and
+if @var{b} is omitted.  This request modifies the formatter's internal
+state; it does not produce a token (@pxref{Gtroff Internals}).
 
 The read-only register @code{.color} interpolates@tie{}1 if color
 support is enabled, 0@tie{}otherwise.
@@ -14667,11 +14666,11 @@ @node Vertical Position Traps
 @cindex enabling vertical position traps (@code{vpt})
 @cindex vertical position traps, enabling (@code{vpt})
 @cindex vertical position trap enable register (@code{.vpt})
-Enable vertical position traps if the expression @var{b} is non-zero;
-disable them otherwise.  They are enabled by default, and if @var{b} is
-omitted.  Vertical position traps are those set by the @code{wh} request
-or by @code{dt} within a diversion.  Vertical position trap enablement
-is global.  Its status is stored in the @code{.vpt} read-only register.
+Enable or disable vertical position traps per Boolean expression
+@var{b}.  They are enabled by default, and if @var{b} is omitted.
+Vertical position traps are those set by the @code{wh} request or by
+@code{dt} within a diversion.  Vertical position trap enablement is
+global.  Its status is stored in the @code{.vpt} read-only register.
 
 @cindex page break, prevented by @code{vpt}
 @cindex break, page, prevented by @code{vpt}
@@ -17479,10 +17478,10 @@ @node Compatibility Mode
 
 @DefreqList {cp, [@Var{b}]}
 @DefregListEndx {.C}
-Enable AT&T @command{troff} compatibility mode if the expression
-@var{b} is non-zero; disable it otherwise.  It is disabled by default,
-and enabled if @var{b} is omitted.  In compatibility mode, long names
-are not recognized, and the incompatibilities they cause do not arise.
+Enable or disable AT&T @command{troff} compatibility mode per Boolean
+expression @var{b}.  It is disabled by default, and enabled if @var{b}
+is omitted.  In compatibility mode, long names are not recognized, and
+the incompatibilities they cause do not arise.
 
 The read-only register @code{.C} interpolates@tie{}1 if compatibility
 mode is enabled, 0@tie{}otherwise.
diff --git a/man/groff.7.man b/man/groff.7.man
index 2135ac4af..38a51e56e 100644
--- a/man/groff.7.man
+++ b/man/groff.7.man
@@ -2261,6 +2261,12 @@ .SH "Syntax reference conventions"
 trailing whitespace generally is not.
 .
 .TPx
+.I b
+is a numerical expression evaluated as a Boolean;
+positive values are true,
+others false.
+.
+.TPx
 .I c
 denotes a single input character,
 ordinary or special.
@@ -2813,12 +2819,9 @@ .SH "Request short reference"
 .
 .TPx
 .REQ .color b
-If
-.I b
-is zero,
-disable output of color-related device-independent output commands;
-otherwise,
-enable them.
+Enable or disable output of color-related device-independent output
+commands per Boolean expression
+.IR b .
 .
 .TPx
 .REQ .composite "c1 c2"
@@ -2846,13 +2849,10 @@ .SH "Request short reference"
 .
 .TPx
 .REQ .cp b
-If
-.I b
-is zero,
-disable AT&T
+Enable or disable AT&T
 .I troff \" AT&T
-compatibility mode,
-otherwise enable it.
+compatibility mode per Boolean expression
+.IR b .
 .
 .TPx
 .REQ .cs "font n m"
@@ -3586,11 +3586,9 @@ .SH "Request short reference"
 .
 .TPx
 .REQ .linetabs b
-If
-.I b
-is zero,
-deactivate line-tabs in the environment,
-otherwise enable them.
+Activate or deactivate line-tabs in the environment per Boolean
+expression
+.IR b .
 .
 .TPx
 .REQ .lf n
@@ -4578,11 +4576,8 @@ .SH "Request short reference"
 .
 .TPx
 .REQ .vpt b
-If
-.I b
-is zero,
-disable vertical position traps,
-otherwise enable them.
+Enable or disable vertical position traps per Boolean expression
+.IR b .
 .
 .TPx
 .REQ .vs
diff --git a/man/groff_diff.7.man b/man/groff_diff.7.man
index 27e9e7eaf..97d8e662e 100644
--- a/man/groff_diff.7.man
+++ b/man/groff_diff.7.man
@@ -2123,27 +2123,28 @@ .SS "New requests"
 .TP
 .BR .color\~ [\c
 .IR b ]
-If
-.I b
-is non-zero or missing,
-enable output of color-related device-independent output commands,
-otherwise disable them.
+Enable or disable output of color-related device-independent output
+commands per Boolean expression
+.IR b .
 .
-It is enabled by default.
+It is enabled by default,
+and if
+.I b
+is omitted.
 .
 .
 .TP
 .BR .cp\~ [\c
 .IR b ]
-If
-.I b
-is non-zero or missing,
-enable AT&T
+Enable or disable AT&T
 .I troff \" AT&T
-compatibility mode,
-otherwise disable it.
+compatibility mode per Boolean expression
+.IR b .
 .
-It is disabled by default.
+It is disabled by default,
+and enabled if
+.I b
+is omitted.
 .
 In compatibility mode,
 long names are not recognized,
@@ -2971,13 +2972,14 @@ .SS "New requests"
 .TP
 .BR .linetabs\~ [\c
 .IR b ]
-If
-.I b
-is non-zero or missing,
-activate line-tabs in the environment,
-otherwise disable it.
+Activate or deactivate line-tabs in the environment per Boolean
+expression
+.IR b .
 .
-They are inactive by default.
+They are inactive by default,
+and activated if
+.I b
+is omitted.
 .
 When line-tabs are active,
 tab stops are computed relative to the start of the pending output line
@@ -3696,13 +3698,13 @@ .SS "New requests"
 .TP
 .BR .vpt\~ [\c
 .IR b ]
-If
-.I b
-is non-zero or missing,
-enable vertical position traps,
-otherwise disable them.
+Enable or disable vertical position traps per Boolean expression
+.IR b .
 .
-They are enabled by default.
+They are enabled by default,
+and if
+.I b
+is omitted.
 .
 .
 .IP
diff --git a/src/roff/troff/div.cpp b/src/roff/troff/div.cpp
index 29d6ebe20..cb508b322 100644
--- a/src/roff/troff/div.cpp
+++ b/src/roff/troff/div.cpp
@@ -985,7 +985,7 @@ void vertical_position_traps()
 {
   int n;
   if (has_arg() && get_integer(&n))
-    vertical_position_traps_flag = (n != 0);
+    vertical_position_traps_flag = (n > 0);
   else
     vertical_position_traps_flag = 1;
   skip_line();
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index b916ae37b..545765c8f 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -208,7 +208,7 @@ void widow_control_request()
 {
   int n;
   if (has_arg() && get_integer(&n))
-    curenv->widow_control = n != 0;
+    curenv->widow_control = (n > 0);
   else
     curenv->widow_control = 1;
   skip_line();
@@ -2891,7 +2891,7 @@ void line_tabs_request()
 {
   int n;
   if (has_arg() && get_integer(&n))
-    curenv->line_tabs = n != 0;
+    curenv->line_tabs = (n > 0);
   else
     curenv->line_tabs = 1;
   skip_line();
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 78a93b27d..b2d54a033 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -1487,7 +1487,7 @@ static void activate_color()
 {
   int n;
   if (has_arg() && get_integer(&n))
-    color_flag = n != 0;
+    color_flag = (n > 0);
   else
     color_flag = 1;
   skip_line();
@@ -2616,7 +2616,7 @@ void compatible()
 {
   int n;
   if (has_arg() && get_integer(&n))
-    compatible_flag = n != 0;
+    compatible_flag = (n > 0);
   else
     compatible_flag = 1;
   skip_line();

Attachment: signature.asc
Description: PGP signature

Reply via email to