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.
Asked
Active
Viewed 172 times
1
-
Do you want to wrap the macro, or the replacement text of the macro? – Kerrek SB Jul 02 '15 at 20:23
-
@KerrekSB the replacement macro in a quote. – user5075412 Jul 02 '15 at 20:24
-
In what way are you using C++? Do you mean that you are using m4 to generate C++ code? – William Pursell Jul 02 '15 at 22:08
1 Answers
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