groff-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[groff] 27/44: [troff]: `pnr` request now accepts arguments.


From: G. Branden Robinson
Subject: [groff] 27/44: [troff]: `pnr` request now accepts arguments.
Date: Tue, 3 Sep 2024 08:05:46 -0400 (EDT)

gbranden pushed a commit to branch master
in repository groff.

commit 13866fdf0b9f154f6f38cca65280d66f19b392f7
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Tue Sep 3 03:21:24 2024 -0500

    [troff]: `pnr` request now accepts arguments.
    
    Didja ever notice that `pnr` produces a lot of output, and it isn't
    sorted?  The `pnr` request now supports dumping only of registers
    specified as arguments.
    
    * src/roff/troff/reg.h (look_up_register): Add second argument,
      `suppress_creation`, with default `false` value, in declaration.
    
    * src/roff/troff/reg.cpp (look_up_register): Skip emission of warning
      and register definition on lookup of nonexistent register if
      `suppress_creation` is true.
    
      (dump_register): New function takes over the work, formerly in
      `dump_register_request()`, of writing to stderr.
    
      (dump_register_request): Handle arguments, treating each as a register
      identifier and dumping it.  Otherwise behave as before.
    
    * doc/groff.texi.in (Debugging):
    * man/groff.7.man (Request short reference):
    * man/groff_diff.7.man (New requests):
    * NEWS: Document it.
---
 ChangeLog              | 21 +++++++++++++++++++++
 NEWS                   |  4 ++++
 doc/groff.texi.in      |  7 ++++---
 man/groff.7.man        |  8 ++++++++
 man/groff_diff.7.man   | 15 ++++++++++-----
 src/roff/troff/reg.cpp | 41 ++++++++++++++++++++++++++++-------------
 src/roff/troff/reg.h   |  4 ++--
 7 files changed, 77 insertions(+), 23 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 03b6f1a3c..bb54af3ba 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2024-09-03  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       [troff]: Didja ever notice that `pnr` produces a lot of output,
+       and it isn't sorted?  The `pnr` request now supports dumping
+       only of registers specified as arguments.
+
+       * src/roff/troff/reg.h (look_up_register): Add second argument,
+       `suppress_creation`, with default `false` value, in declaration.
+       * src/roff/troff/reg.cpp (look_up_register): Skip emission of
+       warning and register definition on lookup of nonexistent
+       register if `suppress_creation` is true.
+       (dump_register): New function takes over the work, formerly in
+       `dump_register_request()`, of writing to stderr.
+       (dump_register_request): Handle arguments, treating each as a
+       register identifier and dumping it.  Otherwise behave as before.
+
+       * doc/groff.texi.in (Debugging):
+       * man/groff.7.man (Request short reference):
+       * man/groff_diff.7.man (New requests):
+       * NEWS: Document it.
+
 2024-09-03  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        * src/roff/troff/reg.cpp (dump_register_request): Report the
diff --git a/NEWS b/NEWS
index 34064e761..9e5d4171d 100644
--- a/NEWS
+++ b/NEWS
@@ -119,6 +119,10 @@ o A new request, `pline`, reports to the standard error 
stream the list
   of output nodes (an internal data structure) corresponding to
   the pending output line.  The list is empty if no such nodes exist.
 
+o The `pnr` request now accepts arguments; each is treated as
+  identifying a register, and its properties reported to the standard
+  error stream.
+
 o The `hla` request, when invoked with no arguments, now clears the
   hyphenation language, disabling automatic hyphenation.
 
diff --git a/doc/groff.texi.in b/doc/groff.texi.in
index 97a1451da..76fb73e88 100644
--- a/doc/groff.texi.in
+++ b/doc/groff.texi.in
@@ -17171,11 +17171,12 @@ Report, to the standard error stream, the names of 
all defined macros,
 strings, and diversions with their sizes in bytes.
 @endDefreq
 
-@Defreq {pnr, }
+@Defreq {pnr, [@Var{reg} @r{@dots{}}]}
 @cindex dumping registers (@code{pnr})
 @cindex registers, dumping (@code{pnr})
-Report the names, contents, and assigned formats of all defined
-registers to the standard error stream.
+Report the name, value, and assigned format of each register @var{reg},
+or, without arguments, those of all defined registers, to the standard
+error stream.
 @endDefreq
 
 @Defreq {ptr, }
