gbranden pushed a commit to branch master
in repository groff.

commit 6fcc1f9ce7cec551b8d338ad074c4a487d0bd81a
Author: G. Branden Robinson <[email protected]>
AuthorDate: Thu Nov 12 06:28:54 2026 -0600

    [libgroff,troff]: Fix Savannah #68600.
    
    Make troff report macro file search path in `--version` output.
    
    * src/include/searchpath.h (class search_path): Declare new member
      function `contents()`, which, like the same-named member functions of
      groff's `string` and `symbol` classes, returns a pointer to `const
      char`.
    
    * src/libs/libgroff/searchpath.cpp (search_path::contents): Return the
      contents of `dirs` as-is (but hardened to `const`).  A refactoring of
      this class might store directory names as elements of a list (an
      `std::vector`?) and compute the path element separator.  On the other
      hand, no one seems for several years to have bothered building groff
      on a non-POSIX system.
    
    * src/roff/troff/input.cpp (main): Declare new Boolean variable
      `want_version_report`, defaulting `false`.  When processing `-v`
      command-line option, simply set this flag to `true` and stop printing
      anything or exiting early.  We need to process the remainder of the
      command line to determine what the macro file search path is; `-M`
      options might follow `-v`.  After command-line processing is complete,
      check the flag variable, and if it is true, report version and macro
      path search information, and exit(3) successfully.
    
    Fixes <https://savannah.gnu.org/bugs/?68600>.
---
 ChangeLog                        | 26 ++++++++++++++++++++++++++
 src/include/searchpath.h         |  1 +
 src/libs/libgroff/searchpath.cpp |  5 +++++
 src/roff/troff/input.cpp         | 15 ++++++++++-----
 4 files changed, 42 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 35ad17e93..20bb9df2a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,29 @@
+2026-11-12  G. Branden Robinson <[email protected]>
+
+       [troff]: Report macro file search path in `--version` output.
+
+       * src/include/searchpath.h (class search_path): Declare new
+       member function `contents()`, which, like the same-named member
+       functions of groff's `string` and `symbol` classes, returns a
+       pointer to `const char`.
+       * src/libs/libgroff/searchpath.cpp (search_path::contents):
+       Return the contents of `dirs` as-is (but hardened to `const`).
+       A refactoring of this class might store directory names as
+       elements of a list (an `std::vector`?) and compute the path
+       element separator.  On the other hand, no one seems for several
+       years to have bothered building groff on a non-POSIX system.
+       * src/roff/troff/input.cpp (main): Declare new Boolean variable
+       `want_version_report`, defaulting `false`.  When processing `-v`
+       command-line option, simply set this flag to `true` and stop
+       printing anything or exiting early.  We need to process the
+       remainder of the command line to determine what the macro file
+       search path is; `-M` options might follow `-v`.  After
+       command-line processing is complete, check the flag variable,
+       and if it is true, report version and macro path search
+       information, and exit(3) successfully.
+
+       Fixes <https://savannah.gnu.org/bugs/?68600>.
+
 2026-11-11  G. Branden Robinson <[email protected]>
 
        [tbl]: Guard unreachable code with new preprocessor
diff --git a/src/include/searchpath.h b/src/include/searchpath.h
index 444acf880..283aebd6a 100644
--- a/src/include/searchpath.h
+++ b/src/include/searchpath.h
@@ -25,6 +25,7 @@ public:
   search_path(const char *envvar, const char *standard,
              int add_home, int add_current);
   ~search_path();
+  const char* contents() const;
   void command_line_dir(const char *);
   FILE *open_file(const char *, char **);
   FILE *open_file_cautiously(const char *, char ** = 0 /* nullptr */,
diff --git a/src/libs/libgroff/searchpath.cpp b/src/libs/libgroff/searchpath.cpp
index a3a56baae..691ad7205 100644
--- a/src/libs/libgroff/searchpath.cpp
+++ b/src/libs/libgroff/searchpath.cpp
@@ -91,6 +91,11 @@ search_path::~search_path()
   delete[] dirs;
 }
 
+const char *search_path::contents() const
+{
+  return static_cast<const char *>(dirs);
+}
+
 void search_path::command_line_dir(const char *s)
 {
   char *old = dirs;
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 03cca7518..1c5254139 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -10270,6 +10270,7 @@ int main(int argc, char **argv)
   string_list *macros = 0 /* nullptr */;
   string_list *register_assignments = 0 /* nullptr */;
   string_list *string_assignments = 0 /* nullptr */;
+  bool want_version_report = false;
   bool want_stdin_read_last = false;
   bool have_explicit_device_argument = false;
   bool have_explicit_default_family = false;
@@ -10304,11 +10305,8 @@ int main(int argc, char **argv)
         != EOF)
     switch (c) {
     case 'v':
-      {
-       printf("GNU troff (groff) version %s\n", Version_string);
-       exit(EXIT_SUCCESS);
-       break; // NOTREACHED
-      }
+      want_version_report = true;
+      break; // NOTREACHED
     case 'I':
       // Search path for .psbb files
       // and most other non-system input files.
@@ -10437,6 +10435,13 @@ int main(int argc, char **argv)
     }
   if (want_unsafe_requests)
     mac_path = &macro_path;
+  if (want_version_report) {
+    (void) printf("GNU troff (groff) version %s\n", Version_string);
+    (void) putc('\n', stdout);
+    (void) printf("macro search path: %s\n",
+                 mac_path->contents());
+    exit(EXIT_SUCCESS);
+  }
   set_string(".T", device);
   // TODO: Kill this off in groff 1.24.0 release + 2 years.  See env.cpp.
   if ((strcmp("pdf", device) == 0) || strcmp("ps", device) == 0)

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

Reply via email to