groff
[Top][All Lists]
Advanced

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

Re: [Groff] Combining logical operators and conditions


From: Werner LEMBERG
Subject: Re: [Groff] Combining logical operators and conditions
Date: Fri, 28 Jan 2011 13:11:41 +0100 (CET)

> I want to check whether a number register contains a certain number
> and a string register contains one of the predefined strings:
> 
> .ds str1 bar
> .nr nr1 5
> .if ((\n[nr1]=5) & ("\*[str1]"foo" : "\*[str1]"bar" : "\*[str1]"baz")) \{\
> .  tm okay
> .\}

This doesn't work.  groff.info says about 'XXX'YYY' and other
operators:

   Note that these operators can't be combined with other operators
   like `:' or `&'; only a leading `!' (without whitespace between the
   exclamation mark and the operator) can be used to negate the
   result.


> .ds str1 bar
> .nr nr1 5
> .nr nr2 0
> .if "\*[str1]"foo" .nr nr2 1
> .if "\*[str1]"bar" .nr nr2 1
> .if "\*[str1]"baz" .nr nr2 1
> .if ((\n[nr1]=5) & (\n[nr2]=1)) \{\
> .  tm okay
> .\}
> .rr nr2
> 
> That works as expected, but there has to be an obvious and easy
> solution without the additional number register.

Not that I'm aware of.  Note, however, if you have a lot of such
comparisons, you could do the following:

  .ds str1 bar
  .
  .nr nr1 5
  .ds str1-foo \"
  .ds str1-bar \"
  .ds str1-baz \"
  .
  .if d str1-\*[str1] \
  .  if (\n[nr1] == 5 ) \
  .    tm okay


     Werner



reply via email to

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