bugGNU roff - Bugs: bug #61019, [me] using PS and n1 together...

 
 

bug #61019: [me] using PS and n1 together produces a lot of diagnostic noise

Submitter:  G. Branden Robinson <gbranden>
Submitted:  Sat 07 Aug 2021 03:44:48 PM UTC
   
 
Category:  Macro package me Severity:  2 - Minor
Item Group:  Warning/Suspicious behaviour Status:  Fixed
Privacy:  Public Assigned to:  gbranden
Open/Closed:  Closed Planned Release:  1.23.0
* Mandatory Fields

Add a New Comment Rich Markup
   

Sun 08 Aug 2021 10:02:48 AM UTC, comment #3: 


commit 155540306593ac4c81bb3a3fcc04793f44be8541
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
Date:   Sun Aug 8 01:58:43 2021 +1000

    [me]: Fix PS/n1 combination diagnostic spew.

    * tmac/e.tmac (@h): Place comment escape sequence immediately after
      macro argument.  (When redefining a request, one needs to remember
      that request arguments are not parsed exactly as macro arguments are.)
      (n2): Prefix with `do` requests using long register names.
      (n2): Add macro-local register `|l` to store length of first argument.
      Don't attempt to extract a substring beyond its bounds, which produces
      a warning diagnostic.
      (&&): Define no-op macro for use as end macro in nested macro
      definition.
      (PS): Fix unbalanced-else diagnostic by changing `if` to `ie`.
      (PS): Initialize `PS_nm_cnt` register to 0 instead of relying on
      implicit definition.
      (PS): Prefix with `do` definition of long macro name.
      (PS): Indent call of end macro.
      (PS): Add comment after escaped space.
      (PS, PF): Prefix with `do` call of long macro name.

    Fixes <https://savannah.gnu.org/bugs/?61019>.


G. Branden Robinson <gbranden>
Group administrator
Sat 07 Aug 2021 06:12:43 PM UTC, comment #2: 

Thanks, Bjarni.

I already reached the same conclusion; that's why I marked the status as "In Progress".

Here's the current state in my working tree.  I haven't pushed this yet.


diff --git a/ChangeLog b/ChangeLog
index f04a058a..1f9e566d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,28 @@
+2021-08-08  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       [me]: Fix PS/n1 combination diagnostic spew and apparent logic
+       error.
+
+       * tmac/e.tmac (@h): Place comment escape sequence immediately
+       after macro argument.  (When redefining a request, one needs to
+       remember that request arguments are not parsed exactly as macro
+       arguments are.)
+       (n2): Prefix with `do` requests using long register names.
+       (n2): Add macro-local register `|l` to store length of first
+       argument.  Don't attempt to extract a substring beyond its
+       bounds, which produces a warning diagnostic.
+       (&&): Define no-op macro for use as end macro in nested macro
+       definition.
+       (PS): Fix unbalanced-else diagnostic by changing `if` to `ie`.
+       (PS): Initialize `PS_nm_cnt` register to 0 instead of relying on
+       implicit definition.
+       (PS): Prefix with `do` definition of long macro name.
+       (PS): Indent call of end macro.
+       (PS): Add comment after escaped space.
+       (PS, PE): Prefix with `do` call of long macro name.
+
+       Fixes <https://savannah.gnu.org/bugs/?61019>.
+
 2021-08-08  G. Branden Robinson <g.branden.robinson@gmail.com>

        * src/utils/grog/grog.pl (do_line): Recognize `n1` and `n2` as
