bugGNU roff - Bugs: bug #64529, [ms] confusing diagnostics when...

 
 

bug #64529: [ms] confusing diagnostics when starting document with blank line or `KF` call

Submitter:  Dave <barx>
Submitted:  Tue 08 Aug 2023 10:47:42 AM UTC
   
 
Category:  Macro ms Severity:  3 - Normal
Item Group:  Warning/Suspicious behaviour Status:  Need Info
Privacy:  Public Assigned to:  None
Open/Closed:  Open Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Sat 13 Jan 2024 09:17:43 PM UTC, comment #4: 


comment #3:

> [Savannah thinks I'm the submitter, but it's really Doug--unfortunately, this field isn't editable.]


Ah, thanks, Dave.

Doug,

Any thoughts on comment #1?

Regards,
Branden

G. Branden Robinson <gbranden>
Group administrator
Sat 13 Jan 2024 09:13:46 PM UTC, comment #3: 

[Savannah thinks I'm the submitter, but it's really Doug--unfortunately, this field isn't editable.]

Dave <barx>
Group Member
Sat 13 Jan 2024 03:57:54 PM UTC, comment #2: 

Unassigning from self--"Need Info" status is waiting on submitter (or the general public), not me.

G. Branden Robinson <gbranden>
Group administrator
Tue 22 Aug 2023 05:05:58 PM UTC, comment #1: 

I thought there was a rule that you absolutely had to call an ms macro of some sort (no explicit list is known to me) before attempting to produce any output, and a blank input line produces output.

Let me grub around for Lesk 197something...

Hmm.  Well, Lesk doesn't quite come out and say that.

He says, "Type normally, except that instead of indenting for paragraphs, place a line reading ‘‘.PP’’ before each paragraph. This will produce indenting and extra space. Alternatively, the command .LP ... will produce a left-aligned (block) paragraph."

A bit later, "The first line of a document signals the general format of the first page."

I can't find a sterner admonition than this, and it's not all that stern.

I reckon the more important question is, what should GNU do?

As a first stab, we can give the user a more helpful diagnostic message.

Here are the two input exhibits.


$ cat EXPERIMENTS/premature-input1.ms
.KF
.LP
.KE
$ cat EXPERIMENTS/premature-input2.ms

.KF
.LP
.KE


groff 1.23.0 output:


$ nroff -ms EXPERIMENTS/premature-input1.ms |cat -s
s.tmac:EXPERIMENTS/premature-input1.ms:2: error: must be in top-level environment, not 'k', when first page is started
s.tmac:EXPERIMENTS/premature-input1.ms:3: error: .KE without .KS or .KF
$ nroff -ms EXPERIMENTS/premature-input1.ms |cat -s
s.tmac:EXPERIMENTS/premature-input2.ms:4: error: .KE without .KS or .KF


Patch:


$ git diff tmac/
diff --git a/tmac/s.tmac b/tmac/s.tmac
index d3896c791..cd1d9130c 100644
--- a/tmac/s.tmac
+++ b/tmac/s.tmac
@@ -30,6 +30,8 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 .if r GS .nx
 .nr GS 1
 .
+.nr @ms-is-initialized 0
+.
 .mso devtag.tmac
 .nr s@devtag-needs-end-of-heading 0
 .nr s@devtag-needs-end-of-title 0
@@ -119,6 +121,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 .ev nf
 'nf
 .ev
+.nr @ms-is-initialized 1
 ..
 .ds REFERENCES References
 .ds ABSTRACT ABSTRACT
@@ -188,6 +191,12 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 .als AI cov*err-not-before-tl
 .als AB cov*err-not-before-tl
 .de cov*first-page-init
+.if !\\n[@ms-is-initialized] \{\
+.      ds cov*msg formatting output before package initialized;\"
+.      as cov*msg " call .LP, .NH, or similar first
+.      @error \\*[cov*msg]
+.      rm cov*msg
+.\}
 .\" Invoked by '.wh 0' trap on first page.
 .\" We should not come here again, but at short page length,
 .\" recursion may occur; remove trap and macro to avoid it.


New output:


$ ./build/test-groff -m s -T utf8 ./EXPERIMENTS/premature-input1.ms |cat -s
s.tmac:./EXPERIMENTS/premature-input1.ms:2: error: formatting output before package initialized; call .LP, .NH, or similar first
s.tmac:./EXPERIMENTS/premature-input1.ms:2: error: must be in top-level environment, not 'k', when first page is started
s.tmac:./EXPERIMENTS/premature-input1.ms:3: error: .KE without .KS or .KF

$ ./build/test-groff -m s -T utf8 ./EXPERIMENTS/premature-input2.ms |cat -s
s.tmac:./EXPERIMENTS/premature-input2.ms:1: error: formatting output before package initialized; call .LP, .NH, or similar first
s.tmac:./EXPERIMENTS/premature-input2.ms:4: error: .KE without .KS or .KF


Chatty, I know.  Part of the problem is that, as Doug points out, ms doesn't expect you to start a document with a floating keep.

We could make premature input a fatal error, though GNU ms doesn't yet have any of those.

So the package needs an audit of its externally facing macros to ensure that they all either perform initialization or don't assume that it has occurred.  That's a somewhat longer pole.

Comments?

G. Branden Robinson <gbranden>
Group administrator
Tue 08 Aug 2023 10:47:42 AM UTC, original submission:  

Reported by Doug McIlroy, some time ago (http://lists.gnu.org/r/bug-groff/2011-02/msg00009.html).  He discovered it in 1.20.1, but both examples produce essentially the same stderr in 1.23.  In his words:

In groff 1.20.1, -ms input that begins

.KF
.LP

draws a special diagnostic that says .LP "must be in top-level environment, not `k', when first page is started"

But ...  if you put a blank line before .KF,


.KF
.LP
.KE

you get a nonsense diagnostic: "KE without KS or KF".

Both diagnostics strike me as wrong. Why shouldn't a document begin with a keep?

I met the problem in real life, while debugging pic input.  The picture, which was ultimately to be included in a bigger document via .PS <file, was accompanied by a caption--thus it was bracketed by .KF/.KE.

Dave <barx>
Group Member

 

(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 gbranden (Posted a comment)
  • -email is unavailable- added by barx (Submitted the item)
  • -email is unavailable- added by barx (original reporter)
  •  

    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 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2024-01-13 gbranden Assigned togbranden None
    2023-08-22 gbranden StatusNone Need Info
        Assigned toNone gbranden
        Summary[ms] anomalous diagnostic for initial keep [ms] confusing diagnostics when starting document with blank line or `KF` call
    2023-08-08 barx Carbon-Copy- Added -email is unavailable-

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code