09.06.2013 Views

Intel XENIX 286 Programmers Guide (86) - Tenox.tc

Intel XENIX 286 Programmers Guide (86) - Tenox.tc

Intel XENIX 286 Programmers Guide (86) - Tenox.tc

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

m4: Macro Processor <strong>XENIX</strong> Programming<br />

Invoking m4<br />

The invocat ion syntax for m4 is<br />

m4 [ filename ] . ..<br />

Each filename argument is processed in order. If there are no arguments, or ·if an<br />

argument is a dash (-), then the standard input is read. The processed text is written to<br />

the standard output and can be redirected as in the following example:<br />

m4 file1 file2 - >outputfi le<br />

Note the use of the dash in the above example to indicate processing of the standard<br />

input, after the files filel and file2 have been processed by m4.<br />

Defining Macros<br />

The primary built-in function of m4 is define, which is used to define new macros. The<br />

input<br />

define(name, stuff)<br />

causes the string name to be defined as stuff. All subsequent occurrences of name will<br />

be replaced by stuff. name must be alphanumeric and must begin with a letter (the<br />

underscore ( ) counts as a letter). stuff is any text, including text that contains<br />

balanced parentheses; it may stre<strong>tc</strong>h over multiple lines.<br />

Thus, as a typical example<br />

defi ne(N, 1 00)<br />

if (i > N)<br />

defines N to be 100 and uses this symbolic constant in a later if statement.<br />

The left parenthesis must immediately follow the word define, to signal that define has<br />

arguments. If a macro or built-in name is not followed immediately by a left<br />

parenthesis, it is assumed to have no arguments. This is the situation for N above; it is<br />

actually a macro with no arguments. Thus, when it is used, no parentheses are needed<br />

following its name.<br />

11-2

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!