gbranden pushed a commit to branch master
in repository groff.

commit 725f44200e76cb8e327602a574d8e9230b8da73e
Author: G. Branden Robinson <[email protected]>
AuthorDate: Sun Nov 22 21:54:35 2026 -0600

    [troff]: `pstream` request accepts arguments.
    
    * src/roff/troff/input.cpp (struct grostream): Declare new member
      function `dump()`.
    
      (grostream::dump): New member function takes (arbitrary) stream name
      as argument and dumps stream properties in JSON format to standard
      error stream.  Logic factored out from `print_stream_request()`.
    
      (print_stream_request): Accept arguments; interpret each as a stream
      name, and dump its info if it exists.  in range.  Migrate existing
      report of all open streams to use new function.
    
    Begins fixing <https://savannah.gnu.org/bugs/?68952>.
---
 ChangeLog                | 12 ++++++++++
 src/roff/troff/input.cpp | 60 +++++++++++++++++++++++++++++++++---------------
 2 files changed, 53 insertions(+), 19 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 8f4bd9860..a3792bbaa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2026-11-22  G. Branden Robinson <[email protected]>
+
+       * src/roff/troff/input.cpp (struct grostream): Declare new
+       member function `dump()`.
+       (grostream::dump): New member function takes (arbitrary) stream
+       name as argument and dumps stream properties in JSON format to
+       standard error stream.  Logic factored out from
+       `print_stream_request()`.
+       (print_stream_request): Accept arguments; interpret each as a
+       stream name, and dump its info if it exists.  in range.  Migrate
+       existing report of all open streams to use new function.
+
 2026-11-22  G. Branden Robinson <[email protected]>
 
        * src/roff/troff/input.cpp (struct grostream): Fix code style
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index fa99ea38b..448227421 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -8575,6 +8575,7 @@ struct grostream : object {
   FILE * const file;
   grostream(const char *, symbol, FILE *);
   ~grostream();
+  void dump(symbol);
 };
 
 grostream::grostream(const char *fn, symbol m, FILE *fp)
@@ -8586,31 +8587,52 @@ grostream::~grostream()
 {
 }
 
+void grostream::dump(symbol nm)
+{
+  errprint("{\"stream\": ");
+  nm.json_dump();
+  errprint(", \"file name\": ");
+  filename.json_dump();
+  errprint(", \"mode\": ");
+  mode.json_dump();
+  errprint("}");
+  fflush(stderr);
+}
+
 object_dictionary stream_dictionary(20);
 
-// TODO: Support reading a list of stream identifiers as arguments, like
-// `pnr` and `pm`.
 static void print_stream_request() // .pstream
 {
-  object_dictionary_iterator iter(stream_dictionary);
-  symbol stream_name;
+  symbol nm; // stream identifier
   grostream *grost;
-  errprint("[");
   bool need_comma = false;
-  while (iter.get(&stream_name, (object **)&grost)) {
-    assert(!stream_name.is_null());
-    if (stream_name != 0 /* nullptr */) {
-      if (need_comma)
-       errprint(", ");
-      errprint("{\"stream\": ");
-      stream_name.json_dump();
-      errprint(", \"file name\": ");
-      grost->filename.json_dump();
-      errprint(", \"mode\": ");
-      grost->mode.json_dump();
-      errprint("}");
-      fflush(stderr);
-      need_comma = true;
+  errprint("[");
+  if (has_arg()) {
+    do {
+      nm = read_identifier();
+      if (nm.is_null()) {
+       skip_rest_of_argument();
+       continue;
+      }
+      grost = static_cast<grostream *>(stream_dictionary.lookup(nm));
+      if (grost != 0 /* nullptr */) {
+       if (need_comma)
+         errprint(", ");
+       grost->dump(nm);
+       need_comma = true;
+      }
+    } while (has_arg());
+  }
+  else {
+    object_dictionary_iterator iter(stream_dictionary);
+    while (iter.get(&nm, (object **)&grost)) {
+      assert(!nm.is_null());
+      if (nm != 0 /* nullptr */) {
+       if (need_comma)
+         errprint(", ");
+       grost->dump(nm);
+       need_comma = true;
+      }
     }
   }
   // !need_comma implies that the list was empty.  JSON convention is to

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

Reply via email to