groff-commit
[Top][All Lists]
Advanced

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

[groff] 01/03: Implement new read-only register ".nm".


From: G. Branden Robinson
Subject: [groff] 01/03: Implement new read-only register ".nm".
Date: Thu, 25 Feb 2021 01:45:56 -0500 (EST)

gbranden pushed a commit to branch master
in repository groff.

commit 8ebfa98ccdaead192ff13232107d2f376f8115a8
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Thu Feb 25 09:32:18 2021 +1100

    Implement new read-only register ".nm".
    
    It reports the enablement status of output line numbering (caused by the
    .nm request) irrespective of the temporary suspension of numbering with
    the .nn request.  Needed because there was no way to introspect its
    state, tbl(1) needs to do so, and the writable line number register
    \n[ln] is not a reliable proxy for it.
    
    * src/roff/troff/env.h: Add get_numbering_nodes(), returning `int`,  to
      public interface of `environment` class.
    * src/roff/troff/env.cpp: Implement get_numbering_nodes().
    
    * src/roff/groff/tests/dot-nm_register_works.sh: Test it.
    * src/roff/groff/groff.am (groff_TESTS): Run test.
    
    * doc/groff.texi (Miscellaneous):
    * man/groff_diff.7.man (Language/New number registers):
    * man/groff.7.man (Registers/Read-only registers): Document it.
    
    * NEWS: Add item.
---
 ChangeLog                                     | 22 +++++++++++++++
 NEWS                                          |  9 +++++-
 doc/groff.texi                                |  7 ++++-
 man/groff.7.man                               | 10 ++++++-
 man/groff_diff.7.man                          | 10 ++++++-
 src/roff/groff/groff.am                       |  1 +
 src/roff/groff/tests/dot-nm_register_works.sh | 40 +++++++++++++++++++++++++++
 src/roff/troff/env.cpp                        |  6 ++++
 src/roff/troff/env.h                          |  1 +
 9 files changed, 102 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index db32a2f..e895bf9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+2021-02-25  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       Implement new read-only register ".nm".  It reports the
+       enablement status of output line numbering (caused by the .nm
+       request) irrespective of the temporary suspension of numbering
+       with the .nn request.  Needed because there was no way to
+       introspect its state, tbl(1) needs to do so, and the writable
+       line number register \n[ln] is not a reliable proxy for it.
+
+       * src/roff/troff/env.h: Add get_numbering_nodes(), returning
+       `int`,  to public interface of `environment` class.
+       * src/roff/troff/env.cpp: Implement get_numbering_nodes().
+
+       * src/roff/groff/tests/dot-nm_register_works.sh: Test it.
+       * src/roff/groff/groff.am (groff_TESTS): Run test.
+
+       * doc/groff.texi (Miscellaneous):
+       * man/groff_diff.7.man (Language/New number registers):
+       * man/groff.7.man (Registers/Read-only registers): Document it.
+
+       * NEWS: Add item.
+
 2021-02-23  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        * tmac/s.tmac: Emit warning diagnostic when using a multi-page
diff --git a/NEWS b/NEWS
index eae82e1..0510fd4 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,4 @@
-    Copyright (C) 1992-2020 Free Software Foundation, Inc.
+    Copyright (C) 1992-2021 Free Software Foundation, Inc.
 
     Copying and distribution of this file, with or without modification,
     are permitted in any medium without royalty provided the copyright
@@ -18,6 +18,13 @@ o A new read-only register ".cp" is implemented.  Within a 
.do request,
   groff_diff(7) or the groff Texinfo manual for rationale, use case, and
   example.
 
+o A new read-only register ".nm" is implemented.  It reports the
+  enablement status of output line numbering (caused by the .nm
+  request) irrespective of the temporary suspension of numbering with
+  the .nn request.  This register was introduced because there was no
+  way to introspect its state, tbl(1) needs to be able to do so, and the
+  writable line number register \n[ln] is not a reliable proxy for it.
+
 o Point-size escapes of the form '\sNN', where NN is in the range 10-39,
   are now recognized only in compatibility mode (groff -C); when
   encountered, an error diagnostic is emitted.  In normal mode, \sN is
diff --git a/doc/groff.texi b/doc/groff.texi
index 196576c..042e761 100644
--- a/doc/groff.texi
+++ b/doc/groff.texi
@@ -14627,7 +14627,8 @@ Commands}).
 This section documents parts of @code{gtroff} that cannot (yet) be
 categorized elsewhere in this manual.
 
-@Defreq {nm, [@Var{start} [@Var{inc} [@Var{space} [@Var{indent}]]]]}
+@DefreqList {nm, [@Var{start} [@Var{inc} [@Var{space} [@Var{indent}]]]]}
+@DefregListEndx {.nm}
 @cindex printing line numbers (@code{nm})
 @cindex line numbers, printing (@code{nm})
 @cindex numbers, line, printing (@code{nm})
@@ -14662,6 +14663,10 @@ The parameters of @code{nm} are associated with the 
current environment
 (@pxref{Environments}).  The current output line number is available in
 the register @code{ln}.
 
+The @code{.nm} register tracks the enablement status of line numbering.
+Temporary suspension of numbering with the @code{nn} request does
+@emph{not} alter its value.
+
 @Example
 .po 1m
 .ll 2i
