[Top][All Lists]

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

Re: string manipulation : removing a part of a string

From: Eric Blake
Subject: Re: string manipulation : removing a part of a string
Date: Fri, 15 Jun 2012 08:33:05 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20120430 Thunderbird/12.0.1

On 06/15/2012 07:18 AM, Vincent Torri wrote:

>> Show more context of what you are trying to do.
> dnl Macro that checks for a compiler flag availability
> dnl
> dnl AC_SUBST : EFL_CFLAGS (EFL being replaced by its value)
> dnl AM_CONDITIONAL : EFL_HAVE_FLAG (FLAG being replaced by its value)

Now we're getting somewhere.  I'm assuming a typical caller would be:

EFL_CHECK_COMPILER([efl], [-Wno-foo], ...)

> [
> m4_pushdef([UPEFL], m4_translit([$1], [-a-z], [_A-Z]))dnl
> m4_pushdef([UP], m4_translit([$2], [-a-z], [_A-Z]))dnl

Unrelated, but this is underquoted, although it is is probably okay
based on your intended usage of EFL_CHECK_COMPILER_FLAG.  A fully-quoted
version would be:

m4_pushdef([UP], m4_translit([[$2]], [-a-z], [_A-Z]))

where the first argument of m4_translit is double-quoted, since
m4_translit strips one level of quoting but you don't want the output ot
m4_translit to be reinterpreted as a macro that might accidentally be
expanded before you get a chance to assign the macro UP.

But what you are doing here is creating a new m4 macro, "UP", whose
contents are the munged value of $2 - or in my example caller above,
that means UP would be defined as "_WNO_FOO".

> tmp=$2

This is a shell assignment (configure-time processing).  It says define
the shell variable tmp to the literal string passed in as the second
argument to EFL_CHECK_COMPILER_FLAG.  Or at shell time, $tmp would
evaluate to "-Wno-foo".

> m4_if(m4_index([$tmp], [-Wno-]), 0, [m4_define([flagm4],
> [m4_bpatsubst([[$tmp]], [no-])])], [m4_define([flagm4], [$tmp])])

But this says to do m4-time processing on the literal string $tmp,
which, since it does not start with -Wno-, always falls to the else
clause of the m4_if.  It sounds like you really wanted to do m4-time
processing on the munged value of $2, not on the literal shell text
$tmp.  And why are you using m4_define here but m4_pushdef above?  It
sounds like you want 'UP' and 'flagm4' to both be in the same category
of temporary m4 variables that contain munged version of the literal
arguments, and where you will popdef them at the end of your macro.  So
why not write it that way?

m4_if(m4_index([$2], [-Wno-]), [0], [m4_pushdef([flagm4],
[m4_bpatsubst([[$2]], [no-])])], [m4_pushdef([flagm4], [$2])])

> flag=flagm4

at which point, since flagm4 is a macro, this would result in the shell


> AC_MSG_NOTICE([flagval :: $flag])

and this would result in a message containing "flagval :: -Wfoo".

Or why even bother with shell variables?  As long as you've got the m4
variable, why not use it directly:

AC_MSG_NOTICE([flagval :: ]flagm4)

Eric Blake   address@hidden    +1-919-301-3266
Libvirt virtualization library

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

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