diff options
author | G. Branden Robinson <g.branden.robinson@gmail.com> | 2022-11-28 00:33:16 -0600 |
---|---|---|
committer | G. Branden Robinson <g.branden.robinson@gmail.com> | 2022-11-28 00:33:16 -0600 |
commit | 51f12c7f61bebe78730e561ef4786fdc32b4b687 (patch) | |
tree | 8a8b928feffbf7f0cdb05ff9359c7dbb8bd6676a /src/roff | |
parent | 45515a052d178681891fa5cfc172b7ac3cf3dd6e (diff) | |
download | groff-git-51f12c7f61bebe78730e561ef4786fdc32b4b687.tar.gz |
[troff]: Implement new `.nn` register
...to report the remaining count of lines to have their numbering
suppressed.
* src/roff/troff/env.h (class environment): Declare new member function
`get_no_number_count()`.
* src/roff/troff/env.cpp (get_no_number_count): Define new member
function, returning value of member variable `no_number_count`.
(init_env_requests): Define new ".nn" register and attach it to
`get_no_number_count()`.
* doc/groff.texi (Miscellaneous): Document it. Include example of use
to determine whether current output line will be numbered. Also
clarify meaning of register; `.nn` is not decremented except when
output line numbering is enabled.
* man/groff.7.man (Read-only registers): Document it.
* src/roff/groff/tests/dot-nn_register_works.sh: Test it.
* src/roff/groff/groff.am (groff_TESTS): Run test.
* NEWS: Add item.
See <https://lists.gnu.org/archive/html/groff/2022-11/msg00153.html>.
Diffstat (limited to 'src/roff')
-rw-r--r-- | src/roff/groff/groff.am | 1 | ||||
-rwxr-xr-x | src/roff/groff/tests/dot-nn_register_works.sh | 77 | ||||
-rw-r--r-- | src/roff/troff/env.cpp | 6 | ||||
-rw-r--r-- | src/roff/troff/env.h | 1 |
4 files changed, 85 insertions, 0 deletions
diff --git a/src/roff/groff/groff.am b/src/roff/groff/groff.am index 874400887..8937d4ced 100644 --- a/src/roff/groff/groff.am +++ b/src/roff/groff/groff.am @@ -43,6 +43,7 @@ groff_TESTS = \ 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/dot-nn_register_works.sh \ src/roff/groff/tests/evc_produces_no_output_if_invalid.sh \ src/roff/groff/tests/fp_should_not_traverse_directories.sh \ src/roff/groff/tests/handle_special_input_code_points.sh \ diff --git a/src/roff/groff/tests/dot-nn_register_works.sh b/src/roff/groff/tests/dot-nn_register_works.sh new file mode 100755 index 000000000..0998cb05a --- /dev/null +++ b/src/roff/groff/tests/dot-nn_register_works.sh @@ -0,0 +1,77 @@ +#!/bin/sh +# +# Copyright (C) 2022 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" + +# Unit test .nn register. + +fail= + +wail () { + echo ...FAILED >&2 + fail=YES +} + +input='.ec @ +.de is-numbered +. nop This line +. ie (@@n[.nm] & (1-@@n[.nn])) IS +. el ISN'"'"'T +. nop numbered. +. br +.. +Test line numbering. +.is-numbered +.nm 1 +.nn 2 +.is-numbered +.is-numbered +.is-numbered +.nm +.is-numbered +.pl @n[nl]u' + +# Apply line numbers to the output externally for easy grepping. +output=$(echo "$input" | $groff -Tascii | nl) +echo "$output" + +echo "verifying that line 1 isn't numbered" >&2 +echo "$output" | \ + grep -Eq "[[:space:]]+1[[:space:]]+Test line numbering\." || wail + +echo "verifying that line 2 isn't numbered" >&2 +echo "$output" | \ + grep -Eq "[[:space:]]+2[[:space:]]+This line ISN'T" || wail + +echo "verifying that line 3 isn't numbered" >&2 +echo "$output" | \ + grep -Eq "[[:space:]]+3[[:space:]]+This line ISN'T" || wail + +echo "verifying that line 4 is numbered" >&2 +echo "$output" | \ + grep -Eq "[[:space:]]+4[[:space:]]+1 +This line IS numbered" || wail + +echo "verifying that line 5 isn't numbered" >&2 +echo "$output" | \ + grep -Eq "[[:space:]]+5[[:space:]]+This line ISN'T" || wail + +test -z "$fail" + +# vim:set autoindent expandtab shiftwidth=2 tabstop=2 textwidth=72: diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp index 71bb88581..68aafaa0c 100644 --- a/src/roff/troff/env.cpp +++ b/src/roff/troff/env.cpp @@ -417,6 +417,11 @@ int environment::get_right_justify_lines() return right_justify_lines; } +int environment::get_no_number_count() +{ + return no_number_count; +} + void environment::add_italic_correction() { if (current_tab) { @@ -3493,6 +3498,7 @@ void init_env_requests() 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(".nn", get_no_number_count); 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 c7c6e2039..f6c1d211c 100644 --- a/src/roff/troff/env.h +++ b/src/roff/troff/env.h @@ -311,6 +311,7 @@ public: hunits get_hyphenation_margin(); int get_center_lines(); int get_right_justify_lines(); + int get_no_number_count(); int get_prev_line_interrupted() { return prev_line_interrupted; } color *get_fill_color(); color *get_glyph_color(); |