diff --git a/man/groff.7.man b/man/groff.7.man
index 6f3609e44..033e423bc 100644
--- a/man/groff.7.man
+++ b/man/groff.7.man
@@ -4042,6 +4042,14 @@ and assigned formats
 of all defined registers to the standard error stream.
 .
 .TPx
+.REQ .pnr "reg \fR\&.\|.\|.\&\fP"
+Report the name,
+value,
+and assigned format of each register
+.I reg
+to the standard error stream.
+.
+.TPx
 .REQ .po
 Change to previous page offset.
 .
diff --git a/man/groff_diff.7.man b/man/groff_diff.7.man
index d96196b6a..767f5e216 100644
--- a/man/groff_diff.7.man
+++ b/man/groff_diff.7.man
@@ -3293,11 +3293,16 @@ The list is empty if there are none.
 .
 .
 .TP
-.B .pnr
-Report the names,
-contents,
-and assigned formats
-of all defined registers to the standard error stream.
+.BR .pnr \~[\c
+.IR reg \~.\|.\|.]
+Report the name,
+value,
+and assigned format of each register
+.IR reg ,
+or,
+without arguments,
+those of all defined registers,
+to the standard error stream.
 .
 .
 .TP
diff --git a/src/roff/troff/reg.cpp b/src/roff/troff/reg.cpp
index 0e767eca9..4aa169a6f 100644
--- a/src/roff/troff/reg.cpp
+++ b/src/roff/troff/reg.cpp
@@ -398,10 +398,10 @@ void set_register(symbol nm, units n)
   r->set_value(n);
 }
 
-reg *look_up_register(symbol nm)
+reg *look_up_register(symbol nm, bool suppress_creation)
 {
   reg *r = static_cast<reg *>(register_dictionary.lookup(nm));
-  if (0 /* nullptr */ == r) {
+  if ((0 /* nullptr */ == r) && !suppress_creation) {
     warning(WARN_REG, "register '%1' not defined", nm.contents());
     r = new number_reg;
     register_dictionary.define(nm, r);
@@ -504,21 +504,36 @@ void rename_register_request()
   skip_line();
 }
 
+static void dump_register(symbol *id, reg *r)
+{
+  errprint("%1\t", id->contents());
+  const char *value = r->get_string();
+  if (value)
+    errprint("%1", value);
+  const char *format = r->get_format();
+  if (format)
+    errprint("\t\%1", format);
+  errprint("\n");
+}
+
 void dump_register_request()
 {
-  object_dictionary_iterator iter(register_dictionary);
   reg *r;
   symbol identifier;
-  while (iter.get(&identifier, reinterpret_cast<object **>(&r))) {
-    assert(!identifier.is_null());
-    errprint("%1\t", identifier.contents());
-    const char *value = r->get_string();
-    if (value)
-      errprint("%1", value);
-    const char *format = r->get_format();
-    if (format)
-      errprint("\t\%1", format);
-    errprint("\n");
+  if (has_arg()) {
+    do {
+      identifier = get_name();
+      r = look_up_register(identifier, true /* suppress creation */);
+      if (r != 0 /* nullptr */)
+       dump_register(&identifier, r);
+    } while (has_arg());
+  }
+  else {
+    object_dictionary_iterator iter(register_dictionary);
+    while (iter.get(&identifier, reinterpret_cast<object **>(&r))) {
+      assert(!identifier.is_null());
+      dump_register(&identifier, r);
+    }
   }
   fflush(stderr);
   skip_line();
diff --git a/src/roff/troff/reg.h b/src/roff/troff/reg.h
index 415c4160f..9f2a7ea75 100644
--- a/src/roff/troff/reg.h
+++ b/src/roff/troff/reg.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1989-2020 Free Software Foundation, Inc.
+/* Copyright (C) 1989-2024 Free Software Foundation, Inc.
      Written by James Clark (jjc@jclark.com)
 
 This file is part of groff.
@@ -76,7 +76,7 @@ extern void set_register(symbol nm, units n);
 extern void check_output_limits(int x, int y);
 extern void reset_output_registers();
 
-extern reg *look_up_register(symbol);
+extern reg *look_up_register(symbol, bool suppress_creation = false);
 #if 0
 void inline_define_register();
 #endif



reply via email to

[Prev in Thread] Current Thread [Next in Thread]