Update of bug #68600 (group groff):

                 Summary: [troff] make `--version` output report macro search
path => [PATCH] [troff] make `--version` output report macro search path

    _______________________________________________________

Follow-up Comment #3:


diff --git a/ChangeLog b/ChangeLog
index 35ad17e93..97080f9f9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,27 @@
+2026-11-12  G. Branden Robinson <[email protected]>
+
+       Fix Savannah #68600.
+
+       * 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).
+
 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)


Illustration:


$ troff --version
GNU troff (groff) version 1.25.0.63-4acf8

macro search path:
/home/branden:/home/branden/groff-HEAD/lib/groff/site-tmac:/home/branden/groff-HEAD/share/groff/site-tmac:/home/branden/groff-HEAD/share/groff/1.25.0/tmac




    _______________________________________________________

Reply to this item at:

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

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

Attachment: signature.asc
Description: PGP signature

Reply via email to