groff
[Top][All Lists]
Advanced

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

[Groff] Re: Disabling SGR in grotty(1): gory details


From: Ruslan Ermilov
Subject: [Groff] Re: Disabling SGR in grotty(1): gory details
Date: Thu, 24 Oct 2002 13:48:29 +0300
User-agent: Mutt/1.3.99i

On Wed, Oct 23, 2002 at 11:49:37PM +0200, Werner LEMBERG wrote:
> > This seemed to work at a glance, but later I discovered the
> > new .output command, and modified this as follows (the new
> > version produced less noise for ``troff -Tascii /dev/null''):
> >
> > .if n .do output "x X tty: sgr 0
> 
> See below.
> 
> > This seemed to work too, but after a further inspection it
> > turned out it did not -- it broke horribly with everything
> > formatted with the -ms package -- try it with this small
> > chunk of -ms formatted text:
> >
> > .TL
> > Title
> > .AU
> > Author
> > .PP
> >
> > $ groff -b -Tascii -mtty-char -ms <this_chunk>
> > /usr/share/tmac/s.tmac:1095: backtrace: macro address@hidden'
> > /usr/share/tmac/s.tmac:172: backtrace: macro `TL'
> > x:1: warning: number register `0:LL' not defined
> > /usr/share/tmac/s.tmac:1095: backtrace: macro address@hidden'
> > /usr/share/tmac/s.tmac:172: backtrace: macro `TL'
> > x:1: warning: number register `0:ri' not defined
> > /usr/share/tmac/s.tmac:1095: backtrace: macro address@hidden'
> > /usr/share/tmac/s.tmac:172: backtrace: macro `TL'
> > x:1: warning: number register `0:pri' not defined
> > ...
> 
> Reason for the failure is that the ms package plants a trap at
> position zero to call cov*first-page-init; after executing the .output
> request *before* loading the ms macros this trap isn't called at the
> right time.
> 
So technically, this is the result of .output changing the \n[nl]
register, right?

> > Then I remembered seeing this in the Groff info document:
> >
> > : This request can't be used before the first page has started - if
> > : you get an error, simply insert `.br' before the `output' request.
> >
> > I wondered why I do not get any meaningful error as was promised.
> 
> Because the error is based on a not-called macro, and not of an
> internal failure of groff; since .output is called in the top
> diversion, a new page is started automatically.
> 
Let me see if I got you right.  Not-called macro here being .br?
With the .output at the end of troffrc-end, I get:

$ troff -Tascii /dev/null
x T ascii
x res 240 24 40
x init
p1
x X tty: sgr 0
x trailer
V2640
x stop

$ troff -Tascii -ms /dev/null 2>&1
x T ascii
x res 240 24 40
x init
p1
/usr/share/tmac/troffrc-end:21: fatal error: sorry, I didn't manage to begin 
the first page in time: use an explicit .br request
x trailer
V2640
x stop

Is the difference in the -ms case because .output is run while in a
diversion?  I don't quite get it because in both cases I see the `p'
command that is supposed to start a new page.

> > So I have a bunch of questions here, in the order of importancy:
> >
> > 1.  How do I disable the SGR output from troffrc or troffrc-end?
> 
> You must undo the top of page transition by setting the `nl' register
> to a negative value:
> 
>   .if n \{\
>   .  do output "x X tty: sgr 0
>   .  nr nl 0-1
>   .\}
> 
> A very obscure feature but documented in groff.texinfo...  BUT see
> below.
> 
> > 2.  Why don't I get the same error from using .output in troffrc
> >     as if I put it in troffrc-end?
> 
> Because the first time the trap isn't invoked, and the second time it
> is.
> 
> > 3.  Why am I getting these spurious ``character above first line
> >     discarded'' warnings from all -ms formatted texts when SGR
> >     encoded output is enabled?
> 
> If you look at the troff output (with the above change to troffrc),
> you see something similar to this:
> 
>   x T ascii
>   x res 240 24 40
>   x init
>   p1
>   x X tty: sgr 0
>   DFd
>   x font 1 R
>   f1
>   s10
>   V160
>   H696
>   md
>   t-2-
>   ...
> 
> The `x X' line is emitted with the vertical position at zero.
> `Vertical position' is the position of the *baseline*; since there are
> no default offsets for tty, line 0 can't be displayed and is thus
> discarded.  As soon as there is real output, the line number is
> increased by one.
> 
> Thus our next job is to ensure that the vertical position is not zero
> while emitting the `x X' line:
> 
>   .if n \{\
>   .  do nop \X'tty: sgr 0'
>   .  sp -1
>   .  nr nl 0-1
>   .\}
> 
> Result:
> 
>   x T ascii
>   x res 240 24 40
>   x init
>   p1
>   V40
>   H0
>   x font 1 R
>   f1
>   s10
>   md
>   DFd
>   x X tty: sgr 0
>   n40 0
>   V160
>   H696
>   t-2-
>   ...
> 
> This is still not correct: Note the `t-2-' line.  As the last
> correction, we have to decrease the current page number by 1.
> 
>   .if n \{\
>   .  do nop \X'tty: sgr 0'
>   .  sp -1
>   .  nr % -1 
>   .  nr nl 0-1
>   .\}
> 
> Please test.
> 
Seems like what I need.  BUT...  You missed my point.  I get
these spurious warnings when SGR output is on, i.e., with the
stock troffrc and troffrc-end, yet I get them when I set the
GROFF_NO_SGR in environment:

Without SGR disabling stuff in troffrc and troffrc-end, with
the above example -ms chunk, I get:

$ troff -Tascii -ms x |head
x T ascii
x res 240 24 40
x init
p1
DFd
x font 3 B
f3
s10
V400
H648

$ troff -Tascii -ms x |grotty >/dev/null
grotty:<standard input>:5: character above first line discarded

This is fatal for some -ms documents.  For example, the attached
rcs.ms document loses its Abstract section.  The funny thing is
that the SGR disabling stuff you proposed "fixes" this.  :-)


Cheers,
-- 
Ruslan Ermilov          Sysadmin and DBA,
address@hidden          Sunbay Software AG,
address@hidden          FreeBSD committer,
+380.652.512.251        Simferopol, Ukraine

http://www.FreeBSD.org  The Power To Serve
http://www.oracle.com   Enabling The Information Age

Attachment: rcs.ms.gz
Description: application/gunzip


reply via email to

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