gbranden pushed a commit to branch master
in repository groff.

commit 513dd780b99c087f8f4572f369b5ba5ac3fc2cb2
Author: G. Branden Robinson <[email protected]>
AuthorDate: Sat Aug 30 03:53:20 2025 -0500

    [troff]: Make `-c` option neuter `color` request.
    
    * src/roff/troff/input.cpp: Add `permit_color_output` static Boolean
      variable.
    
      (activate_color): Introduce `is_color_desired` local Boolean.  If
      `permit_color_output` is false and color enablement is attempted,
      refuse with an error diagnostic.
    
      (main): `-c` option configures value of `permit_color_output` rather
      than `want_color_output`.
    
    * doc/groff.texi.in (Groff Options) <-c>:
    * src/roff/troff/troff.1.man (Options) <-c>:
    * NEWS: Add item.
    
    Fixes <https://savannah.gnu.org/bugs/?67309>.
---
 ChangeLog                  | 18 ++++++++++++++++++
 NEWS                       |  3 +++
 doc/groff.texi.in          |  4 +++-
 src/roff/troff/input.cpp   | 13 ++++++++++---
 src/roff/troff/troff.1.man |  4 +++-
 5 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index fc6956554..02493088d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2025-08-30  G. Branden Robinson <[email protected]>
+
+       [troff]: Make `-c` option neuter the `color` request.
+
+       * src/roff/troff/input.cpp: Add `permit_color_output` static
+       Boolean variable.
+       (activate_color): Introduce `is_color_desired` local Boolean.
+       If `permit_color_output` is false and color enablement is
+       attempted, refuse with an error diagnostic.
+       (main): `-c` option configures value of `permit_color_output`
+       rather than `want_color_output`.
+
+       * doc/groff.texi.in (Groff Options) <-c>:
+       * src/roff/troff/troff.1.man (Options) <-c>:
+       * NEWS: Document it.
+
+       Fixes <https://savannah.gnu.org/bugs/?67309>.
+
 2025-08-28  Dave Kemper <[email protected]>
 
        * tmac/fallbacks.tmac: Add fallback character definitions for
diff --git a/NEWS b/NEWS
index 2bb701ccf..72ce76063 100644
--- a/NEWS
+++ b/NEWS
@@ -252,6 +252,9 @@ troff
    units, such as the `ps` request and `\s` escape sequence, now also
    accept `p` and `s`.
 
+*  The `-c` command-line option now also removes the `color` request's
+   ability to enable multi-color output.
+
 *  In compatibility mode, GNU troff now accepts delimiters that it
    rejects when not in compatibility mode--namely, ordinary characters
    that can validly begin numeric expressions (which are often
diff --git a/doc/groff.texi.in b/doc/groff.texi.in
index a6e41dbf7..497a12ba6 100644
--- a/doc/groff.texi.in
+++ b/doc/groff.texi.in
@@ -1036,7 +1036,9 @@ append to
 macros.
 
 @item -c
-Start with color output disabled.
+Disable multi-color output and
+@code{color}
+request's ability to enable it.
 
 @item -C
 Enable AT&T @command{troff} compatibility mode; implies @option{-c}.
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 56877ffad..41b81ca0b 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -102,6 +102,7 @@ void transparent_file();
 token tok;
 bool want_break = false;
 bool using_character_classes = false;
+static bool permit_color_output = true;
 bool want_color_output = true;
 static bool want_backtraces = false;
 char *pipe_command = 0 /* nullptr */;
@@ -1523,10 +1524,16 @@ static color *read_gray(char end = 0)
 static void activate_color()
 {
   int n;
+  bool is_color_desired = false;
   if (has_arg() && get_integer(&n))
-    want_color_output = (n > 0);
+    is_color_desired = (n > 0);
   else
-    want_color_output = true;
+    is_color_desired = true;
+  if (is_color_desired && !permit_color_output) {
+    error("color output disabled via command line");
+    is_color_desired = false;
+  }
+  want_color_output = is_color_desired;
   skip_line();
 }
 
@@ -9265,7 +9272,7 @@ int main(int argc, char **argv)
       want_att_compat = true;
       // fall through
     case 'c':
-      want_color_output = false;
+      permit_color_output = false;
       break;
     case 'M':
       macro_path.command_line_dir(optarg);
diff --git a/src/roff/troff/troff.1.man b/src/roff/troff/troff.1.man
index 13e1d566f..5bffe9b03 100644
--- a/src/roff/troff/troff.1.man
+++ b/src/roff/troff/troff.1.man
@@ -228,7 +228,9 @@ macros.
 .
 .TP
 .B \-c
-Start with color output disabled.
+Disable multi-color output and
+.RB \[lq] color \[rq]
+request's ability to enable it.
 .
 .
 .TP

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

Reply via email to