PowerAda m4

From OC Systems Wiki!
< PowerAda:APPENDIX E. Tools Reference
Revision as of 13:09, 24 April 2019 by imported>WikiVisor
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


m4 - preprocesses files, expanding macro definitions


m4 [ -e] [ -s] [ -l] [ -BNumber] [ -HNumber] [ -SNumber]
    [ -TNumber] [ -DName [=Value] [-UName]]... [File...]


The m4 command is a macro processor used as a preprocessor for C and other languages. You can use it to process built-in macros or user-defined macros.

Each File is processed in order. If you do not specify a File or if you give a - (minus) as a file name, the m4 command reads standard input. It writes the processed macros to standard output. Macro calls follow the form:

macroname(argument . . . )

The left parenthesis must immediately follow macroname. If the left parenthesis does not follow the name of a defined macro, the m4 command reads it as a macro call with no arguments. Macro names consist of ASCII alphabetic letters, digits, and the _ (underscore) character. Extended characters are not allowed in macro names. The first character cannot be a digit.

While collecting arguments, the m4 command ignores unquoted leading blanks, tabs, and new-line characters. Use single quotation marks to quote strings. The value of a quoted string is the string with the quotation marks stripped off.

When the m4 command recognizes a macro, it collects arguments by searching for a matching right parenthesis. If you supply fewer arguments than appear in the macro definition, the m4 command considers the trailing arguments in the definition to be null. Macro evaluation proceeds normally during the collection of the arguments. All commas or right parentheses within the value of a nested call are translated literally; they do not need an escape character or quotation marks. After collecting arguments, the m4 command pushes the value of the macro back onto the input stream and scans again.


The m4 command makes available the following built-in macros. You may redefine them, but you will lose the original meaning. The values of these macros are null unless otherwise stated:


Replaces the macro Name with the value of NewName. The NewName string can take the form $n... (where n is a digit). In this case, each occurrence of n in the replacement text is replaced by the nth argument of Name. $0 is the name of the macro. The null string replaces missing arguments. The number of arguments replaces $#. A comma-separated list of all arguments replaces $*. $@ acts like $*, but each argument is quoted with the current quotation character (see changequote).


Removes the definition of Name.


Returns the quoted definition of Name.

pushdef(Name, NewName)

Redefines Name with NewName as in define, but saves any previous definition.

popdef(Name . . . )

Removes the current definition of Name and returns to the previous definition, if one existed.


Returns the value of True only if Name is defined, otherwise returns False. If you do not supply False, its value is null.

shift(Argument . . . )

Returns all but the first argument. The other arguments are quoted and pushed back with commas in between. The quoting nullifies the effect of the extra scan that is subsequently performed.


Changes quote symbols to L and R. The symbols can be up to 5 bytes long. changequote without arguments restores the original values (` ').


Changes left and right comment markers from the default # and new-line character to L and R. With no arguments, the comment mechanism is disabled. With one argument, the left marker becomes the parameter and the right marker becomes a new- line character. With two arguments, both markers are affected. Comment markers can be up to 5 bytes long.


Changes the current output stream to stream Number. There are 10 output streams, numbered 0-9. The final output is the concatenation of the streams in numerical order. Initially, stream 0 is the current stream. The m4 command discards output diverted to a stream other than 0-9.

undivert(Number . . . )

Causes immediate output of text from the specified diversions (or all diversions if there is no argument). Text may be undiverted into another diversion. Undiverting discards the diverted text.


Returns the value of the current output stream.


Reads and discards characters up to and including the next new-line character.

ifelse([String1,String2,True,[False]] . . . )

If String1 and String2 are the same then the value is True. If they are not and if there are more than four arguments, the m4 command repeats the process with the additional arguments (4, 5, 6, and 7). Otherwise, the value is either False or null if you provide no value for False.


Returns the value of its argument incremented by 1.


Returns the value of its argument decreased by 1.


Evaluates its first argument as an arithmetic expression, using 32-bit arithmetic. The operators you can use are +, -, *, /,%, ^ (exponentiation), bitwise &, | , ~, and ^ relationals, and parentheses. Octal and hex numbers can be specified as in C. Number1 specifies the radix for the result of the expression. The default radix is 10. The optional Number2 specifies the minimum number of digits in the result.


Returns the number of bytes in String.


Returns the number of displayable characters in String; that is, two-byte extended characters are counted as one displayable character.


Returns the position in the string String1 where the string String2 begins (zero origin), or -1 if the second parameter does not occur.

substr(String,Position, [Number] )

Returns a substring of String. The beginning of the substring is selected with Position, and Number indicates the length of the substring. Without Number, the substring includes everything to the end of the first string.


Transliterates the characters in String from the set given by From to the set given by To. No abbreviations are permitted. Two-byte extended characters are correctly mapped into the corresponding replacement characters.


Returns the contents of File or displays an error message if it cannot access the file.


Returns the contents of File, but it gives no error message if File is inaccessible.


Runs the Command. No value is returned.


Returns the return code from the last call to syscmd.

maketemp( . . . nnnn . . . )

Replaces nnnn in its argument with the current process ID number.


Exits from m4 immediately, returning the specified exit Value (the default is 0).


Runs LastMacro after reading the end-of-file character. For example, m4wrap ('cleanup ()') runs the cleanup macro at the end of m4.


Includes Message on the diagnostic output file.

dumpdef([Name . . . ])

Writes to standard output the current names and definitions for the named items or for all if no arguments are provided.


Turns on tracing for Macro. If none is named, tracing is turned on for all macros.

traceoff(Macro . . . )

Turns off trace globally and for any Macro specified. Macros specifically traced by traceon can be untraced only by specific calls to traceoff.


Makes Number the size of the push-back and parameter collection buffers (the default is 4096).
Operates interactively. Interrupts are ignored and the output is not buffered.
Makes Number the size of the symbol table hash array (the default is 199). The size must be a prime number.
Enables line numbering output for the assembler (.xline . . .).
Enables the line sync output for the C preprocessor (#line . . .).
Makes Number the size of the call stack (the default is 100 slots). Macros take three slots, and non-macro arguments take one.
Makes Number the size of the token buffer (the default is 512 bytes).
The preceding flags must appear before any file names and before any -D or -U flags.
Defines Name as Value. If Value is not specified, Name becomes null.
Undefines a Name previously defined with the -D flag.


This command returns the following exit values:

0 - Successful completion.
>0 - An error occurred.

If the m4exit macro is used, the exit value can be specified by the input file.



contains the m4 command.


This must be defined and indicate the powerada/ada95 directory in the PowerAda installation.


To preprocess a C language program with the m4 command and compile it:

m4 prog.m4 > prog.c cc prog.c


aprojbaseline, aprojbaseline, areport.