7 /* match a string against a pattern list
9 /* #include <string_list.h>
11 /* STRING_LIST *string_list_init(flags, pattern_list)
13 /* const char *pattern_list;
15 /* int string_list_match(list, name)
19 /* void string_list_free(list)
22 /* This is a convenience wrapper around the match_list module.
24 /* This module implements tests for list membership of a string.
26 /* Patterns are separated by whitespace and/or commas. A pattern
27 /* is either a string, a file name (in which case the contents
28 /* of the file are substituted for the file name) or a type:name
29 /* lookup table specification.
31 /* A string matches a string list when it appears in the list of
32 /* string patterns. The matching process is case insensitive.
33 /* In order to reverse the result, precede a pattern with an
34 /* exclamation point (!).
36 /* string_list_init() performs initializations. The flags argument
37 /* is ignored; pattern_list specifies a list of string patterns.
39 /* string_list_match() matches the specified string against the
40 /* compiled pattern list.
42 /* string_list_free() releases storage allocated by string_list_init().
44 /* Fatal error: unable to open or read a pattern file or table.
46 /* match_list(3) generic list matching
47 /* match_ops(3) match strings by name or by address
51 /* The Secure Mailer license must be distributed with this software.
54 /* IBM T.J. Watson Research
56 /* Yorktown Heights, NY 10598, USA
63 /* Utility library. */
65 #include <match_list.h>
69 #include "string_list.h"
78 #include <msg_vstream.h>
80 static void usage(char *progname
)
82 msg_fatal("usage: %s [-v] patterns string", progname
);
85 int main(int argc
, char **argv
)
91 msg_vstream_init(argv
[0], VSTREAM_ERR
);
93 while ((ch
= GETOPT(argc
, argv
, "v")) > 0) {
102 if (argc
!= optind
+ 2)
104 list
= string_list_init(MATCH_FLAG_NONE
, argv
[optind
]);
105 string
= argv
[optind
+ 1];
106 vstream_printf("%s: %s\n", string
, string_list_match(list
, string
) ?
108 vstream_fflush(VSTREAM_OUT
);
109 string_list_free(list
);