groff-commit
[Top][All Lists]
Advanced

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

[groff] 28/33: [me]: Add `ld` macro to re-init date/l10n stuff.


From: G. Branden Robinson
Subject: [groff] 28/33: [me]: Add `ld` macro to re-init date/l10n stuff.
Date: Thu, 30 Dec 2021 00:46:50 -0500 (EST)

gbranden pushed a commit to branch temp-mail-fail
in repository groff.

commit 834a9c43bdfe7f538a28553f8124e297e0d0d937
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Sun Dec 26 04:47:19 2021 +1100

    [me]: Add `ld` macro to re-init date/l10n stuff.
    
    * tmac/e.tmac (ld): New macro updates `y2` and `y4` registers and `wa`,
      `wc`, `mo`, `dw`, and `td` strings.
    
    * doc/meref.me.in (Miscellaneous, Predefined Strings):
    * tmac/groff_me.7.man (Macros): Document it.
    
    * tmac/tests/e_ld-works.sh: Add unit test.
    * tmac/tmac.am (tmac_TESTS): Run test.
    
    Fixes <https://savannah.gnu.org/bugs/?61670>.
---
 ChangeLog                | 15 ++++++++++++
 doc/meref.me.in          | 43 ++++++++++++++++++++++++++++++++--
 tmac/e.tmac              | 57 +++++++++++++++++++++++++--------------------
 tmac/groff_me.7.man      |  1 +
 tmac/tests/e_ld-works.sh | 60 ++++++++++++++++++++++++++++++++++++++++++++++++
 tmac/tmac.am             |  1 +
 6 files changed, 150 insertions(+), 27 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index f51cefcf..1eabaaae 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2021-12-26  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       [me]: Add `ld` macro to re-init date/l10n stuff.
+
+       * tmac/e.tmac (ld): New macro updates `y2` and `y4` registers
+       and `wa`, `wc`, `mo`, `dw`, and `td` strings.
+
+       * doc/meref.me.in (Miscellaneous, Predefined Strings):
+       * tmac/groff_me.7.man (Macros): Document it.
+
+       * tmac/tests/e_ld-works.sh: Add unit test.
+       * tmac/tmac.am (tmac_TESTS): Run test.
+
+       Fixes <https://savannah.gnu.org/bugs/?61670>.
+
 2021-12-26  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        * tmac/tests/e_chapter-titles-work.sh: Add unit test for chapter
diff --git a/doc/meref.me.in b/doc/meref.me.in
index 55eacfb6..5d859069 100644
--- a/doc/meref.me.in
+++ b/doc/meref.me.in
@@ -1553,6 +1553,24 @@ picture,
 leaving the drawing position at the top of the picture.
 .sh 1 "Miscellaneous"
 .TL
