Stepan Kasal | 10 Jan 2005 14:06
Picon

Re: Bug in M4 documentation

Hello,

[the best place to discuss m4 bugs is bug-m4, so I'm moving the
discussion there]

On Sun, Jan 09, 2005 at 07:38:26PM +0100, Sam Lauber wrote:
> "It is safe to call `m4wrap' from saved text, but the order 
> in which the saved text is read is undefined."
> 
> I do not understand that paragraph, and I think it should be
> changed to a more understandable form.

I think I understand it:
1) it's not an error to call m4wrap in the text saved by m4wrap.
2) the text will be read back before m4 exits, but you cannot say when;
it may be after all other texts saved by m4wrap so far, or between two
of them; I suppose that no text saved by m4wrap will be interrupted by
another text saved this way.

Well, I see now that this formulation leaves space for various
interpretation.

Thank you for reporting this problem.  If you have capacities to help
even more, you could perhaps suggest an explanation.  The developers
would check that it describes what they meant to promise, and update
the documentation.

Thanks,
	Stepan Kasal
(Continue reading)

Stepan Kasal | 10 Jan 2005 14:23
Picon

Re: Bug in M4

Hello,

[again, I'm moving the discussion to bug-m4]

in the bug report below, you say that the text saved by m4wrap should
not be processed at the end of the input when the m4 run is to be frozen.
The text should be saved to the frozen file instead.

I read the node `Frozen files' of the GNU m4 manual, and I think you are
right.  The diversions are already handled like this, and the text saved
by m4wrap should be handled analogically.

I guess this change could be introduced in the next version of m4, as I
hope that people don't usually use m4wrap to get text executed just
before a frozen file is created.

I'm just a member of the bug-m4 list, so my word cannot be taken as a
final decision.  If the maintaners/developers agreed, another question
would be who has time to implement this.  Do you have capacities to
write and donate a patch?

Thank you very much for reporting this problem,
	Stepan Kasal

[The test file from the original bug report is attached to this mail, too.]

On Sun, Jan 09, 2005 at 08:00:44PM +0100, Sam Lauber wrote:
> I am using M4 1.4.2.
> I wrote an example of m4wrap which did the following:
> 
(Continue reading)

Sam Lauber | 13 Jan 2005 02:30

Re: Bug in M4 documentation

I changed it to

`m4wrap can be called from m4wrapped text.  However, the 
order of evaluation can not be determined ahead of time.'

I've attached a diff to m4.texinfo, if that is correct.

Samuel Lauber

----- Original Message -----
From: "Stepan Kasal" <kasal <at> ucw.cz>

> Hello,
> 
> [the best place to discuss m4 bugs is bug-m4, so I'm moving the
> discussion there]
> 
> On Sun, Jan 09, 2005 at 07:38:26PM +0100, Sam Lauber wrote:
> > "It is safe to call `m4wrap' from saved text, but the order in 
> > which the saved text is read is undefined."
> >
> > I do not understand that paragraph, and I think it should be
> > changed to a more understandable form.
> 
> I think I understand it:
> 1) it's not an error to call m4wrap in the text saved by m4wrap.
> 2) the text will be read back before m4 exits, but you cannot say when;
> it may be after all other texts saved by m4wrap so far, or between two
> of them; I suppose that no text saved by m4wrap will be interrupted by
> another text saved this way.
(Continue reading)

David A. Caplan | 14 Jan 2005 16:39
Favicon

m4 comment bug

