[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Cannot run even a simplest example of define(A, `Harry, MET.')
From: |
Eric Blake |
Subject: |
Re: Cannot run even a simplest example of define(A, `Harry, MET.') |
Date: |
Fri, 7 Jul 2023 10:24:20 -0500 |
User-agent: |
NeoMutt/20230517 |
On Sun, Jun 11, 2023 at 01:42:58PM +0200, 徐心仪 wrote:
> Dear author:
>
> Sorry to bother you with such an easy problem, but I cannot run even the
> simplest example to quote a string:
> I have tried:
> ```
> define(A, 'Harry, MET.')
Wrong. In m4, the open and close quote sequences must be distinct, in
order to allow nesting of quotes. (Technically, m4 won't complain if
you do try to use changequote to set the open and close quotes to the
same string, but the behavior gets quite weird if you do). But
surprisingly, it does NOT cause an error out-of-the box; rather, m4
treats an unmatched close quote character as literal text, so executed
like this, you have defined macro "A" to the contents "'Harry, MET.'"
(including the two unmatched ').
> ```
> and
>
> ```
> define(A, `Harry, MET.')
That is the out-of-the-box default quotation characters, provided you
used actual back-tick and single-quote (ascii \x60 and \x27) and not
some other UTF-8 character accidentally copy-pasted from something
that rendered with "nicer-looking" characters. If this was your first
line of input to m4, it results in macro "A" having contents "Harry,
MET." (no embedded quoting characters, because the quotes were
stripped while collecting arguments to the define macro).
> ```
> and
> ```
> define(A, [Harry, MET.])
That is only possible if you first used changequote([,]) to change
from `' to [] quoting. If you are used to programming for autoconf,
that aspect of the environment was already set up for you (mainly
because autoconf focuses on using m4 to produce shell script snippets,
and it is REALLY hard to write shell scripts with unbalanced ` or ',
but fairly easy to see balanced [] in shell scripts, so changing
quoting to [] makes life easier). Out of the box with `' quoting,
this defines "A" with contents "[Harry, MET.]"; but with a leading
changequote([,]), it would define "A" to contents "Harry, MET.".
> ```
> and
>
> ```
> define(A, [`Harry, MET.'])
That "works", but does different things depending on the current quote
characters. Out of the box, it defines "A" to contents "[Harry,
MET.]" (the fact that [ and ] are outside of the `' quoting is
irrelevant; m4 concatenates raw characters with quoted string
contents). With a leading changequote([,]), it defines "A" to
contents "`Harry, MET.'".
Furthermore, in all of the above, the fact that you did NOT quote
argument A is a potential pitfall; the macro name argument to the
define macro must generally be quoted so as not to inadvertently
trigger macro expansion. So if you are showing snippets attempted
from a single m4 implementation, where your first messed-up define(A,
'Harry, MET.') was already in force, then your second attempt at
define(A, `Harry, MET.') ends up actually invoking the define macro
with the two arguments "'Harry, MET.'" and "Harry, MET."; not the
macro you intended to have defined. You REALLY want to write
define(`A', `Harry, MET.') if using default `' quoting.
> ```
> In addition, the manual in http://gnu.ist.utl.pt/software/m4/manual/m4.pdf
> still describes version 1.4.7, however, my m4 version is 1.4.18.
> I tried to build a manual from https://git.savannah.gnu.org/git/m4.git,
> branch 1.4, however, I couldn't do that.
> ```
> autoreconf -i
> sh: 1: build-aux/git-version-gen: not found
You didn't run ./bootstrap first. bootstrap is only necessary when
checking out from git (if you build from a pre-released tarball, you
don't need to do it). Building from git is not for the faint of heart
- it requires that you already have a pre-installed working m4 from a
tarball in place (the dependency is not circular, but also not
trivial); which is why we recommend that most users build m4 from
release tarballs rather than from git.
> configure.ac:25: error: AC_INIT should be called with package and version
> arguments
> /usr/share/aclocal-1.16/init.m4:29: AM_INIT_AUTOMAKE is expanded from...
> configure.ac:25: the top level
> autom4te: error: /usr/bin/m4 failed with exit status: 1
> aclocal: error: /usr/bin/autom4te failed with exit status: 1
> autoreconf: error: aclocal failed with exit status: 1
> ```
>
> Thank you for your precious time!
>
> Best,
> Xinyi
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: Cannot run even a simplest example of define(A, `Harry, MET.'),
Eric Blake <=