diff --git a/man/groff.7.man b/man/groff.7.man
index a815fd3..1f5d9b6 100644
--- a/man/groff.7.man
+++ b/man/groff.7.man
@@ -8,7 +8,7 @@ groff \- GNU roff language reference
 .\" Legal Terms
 .\" ====================================================================
 .\"
-.\" Copyright (C) 2000-2018, 2020 Free Software Foundation, Inc.
+.\" Copyright (C) 2000-2018, 2020-2021 Free Software Foundation, Inc.
 .\"
 .\" This file is part of groff, the GNU roff type-setting system.
 .\"
@@ -4484,6 +4484,14 @@ request that caused a trap to be sprung.
 Useful in conjunction with register
 .BR .trunc .
 .
+.
+.TPx
+.REG .nm
+1\~if output line numbering is enabled
+(even if temporarily suppressed),
+0\~otherwise.
+.
+.
 .TPx
 .REG .ns
 1\~if in no-space mode, 0\~otherwise.
diff --git a/man/groff_diff.7.man b/man/groff_diff.7.man
index d7f135c..837152e 100644
--- a/man/groff_diff.7.man
+++ b/man/groff_diff.7.man
@@ -8,7 +8,7 @@ groff_diff \- differences between GNU roff and AT&T troff
 .\" Legal Terms
 .\" ====================================================================
 .\"
-.\" Copyright (C) 1989-2018, 2020 Free Software Foundation, Inc.
+.\" Copyright (C) 1989-2018, 2020-2021 Free Software Foundation, Inc.
 .\"
 .\" This file is part of groff, the GNU roff type-setting system.
 .\"
@@ -3732,6 +3732,14 @@ Useful in conjunction with the
 .B \[rs]n[.trunc]
 register.
 .
+.
+.TP
+.B \[rs]n[.nm]
+1\~if output line numbering is enabled
+(even if temporarily suppressed),
+0\~otherwise.
+.
+.
 .TP
 .B \[rs]n[.ns]
 1\~if no-space mode is active, 0\~otherwise.
diff --git a/src/roff/groff/groff.am b/src/roff/groff/groff.am
index 60872d0..7e50651 100644
--- a/src/roff/groff/groff.am
+++ b/src/roff/groff/groff.am
@@ -44,6 +44,7 @@ groff_TESTS = \
   src/roff/groff/tests/adjustment_works.sh \
   src/roff/groff/tests/do_not_loop_infinitely_when_breaking_cjk.sh \
   src/roff/groff/tests/dot-cp_register_works.sh \
+  src/roff/groff/tests/dot-nm_register_works.sh \
   src/roff/groff/tests/on_latin1_device_oq_is_0x27.sh \
   src/roff/groff/tests/recognize_end_of_sentence.sh \
   src/roff/groff/tests/regression_savannah_56555.sh \
diff --git a/src/roff/groff/tests/dot-nm_register_works.sh 
b/src/roff/groff/tests/dot-nm_register_works.sh
new file mode 100755
index 0000000..809bbd3
--- /dev/null
+++ b/src/roff/groff/tests/dot-nm_register_works.sh
@@ -0,0 +1,40 @@
+#!/bin/sh
+#
+# Copyright (C) 2021 Free Software Foundation, Inc.
+#
+# This file is part of groff.
+#
+# groff is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# groff is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+groff="${abs_top_builddir:-.}/test-groff"
+
+DOC='\
+.nf
+foo (\n[.nm])
+.nm 1
+bar (\n[.nm])
+.nn
+baz (\n[.nm])
+.nm
+qux (\n[.nm])
+.fi
+'
+
+set -e
+
+printf '%s' "$DOC" | "$groff" -T utf8 | grep -Fqx 'foo (0)'
+printf '%s' "$DOC" | "$groff" -T utf8 | grep -Fqx '  1 bar (1)'
+printf '%s' "$DOC" | "$groff" -T utf8 | grep -Fqx 'baz (1)'
+printf '%s' "$DOC" | "$groff" -T utf8 | grep -Fqx 'qux (0)'
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index 83e2985..1be8647 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -3151,6 +3151,11 @@ int environment::get_zoom()
   return env_get_zoom(this);
 }
 
+int environment::get_numbering_nodes()
+{
+  return (curenv->numbering_nodes ? 1 : 0);
+}
+
 const char *environment::get_font_family_string()
 {
   return family->nm.contents();
@@ -3488,6 +3493,7 @@ void init_env_requests()
   init_string_env_reg(".M", get_fill_color_string);
   init_string_env_reg(".m", get_glyph_color_string);
   init_hunits_env_reg(".n", get_prev_text_length);
+  init_int_env_reg(".nm", get_numbering_nodes);
   init_int_env_reg(".ps", get_point_size);
   init_int_env_reg(".psr", get_requested_point_size);
   init_vunits_env_reg(".pvs", get_post_vertical_spacing);
diff --git a/src/roff/troff/env.h b/src/roff/troff/env.h
index eb1155b..0c8b8b8 100644
--- a/src/roff/troff/env.h
+++ b/src/roff/troff/env.h
@@ -281,6 +281,7 @@ public:
   hunits get_digit_width();
   int get_font() { return fontno; };   // .f
   int get_zoom();                      // .zoom
+  int get_numbering_nodes();           // .nm
   font_family *get_family() { return family; }
   int get_bold();                      // .b
   int get_adjust_mode();               // .j



reply via email to

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