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.

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

The built-in ifdef provides a way to determine if a macro is currently defined. For<br />

instance, pretend that either the word "xenix" or "unix" is defined according to a<br />

particular implementation of a program. To perform operations according to which<br />

system you have, you might use:<br />

ifdef('xenix', 'define(system, 1 )' )<br />

ifdef('unix', 'define(system,2)' )<br />

Don't forget the quotation marks in the above example.<br />

ifdef actually permits three argu ments; if the name is undefined, the value of ifdef is<br />

then the third argument, as in<br />

ifdef('xenix', on <strong>XENIX</strong>, not on <strong>XENIX</strong>)<br />

Using Arguments<br />

So far we have discussed the simplest form of macro processing--replacing one string by<br />

another (fixed) string. User-defined macros may also have arguments, so different<br />

invocations can have different results. Within the replacement text for a macro (the<br />

second argument of its define) any occurrence of $n will be replaced by the nth<br />

argument when the macro is actually used. Thus, the macro bump, defined as<br />

define(bump, $1 = $1 + 1)<br />

generates code to increment its argument by 1:<br />

is<br />

bump(x)<br />

X = X + 1<br />

A macro can have any nu mber of argu ments, but only the first nine are accessible, as $1<br />

to $9. (The macro name itself is $0.) Arguments not supplied are replaced by null<br />

strings, so we can define a macro cat that simply concatenates its argu ments, like this:<br />

Thus<br />

define( cat, $1 $2$3$4$5$6$7$8$9)<br />

cat(x, y, z)<br />

is equivalent to<br />

xyz<br />

The arguments $4 through $9 are null, since no corresponding argu ments were provided.<br />

11-5

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

Saved successfully!

Ooh no, something went wrong!