bug-m4
[Top][All Lists]
Advanced

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

Re: m4 bug?


From: Gary V . Vaughan
Subject: Re: m4 bug?
Date: Thu, 9 Aug 2001 10:09:30 +0100

In an ancient message, Pavel Aksonov wrote:
> Could you help me?
> ================================================
> define(_if,`<if cond="$1">$2<else/>$3</if>')dnl
> define(_goto,`<goto next="#$1"/>')dnl
> define(_if_goto,`_if($1,`_goto($1)',`_goto($2)')')dnl
> _if_goto(a, b, c)
> ================================================
> Why this cod gives:
> <if cond="a"><goto next="#a"/><else/>_goto(b)</if>
>
> instead of
>
> <if cond="a"><goto next="#a"/><else/><goto next="#b"/></if>

Just incase you didn't figure this out by other means, the reason is that
`#' is the m4 comment start character, and rescanning stops when it sees
an unquoted comment start.  The following all work correctly:

  $ m4
  define(`_if', `<if cond="$1">$2<else/>$3</if>')dnl
  define(`_goto', `<goto next="$1"/>')dnl
  define(`_if_goto', `_if($1,`_goto($1)',`_goto($2)')')dnl
  _if_goto(a, b, c)

  <if cond="a"><goto next="a"/><else/><goto next="b"/></if>
  define(`_goto', `<goto next="`#'$1"/>')dnl
  _if_goto(a, b, c)

  <if cond="a"><goto next="#a"/><else/><goto next="#b"/></if>
  define(`_goto', `<goto next="#$1"/>')dnl
  changecom(`', `')dnl
  _if_goto(a, b, c)

  <if cond="a"><goto next="#a"/><else/><goto next="#b"/></if>

Cheers,
        Gary.
-- 
  ())_. Gary V. Vaughan     gary@(oranda.demon.co.uk|gnu.org)
  ( '/  Research Scientist  http://www.oranda.demon.co.uk       ,_())____
  / )=  GNU Hacker          http://www.gnu.org/software/libtool  \'      `&
`(_~)_  Tech' Author        http://sources.redhat.com/autobook   =`---d__/



reply via email to

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