m4 seems to be picking up single quote characters (') within comment lines 
(both when using # and dnl).  I am using "GNU m4 1.4.1". It also expands 
$1, $2,... if they are within a comment.

Example:
define(`foo',`
# there aren't any arguments to this macro
this is output of the fo`o' macro')
foo

produces an output loop (because foo is recursively called),
=>
=>
=># there arent any arguments to this macro
=>this is output of the
=># there arent any arguments to this macro
=>this is output of the
...

where:
define(`foo',`
# there arent any arguments to this macro
this is output of the `fo'o macro')
foo

The output is:
=>
=>
=># there arent any arguments to this macro
=>this is output of the foo macro
(Continue reading)

Gary V. Vaughan | 14 Jan 2005 18:00
Picon
Gravatar

Re: m4 comment bug

Hi David,

David A. Caplan wrote:
> m4 seems to be picking up single quote characters (') within comment
> lines (both when using # and dnl).  I am using "GNU m4 1.4.1". It also
> expands $1, $2,... if they are within a comment.
> 
> Example:
> define(`foo',`
> # there aren't any arguments to this macro
> this is output of the fo`o' macro')
> foo

I can see 3 problems with this code:

1. The m4 reader breaks tokens up on quote pairs (among others) before it
   starts any parsing, though it strips outer quotes almost immediately:

    token1: define
    token2: (
    token3: foo     {quotes are stripped)
    token4: \n#there aren
    token5: t any arguments to this macro\nthis is output of the foo macro'
    token6: )

   Note that token4 is considered complete when a matching ' character is
   read; token 5 has an unbalanced ' character, and the quotes inside foo
   are stripped because they are a matching outer pair.

   You have to change the quote characters to stop the reader treating
(Continue reading)

Karl Berry | 15 Jan 2005 20:31

m4 manual woes

In m4 1.4.2, the m4.texinfo file uses  <at> ifinfo around the Top node
instead of  <at> ifnottex.  As a result, proper HTML cannot be generated.

Also, since Texinfo has acquired accent commands, they might as well be
used for Francois Pinard's name.

The diff below handles those two things.

I did this in order to update the m4 manual in webcvs, which a user
reported problems with a while ago.  Hope that's ok.  Gary, I don't know
html_node/index.html was not being generated properly by
makeinfo/gendocs.sh for you -- makeinfo has code to handle that case,
and anyway the name of the node is Index not index, so there should be
no collision.  Were you running on Windows?  Anyway, let me know if
problems.

Other fixes needed, not in the diff:
- use  <at> copying and the GFDL instead of the old permission text.
http://www.gnu.org/software/texinfo/manual/texinfo/html_node/Document-Permissions.html

- the START-INFO-DIR-ENTRY stuff should be changed to use  <at> direntry, as in:
 <at> dircategory Text creation and manipulation
 <at> direntry
* m4: (m4).			General-purpose text macro processor.
 <at> end direntry

Happy hacking,
karl

--- /usr/local/gnu/src/m4-1.4.2/doc/orig	2005-01-15 11:12:49.000000000 -0800
(Continue reading)

Wim | 16 Jan 2005 13:58
Favicon

upload

http://ftp.gnu.org/gnu/m4/ gives me strange files. tar.tar instead of tar.gz.
_______________________________________________
Bug-m4 mailing list
Bug-m4 <at> gnu.org
http://lists.gnu.org/mailman/listinfo/bug-m4
Stepan Kasal | 17 Jan 2005 10:27
Picon

Re: upload

Hi,

On Sun, Jan 16, 2005 at 01:58:57PM +0100, Wim wrote:
> http://ftp.gnu.org/gnu/m4/ gives me strange files. tar.tar instead of tar.gz.

I'm not able to reproduce your problem.  Could you please give us more
details?

Regards,
	Stepan Kasal
Gary V. Vaughan | 17 Jan 2005 17:21
Picon
Gravatar

Re: m4 comment bug

David Caplan wrote:
> Hi Gary,

Hi David!

> Thanks for the quick response!

No probs.

> According to the documentation "All characters between the comment
> delimeters are ignored", but you are saying that m4 tokenizes on quotes
> as the very first pass.

Yeah, kindof.  A quoted comment (ala your define argument) is slightly
different to an unquoted comment.  When M4 see's an open quote, then it
reads to the matching close quote, strips the outer quotes and then
goes on to process the quoted content.

> This seems contrary to the documentation as
> well as how every other programming language is parsed.  I think the
> reasonable expectation when one inserts a comment is that the comment
> text will not be parsed or processed in any way.

But similarly, M4 is supposed to read text between quotes without looking
at the content and behaving differently depending on what it sees.

> Is the difference because m4 is not really a traditional programming
> language, but a pre-processing language?  I still think it is
> unreasonable (i.e., a bug) to allow processing to be done within a
> comment by default.

I think I see where we differ here, and it is unfortunate that quoting
in M4 is so difficult to get right.  Rest assured that when you have
mastered the subtleties of quoting and rescanning, then M4s behaviour
becomes much more predictable.

I think you meant to write this:

  define(`foo',
  # there aren't any arguments to foo
  ``this is output of the foo macro'')

Notice that the comment is not quoted now, so references to macros (foo)
and unbalanced quotes (') are left untouched as the reader tokenises the
text between # and \n as a single comment token.

> I think the reasonable solution is to use the
> changequote, or changecom, when one _desires_ parsing of something
> normally thought of as a comment (see example in documentation for
> changecom).

The opposite is true of M4, so unfortunately, I think you will be surprised
by the expansion of foo given the definition above:

  foo
    => # there aren't any arguments to foo
       this is output of the foo macro

But this is correct according to POSIX SUSv3
(http://www.opengroup.org/onlinepubs/009695399/utilities/m4.html):

   Comments are written but not scanned for matching macro names; by
   default, the begin-comment string consists of the number sign character
   and the end-comment string consists of a <newline>.

If you want to write text in the arguments to macros, but have it removed,
then you must remove it yourself since comments in m4 are also a little
different to what you might expect to see in an imperative language.
Fortunately, because arguments are rescanned for expansions, it is easy
to do this (it is referenced in the GNU M4 docs IIRC):

   define(`foo', ifelse(
   # there aren't any arguments to foo
   )``this is output of the foo macro'')
     =>
   foo
     => this is output of the foo macro

So, I've used ifelse to discard the text during scanning, but carefully
retained the # comment start character to prevent the unmatched ' or the
reference to foo from being expanded during rescanning (of the argument
to ifelse).  The original "output" string is still double quoted to prevent
expansion of foo.

Note that if I had started the quotes before ifelse, then the ' in aren't
would have been matched as the end of a quoted string, because the # would
have been quoted.  So this is WRONG:

   define(`foo', `ifelse(
   # there aren't any arguments to foo
   )`this is output of the foo macro'')

Note also that double quoting the entire argument would prevent the ifelse
from being expanded (and discarding its argument) during rescanning.  So this
is WRONG too:

   define(`foo', ``ifelse(
   # there aren't any arguments to foo
   )this is output of the foo macro'')

It is good style to single quote all arguments to macros, except where macros
should be expanded (or comments noticed!) during tokenising, in which case the
quotes must be left off; or when an argument must be left untouched, when
double quoting must be used.  So stylisticly, this is better (although a
little harder to understand):

   define(`foo', `ifelse('
   # there aren't any arguments to foo
   `)`this is output of the foo macro'')
     =>
   foo
     =>this is output of the foo macro

If you are still getting to grips with M4, then there are more surprises ahead
when positional parameters ($1 etc.) come in to play, but feel free to ask on
the list if they are not behaving as you expect.

Also you need to be careful about quoting commas correctly otherwise you
might find the reader starts the next argument prematurely.  And remember
that when the text of arguments to macros are rescanned for expansions,
an unexpected comma could be inserted...

> In your example you changed the quote characters to brackets.  I think
> that it becomes overwhelming to have to constantly change the quote
> characters or comment characters because of punctuation one wants to use
> in a comment.

Indeed.  And, especially because the choice is so critical to the behaviour of
the tokeniser and parser, it is important to choose comment and quote
characters that will not interfere with the body of the files that are
being processed.  In practice, the standard `' quotes occur alone in english
text so often that it is unusual NOT to change them.  The normal practice is
to change them once right at the start of the file, choosing the replacements
wisely to avoid having to change them again later in the file just to avoid
the kinds of problems you are encountering.  Autoconf uses [] because
those characters almost never occur unpaired, so they can be double quoted
to pass them through to the output.

   changequote([,])
   define([foo],
   [[open: [, close: ]]])
     =>
   foo
     => open: [, close: ]

> I'm working with SELinux policy, which uses m4 macros as a convention
> for generating parts of the security policy.  I've found that people
> occasionally put quotes in their comments and this hoses up the
> policies. Perhaps this "convention" was an inappropriate use of m4?

Unfortunately so.  But it is a very common misunderstanding.

> At any rate, as the official voice of m4, you are saying that this is
> not a bug and is the appropriate, reasonable, and expected behavior for
> m4, correct?

Absolutely.  I'm only the official voice of GNU M4 though, the POSIX
committee holds the reins of the standard.

> [I don't intend for this to come across as overly argumentative.  I just
> want to make my case to you/whoever is in charge of m4.]

Not at all.

Hopefully, my long explanation will save others from tripping over the
same gotchas.

Cheers,
	Gary.
--

-- 
Gary V. Vaughan      ())_.  gary <at> {lilith.warpmail.net,gnu.org}
Research Scientist   ( '/   http://tkd.kicks-ass.net
GNU Hacker           / )=   http://www.gnu.org/software/libtool
Technical Author   `(_~)_   http://sources.redhat.com/autobook
_______________________________________________
Bug-m4 mailing list
Bug-m4 <at> gnu.org
http://lists.gnu.org/mailman/listinfo/bug-m4
Roberto Barraco | 18 Jan 2005 14:55
Picon

M4 compilation error

Hi,
I have downloaded today the m4-1.4.1.tar.gz file . 
I have an IBM P615 with AIX 5.2.0.
I have logged as "root"
I have created a temporary directory and gunzipped and untar the
m4-1.4.1.tar.gz file.
I have issued ./configure and then the "make" command ad I receive the
following error :

> make
        CONFIG_FILES= CONFIG_HEADERS=config.h ./config.status
config.status: creating config.h
config.status: config.h is unchanged
config.status: executing default commands
        for subdir in doc lib src checks examples; do  echo making all
in $subdir;  (cd $subdir && make CC='cc' CFLAGS='-g' LDFLAGS=
'' LIBS=''  prefix='/usr/local' exec_prefix='/usr/local' 
bindir='/usr/local/bin' infodir='/usr/local/info' all) || exit 1;  done
making all in doc
        cd . && makeinfo m4.texinfo
Target "all" is up to date.
making all in lib
Target "all" is up to date.
making all in src
        cc -c -DHAVE_CONFIG_H -I.. -I. -I./../lib  -g debug.c
"debug.c", line 228.15: 1506-275 (S) Unexpected text '...'
encountered.
"debug.c", line 246.3: 1506-045 (S) Undeclared identifier va_alist.
make: The error code from the last command is 1.

Stop.
make: The error code from the last command is 1.

Stop.
>

Can you give me any suggestion ?
Many Thanks

Roberto Barraco
Resp. Gestione Sistemi
S.p.A. Autovie Venete
Centro Servizi Palmanova
33050 Bagnaria Arsa (UD)
0432-925438 
fax 0432-925512

Gmane