Expand PMF_FN_* macros.
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / global / string_list.c
blobbcacc968a01b7908e20131321bdb079c7218efd5
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* string_list 3
6 /* SUMMARY
7 /* match a string against a pattern list
8 /* SYNOPSIS
9 /* #include <string_list.h>
11 /* STRING_LIST *string_list_init(flags, pattern_list)
12 /* int flags;
13 /* const char *pattern_list;
15 /* int string_list_match(list, name)
16 /* STRING_LIST *list;
17 /* const char *name;
19 /* void string_list_free(list)
20 /* STRING_LIST *list;
21 /* DESCRIPTION
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().
43 /* DIAGNOSTICS
44 /* Fatal error: unable to open or read a pattern file or table.
45 /* SEE ALSO
46 /* match_list(3) generic list matching
47 /* match_ops(3) match strings by name or by address
48 /* LICENSE
49 /* .ad
50 /* .fi
51 /* The Secure Mailer license must be distributed with this software.
52 /* AUTHOR(S)
53 /* Wietse Venema
54 /* IBM T.J. Watson Research
55 /* P.O. Box 704
56 /* Yorktown Heights, NY 10598, USA
57 /*--*/
59 /* System library. */
61 #include <sys_defs.h>
63 /* Utility library. */
65 #include <match_list.h>
67 /* Global library. */
69 #include "string_list.h"
71 #ifdef TEST
73 #include <msg.h>
74 #include <stdlib.h>
75 #include <unistd.h>
76 #include <vstream.h>
77 #include <vstring.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)
87 STRING_LIST *list;
88 char *string;
89 int ch;
91 msg_vstream_init(argv[0], VSTREAM_ERR);
93 while ((ch = GETOPT(argc, argv, "v")) > 0) {
94 switch (ch) {
95 case 'v':
96 msg_verbose++;
97 break;
98 default:
99 usage(argv[0]);
102 if (argc != optind + 2)
103 usage(argv[0]);
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) ?
107 "YES" : "NO");
108 vstream_fflush(VSTREAM_OUT);
109 string_list_free(list);
110 return (0);
113 #endif