gbranden pushed a commit to branch master in repository groff. commit 5dcf31ee541676d74f59684bbe61a05e4f287690 Author: G. Branden Robinson <g.branden.robin...@gmail.com> AuthorDate: Thu Feb 27 02:15:16 2025 -0600
[troff]: `pnr` request reports autoincr amounts. * src/roff/troff/reg.h (class reg): Declare `const` virtual functions `get_increment()` and `can_autoincrement()` returning `int` and `bool`, respectively. These exist at the root of the register class hierarchy because the `dictionary` class that tracks defined registers effectively erases details of their types. (groff doesn't use RTTI anywhere, and doing so seemed unnecessary, so I didn't explore it.) (class general_reg): Declare non-virtual versions of `get_increment()` and `can_autoincrement()`. * src/roff/troff/reg.cpp: Include "lib.h" since we now need its `INT_DIGITS` symbol. (reg::get_increment): Define as returning constant zero. (reg::can_autoincrement): Define as returning constant false. (general_reg::get_increment): Define. (general_reg::can_autoincrement): Define as returning constant true. (dump_register): If the register can autoincrement, report the autoincrement amount, with an explicit sign for clarity and easy distinction from the register's value and number format. * doc/groff.texi.in (Debugging) <pnr>: * man/groff.7.man (Request short reference) <pnr>: * man/groff_diff.7.man (New requests) <pnr>: Document it. Illustration: $ printf '.nr a 1\n.nr b 2 2\n.nr c 3 999999\n.nr d 4 -2\n.nr e 2147483647 2147483647\n.af b i\n.pnr .a a b c d e\n' | ./build/test-groff .a 0 a 1 +0 0 b 2 +2 i c 3 +999999 0 d 4 -2 0 e 2147483647 +2147483647 0 --- ChangeLog | 28 ++++++++++++++++++++++++++++ doc/groff.texi.in | 11 ++++++++--- man/groff.7.man | 6 ++++-- man/groff_diff.7.man | 2 +- src/roff/troff/reg.cpp | 29 ++++++++++++++++++++++++++++- src/roff/troff/reg.h | 6 +++++- 6 files changed, 74 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index adbd4ee0f..a3212a1ee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,31 @@ +2025-02-27 G. Branden Robinson <g.branden.robin...@gmail.com> + + [troff]: Make `pnr` request report autoincrement amounts. + + * src/roff/troff/reg.h (class reg): Declare `const` virtual + functions `get_increment()` and `can_autoincrement()` returning + `int` and `bool`, respectively. These exist at the root of the + register class hierarchy because the `dictionary` class that + tracks defined registers effectively erases details of their + types. (groff doesn't use RTTI anywhere, and doing so seemed + unnecessary, so I didn't explore it.) + (class general_reg): Declare non-virtual versions of + `get_increment()` and `can_autoincrement()`. + * src/roff/troff/reg.cpp: Include "lib.h" since we now need its + `INT_DIGITS` symbol. + (reg::get_increment): Define as returning constant zero. + (reg::can_autoincrement): Define as returning constant false. + (general_reg::get_increment): Define. + (general_reg::can_autoincrement): Define as returning constant + true. + (dump_register): If the register can autoincrement, report the + autoincrement amount, with an explicit sign for clarity and easy + distinction from the register's value and number format. + + * doc/groff.texi.in (Debugging) <pnr>: + * man/groff.7.man (Request short reference) <pnr>: + * man/groff_diff.7.man (New requests) <pnr>: Document it. + 2025-02-26 G. Branden Robinson <g.branden.robin...@gmail.com> * doc/doc.am: In `DOC_PDFMOM` macro, use `PDFMOMBIN` macro diff --git a/doc/groff.texi.in b/doc/groff.texi.in index 51890e3ff..ffb413860 100644 --- a/doc/groff.texi.in +++ b/doc/groff.texi.in @@ -17580,9 +17580,14 @@ strings, and diversions with their sizes in bytes. @Defreq {pnr, [@Var{reg} @r{@dots{}}]} @cindex dumping registers (@code{pnr}) @cindex registers, dumping (@code{pnr}) -Report the name and value and, if the value is numeric, the assigned -format of each register @var{reg}, or, without arguments, those of all -defined registers, to the standard error stream. +Report the name and value and, +if the value is numeric, +the autoincrement amount and assigned format of each register +@var{reg}, +or, +without arguments, +those of all defined registers, +to the standard error stream. @endDefreq @Defreq {pstream, } diff --git a/man/groff.7.man b/man/groff.7.man index b53338a5d..8c9747d2e 100644 --- a/man/groff.7.man +++ b/man/groff.7.man @@ -4173,14 +4173,16 @@ Report the names, values, and (as applicable) +autoincrement amounts and assigned formats of all defined registers to the standard error stream. . .TPx .REQ .pnr "reg \fR\&.\|.\|.\&\fP" Report the name and value and, if the value is numeric, -the assigned format of each register -.IR reg , +the autoincrement amount and assigned format, +of each register +.I reg to the standard error stream. . .TPx diff --git a/man/groff_diff.7.man b/man/groff_diff.7.man index e248b688d..e12f05848 100644 --- a/man/groff_diff.7.man +++ b/man/groff_diff.7.man @@ -3403,7 +3403,7 @@ The list is empty if there are none. .IR reg \~.\|.\|.] Report the name and value and, if the value is numeric, -the assigned format of each register +the autoincrement amount and assigned format of each register .IR reg , or, without arguments, diff --git a/src/roff/troff/reg.cpp b/src/roff/troff/reg.cpp index c22b088c2..9de106b85 100644 --- a/src/roff/troff/reg.cpp +++ b/src/roff/troff/reg.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 1989-2024 Free Software Foundation, Inc. +/* Copyright (C) 1989-2025 Free Software Foundation, Inc. Written by James Clark (j...@jclark.com) This file is part of groff. @@ -24,6 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "troff.h" #include "dictionary.h" +#include "lib.h" // INT_DIGITS #include "token.h" #include "request.h" #include "reg.h" @@ -50,6 +51,11 @@ void reg::set_increment(units /*n*/) error("cannot automatically increment read-only register"); } +int reg::get_increment() const +{ + return 0; +} + void reg::alter_format(char /*f*/, int /*w*/) { error("cannot assign format of read-only register"); @@ -65,6 +71,11 @@ void reg::set_value(units /*n*/) error("cannot write read-only register"); } +bool reg::can_autoincrement() const +{ + return false; +} + general_reg::general_reg() : format('1'), width(0), inc(0) { } @@ -235,6 +246,16 @@ void general_reg::set_increment(units n) inc = n; } +int general_reg::get_increment() const +{ + return inc; +} + +bool general_reg::can_autoincrement() const +{ + return true; +} + void general_reg::alter_format(char f, int w) { format = f; @@ -521,9 +542,15 @@ void rename_register_request() static void dump_register(symbol *id, reg *r) { int n; + const size_t sz = INT_DIGITS + 1 /* leading sign */; + char inc[sz]; errprint("%1\t", id->contents()); if (r->get_value(&n)) { errprint("%1", n); + if (r->can_autoincrement()) { + (void) snprintf(inc, sz, "%+d", r->get_increment()); + errprint("\t%1", inc); + } const char *f = r->get_format(); assert(f != 0 /* nullptr */); if (f != 0 /* nullptr*/) diff --git a/src/roff/troff/reg.h b/src/roff/troff/reg.h index 9f2a7ea75..d617998eb 100644 --- a/src/roff/troff/reg.h +++ b/src/roff/troff/reg.h @@ -1,4 +1,4 @@ -/* Copyright (C) 1989-2024 Free Software Foundation, Inc. +/* Copyright (C) 1989-2025 Free Software Foundation, Inc. Written by James Clark (j...@jclark.com) This file is part of groff. @@ -24,9 +24,11 @@ public: virtual void increment(); virtual void decrement(); virtual void set_increment(units); + virtual int get_increment() const; virtual void alter_format(char f, int w = 0); virtual const char *get_format(); virtual void set_value(units); + virtual bool can_autoincrement() const; }; // TODO: Use template to parameterize class in the pointed-to data type? @@ -56,6 +58,8 @@ public: void decrement(); void alter_format(char f, int w = 0); void set_increment(units); + int get_increment() const; + bool can_autoincrement() const; const char *get_format(); void add_value(units); _______________________________________________ groff-commit mailing list groff-commit@gnu.org https://lists.gnu.org/mailman/listinfo/groff-commit