+.b .ld
+.DE
+Update the
+.NR (y2
+and
+.NR (y4
+registers based on the current value of
+.NR (yr ,
+reinitialize the localized strings
+.ST (dw ,
+.ST (mo ,
+.ST (wa ,
+and
+.ST (wc ,
+and reset
+.ST (td
+based on the foregoing.
+.TL
 .b .re
 .DE
 Reset tab stops to every 0.5i.
@@ -1879,6 +1897,27 @@ reverse the motion and type size change of
 .ST < .
 In \*N mode,
 output a right angle bracket.
+.pp
+\*G \*(ME provides localized strings
+to support documents in several input languages;
+see the
+.i groff_tmac (5)
+man page.
+The date-related strings are initialized
+based on the current date
+when the formatter runs.
+To encode a different date in your document,
+change the \*T date registers as desired
+and then call
+.b .ld
+to update the strings.
+The day of the week is
+.i not
+recomputed from a new calendar date;
+.NR (dw
+must be modified manually.
+The strings can also be defined directly.
+.(b L F
 .TL
 .ST (dw
 .DE
@@ -1903,8 +1942,6 @@ Construct other date formats with
 and
 .NR (y2
 (year of the century).
-Assign the registers to set the date;
-the default is the date of formatting by \*T.
 .TL
 .ST (wa
 .DE
@@ -1919,6 +1956,7 @@ The term the
 .b .$c
 macro uses for
 .q chapter .
+.)b
 .sh 1 "Special Characters"
 .pp
 For modern documents,
@@ -2242,6 +2280,7 @@ and a square \(sq marks \*G extensions.
 \&.ix  M       set indentation without break
 \el\(aq\fI\,d\/\fP\(aq F\(sc   draw horizontal line of length \fId\fP
 \&.lc  M\(sc   set leader repetition character
+\&.ld  M\(sq   reset localization and date info
 \&.ll  M       set line length in \fIme\fP environments
 \&.lp  M       begin fully left-aligned paragraph
 \e*(lq S       left double quotation mark
diff --git a/tmac/e.tmac b/tmac/e.tmac
index 2ed16488..94ac8bf8 100644
--- a/tmac/e.tmac
+++ b/tmac/e.tmac
@@ -1944,34 +1944,41 @@
 .pn \\n%
 ..
 .
-.\" Work around troff `yr` register's y2k problem.
-.nr y2 \n(yr%100
-.af y2 00
-.nr y4 \n(yr+1900
+.\"            *** DATE AND LOCALIZATION ***
 .
-.\"            *** LOCALIZATION ***
+.de ld                 \" *** (re-)initialize date and localization
 .ds wa Appendix\"
 .ds wc Chapter\"
-.if \n(mo=1 .ds mo January
-.if \n(mo=2 .ds mo February
-.if \n(mo=3 .ds mo March
-.if \n(mo=4 .ds mo April
-.if \n(mo=5 .ds mo May
-.if \n(mo=6 .ds mo June
-.if \n(mo=7 .ds mo July
-.if \n(mo=8 .ds mo August
-.if \n(mo=9 .ds mo September
-.if \n(mo=10 .ds mo October
-.if \n(mo=11 .ds mo November
-.if \n(mo=12 .ds mo December
-.if \n(dw=1 .ds dw Sunday
-.if \n(dw=2 .ds dw Monday
-.if \n(dw=3 .ds dw Tuesday
-.if \n(dw=4 .ds dw Wednesday
-.if \n(dw=5 .ds dw Thursday
-.if \n(dw=6 .ds dw Friday
-.if \n(dw=7 .ds dw Saturday
-.ds td \*(mo \n(dy, \n(y4
+.
+.\" Work around troff `yr` register's y2k problem.
+.nr y2 \\n(yr%100
+.af y2 00
+.nr y4 \\n(yr+1900
+.
+.if \\n(mo=1 .ds mo January\"
+.if \\n(mo=2 .ds mo February\"
+.if \\n(mo=3 .ds mo March\"
+.if \\n(mo=4 .ds mo April\"
+.if \\n(mo=5 .ds mo May\"
+.if \\n(mo=6 .ds mo June\"
+.if \\n(mo=7 .ds mo July\"
+.if \\n(mo=8 .ds mo August\"
+.if \\n(mo=9 .ds mo September\"
+.if \\n(mo=10 .ds mo October\"
+.if \\n(mo=11 .ds mo November\"
+.if \\n(mo=12 .ds mo December\"
+.if \\n(dw=1 .ds dw Sunday\"
+.if \\n(dw=2 .ds dw Monday\"
+.if \\n(dw=3 .ds dw Tuesday\"
+.if \\n(dw=4 .ds dw Wednesday\"
+.if \\n(dw=5 .ds dw Thursday\"
+.if \\n(dw=6 .ds dw Friday\"
+.if \\n(dw=7 .ds dw Saturday\"
+.
+.ds td \\*(mo \\n(dy, \\n(y4\"
+..
+.
+.ld
 .
 .
 .\"            *** PARAMETRIC INITIALIZATIONS ***
diff --git a/tmac/groff_me.7.man b/tmac/groff_me.7.man
index 19788b93..cad3fbb8 100644
--- a/tmac/groff_me.7.man
+++ b/tmac/groff_me.7.man
@@ -279,6 +279,7 @@ hx  suppress next page's headers/footers
 i      italicize argument
 ip     begin indented paragraph
 ix     set indentation without break
+ld     reset localization and date info
 ll     set line length
 lp     begin fully left-aligned paragraph
 m1     set page top to header distance
diff --git a/tmac/tests/e_ld-works.sh b/tmac/tests/e_ld-works.sh
new file mode 100755
index 00000000..0c348bc2
--- /dev/null
+++ b/tmac/tests/e_ld-works.sh
@@ -0,0 +1,60 @@
+#!/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"
+
+# Test the `ld` macro.
+
+input='.nr yr 108
+.nr mo 12
+.nr dy 15
+.nr dw 2
+.ld
+.++ C
+.+c "Fleeing the Impoverished, Drunken Countryside for Dublin"
+.pp
+The day was \\*(dw, \\*(td.
+.++ A
+.+c "How to Write for The Toast"
+.pp
+Submit it on spec.'
+
+fail=
+
+wail () {
+    echo "...FAILED" >&2
+    fail=YES
+}
+
+output=$(echo "$input" | "$groff" -Tascii -P-cbou -me)
+
+echo 'checking that `td` string updated correctly' >&2
+echo "$output" | grep -q 'The day was Monday, December 15, 2008\.$' \
+    || wail
+
+echo 'checking for correct English "Chapter" string' >&2
+echo "$output" | grep -Eqx ' +Chapter 1' || wail
+
+echo 'checking for correct English "Appendix" string' >&2
+echo "$output" | grep -Eqx ' +Appendix A' || wail
+
+test -z "$fail"
+
+# vim:set ai et sw=4 ts=4 tw=72:
diff --git a/tmac/tmac.am b/tmac/tmac.am
index 1ecf19ae..a3d4c3cc 100644
--- a/tmac/tmac.am
+++ b/tmac/tmac.am
@@ -189,6 +189,7 @@ tmac_TESTS = \
   tmac/tests/e_delayed-text-marks-work.sh \
   tmac/tests/e_footnote-marks-work.sh \
   tmac/tests/e_footnotes-work-with-columns.sh \
+  tmac/tests/e_ld-works.sh \
   tmac/tests/s_IP-indents-using-paragraph-type-size.sh \
   tmac/tests/s_IP-respects-inter-sentence-space-in-tags.sh \
   tmac/tests/s_PN-works.sh \



reply via email to

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