bug: quote include makes patsubst no longer handle ^ correctly

Lesmana Zimmer <[email protected]>
Newsgroups gmane.comp.gnu.m4.bugs
Message-ID <[email protected]>
hello fine m4 developers,
i may have found a bug in m4: quoting include makes patsubst no longer 
recognize ^ (beginning of line) in the text apart from the first line.

observe:

     $ cat textnocomma
     some text.
     with sentences.
     and no commas.

     $ cat includenocomma
     foo
     patsubst(include(textnocomma), `^', `    ')
     bar
     patsubst(`include(textnocomma)', `^', `    ')
     baz

     $ m4 includenocomma
     foo
         some text.
         with sentences.
         and no commas.

     bar
         some text.
     with sentences.
     and no commas.

     baz

this also happens when defining the text as "string literals" instead of 
`include`:

     $ cat definestringliterals
     define(`sometext', `first line
     second line
     third line')dnl
     foo
     patsubst(sometext, `^', `    ')
     bar
     patsubst(`sometext', `^', `    ')
     baz

     $ m4 definestringliterals
     foo
         first line
         second line
         third line
     bar
         first line
     second line
     third line
     baz

strangely this does not happen if putting the string literals directly 
inside `patsubst`:

     $ cat patsubststringliterals
     foo
     patsubst(first line
     second line
     third line, `^', `    ')
     bar
     patsubst(`first line
     second line
     third line', `^', `    ')
     baz

     $ m4 patsubststringliterals
     foo
         first line
         second line
         third line
     bar
         first line
         second line
         third line
     baz

using parens to "quote" the text does not have this problem. but now my 
text has parens around it:

     $ cat textcomma
     some text.
     with sentences.
     and, commas.

     $ cat includecomma
     foo
     patsubst(include(textcomma), `^', `    ')
     bar
     patsubst(`include(textcomma)', `^', `    ')
     baz
     patsubst((include(textcomma)), `^', `    ')
     qux

     $ m4 includecomma
     foo
     m4:includecomma:2: Warning: excess arguments to builtin `patsubst' 
ignored
     some text.
     with sentences.
     and
     bar
         some text.
     with sentences.
     and, commas.

     baz
         (some text.
         with sentences.
         and, commas.
         )
     qux

so i guess this is a bug. if quoting `include` then `patsubst` will no 
longer recognize `^` apart from the first line. But quoting `include` is 
necessary to prevent a comma in the text to be interpreted as syntax.

here is the stackoverflow thread which led me to stumble upon this bug:
https://stackoverflow.com/questions/54798556/include-file-and-indent-every-line

my m4 version

     $ m4 --version
     m4 (GNU M4) 1.4.18
     ...

i use the provided m4 from arch repositories

here is the build file: 
https://git.archlinux.org/svntogit/packages.git/tree/trunk/PKGBUILD?h=packages/m4

and the patch used in the build file: 
https://git.archlinux.org/svntogit/packages.git/tree/trunk/m4-1.4.18-glibc-change-work-around.patch?h=packages/m4

the patch is to fix this bug: https://bugs.archlinux.org/task/59562

which seems to be known in the m4 mailing list: 
http://lists.gnu.org/archive/html/bug-m4/2018-12/msg00001.html

so as far as i understand it is the vanilla gnu m4 version 1.4.18 with a 
patch which fixes the build process.

i hope this helps you guys to track this bug down.

if you have questions you can write me. i will try to help.

lesmana zimmer
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.