m4: how to define var if another defined

m4: how to define var if another defined

Post by Brian C Hi » Fri, 07 May 1999 04:00:00



        I want to do something like this:

        ifelse(YN,`Y',dnl
        define(NAMED,`yes')dnl
        ,`dnl
        ')dnl

        This doesn't work, of course. How do I
define NAMED _only_ if YN is defined?

--
   _____________________________________________________________________

  | Systems Programmer          University of California, Davis         |
  | Unix Specialist             BCH Technical Services                  |

 
 
 

m4: how to define var if another defined

Post by Kjetil Torgrim Homm » Fri, 07 May 1999 04:00:00


[Brian C. Hill]

Quote:>    I want to do something like this:

>    ifelse(YN,`Y',dnl
>    define(NAMED,`yes')dnl
>    ,`dnl
>    ')dnl

>    This doesn't work, of course. How do I
>   define NAMED _only_ if YN is defined?

ifdef(YN, ifelse(...))dnl

Read the fine manual.  The GNU m4 manual (in info-format) is worth a
read as well.

Kjetil T.

 
 
 

m4: how to define var if another defined

Post by Kjetil Torgrim Homm » Sat, 08 May 1999 04:00:00


[Brian C. Hill]

Quote:>    I want to do something like this:

>    ifelse(YN,`Y',dnl
>    define(NAMED,`yes')dnl
>    ,`dnl
>    ')dnl

>    This doesn't work, of course. How do I
>   define NAMED _only_ if YN is defined?

[Kjetil Torgrim Homme]

Quote:>   ifdef(YN, ifelse(...))dnl

This is wrong, of course.  The first problem is that you need to quote
the first argument in an ifdef.  The second problem is that all
arguments to an ifdef or ifelse are evaluated.  My second (imperfect)
attempt would be:

define(`NAMED', `yes')
undefine(ifdef(`YN', __unlikely_symbol__, ``NAMED''))

I don't know offhand how to make a solution which will not clobber
NAMED.

Kjetil T.

 
 
 

1. gcc #define #define #define

Simple. There are several standards designed to alleviate
porting pains. ANSI C, POSIX, X/Open are the major ones.
As long as your program adheres to the above standards it
is easily portable. E.g. for most Xlib and/or Motif programs
it is only required that you need a different makefile
because of various include and lib directories. In fact,
Linux is one of platforms that provide both BSD and SysV
library calls and other features. Try to write or port
something to/from SunOS to IRIX then you will see what all
those #ifdefs are all about. :)

Let me find an example to back up my point: I write a
program and I need to find a way to zero out a memory
area. I found several library functions that can do that,
bzero() and memset(). I look at the bottom of the man
pages:

bzero() CONFORMING TO BSD 4.3

memset() CONFORMING TO SVID 3, BSD 4.3, ISO 9899

Now it is obvious that it is better to use the latter.

Unless, of course, I misunderstood you. What exactly are
you dealing with where you have problems with lots of #ifdefs?
Then maybe me or someone else can provide you some more
specific assistance?

--
<vladimip at uniserve com> | Good pings come in small packets
     Vancouver, BC | SIGSIG: signature too long (core dumped)
Things are more like they are today than they ever were before -
(From a crosspost between alt.suicide and alt.destroy.microsoft)

2. Info needed - How many PPP's at once?

3. #define _POSIX_C_SOURCE and other defines

4. X config problem

5. define env vars for apache on debian

6. TLZ10 only 2GB under 4.0D

7. define a var at lilo prompt

8. Win95 like-FVWM...Here's a start.

9. splitting a var with IFS...

10. Is it OK to replace m4 with GNU m4?

11. make problem with libpcap - m4 and m4 sugar?

12. m4 realtime performance (also, m4 Apache module)?

13. #if defined .... some problems....