Article View: comp.text
Article #1602Re: troff string register interpolation if strange char
From: Michael Morrell
Date: Fri, 08 Jun 1990 02:36
Date: Fri, 08 Jun 1990 02:36
58 lines
2314 bytes
2314 bytes
/ hpcuhb:comp.text / leff@.seas.smu.edu (leff) / 1:41 pm Jun 1, 1990 /
A strange control character is being inserted on character interpolations
before a closing \} of an if statement.
In the example below, there are two operations involving interpolation of a
string register before a \} of an if. In the first operation, the output of
the "tm" inside of the macro, M1, includes both an X and a control character.
The second operation shows that the string register X2 receives both an X
and a control character.
I have experienced this problem with both nroff and ditroff.
nroff inserts an octal 36 (^^) while ditroff inserts a control-Q.
The obvious workaround is to insert a dummy statement just before the \}
but I would like to understand what is happening. Any ideas?
.de M1
.if X\\n(R1X1X \{\
.tm \\*(U1\}
.if X\\n(R1X1X \{\
.ds X2 \\*(U1\}
..
.ds U1 X
.nr R1 1
.M1
.tm \*(X2X
----------
The input parsing nroff/troff is very brain-damaged. The \} gets converted to
a token during the early stages (the octal 36 or ^Q you saw). For all the
commands which take as arguments the rest of the line (.ab, .tm, .ds, .as, and
maybe others), the parser will grab all input up to the newline, including the
tokenized \} (fortunately, comments started by \" are converted to a newline
before this step or they would also cause a problem). Note that this also
causes problems with macro calls. As an example:
.de xy
Arg count = \\n(.$
..
.if 1=1 \{\
.xy foo \}
will show that 2 arguments are passed!
I know of no version of nroff or troff which fixes this (and in fact all of the
standard macro packages have errors of this sort). My suggestion is to always
use the following style:
.if <cond> \{. \" comment
<stuff>
.\}
I avoid using "\{\" on the first line since it lets you put a comment on the
if line.
Michael
Technical Details
Message-ID:
<4360003@hpcuhb.HP.COM>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!hplabs!hpcc01!hpcuhb!morrellReferences:
<16321@smunews.UUCP>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!hplabs!hpcc01!hpcuhb!morrell From: morrell@hpcuhb.HP.COM (Michael Morrell) Newsgroups: comp.text Subject: Re: troff string register interpolation if strange char Message-ID: <4360003@hpcuhb.HP.COM> Date: 8 Jun 90 02:36:57 GMT References: <16321@smunews.UUCP> Organization: Hewlett Packard, Cupertino Lines: 58