?? m4
字號:
.P2is equivalent to.P1xyz.P2.UL $4through.UL $9are null, since no corresponding arguments were provided..PP.PPLeading unquoted blanks, tabs, or newlines that occur during argument collectionare discarded.All other white space is retained.Thus.P1define(a, b c).P2defines.UL ato be.UL b\ \ \ c ..PPArguments are separated by commas, but parentheses are counted properly,so a comma ``protected'' by parentheses does not terminate an argument.That is, in.P1define(a, (b,c)).P2there are only two arguments;the second is literally.UL (b,c) .And of course a bare comma or parenthesis can be inserted by quoting it..SHArithmetic Built-ins.PPM4 provides two built-in functions for doing arithmeticon integers (only).The simplest is.UL incr ,which increments its numeric argument by 1.Thus to handle the common programming situationwhere you want a variable to be defined as ``one more than N'',write.P1define(N, 100)define(N1, `incr(N)').P2Then.UL N1is defined as one more than the current value of.UL N ..PPThe more general mechanism for arithmetic is a built-incalled.UL eval ,which is capable of arbitrary arithmetic on integers.It provides the operators(in decreasing order of precedence).DSunary + and \(mi** or ^ (exponentiation)* / % (modulus)+ \(mi== != < <= > >=! (not)& or && (logical and)\(or or \(or\(or (logical or).DEParentheses may be used to group operations where needed.All the operands ofan expression given to.UL evalmust ultimately be numeric.The numeric value of a true relation(like 1>0)is 1, and false is 0.The precision in.UL evalis32 bits on.UC UNIXand 36 bits on.UC GCOS ..PPAs a simple example, suppose we want .UL Mto be .UL 2**N+1 .Then.P1define(N, 3) define(M, `eval(2**N+1)').P2As a matter of principle, it is advisableto quote the defining text for a macrounless it is very simple indeed(say just a number);it usually gives the result you want,and is a good habit to get into..SHFile Manipulation.PPYou can include a new file in the input at any time bythe built-in function.UL include :.P1include(filename).P2inserts the contents of.UL filenamein place of the.UL includecommand.The contents of the file is often a set of definitions.The valueof.UL include(that is, its replacement text)is the contents of the file;this can be captured in definitions, etc..PPIt is a fatal error if the file named in.UL includecannot be accessed.To get some control over this situation, the alternate form.UL sincludecan be used;.UL sinclude (``silent include'')says nothing and continues if it can't access the file..PPIt is also possible to divert the output of M4 to temporary files during processing,and output the collected material upon command.M4 maintains nine of these diversions, numbered 1 through 9.If you say.P1divert(n).P2all subsequent output is put onto the end of a temporary filereferred to as.UL n .Diverting to this file is stopped by another .UL divert command;in particular,.UL divertor.UL divert(0)resumes the normal output process..PPDiverted text is normally output all at onceat the end of processing,with the diversions output in numeric order.It is possible, however, to bring back diversionsat any time,that is, to append them to the current diversion..P1undivert.P2brings back all diversions in numeric order, and.UL undivertwith arguments brings back the selected diversionsin the order given.The act of undiverting discards the diverted stuff,as does diverting into a diversion whose number is not between 0 and 9 inclusive..PPThe value of.UL undivertis.ulnotthe diverted stuff.Furthermore, the diverted material is.ulnotrescanned for macros..PPThe built-in.UL divnumreturns the number of the currently active diversion.This is zero during normal processing..SHSystem Command.PPYou can run any program in the local operating systemwith the.UL syscmdbuilt-in.For example,.P1syscmd(date).P2on.UC UNIXruns the.UL datecommand.Normally.UL syscmdwould be used to create a filefor a subsequent.UL include ..PPTo facilitate making unique file names, the built-in.UL maketempis provided, with specifications identical to the system function.ulmktemp:a string of XXXXX in the argument is replacedby the process id of the current process..SHConditionals.PPThere is a built-in called.UL ifelsewhich enables you to perform arbitrary conditional testing.In the simplest form,.P1ifelse(a, b, c, d).P2compares the two strings.UL aand.UL b .If these are identical, .UL ifelsereturnsthe string.UL c ;otherwise it returns.UL d .Thus we might define a macro called.UL comparewhich compares two strings and returns ``yes'' or ``no''if they are the same or different..P1define(compare, `ifelse($1, $2, yes, no)').P2Note the quotes,which prevent too-early evaluation of.UL ifelse ..PPIf the fourth argument is missing, it is treated as empty..PP.UL ifelsecan actually have any number of arguments,and thus provides a limited form of multi-way decision capability.In the input.P1ifelse(a, b, c, d, e, f, g).P2if the string.UL amatches the string.UL b ,the result is.UL c .Otherwise, if.UL dis the same as.UL e ,the result is.UL f .Otherwise the result is.UL g .If the final argumentis omitted, the result is null,so.P1ifelse(a, b, c).P2is.UL cif .UL amatches.UL b ,and null otherwise..SHString Manipulation.PPThe built-in.UL lenreturns the length of the string that makes up its argument.Thus.P1len(abcdef).P2is 6, and.UL len((a,b))is 5..PPThe built-in.UL substrcan be used to produce substrings of strings..UL substr(s,\ i,\ n)returns the substring of.UL sthat starts at the.UL i thposition(origin zero),and is.UL ncharacters long.If .UL nis omitted, the rest of the string is returned,so.P1substr(`now is the time', 1).P2is.P1ow is the time.P2If .UL ior.UL nare out of range, various sensible things happen..PP.UL index(s1,\ s2)returns the index (position) in.UL s1where the string.UL s2occurs, or \-1if it doesn't occur.As with.UL substr ,the origin for strings is 0..PPThe built-in.UL translitperforms character transliteration..P1translit(s, f, t).P2modifies.UL sby replacing any character found in.UL fby the corresponding character of.UL t .That is,.P1translit(s, aeiou, 12345).P2replaces the vowels by the corresponding digits.If.UL tis shorter than.UL f ,characters which don't have an entry in.UL tare deleted; as a limiting case,if.UL tis not present at all,characters from .UL fare deleted from .UL s .So.P1translit(s, aeiou).P2deletes vowels from .UL s ..PPThere is also a built-in called.UL dnlwhich deletes all characters that follow it up toand including the next newline;it is useful mainly for throwing away empty lines that otherwise tend to clutter up M4 output.For example, if you say.P1define(N, 100)define(M, 200)define(L, 300).P2the newline at the end of each line is not part of the definition,so it is copied into the output, where it may not be wanted.If you add.UL dnlto each of these lines, the newlines will disappear..PPAnother way to achieve this, due to J. E. Weythman,is.P1divert(-1) define(...) ...divert.P2.SHPrinting.PPThe built-in.UL errprintwrites its arguments out on the standard error file.Thus you can say.P1errprint(`fatal error').P2.PP.UL dumpdefis a debugging aid whichdumps the current definitions of defined terms.If there are no arguments, you get everything;otherwise you get the ones you name as arguments.Don't forget to quote the names!.SHSummary of Built-ins.PPEach entry is preceded by thepage number where it is described..DS.tr '\'`\`.ta .25i3 changequote(L, R)1 define(name, replacement)4 divert(number)4 divnum5 dnl5 dumpdef(`name', `name', ...)5 errprint(s, s, ...)4 eval(numeric expression)3 ifdef(`name', this if true, this if false)5 ifelse(a, b, c, d)4 include(file)3 incr(number)5 index(s1, s2)5 len(string)4 maketemp(...XXXXX...)4 sinclude(file)5 substr(string, position, number)4 syscmd(s)5 translit(str, from, to)3 undefine(`name')4 undivert(number,number,...).DE.SHAcknowledgements.PPWe are indebted to Rick Becker, John Chambers,Doug McIlroy,and especially Jim Weythman,whose pioneering use of M4 has led to several valuable improvements.We are also deeply grateful to Weythman for several substantial contributionsto the code..SG.SHReferences.LP.IP [1]B. W. Kernighan and P. J. Plauger,.ulSoftware Tools,Addison-Wesley, Inc., 1976.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -