gbranden pushed a commit to branch master
in repository groff.

commit df8d63c38f4ee583d9d0c8b1d4b0eeebfca8c2a0
Author: G. Branden Robinson <[email protected]>
AuthorDate: Sat Apr 12 08:02:11 2025 -0500

    [troff]: Report open streams using JSON syntax.
    
    * src/roff/troff/input.cpp (print_streams): Do it.
    
    * doc/groff.texi.in (Debugging):
    * man/groff.7.man (Request short reference):
    * man/groff_diff.7.man (New requests): Document it.
    
    Input:
    
    .open thing thing.txt
    .open otherthing otherthing.txt
    .pstream
    .close thing
    .pstream
    .close otherthing
    .pstream
    
    Before:
    
    thing   thing.txt       writing
    otherthing      otherthing.txt  writing
    otherthing      otherthing.txt  writing
    
    After:
    
    $ tg -Uz EXPERIMENTS/test-streams3.groff
    [ {"stream": "otherthing", "file name": "otherthing.txt\u0000\u0000", 
"mode": "writing"}, {"stream": "thing", "file name": "thing.txt\u0000\u00E6", 
"mode": "writing"} ]
    [ {"stream": "otherthing", "file name": "otherthing.txt\u0000\u0000", 
"mode": "writing"} ]
    [  ]
    
    ("Why the nulls in the file name?"  Because the `grostream` structure
    backs the file name with a groff `string` object, which can contain
    nulls, instead of a `symbol`.  That should be fixed.)
---
 ChangeLog                |  9 +++++++++
 doc/groff.texi.in        | 16 ++++++++++++++--
 man/groff.7.man          |  7 +++++--
 man/groff_diff.7.man     |  7 +++++--
 src/roff/troff/input.cpp | 17 ++++++++++++++---
 5 files changed, 47 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 1af1f746b..035c430f2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2025-04-12  G. Branden Robinson <[email protected]>
+
+       * src/roff/troff/input.cpp (print_streams): Report open streams
+       using JSON syntax.
+
+       * doc/groff.texi.in (Debugging):
+       * man/groff.7.man (Request short reference):
+       * man/groff_diff.7.man (New requests): Document it.
+
 2025-04-13  G. Branden Robinson <[email protected]>
 
        * src/roff/troff/input.cpp (grostream::grostream):
diff --git a/doc/groff.texi.in b/doc/groff.texi.in
index b4e0007db..9d5b66231 100644
--- a/doc/groff.texi.in
+++ b/doc/groff.texi.in
@@ -17935,8 +17935,20 @@ to the standard error stream.
 @cindex dumping open streams (@code{pstream})
 @cindex open streams, dumping (@code{pstream})
 @cindex streams, open, dumping (@code{pstream})
-Report, to the standard error stream, the name of each opened stream,
-the name of the file backing it, and its mode (writing or appending).
+Report,
+in
+@acronym{JSON}
+syntax to the standard error stream,
+the list of open streams,
+including the name of each open stream,
+the name of the file backing it,
+and its mode
+(writing or appending).
+In
+@acronym{JSON},
+a pair of empty brackets
+@samp{[ ]}
+represents an empty list.
 @endDefreq
 
 @Defreq {ptr, }
diff --git a/man/groff.7.man b/man/groff.7.man
index f5f11dad2..986bd1b95 100644
--- a/man/groff.7.man
+++ b/man/groff.7.man
@@ -4306,8 +4306,11 @@ disabled by default.
 .TPx
 .REQ .pstream
 Report,
-to the standard error stream,
-the name of each opened stream,
+in
+JSON
+syntax to the standard error stream,
+the list of open streams,
+including the name of each open stream,
 the name of the file backing it,
 and its mode
 (writing or appending).
diff --git a/man/groff_diff.7.man b/man/groff_diff.7.man
index b87f891cd..5735536aa 100644
--- a/man/groff_diff.7.man
+++ b/man/groff_diff.7.man
@@ -3498,8 +3498,11 @@ which is passed to
 .TP
 .B .pstream
 Report,
-to the standard error stream,
-the name of each open stream,
+in
+JSON
+syntax to the standard error stream,
+the list of open streams,
+including the name of each open stream,
 the name of the file backing it,
 and its mode
 (writing or appending).
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index b97e2cf5e..e30b3f751 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -7634,14 +7634,25 @@ void print_streams()
   object_dictionary_iterator iter(stream_dictionary);
   symbol stream_name;
   grostream *grost;
+  errprint("[ ");
+  bool need_comma = false;
   while (iter.get(&stream_name, (object **)&grost)) {
     assert(!stream_name.is_null());
     if (stream_name != 0 /* nullptr */) {
-      errprint("%1\t", stream_name.contents());
-      errprint("%1\t%2\n", grost->filename.contents(),
-              grost->mode.contents());
+      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(" ]\n");
   fflush(stderr);
   skip_line();
 }

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

Reply via email to