1

How can I wrap LINE and FILE macros in M4 to display '4' or "4". I want it to be ready for output to the console. I am using C++ for this.

1 Answers1

1

Not 100% percent sure if this is what you're after but this makes __file__ to output filename in quotes (on my mac os):

define(`_m4__file__',defn(`__file__'))
pushdef(`__file__',`"_m4__file__"')

define(`_m4__line__',defn(`__line__'))
pushdef(`__line__',`"_m4__line__"')

define(`echo',`$*')
echo(__file__,__line__)
echo(__file__,__line__)

output:

"m4.t","8"
"m4.t","9"

for single quotes use a bit more escaping:

define(`_m4__file__',defn(`__file__'))
pushdef(`__file__',`''`_m4__file__'`'')

define(`_m4__line__',defn(`__line__'))
pushdef(`__line__',`''`_m4__line__'`'')

define(`echo',`$*')
echo(__file__,__line__)
echo(__file__,__line__)

outputs:

'm4.t','8'
'm4.t','9'
Alexander Balabin
  • 2,055
  • 11
  • 13