32. Class Macros
Contents:
A class is like an array of string values. In the LHS of rules it is sometimes advantageous to compare individual tokens to multiple strings when determining a match. The configuration class command provides this ability. The class command is similar to the macro definition command, except that instead of assigning a single value to a macro, it assigns many values to a class. Classes differs from macros in that they can be used only in the LHS of rules, whereas macros can be used in either the RHS or the LHS.
Two different configuration commands can be used to assign values to
a class.
The You may wish to review the tutorial in Chapter 12, Class , to see a few typical applications of class. 32.1 Class Configuration CommandsThe three forms for the class configuration command are the following:
C
The class configuration command starts with either the letter
The
C See Section 31.4.2, "Multicharacter Names" for a full discussion of how to use multicharacter names. Note that classes are separate from macros, so they may both use the same letter or name with no conflict. The sendmail program reserves the lowercase letters for its own use as internally defined class names (although currently only a few are actually used). All uppercase letters and all names that begin with uppercase letters are available for use. 32.1.1 The C Class Command
The
C
Here, a
Multiple declarations of the same named class may coexist in the configuration file. Each declaration after the first appends its string elements to the preceding list. That is,
CX string1 string2 CX string3 string4 produces the same class as does
CX string1 string2 string3 string4 Both create a class with four strings as elements.
When an array of values is built, whitespace is used to
separate one value from another. Whitespace is defined by
the C language
isspace
(3) routine and usually includes
the space, tab, newline, carriage-return, and form-feed characters.
Each line of text assigned to a class is broken up by
sendmail
into whitespace delimited words.
When a line
is indented with a space or a tab, that line is joined by
sendmail
to the preceding line. Thus the following three declarations
also append four words to the class
CX string1 CX string2 CX string3 string4 tab Words that are added to a class cannot be removed after sendmail has read them. Instead, they must be edited out of whatever file or program produced them, and the sendmail daemon must be killed and restarted.
The list of words in a class declaration can include macros. For example
the following assigns the same values to class
D{LIST} string1 string2 string3 string4 CX ${LIST}
Macros used in class declarations are expanded when the configuration file
is read. Deferred macros (those with the
CX ourhost$?{Domain}.${Domain}$. 32.1.2 The F Class Command
The
F
The
If SCANF was defined when
sendmail
was compiled
(see
Section 18.8.39, SCANF
),
each line that is read from a file or program
is parsed by the C language
scanf
(3) library routine.
The formatting pattern given to
scanf
(3) is
cannot open what :
Here, the
what
is the exact text that was given in the configuration
file, and
For the file form only,
if the file may optionally not exist, you can prefix its name
with a
F
This tells
sendmail
to remain silent if the file does not exit.
The
The
string3 string4
The following two configuration commands add the same
four strings to the class
CX string1 string2 FX /etc/local/names
This creates a class with four strings as array elements. Whitespace
delimits one string from the others in the 32.1.2.1 scanf(3) variations
The file form of the class configuration command
allows different formatting patterns to be used with
scanf
(3).
[3]
But the program form does not
allow any variation,
and so its
scanf
(3) pattern is always
F
If the optional
sscanf(result, pat, input)
Here,
After each line of text is read from the file and filtered with the scanf (3) pattern, it is further subdivided by sendmail into individual words. That subdividing uses whitespace (as defined by the C language isspace (3) routine) to separate words. Each separate word is then appended as an individual element to the class array. Consider the contents of the following file named /etc/local/myhosts :
server1 server2 # my two nets uuhost # my uucp alias #mailhost # mail server alias (retired 06,23,91)
This file contains three hostname aliases to be added
to a class, say
FH /etc/local/myhosts %[^\#]
The pattern |
|