Eric Blake | 11 May 02:08 2007

Re: M4 buffering problem? 0d0a -> 0d0d0a

According to MS on 5/9/2007 8:05 AM:
> Hello,
> Versions : 
> i tried M4 1.4 and M4 1.4.7 which both shows the problem
> M4 1.4.4 do not show the problem, but i cannot see a comment, that something
> is fixed in this area

Thanks for the report.  Which platform are you running on (cygwin with
text mounts, mingw, or other)?  I'm assuming it's windows-based and text
file related, since I can't reproduce it on cygwin with binary mounts; I
also suspect that the bug you are seeing is not in m4 proper but in the
stdio library of your platform.  But m4 should still be able to work
around the bug, if possible.  I'm hoping to release m4 1.4.10 once gnulib
is able to work around the known bugs in cygwin's fseeko and mingw's
ftell, and hopefully that will fix the bug for you.

Don't work too hard, make some time for fun as well!

Eric Blake             ebb9 <at>
Eric Blake | 11 May 14:33 2007

[sr #105855] Multi-op patsubst() and translit()

Follow-up Comment #1, sr #105855 (project m4):

Why can't you write your own recursive macro that does this?  translit should
be easy:

# translit(string, regex1, replace1, regex2, replace2, ...)
pushdef([translit], [ifelse(eval([$# <= 3]), 1,
  [builtin([translit], $ <at> )],
  [translit(builtin([translit], [$1], [$2], [$3]),
     shift(shift(shift($ <at> ))))])])

patsubst is a bit harder, since 2.0 is adding the optional resyntax parameter
(you almost need to reverse the argument order, and specify the resyntax
parameter before the list, since it is difficult in recursive algorithms to
get the last argument on the first iteration of action), but still something
you should be able to write a wrapper for.  I'm not sure I see modifying the
builtin to do this, if we can't prove that there is an efficiency issue that
can't be worked around by merely writing wrappers around the existing


Reply to this item at:


  Message sent via/by Savannah
(Continue reading)

Daniel Richard G. | 12 May 03:39 2007

[sr #105855] Multi-op patsubst() and translit()

Follow-up Comment #2, sr #105855 (project m4):

(typeytype in the new-and-improved translit macro)
translit([abc123], [[a-z]], [[A-Z]], [[0-4]], [[5-9]])
=> ABC678
translit([abc)123], [[a-z]], [[A-Z]], [[0-4]], [[5-9]])
=> /opt/m4/bin/m4:stdin:7: Warning: translit: too few arguments: 1 < 2

Robustness against meta-characters was the issue for me.

I didn't go so far as to try a recursive macro, but there were two other
approaches I was experimenting with. First, iteratively operating on a
temp-variable macro...

pushdef([tmp], [$1])
define([tmp], patsubst(tmp, [pat1], [rep1]))
define([tmp], patsubst(tmp, [pat2], [rep2]))

Second, just nesting the patsubst() calls:

patsubst(patsubst(patsubst([$1], [pat1], [rep1]), [pat2], [rep2]), ...)

The problem with all these approaches is in quoting the text argument to
(Continue reading)