autoconf
[Top][All Lists]
Advanced

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

Re: m4_unquote


From: Pavel Roskin
Subject: Re: m4_unquote
Date: Mon, 19 Feb 2001 10:18:51 -0500 (EST)

Hello, Akim!

I'm very glad that you are back!

> > I tried to put some sanity checks to AT_DATA, but finally decided that
> > they are not worth the trouble.
> >
> > However, this macro (m4_unquote) appeared in process and can be useful for
> > somebody. It was hard for me to write it (but it was a great exercize in
> > m4!). I'm not suggesting its inclusion to Autoconf, but maybe it could
> > become a part of an unofficial macro library.
>
> I think that byy definition, if you need that macro something dead
> wrong is happening...

The idea was that some macros take some test on input. There are some
constraints on that text. It's better if m4 checks for them rather than
the shell, since the later will be unable to generate useful error
messages.

In the case of AT_DATA, the requirement is that the argument ends with a
newline unless it's empty. Since AT_DATA expands the argument, it's not
unlikely that the callers of AT_DATA will double quote the argument.

Now, there are three allowed cases for the end of the argument -
nothing, end of line and end of line followed by a closing quote. The
later is especially hard to deal with.

So I desided to remove the quotes manually, and then check the argument:

--- tests/atgeneral.m4
+++ tests/atgeneral.m4
@@ -432,7 +432,11 @@
 # This macro is not robust to active symbols in CONTENTS *on purpose*.
 # If you don't want CONTENT to be evaluated, quote it twice.
 m4_define([AT_DATA],
-[AT_CLEANUP_FILES([$1])dnl
+[m4_if(m4_regexp(m4_unquote(m4_translit([[$2]], [
+], address@hidden)), [\(^$\|@$\)]),
+       -1,
+       [m4_fatal([$0: second argument must end with a newline])])dnl
+AT_CLEANUP_FILES([$1])dnl
 cat >$1 <<'_ATEOF'
 $2[]_ATEOF
 ])

The hardest part was to write m4_unquote. But soon I found that in some
places macros are used in the argument to AT_DATA and they only get a
newline after expansion (see e.g. "Torturing config.status"), so I
abandoned this idea.

> > m4_define([m4_unquote],
> > [m4_patsubst([[$1]], [^\[\[\(.*\)\]\]$], [[\1]])])
>
> m4_define([m4_unquote], address@hidden)
>
> or am I missing something?

Let's expand the arguments:

m4_patsubst([$1], ^\[\[\(.*\)\]\]$, [\1])

If [$1] doesn't match, it's expanded so the the quotes are removed and it
remains unchanged.

But if $1 already has quotes around, then we replace double quotes with
single quotes, that in turn disappear when the result is expanded.

Regards,
Pavel Roskin




reply via email to

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