📄 autobook_197.html
字号:
<HTML><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><!-- Created on September, 12 2004 by texi2html 1.64 --><!-- Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author) Karl Berry <karl@freefriends.org> Olaf Bachmann <obachman@mathematik.uni-kl.de> and many others.Maintained by: Olaf Bachmann <obachman@mathematik.uni-kl.de>Send bugs and suggestions to <texi2html@mathematik.uni-kl.de> --><HEAD><TITLE>Autoconf, Automake, and Libtool: Quoting</TITLE><META NAME="description" CONTENT="Autoconf, Automake, and Libtool: Quoting"><META NAME="keywords" CONTENT="Autoconf, Automake, and Libtool: Quoting"><META NAME="resource-type" CONTENT="document"><META NAME="distribution" CONTENT="global"><META NAME="Generator" CONTENT="texi2html 1.64"><script language="Javascript"><!-- // Check the browser version. function checkVersion() { if (navigator.appVersion.charAt(0)>=3) return true; if (navigator.appVersion.charAt(0)>=4) return true; else return false; } if (checkVersion()) { homeon = new Image(); homeon.src = "homeon.png"; homeoff = new Image(); homeoff.src = "home.png"; tocon = new Image(); tocon.src = "tocon.png"; tocoff = new Image(); tocoff.src = "toc.png"; indexon = new Image(); indexon.src = "indexon.png"; indexoff = new Image(); indexoff.src = "index.png"; helpon = new Image(); helpon.src = "helpon.png"; helpoff = new Image(); helpoff.src = "help.png"; backon = new Image(); backon.src = "backon.png"; backoff = new Image(); backoff.src = "back.png"; forwardon = new Image(); forwardon.src = "forwardon.png"; forwardoff = new Image(); forwardoff.src = "forward.png"; prevon = new Image(); prevon.src = "prevon.png"; prevoff = new Image(); prevoff.src = "prev.png"; nexton = new Image(); nexton.src = "nexton.png"; nextoff = new Image(); nextoff.src = "next.png"; upon = new Image(); upon.src = "upon.png"; upoff = new Image(); upoff.src = "up.png"; } function img_act(imgName) { if (checkVersion()) { imgOn = eval(imgName + "on.src"); document [imgName].src = imgOn; } } function img_inact(imgName) { if (checkVersion()) { imgOff = eval(imgName + "off.src"); document [imgName].src = imgOff; } }// --></SCRIPT></HEAD><BODY LANG="EN" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#6688AA" VLINK="#336688" ALINK="#808080"><A NAME="SEC197"></A><TABLE BORDER=0 CELLPADDING=0 CELLSPACING=10><TR VALIGN="TOP"><TD ALIGN="MIDDLE" WIDTH=50 BGCOLOR="#e6e6e6"><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_196.html#SEC196" onMouseover="img_act('prev')" onMouseout="img_inact('prev')"><IMG SRC="prev.png" BORDER="0" ALT="Back: Macros and macro expansion" ALIGN="MIDDLE" NAME="prev"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_198.html#SEC198" onMouseover="img_act('next')" onMouseout="img_inact('next')"><IMG SRC="next.png" BORDER="0" ALT="Forward: Features of M4" ALIGN="MIDDLE" NAME="next"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"> <TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_198.html#SEC198" onMouseover="img_act('back')" onMouseout="img_inact('back')"><IMG SRC="back.png" BORDER="0" ALT="FastBack: Features of M4" ALIGN="MIDDLE" NAME="back"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_194.html#SEC194" onMouseover="img_act('up')" onMouseout="img_inact('up')"><IMG SRC="up.png" BORDER="0" ALT="Up: Fundamentals of M4 processing" ALIGN="MIDDLE" NAME="up"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_198.html#SEC198" onMouseover="img_act('forward')" onMouseout="img_inact('forward')"><IMG SRC="forward.png" BORDER="0" ALT="FastForward: Features of M4" ALIGN="MIDDLE" NAME="forward"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook.html#SEC_Top" onMouseover="img_act('home')" onMouseout="img_inact('home')"><IMG SRC="home.png" BORDER="0" ALT="Top: Autoconf, Automake, and Libtool" ALIGN="MIDDLE" NAME="home"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_toc.html#SEC_Contents" onMouseover="img_act('toc')" onMouseout="img_inact('toc')"><IMG SRC="toc.png" BORDER="0" ALT="Contents: Table of Contents" ALIGN="MIDDLE" NAME="toc"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_285.html#SEC285" onMouseover="img_act('index')" onMouseout="img_inact('index')"><IMG SRC="index.png" BORDER="0" ALT="Index: Index" ALIGN="MIDDLE" NAME="index"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_abt.html#SEC_About" onMouseover="img_act('help')" onMouseout="img_inact('help')"><IMG SRC="help.png" BORDER="0" ALT="About: About this document" ALIGN="MIDDLE" NAME="help"></A></TD></TR></TABLE></TD><TD ALIGN="LEFT"><H3> 21.3.3 Quoting </H3><!--docid::SEC197::--><P>It is been shown how <CODE>m4</CODE> expands macros when it encounters a namethat matches a defined macro in the input. There are times, however,when you wish to defer expansion. Principally, there are three situationswhen this is so:</P><P><DL COMPACT><DT>Free-form text<DD>There may be free-form text that you wish to appear at the output--andas such, be unaltered by any macros that may be inadvertently invoked inthe input. It is not always possible to know if some particular name isdefined as a macro, so it should be quoted.<P><DT>Overcoming syntax rules<DD>Sometimes you may wish to form strings which would violate M4'ssyntax rules -- for example, you might wish to use leading whitespace ora comma in a macro argument. The solution is to quote the entirestring.<P><DT>Macro arguments<DD>This is the most common situation for quoting: when arguments to macrosare to be taken literally and not expanded as the arguments arecollected. In the previous section, an example was given thatdemonstrates the effects of not quoting the first argument to<CODE>define</CODE>. Quoting macro arguments is considered a good practicethat you should emulate.</DL><P>Strings are quoted by surrounding the quoted text with the <SAMP>``'</SAMP> and<SAMP>`''</SAMP> characters. When <CODE>m4</CODE> encounters a quoted string--as atype of token (<A HREF="autobook_195.html#SEC195">21.3.1 Token scanning</A>)--the quoted string is expanded tothe string itself, with the outermost quote characters removed.</P><P>Here is an example of a string that is triple quoted:</P><P><TABLE><tr><td> </td><td class=smallexample><FONT SIZE=-1><pre>```foo'''=>``foo''</FONT></pre></td></tr></table></P><P>A more concrete example uses quoting to demonstrate how to preventunwanted expansion within macro definitions:</P><P><TABLE><tr><td> </td><td class=smallexample><FONT SIZE=-1><pre>define(`foo', ``bar'')dnldefine(`bar', `zog')dnlfoo=>bar</FONT></pre></td></tr></table></P><P>When the macro <SAMP>`foo'</SAMP> is defined, <CODE>m4</CODE> strips off the outermostquotes and registers the definition <CODE>`bar'</CODE>. The <CODE>dnl</CODE> text hasa special purpose, too, which will be covered in <A HREF="autobook_199.html#SEC199">21.4.1 Discarding input</A>.</P><P>As the macro <SAMP>`foo'</SAMP> is expanded, the next pair of quote charactersare stripped off and the string is expanded to <SAMP>`bar'</SAMP>. Since theexpansion of the quoted string is the string itself (minus the quotecharacters), we have prevented unwanted expansion from the string<SAMP>`bar'</SAMP> to <SAMP>`zog'</SAMP>.</P><P>As mentioned in <A HREF="autobook_195.html#SEC195">21.3.1 Token scanning</A>, the default M4 quotecharacters are <SAMP>``'</SAMP> and <SAMP>`''</SAMP>. Since these are two commonly usedcharacters in Bourne shell programming <A NAME="DOCF51" HREF="autobook_fot.html#FOOT51">(51)</A>,Autoconf reassigns these to the <SAMP>`['</SAMP> and <SAMP>`]'</SAMP> characters--asymmetric looking pair of characters least likely to cause problems whenwriting GNU Autotools macros. From this point forward, we shall use<SAMP>`['</SAMP> and <SAMP>`]'</SAMP> as the quote characters and you can forget aboutthe default M4 quotes.</P><P>Autoconf uses M4's built-in <CODE>changequote</CODE> macro toperform this reassignment and, in fact, this built-in is still availableto you. In recent years, the common practice when needing to use thequote characters <SAMP>`['</SAMP> or <SAMP>`]'</SAMP> or to quote a string with anlegitimately imbalanced number of the quote characters has been toinvoke <CODE>changequote</CODE> and temporarily reassign them around theaffected area:</P><P><TABLE><tr><td> </td><td class=smallexample><FONT SIZE=-1><pre>dnl Uh-oh, we need to use the apostrophe! And even worse, we have twodnl opening quote marks and no closing quote marks.changequote(<<, >>)dnlperl -e 'print "$]\n";'changequote([, ])dnl</FONT></pre></td></tr></table></P><P>This leads to a few potential problems, the least of which is that it'seasy to reassign the quote characters and then forget to reset them,leading to total chaos! Moreover, it is possible to entirely disableM4's quoting mechanism by blindly changing the quote charactersto a pair of empty strings.</P><P>In hindsight, the overwhelming conclusion is that using<CODE>changequote</CODE> within the GNU Autotools framework is a bad idea.Instead, leave the quote characters assigned as <SAMP>`['</SAMP> and <SAMP>`]'</SAMP>and use the special strings <CODE>@<:@</CODE> and <CODE>@:>@</CODE> anywhere youwant real square brackets to appear in your output. This is an easypractice to adopt, because it's faster and less error prone than using<CODE>changequote</CODE>:</P><P><TABLE><tr><td> </td><td class=smallexample><FONT SIZE=-1><pre>perl -e 'print "$@:>@\n";'</FONT></pre></td></tr></table></P><P>This, and other guidelines for using M4 in the GNU Autotoolsframework are covered in detail in <A HREF="autobook_205.html#SEC205">21.5 Writing macros within the GNU Autotools framework</A>.</P><P><A NAME="Features of M4"></A></TR></TABLE><BR> <FONT SIZE="-1">This document was generatedby <I>Gary V. Vaughan</I> on <I>September, 12 2004</I>using <A HREF="http://www.mathematik.uni-kl.de/~obachman/Texi2html"><I>texi2html</I></A></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -