On 09/10/2011 03:23 AM, Bruno Haible wrote:
Hi Eric,
Again, I've stumbled across a behaviour of brackets in autoconf macros that
I don't understand.
If in file m4/include_next.m4 at line 210 I add the following code
-------------------------------------------------------------------------------
case "$host_os" in
mingw*)
dnl For the sake of native Windows compilers (excluding
gcc), treat
dnl backslash as a directory separator, like /. Actually,
these
dnl compilers use a double-backslash as directory
separator, inside the
dnl # line "filename"
dnl directives.
gl_absolute_header_sed='\#[/\\]]m4_defn([gl_HEADER_NAME])[#{
^
There's your problem. # is a comment character in m4, which reads until
end-of-line to end the comment. Which means all the [] after the
comment character are treated as part of the comment, instead of as m4
[] quoting.
Rather than trying to use \## matching and s### substitution, why not
use a more traditional character, such as \|| and s|||, which is equally
unlikely to occur in a file name but less likely to trip up m4 quoting
issues?
But when I rearrange the code like this:
gl_dirsep_regex='[/\\]'
Nothing here to prevent the [] from interpretation as m4 quoting
characters - this needs m4 double quoting.
;;
*)
gl_dirsep_regex='/'
;;
esac
gl_absolute_header_sed='\#'"${gl_dirsep_regex}"']m4_defn([gl_HEADER_NAME])[#{
s#.*"\(.*'"${gl_dirsep_regex}"']m4_defn([gl_HEADER_NAME])[\)".*#\1#
s#^/[^/]#//&#
Whereas here, the # turned the rest of the line into an m4 comment, so
the [] is not used as m4 quoting.
Note that the brackets around /\\ have been removed. Why??
And the brackets in the s#^/[^/]#//&# line have not been removed. I don't
see a difference in quotation level between the gl_dirsep_regex definition
and the gl_absolute_header_sed definition.
The difference is in the presence or absence of comments, because of
your choice of # instead of | as the sed delimiter.
If you _must_ use # in your sed script, then you have to double-quote it
in exactly the same situations where you would have to double-quote []
in contexts where you don't want m4 stripping [], something like:
gl_absolute_header_sed='\[#][/\\]]m4_defn([gl_HEADER_NAME])[#{
You can also use m4_changecom() to temporarily disable m4 comments, and
m4_changecom(#,
)
to revert back to normal, to display everywhere within the two changes
where you are relying on m4 comments to suppress m4 expansions.
--
Eric Blake ebl...@redhat.com +1-801-349-2682
Libvirt virtualization library http://libvirt.org