[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Mon, 19 Feb 2001 10:18:51 -0500 (EST)
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
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:
@@ -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.
+], address@hidden)), [\(^$\|@$\)]),
+ [m4_fatal([$0: second argument must end with a newline])])dnl
cat >$1 <<'_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
But if $1 already has quotes around, then we replace double quotes with
single quotes, that in turn disappear when the result is expanded.