General-Purpose Mail Filter
A constant is a symbolic name for an MFL value.
Constants are defined using
[qualifier] const name expr
where name is an identifier, and expr is any valid
MFL expression evaluating immediately to a constant literal
or numeric value. Optional qualifier defines the scope of
visibility for that constant (see scope of visibility): either
After defining, any appearance of name in the program text is replaced by its value. For example:
const x 10/5 const text "X is "
defines the numeric constant ‘x’ with the value ‘5’, and the literal constant ‘text’ with the value ‘X is ’.
Constants can also be used in literals. To expand a constant within a literal string, prepend a percent sign to its name, e.g.:
echo "New %text %x" ⇒ "New X is 2"
This way of expanding constants creates an ambiguity if there happen to be a variable of the same name as the constant. See variable--constant clashes, for more information of this case and ways to handle it.
Several constants are built into the MFL compiler. To discern them from user-defined ones, their names start and end with two underscores (‘__’).
The following constants are defined in
Expands to the name of the current source file.
Expands to the name of the current lexical context, i.e. the function or handler name.
This built-in constant is defined for alpha versions only. Its value is the Git tag of the recent commit corresponding to that version of the package. If the release contains some uncommitted changes, the value of the ‘__git__’ constant ends with the suffix ‘-dirty’.
Expands to the current line number in the input source file.
Expands to the major version number.
The following example uses
__major__ constant to determine
if some version-dependent feature can be used:
if __major__ > 2 # Use some version-specific feature fi
Expands to the minor version number.
Expands to the name of the current module (see Modules).
Expands to the package name (‘mailfromd’)
For alpha versions and maintenance releases expands to the version patch level. For stable versions, expands to ‘0’.
Expands to the default external preprocessor command line, if the preprocessor is used, or to an empty string if it is not, e.g.:
__defpreproc__ ⇒ "/usr/bin/m4 -s"
See Preprocessor, for information on preprocessor and its features.
Expands to the current external preprocessor command line, if the
preprocessor is used, or to an empty string if it is not. Notice,
that it equals
__defpreproc__, unless the preprocessor was
redefined using --preprocessor command line option
Expands to the textual representation of the program version (e.g. ‘3.0.90’)
Expands to the default state directory (see statedir).
Expands to the current value of the program state directory
(see statedir). Notice, that it is the same as
__defstatedir__ unless the state directory was redefined at run
Built-in constants can be used as variables, this allows to expand them within strings or here-documents. The following example illustrates the common practice used for debugging configuration scripts:
func foo(number x) do echo "%__file__:%__line__: foo called with arg %x" … done
If the function
foo were called in line 28 of the
/etc/mailfromd.mf, like this:
foo(10), you will see the following string in your logs:
/etc/mailfromd.mf:28: foo called with arg 10
This document was generated on January 3, 2019 using makeinfo.Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved.