[comp.text] troff question

ring@cg-atla.UUCP (Steve Ring) (01/14/88)

When I create a macro, say
.de XX
.	\" Ignore trailing blank(s), tab, 
.ie '\\$1' ' \{\
.	tm <space> calling NO ARGS:
.	IP
.\}
.el .ie '\\$1'	' \{\
.	tm <tab> calling NO ARGS:
.	IP
.\}
.el \{\
.	tm calling with ARGS:  ["\\$1"] ["\\$2"]
.	IP "\\$1" "\\$2"\}
..

I want to call it with either
.XX
or 
.XX <name> <length>

but if the user has left over <spaces> and/or <tabs> on the end of the .XX
line (when used without parameters), the macro will use these unwanted
<spaces> <tabs> as arguments. The problem is that is you have on a macro line
.<macro><tab>
then the <macros> sees <tab> as argument $1
I want to skip over these. I can test for each one individually as I have
above, but what about the following combinations:

.XX<space><space><tab><EOL>
.XX<tab><tab><tab><EOL>
.XX<space><tab><EOL>
.XX<tab><space><tab><tab><EOL>

in another words, I want the following, somewhat like in sed 
(sed -e 's/[<space><tab>]*//' to get rid of multiple <space><tab> characters).

.ie '\\$1'[<spaces><tabs>]*' .IP	\" There are no arguments
.el .IP \\$1 \\$2

Any help???-- 
Steve Ring, Compugraphic Corp. Wilmington, Mass. 01887 (617)658-5600 X5092
"Transplanted Buckeye - Go BROWNS!"
...!{decvax,ima,ism780c,ulowell,laidbak,cgeuro,cg-f}!cg-atla!ring

hapke@ccvaxa.UUCP (01/16/88)

First of all, you shouldn't need to worry about spaces.  According to
Ossano's "NROFF/TROFF User's Manual", section 7.3, "the argument separator
[for macro arguments] is the space character, ..."  Extra spaces seem to be
ignored in my tests.

Frankly, I've never seen any macro set that checks for the presence on tabs,
etc. in the input.  (I've written and maintained custome macro sets at this
site, and I'm familiar with -ms, -mm, -man, and -me).  Given the clumsy nature
of troff's syntax checking, what you want is probably more effort than it's
worth.  If the macro should have only two or zero arguments, you could use
this code to check that it has the correct number: 

	.de XY
	.\" If the number of args (.$) is either 2 or(:) 0, things are OK
	.ie (\\n(.$=2):(\\n(.$=0) \{\
	.\" body of macro
	.\}
	.el .tm Input error; .XY takes only 2 or 0 arguments
	..

This is more error checking that most macros provided.  Getting the correct
characters in the arguments would be up to the user.

Warren Hapke, Gould CSD-Urbana
   ihnp4!uiucdcs!ccvaxa!hapke

dik@cwi.nl (Dik T. Winter) (01/17/88)

In article <29400005@ccvaxa> hapke@ccvaxa.UUCP writes:
 > 
 > First of all, you shouldn't need to worry about spaces.  According to
 > Ossano's "NROFF/TROFF User's Manual", section 7.3, "the argument separator
 > [for macro arguments] is the space character, ..."  Extra spaces seem to be
 > ignored in my tests.
 > 
Note however that in some cases it is fatal if there are spaces.
E.g. the plain troff request
.tl 'a'b'c'       \" add some spaces
gives unwanted results in nofill mode if the line after it starts
with spaces (tables).  With some versions of troff this results in a wrong
horizontal position for the line.  (This is a bug of course.)
-- 
dik t. winter, cwi, amsterdam, nederland
INTERNET   : dik@cwi.nl
BITNET/EARN: dik@mcvax

morrell@hpsal2.HP.COM (Michael Morrell) (01/20/88)

As a general rule, I've found it useful to get into the habit of making
sure there are no trailing blanks or tabs in my input.  Some people seem
to automatically hit space before return.  Troff treats all tabs as significant
characters and sometimes spaces as well.  I don't think what you're trying to
do is either possible or necessary.


  Michael Morrell
  hpda!morrell

mrc@sceard.Sceard.COM (M.R.Campbell) (09/27/89)

I am looking for a troff macro definition which says from this 
point on the line draw a horizontal line to the right margin.

The idea is the macro will calculate the distance
from the current point on the line to the right margin 
and then pipe the distance to the line drawing function \l.

Of course, the distance to the right margin will 
constantly change.       

Regards,
Michael
__
Mike Campbell  Sceard Systems, Inc. 544 South Pacific St. San Marcos, CA  92069
mrc@Sceard.COM         {hp-sdd,nosc,ucsd,uunet}!sceard!mrc      +1 619 471 0655