4 # Returns a list of entries in the sendmail.mc file, each of which may be a
5 # feature or some other unrecognized line
8 local (@rv, $lnum = 0);
9 open(MC, $config{'sendmail_mc'});
13 if (/^FEATURE\((.*)\)/i) {
14 local ($name, @v) = &split_m4_params($1);
19 elsif (/^(define|undefine)\((.*)\)/i) {
20 local @v = &split_m4_params($2);
21 $f = { 'type' => ($1 eq 'define' ? 2 : 3),
25 elsif (/^MAILER\((.*)\)/i) {
26 local ($mailer) = &split_m4_params($1);
28 'mailer' => $mailer };
30 elsif (/^OSTYPE\((.*)\)/i) {
31 local ($ostype) = &split_m4_params($1);
34 'index' => scalar(@rv),
35 'ostype' => $ostype };
43 $f->{'index'} = scalar(@rv);
53 # split_m4_params(string)
58 while($str =~ /^`([^']*)'\s*,?\s*(.*)$/ ||
59 $str =~ /^([^\s,]+)\s*,?\s*(.*)$/) {
66 # list_feature_types()
67 sub list_feature_types
70 opendir(DIR, "$config{'sendmail_features'}/feature");
71 while($f = readdir(DIR)) {
72 if ($f =~ /^(\S+)\.m4$/) {
73 local $t = $text{'feat_'.lc($1)};
74 push(@rv, [ $1, $t ? "$1 ($t)" : $1 ] );
82 # Returns a list of known define types. Some (but not all) will have human-
83 # readable descriptions
87 open(DEFINES, "$module_root_directory/defines");
88 while($d = <DEFINES>) {
90 local $t = $text{'def_'.lc($d)};
91 push(@rv, [ $d, $t ? "$d ($t)" : $d ]);
101 opendir(DIR, "$config{'sendmail_features'}/mailer");
102 while($f = readdir(DIR)) {
103 if ($f =~ /^(\S+)\.m4$/) {
104 local $t = $text{'mailer_'.lc($1)};
105 push(@rv, [ $1, $t ? "$1 ($t)" : $1 ] );
112 # list_ostype_types()
113 sub list_ostype_types
116 opendir(DIR, "$config{'sendmail_features'}/ostype");
117 while($f = readdir(DIR)) {
118 if ($f =~ /^(\S+)\.m4$/) {
119 local $t = $text{'ostype_'.lc($1)};
120 push(@rv, [ $1, $t ? "$1 ($t)" : $1 ] );
127 # create_feature(&feature)
128 # Adds an entry to the end of the M4 config file
131 &open_tempfile(MC, ">>$config{'sendmail_mc'}");
132 &print_tempfile(MC, &feature_line($_[0]),"\n");
134 $_[0]->{'text'} = &feature_line($_[0]);
137 # delete_feature(&feature)
138 # Deletes one entry from the M4 config file
141 local $lref = &read_file_lines($config{'sendmail_mc'});
142 splice(@$lref, $_[0]->{'line'}, 1);
146 # modify_feature(&feature)
147 # Updates an entry in the M4 config file
150 local $lref = &read_file_lines($config{'sendmail_mc'});
151 splice(@$lref, $_[0]->{'line'}, 1, &feature_line($_[0]));
153 $_[0]->{'text'} = &feature_line($_[0]);
156 # swap_features(&feature1, &feature2)
159 local $lref = &read_file_lines($config{'sendmail_mc'});
160 splice(@$lref, $_[0]->{'line'}, 1, $_[1]->{'text'});
161 splice(@$lref, $_[1]->{'line'}, 1, $_[0]->{'text'});
165 # feature_line(&feature)
168 if ($_[0]->{'type'} == 0) {
169 return $_[0]->{'text'};
171 elsif ($_[0]->{'type'} == 1) {
172 return "FEATURE(".join_m4_params($_[0]->{'name'}, @{$_[0]->{'values'}}).")";
174 elsif ($_[0]->{'type'} == 2) {
175 if ($_[0]->{'value'} eq '') {
176 return "define(".join_m4_params($_[0]->{'name'}).")";
179 return "define(".join_m4_params($_[0]->{'name'},
180 $_[0]->{'value'}).")";
183 elsif ($_[0]->{'type'} == 3) {
184 return "undefine(".join_m4_params($_[0]->{'name'}).")";
186 elsif ($_[0]->{'type'} == 4) {
187 return "MAILER(".join_m4_params($_[0]->{'mailer'}).")";
189 elsif ($_[0]->{'type'} == 5) {
190 return "OSTYPE(".join_m4_params($_[0]->{'ostype'}).")";
196 local @rv = map { $_ =~ /^\d+$/ ? $_ : "`$_'" } @_;
197 return join(",", @rv);