diff --git a/tmac/e.tmac b/tmac/e.tmac
index 47aaff21..e9f4bd87 100644
--- a/tmac/e.tmac
+++ b/tmac/e.tmac
@@ -288,7 +288,7 @@
 .      sp |\\n(tmu             \" move to top of text
 .ev
 .mk _k                         \" for columned output
-.if \\n(?n=1 .nm 1             \" restore line numbering if n1 mode
+.if \\n(?n=1 .nm 1\"           restore line numbering if n1 mode
 .nr $c 1                       \" set first column
 .if \n@>4 .tm -- @h >> .ns nl=\\n(nl %=\\n% _k=\\n(_k tm=\\n(tm
 .ie \\n(?s \
@@ -577,14 +577,16 @@
 \{\
 .              ds |i \\$1
 .              ds |j \\$1
+.              nr |l 0
 .              \" Pick off leading char and rest to check.
 .              do substring |i 0 0  \"
-.              do substring |j 1    \" for +N / -N
+.              do length |l \\$1
+.              if \\n(|l>1 .do substring |j 1  \" for +N / -N
 .              ie `\\*(|i`+` \
-.                      nr ln (\\n[_ln])+\\*(|j
+.                      do nr ln (\\n[_ln])+\\*(|j
 .              el \
 .                      ie `\\*(|i`-` \
-.                              nr ln (\\n[_ln])-\\*(|j
+.                              do nr ln (\\n[_ln])-\\*(|j
 .                      el \
 .                              nr ln \\$1  \" unsigned N
 .              do nr _#p \\n(.s
@@ -592,6 +594,7 @@
 .              nm \\n(ln
 .              nr ?n 2
 .              rm |i |j
+.              rr |l
 .\}
 .      el \
 .              tm Line \\n(.c -- Bad .n2 value
@@ -599,7 +602,7 @@
 .el \
 \{\
 .      nm
-.      nr _ln \\n(ln
+.      do nr _ln \\n(ln
 .      po +\w'0000'u
 .      ll \\n($lu
 .      nr ?n 0
@@ -1325,6 +1328,9 @@
 .ls
 ..
 .
+.de && \" no-op so we can define and end one macro inside another
+..
+.
 .\"
 .\"    PIC
 .\"
@@ -1336,9 +1342,10 @@
 .ne \\$1u
 .nr g7 \\n(.u
 .ls 1
-.if \\n(?n \
+.ie \\n(?n \
 \{\
-.      de PS_nm_check && \" define macro to emit .nm at top diversion
+.      do nr PS_nm_cnt 0
+.      do de PS_nm_check && \" define macro to emit .nm at top diversion
 .      if \n@>4 .tm -- PS: \\\\$1 \\\\$2 .z=\\\\n(.z PS_nm_cnt=\\\\n[PS_nm_cnt]
 .      \" Multiple .PS/.PE in a keep.
 .      if `\\\\$2`init` \
@@ -1359,18 +1366,18 @@
 .\}
 .\}
 .el \!.PS_nm_check \\\\$1
-.&&
+.      &&
 .      mk _q           \" emit a single numbered line for PS picture
 .      rs
-\&\
+\&\ \" space
 .      br
 .      rt \\n(_qu
-.      PS_nm_check suspend init
+.      do PS_nm_check suspend init
 .\}
 ..
 .
 .de PE                 \" *** end picture
-.if \\n(?n .PS_nm_check resume
+.if \\n(?n .do PS_nm_check resume
 .ls
 .in
 .if \\n(g7 .fi


G. Branden Robinson <gbranden>
Group administrator
Sat 07 Aug 2021 05:59:31 PM UTC, comment #1: 

  This is the result of a bad programming practice;

  macros are not initialised before they are used.

  The message:

troff: EXPERIMENTS/pic.me:2: warning: macro '&&' not defined

  is the clue.

  '&&' is here used as a "terminating macro" (when '..' can't be used),
 thus it must exist when it is encountered.

  Defining it as empty is enough,
 or one could put a diagnostic message in it.


Bjarni Ingi Gislason <bjarniig>
Sat 07 Aug 2021 03:44:48 PM UTC, original submission:  

Input:


.n1
.PS
circle
.PE
Hello,
world.
.n2
.PS
circle
.PF
This is a circle.


Standard error output:


$ ./build/test-groff -p -me -z EXPERIMENTS/pic.me
troff: backtrace: '.../build/../tmac/e.tmac':291: trap-called macro '@h'
troff: backtrace: '.../build/../tmac/e.tmac':1332: macro 'PS'
troff: backtrace: file 'EXPERIMENTS/pic.me':2
troff: EXPERIMENTS/pic.me:2: warning: tab character in unquoted macro argument
troff: backtrace: '.../build/../tmac/e.tmac':291
troff: backtrace: '.../build/../tmac/e.tmac':163: macro 'nm'
troff: backtrace: '.../build/../tmac/e.tmac':291: trap-called macro '@h'
troff: backtrace: '.../build/../tmac/e.tmac':1332: macro 'PS'
troff: backtrace: file 'EXPERIMENTS/pic.me':2
troff: EXPERIMENTS/pic.me:2: warning: tab character where number expected
troff: backtrace: '.../build/../tmac/e.tmac':291
troff: backtrace: '.../build/../tmac/e.tmac':163: macro 'nm'
troff: backtrace: '.../build/../tmac/e.tmac':291: trap-called macro '@h'
troff: backtrace: '.../build/../tmac/e.tmac':1332: macro 'PS'
troff: backtrace: file 'EXPERIMENTS/pic.me':2
troff: EXPERIMENTS/pic.me:2: warning: tab character where number expected
troff: backtrace: '.../build/../tmac/e.tmac':291
troff: backtrace: '.../build/../tmac/e.tmac':163: macro 'nm'
troff: backtrace: '.../build/../tmac/e.tmac':291: trap-called macro '@h'
troff: backtrace: '.../build/../tmac/e.tmac':1332: macro 'PS'
troff: backtrace: file 'EXPERIMENTS/pic.me':2
troff: EXPERIMENTS/pic.me:2: warning: tab character where number expected
troff: backtrace: '.../build/../tmac/e.tmac':1362: macro 'PS'
troff: backtrace: file 'EXPERIMENTS/pic.me':2
troff: EXPERIMENTS/pic.me:2: warning: macro '&&' not defined
troff: backtrace: '.../build/../tmac/e.tmac':1345: macro 'PS_nm_check'
troff: backtrace: '.../build/../tmac/e.tmac':1368: macro 'PS'
troff: backtrace: file 'EXPERIMENTS/pic.me':2
troff: EXPERIMENTS/pic.me:2: warning: register 'PS_nm_cnt' not defined


If you turn on compatibility mode, you get some different diagnostics toward the end.


$ ./build/test-groff -C -p -me -z EXPERIMENTS/pic.me
troff: backtrace: '.../build/../tmac/e.tmac':1367: macro 'PS'
troff: backtrace: file 'EXPERIMENTS/pic.me':2
troff: EXPERIMENTS/pic.me:2: warning: register '_q' not defined
troff: backtrace: file 'EXPERIMENTS/pic.me':15
troff: EXPERIMENTS/pic.me:15: warning: register '00' not defined
troff: EXPERIMENTS/pic.me:2: error: end of file while defining macro 'PS'



G. Branden Robinson <gbranden>
Group administrator

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by bjarniig (Posted a comment)
  • -email is unavailable- added by gbranden (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-08-08 gbranden StatusIn Progress Fixed
        Open/ClosedOpen Closed
        Planned ReleaseNone 1.23.0

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code