groff-commit
[Top][All Lists]
Advanced

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

[groff] 35/35: [mm]: Refactor author title handling.


From: G. Branden Robinson
Subject: [groff] 35/35: [mm]: Refactor author title handling.
Date: Fri, 16 Jul 2021 20:39:49 -0400 (EDT)

gbranden pushed a commit to branch master
in repository groff.

commit 4fd984adc9468080aa2c7e762f83dddb28790bd1
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Sat Jul 17 10:19:16 2021 +1000

    [mm]: Refactor author title handling.
    
    * contrib/mm/m.tmac (AU): Emit error diagnostic and skip remainder of
      macro definition if called without arguments; this will keep people
      familiar with the ms package from getting incorrect and surprising
      output.  Initialize `cov*at!` array element to zero for current author
      number (`AT` already updates it).
    
    * contrib/mm/mm/ms.cov (cov@print-authors): Enforce requirement
      documented in groff_mm(7) that .AU is mandatory if .COVER is used.
      Emit diagnostic if `cov*au` is not defined, and skip remainder of
      macro definition.  Test for existence of authors' titles differently;
      now that `cov*at!` (a count of titles for the current author) is
      guaranteed to be initialized, we can use it as part of a while loop
      condition, instead of the hard-coded "9" as an arbitrary limit on the
      allowed quantity of author titles (though surely even that is
      obnoxiously high in practice), and more importantly avoid using a \w
      escape to measure the width of the interpolation of a potentially
      undefined string.  Use `nop` to indent text output.  Delete apparent
      typo causing `mac` warning with respect to undefined `.` macro.
      Introduce temporary strings for the author and author title "loop
      indices" to shorten and clarify logic.  Remove them when done.
    
    Fixes <https://savannah.gnu.org/bugs/?60926>.
---
 contrib/mm/ChangeLog | 28 ++++++++++++++++++++++++++++
 contrib/mm/m.tmac    | 30 +++++++++++++++++-------------
 contrib/mm/mm/ms.cov | 27 +++++++++++++++------------
 3 files changed, 60 insertions(+), 25 deletions(-)

diff --git a/contrib/mm/ChangeLog b/contrib/mm/ChangeLog
index 7b6f4b4..da0d40d 100644
--- a/contrib/mm/ChangeLog
+++ b/contrib/mm/ChangeLog
@@ -1,5 +1,33 @@
 2021-07-17  G. Branden Robinson <g.branden.robinson@gmail.com>
 
+       Refactor author title handling.
+
+       * m.tmac (AU): Emit error diagnostic and skip remainder of macro
+       definition if called without arguments; this will keep people
+       familiar with the ms package from getting incorrect and
+       surprising output.  Initialize `cov*at!` array element to zero
+       for current author number (`AT` already updates it).
+
+       * mm/ms.cov (cov@print-authors): Enforce requirement documented
+       in groff_mm(7) that .AU is mandatory if .COVER is used.  Emit
+       diagnostic if `cov*au` is not defined, and skip remainder of
+       macro definition.  Test for existence of authors' titles
+       differently; now that `cov*at!` (a count of titles for the
+       current author) is guaranteed to be initialized, we can use it
+       as part of a while loop condition, instead of the hard-coded "9"
+       as an arbitrary limit on the allowed quantity of author titles
+       {though surely even that is obnoxiously high in practice}, and
+       more importantly avoid using a \w escape to measure the width of
+       the interpolation of a potentially undefined string.  Use `nop`
+       to indent text output.  Delete apparent typo causing `mac`
+       warning with respect to undefined `.` macro.  Introduce
+       temporary strings for the author and author title "loop indices"
+       to shorten and clarify logic.  Remove them when done.
+
+       Fixes <https://savannah.gnu.org/bugs/?60926>.
+
+2021-07-17  G. Branden Robinson <g.branden.robinson@gmail.com>
+
        * mm/ms.cov (cov@print-title): Enforce requirement documented in
        groff_mm(7) that .TL is mandatory if .COVER is used.  Emit
        diagnostic if `cov*title` is not defined, and skip remainder of
