The Unknown Power Tool: m4, Part Two
Dig deeper into m4, and look at included files, diversions, frozen files, and debugging and tracing.
Tuesday, March 15th, 2005
Last month’s column (available online, beginning in May 2005, at
http://www.linux-mag.com/2005-02/power_01.html) presented some basics of the
m4 macro processor. m4 scans input text for defined symbols–
macros– and replaces those symbols with other text and possibly with other symbols. For example, m4 can convert one language into another.
This month, let’s dig deeper into m4 and look at included files, diversions, frozen files, and debugging and tracing. Along the way, we’ll see some of the rough edges of m4’s minimalist language and explore workarounds. Before we start, though, here’s a warning from the GNU m4 info page:
Some people[ find] m4 to be fairly addictive. They first use m4 for simple problems, then take bigger and bigger challenges, learning how to write complex m4 sets of macros along the way. Once really addicted, users pursue writing of sophisticated m4 applications even to solve simple problems, devoting more time debugging their m4 scripts than doing real work. Beware that m4 may be dangerous for the health of compulsive programmers.
So take a deep breath… Good. Now let’s dig in again!
Included Files
m4’s built-in include() macro takes m4’s input from a named file until the end of that file, when the previous input resumes. sinclude() works like include() except that it won’t complain if the included file doesn’t exist.