home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Oakland CPM Archive
/
oakcpm.iso
/
cpm
/
cug
/
softt-7.lbr
/
MACRO.DQC
/
MACRO.DOC
Wrap
Text File
|
1984-07-05
|
7KB
|
319 lines
.bp 1
.in 0
.he 'MACRO (1)'10/1/79'MACRO (1)'
.in 3
.ti -3
NAME
.br
macro - general-purpose macro processor
.sp
.ti -3
SYNOPSIS
.br
macro [-0] [files...]
.sp
.ti -3
DESCRIPTION
.br
Macro is a general-purpose macro processor.
Macro reads the files and writes onto the standard output
a new file with the macro definitions deleted and the macro
references expanded.
If no files are given, or the file "-" is specified, the standard
input is read.
.sp
Macros permit the definition of
symbolic constants so that subsequent
occurrences of the constant are replaced by the defining
string of characters.
The general form of a macro definition is
.sp
.ce
define(name,replacement text)
.sp
All subsequent occurrences of "name" in the file will be replaced
by "replacement text".
The placement of blanks in definitions is significant;
they should only appear in the replacement
text where desired.
Upper and lower case letters are also significant.
The replacement text may be more than one
line long.
However, when an entire macro definition is followed
immediately by a newline,
the newline is discarded. This prevents extraneous blank lines
from appearing in the output.
.sp
Nesting of definitions is allowed, as is recursion.
.sp
An elementary example of a macro is:
.sp
.ce
define(EOF,-1)
.sp
Thereafter, all occurrences of "EOF" in the file would be replaced
by "-1".
.sp
Macros with arguments may also be specified.
Any occurrence in
the replacement text of "$n", where n is between 1 and 9,
will be replaced by the nth argument when the macro is actually
called.
For example,
.sp
.ti +10
define(copen,$3 = open($1,$2)
.ti +18
if ($3 == ERR)
.ti +21
call cant($1)
)
.sp
would define a macro that, when called
by
.sp
.ce
copen(name, READ, fd)
.sp
would expand into
.in +10
.nf
fd = open(name,READ)
if (fd == ERR)
.ti +3
call cant(name)
.sp
.fi
.in -10
If a macro definition refers to an argument that wasn't supplied,
the "$n" will be ignored.
"$0" refers to the name of the macro itself.
If a character other
than a digit follows "$",
the "$" is taken literally.
.sp
Macros can be nested, and any macros encountered during argument
collection are expanded immediately, unless they are surrounded
by brackets "[]".
That is, input surrounded by brackets is
left absolutely alone, except that one level of [ and ] is
stripped off.
Thus it is possible to write the macro "d" as
.sp
.ce
define(d,[define($1,$2)])
.sp
The replacement text for "d", protected by the brackets is
literally "define($1,$2)" so one could say
.sp
.ce
d(a,bc)
.sp
to define "a" as "bc".
Brackets must also be used when it is desired to redefine
a macro, e.g.
.sp
.in +25
define(x,y)
.br
define(x,z)
.sp
.in -25
would define "y" in the second line, instead of redefining "x".
To avoid redefining "y", the operation must be expressed as
.sp
.in +25
define(x,y)
.br
define([x],z)
.sp
.in -25
Normally, brackets appearing outside any macro calls
("level 0" brackets) are
.ul
not
removed, unless the -0 option is specified.
.sp 2
The following built-in macros are provided:
.sp
define(a,b)
.br
.in +5
defines a to be b and returns the null string.
.in -5
.sp
ifelse(a,b,c,d)
.br
.in +5
returns c if a is identical to b and d otherwise.
.in -5
.sp
incr(a)
.br
.in +5
interprets a as an integer and returns a+1.
.in -5
.sp
substr(a,b,c)
.br
.in +5
returns a substring of "a" starting at character number
b and extending for c characters.
.in -5
.sp
len(a)
.br
.in +5
returns the length of a.
.in -5
.sp
includ(a)
.br
.in +5
returns the contents of file a.
.in -5
.sp
expr(a)
.br
.in +5
returns the result of evaluating infix expression a.
Operators in increasing order of precedence are
as follows. Parentheses may be used as usual.
.br
.sp
.in +5
.nf
| & logical OR and AND
! unary logical NOT
== ^= <= < > >= arithmetic comparison (!= and ~= are
.ti +16
equivalent to ^=)
+ - addition and subtraction
* / % multiplication, division, modulo (remainder)
** exponentiation
+ - unaryáplus and negation
.fi
.sp
.in -5
Logical operators return 0 or 1 (false or true).
.in -5
.sp
.ti -3
FILES
.br
None
.sp
.ti -3
SEE ALSO
.br
Kernighan and Plauger's "Software Tools", pages. 251-283
.br
ratfor
.sp
.ti -3
DIAGNOSTICS
.br
arith evaluation stack overflow
.in +5
The max level of nested arithmetic expressions has been exceeded.
The size is set by the MAXSTACK definition in the source code.
.sp
.in -5
arg stack overflow
.br
.in +5
The maximum number of total arguments has been exceeded;
the size is set by the ARGSIZE definition in the source code.
.in -5
.sp
call stack overflow
.br
.in +5
The maximum level of nesting of definitions has been exceeded.
The size is set by the CALLSIZE definition in the source code.
.in -5
.sp
EOF in string
.br
.in +5
An end-of-file has been encountered before a bracketed string has
been terminated.
.in -5
.sp
evaluation stack overflow
.br
.in +5
The total number of characters permitted for
name, definition, and arguments
has been exceeded.
Set by the EVALSIZE definition in the source code.
.in -5
.sp
unexpected EOF
.br
.in +5
An end-of-file was reached before the macro definition was terminated.
.in -5
.sp
filename: can't open
.br
.in +5
The indicated file could not be opened.
.in -5
.sp
filename: can't includ
.br
.in +5
The indicated file could not be included via the includ builtin.
.in -5
.sp
includs nested too deeply
.br
.in +5
Includ builtins were nested deeper than the system would
allow.
The number is determined by the MAXOFILES definition in the
general symbols definition file.
.in -5
.sp
expression: invalid infix expression
.br
.in +5
There is a syntax error in the indicated infix expression as
passed to the expr builtin.
.in -5
.sp
too many characters pushed back
.br
.in +5
A macro expansion is too large to be rescanned.
The size is set by the BUFSIZE definition in the source code.
.in -5
.sp
name: too many definitions
.br
.in +5
The table space for macro definitions has been exhausted; this
occurred upon the definition of the indicated macro.
.in -5
.sp
token too long
.br
.in +5
A name or symbol in the input was longer than the token buffer.
Size is determined by the MAXTOK definition in the source code.
.in -5
.sp
.ti -3
AUTHORS
.br
Original by Kernighan and Plauger, with enhancements by
David Hanson and friends (U. of Arizona) and Philip
Scherrer (Stanford U.)
.sp
.ti -3
BUGS/DEFICIENCIES
.br
This macro processor is incompatible with the one included
in the ratfor preprocessor.