diff --git a/contrib/mm/m.tmac b/contrib/mm/m.tmac
index e7f1dae..5329eea 100644
--- a/contrib/mm/m.tmac
+++ b/contrib/mm/m.tmac
@@ -3012,23 +3012,27 @@ in=\\n[.i] fi=\\n[.u] .d=\\n[.d] nl=\\n[nl] pg=\\n[%]
 .\" .AU name [initials [loc [dept [ext [room [arg [arg [arg]]]]]]]]
 .de AU
 .cov@title-end
-.pg@disable-top-trap
-.nr cov*au +1
-.nr cov*i 0 1
-.ds cov*au!\\n[cov*au]!1
-.while \\n[.$]>=\\n+[cov*i] \{\
-.      ds cov*au!\\n[cov*au]!\\n[cov*i] "\\$[\\n[cov*i]]
-.\}
-.if (\\n[.$]>=3)&(\w@\\$3@) \{\
-.      if d cov*location-\\$3] \{\
-.              ds cov*au!3!\\n[cov*au] \\*[cov*location-\\$3]
+.ie !\\n[.$] .@error AU: no arguments
+.el \{\
+.      pg@disable-top-trap
+.      nr cov*au +1
+.      nr cov*at!\\n[cov*au] 0 \" no titles for this author yet
+.      nr cov*i 0 1
+.      ds cov*au!\\n[cov*au]!1
+.      while \\n[.$]>=\\n+[cov*i] \{\
+.              ds cov*au!\\n[cov*au]!\\n[cov*i] "\\$[\\n[cov*i]]
+.      \}
+.      if (\\n[.$]>=3)&(\w@\\$3@) \{\
+.              if d cov*location-\\$3] \{\
+.                      ds cov*au!3!\\n[cov*au] \\*[cov*location-\\$3]
+.              \}
 .      \}
 .\}
 ..
 .\"-------------------
-.\" .AT title1 [title2 [... [title9] ]]]]
-.\" Well, thats all that COVEND look for.
-.\" Must appear directly after .AU
+.\" .AT title [...]
+.\" Any quantity of titles may be declared.
+.\" Must be called directly after the corresponding .AU.
 .de AT
 .if \\n[.$]<1 .@error "AT: no arguments"
 .nr cov*at!\\n[cov*au] \\n[.$]
diff --git a/contrib/mm/mm/ms.cov b/contrib/mm/mm/ms.cov
index d371b69..e04727d 100644
--- a/contrib/mm/mm/ms.cov
+++ b/contrib/mm/mm/ms.cov
@@ -43,20 +43,23 @@ http://savannah.gnu.org/bugs/?group=groff.
 ..
 .\"------------
 .de cov@print-authors
-.SP
-.nr cov*i 0 1
-.while \\n+[cov*i]<=\\n[cov*au] \{\
-.      ce
-\fI\\*[cov*au!\\n[cov*i]!1]\fP
-.      nr cov*j 0 1
-.      while \\n+[cov*j]<=9 \{\
-.              if d cov*at!\\n[cov*i]!\\n[cov*j] \{\
-.                      if \w'\\*[cov*at!\\n[cov*i]!\\n[cov*j]]' \{\
-.                              ce
-\s-1\\*[cov*at!\\n[cov*i]!\\n[cov*j]]\s0
-.                      .\}
+.ie !\\n[cov*au] .@error COVEND: no authors (AU) defined
+.el \{
+.      SP
+.      nr cov*i 0 1
+.      while \\n+[cov*i]<=\\n[cov*au] \{\
+.              ds cov*aname \\*[cov*au!\\n[cov*i]!1]
+.              ce
+.              nop \fI\\*[cov*aname]\fP
+.              nr cov*j 0 1
+.              while \\n+[cov*j]<=\\n[cov*at!\\n[cov*i]] \{\
+.                      ds cov*atitle \\*[cov*at!\\n[cov*i]!\\n[cov*j]]
+.                      ce
+.                      nop \s-1\\*[cov*atitle]\s0
 .              \}
+.              rm cov*atitle
 .      \}
+.      rm cov*aname
 .\}
 ..
 .\"------------



reply via email to

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