On Fri, May 16, 2025 at 10:45:54AM -0400, Nikolaos Chatzikonstantinou wrote:
> On Fri, May 16, 2025 at 10:05 AM Eric Blake <ebl...@redhat.com> wrote:
> >
> > On Fri, May 16, 2025 at 08:16:24AM -0500, Eric Blake wrote:
> > > Since you continue to patch things as fast as I report them (now
> > > testing with commit a4cc0f3c):
> > >
> >
> > * At the command line, m4 treats -d as taking an optional argument
> > (POSIX discourages that practice, but m4 was doing it long before
> > POSIX, and since -d is a POSIX extension, it's better to keep status
> > quo).  I don't know how easy or hard it is to make a short option take
> > an optional argument with python's argument parsing libraries; and I
> > also know you are still fine-tuning how debugmode() and --debug
> > behave:
> 
> Yes, I'm aware of that one. There's certain discrepancies between
> argparse and what m4 does. For now I'll try to use argparse and live
> with the differences, but if I manage to get everything else to be
> 100% compatible I will revisit this issue, perhaps write my own argv
> parser.

The python docs for argparse mentions that nargs='?' might work (but
you can't use that with a store_const action).

> 
> > * Commit 45fdad3 broke reading large files:
> > $ seq 2000 > list
> > $ git checkout 45fdad3^
> > $ echo 'len(include(list))' | m4p
> > 8893
> > $ git checkout 45fdad3^
> > $ echo 'len(include(list))' | m4p
> > 8196
> 
> Oops! Thank you, I fixed it and added a test for that as well.

Better, but not perfect:

$ m4 -I tests/resources/
define(list,include(long_file.txt))

len(list)
8893
define(`list',include(long_file.txt`'changecom(1,-))-)

changecom

len(list)
8894
$ m4p -I tests/resources/
define(list,include(long_file.txt))

len(defn(`list'))
8893
define(`list',include(long_file.txt`'changecom(1,-))-)
(hangs here)

(Yes, I have scripts that use changecom inside a call to include in
order to intentionally slurp in an entire file as a comment, by using
a start delimiter present in the file and an end delimiter that I
supply after the include - it makes it possible to handle files as
text without the risk of inadvertent macro expansion and even if the
file's contents are not otherwise balanced m4 constructs)


And another one worth fixing:

$ echo 'define(a,defn(defn))' | m4p --debug aeqt --trace=define
Traceback (most recent call last):
  File "/home/eblake/m4p/.venv/bin/m4p", line 8, in <module>
...
  File "/home/eblake/m4p/m4p/parser.py", line 365, in debug_trace
    debuglevel_args = b"(%b)" % b", ".join(map(self.quote, args[1:]))
                                ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/eblake/m4p/m4p/parser.py", line 263, in quote
    return self.qdelim[0] + s + self.qdelim[1]
           ~~~~~~~~~~~~~~~^~~
TypeError: can't concat Builtin to bytes

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization:  qemu.org | libguestfs.org


Reply via email to