Article View: comp.text
Article #6374Re: A Troff Challenge
From: David Slocombe
Date: Sun, 14 May 1989 22:01
Date: Sun, 14 May 1989 22:01
84 lines
3505 bytes
3505 bytes
In article <4971@wiley.UUCP>
simpson%trwarcadia.uucp@usc.edu (Scott Simpson) writes:
>Also, how does the net world debug troff macros? The .tm request helps
>somewhat but it is always executed as soon as it read and you cannot delay
>its output to print out when the macro is executed, not when it is defined.
The .tm request, like any other troff request that is read in as
part of the body of a macro, is not executed until the macro is
called. However, note that number-register and string references
get evaluated at definition-time unless you "defer" their evaluation
by extra backslashes. Hence the content of the message put out by
.tm may reflect the situation at macro-definition time or at
macro-execution time, depending on the number of backslashes on
the \n and \* escape sequences in the message. One backslash means
the escape sequence is evaluated immediately (as the macro is being
defined), while two backslashes mean it will be evaluated as the
macro is being executed. (Complex circumstances can require four
or even eight backslashes.)
The sqtroff execution trace of the following simple troff input
illustrates this point:
.nf
.nr x 22
.tm The value of x is \nx at start.
.de YY
.tm Value of x is \nx at macro definition but \\nx at execution.
Let's do it in text too: \nx at definition, \\nx at execution.
..
.nr x \nx+11 \" 22 + 11 == 33
.tm The value of x is now \nx, after macro definition and before
.tm the execution of the macro.
.YY
.ex
We run this through sqtroff with call-trace enabled (-C) on the
command line, although with real macro packages we would place
".ctrace on" and ".ctrace off" lines in the macros of immediate
interest. (Lines beginning with "% T" are trace-lines. The actual
outputs of the .tm requests are marked with "stderr->". The rest of
the lines are normal intermediate output):
$ sqtroff -C -Tps dns 2>&1 | more
X ps 300 1 1
% T *.STARTUP 8.5 11 @ 21u 17u 56u 25u 8i 10.7i
Y P default letter 2550 3300 21 17 56 25 2400 3210
% T *.ds .pageinfo "P default letter 2550 3300 21 17 56 25 2400 3210
% T *.ds .T "ps
P 1
% T *.nf
% T *.nr x 22
% T *.tm The value of x is 22 at start.
stderr->The value of x is 22 at start.
% T *.de YY
% T *.nr x 22+11
% T *.tm The value of x is now 33, after macro definition and before
stderr->The value of x is now 33, after macro definition and before
% T *.tm the execution of the macro.
stderr->the execution of the macro.
% T .YY (CALL)
% T .YY *.tm Value of x is 22 at macro definition but 33 at execution.
stderr->Value of x is 22 at macro definition but 33 at execution.
V 50
O 289
w 12
L 1950
I 0
N n l 11 1032
f 10 TR
k 0 1
D w 0
= (Let's do it in text too: 22 at de(fi)nition, 33 at execution.)
n
% T .YY (RETURN)
% T *.ex
p 3300
----------------------------------------------------------------
David Slocombe (416) 963-8337
SoftQuad Inc. (800) 387-2777 (from U.S. only)
720 Spadina Ave. uucp: {uunet,utzoo}!sq!dns
Toronto, Ontario, Canada M5S 2T9 Internet: dns@sq.com
Technical Details
Message-ID:
<1989May14.180149.1446@sq.com>Path:
arc1-ca.pugleaf.net!utzoo!attcan!lsuc!sq!dnsReferences:
<4971@wiley.UUCP>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!lsuc!sq!dns From: dns@sq.com (David Slocombe) Newsgroups: comp.text Subject: Re: A Troff Challenge Keywords: troff macros, debugging troff, sqtroff Message-ID: <1989May14.180149.1446@sq.com> Date: 14 May 89 22:01:49 GMT References: <4971@wiley.UUCP> Reply-To: dns@sq.com (David Slocombe) Organization: SoftQuad Inc., Toronto Lines: 84 Checksum: 12068