This source file includes following definitions.
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 #include <config.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <errno.h>
22 #include <string.h>
23 #include <stdbool.h>
24 #include <fnmatch.h>
25
26 #include "exclude.h"
27 #include "error.h"
28 #include "argmatch.h"
29
30 #ifndef FNM_CASEFOLD
31 # define FNM_CASEFOLD 0
32 #endif
33 #ifndef FNM_LEADING_DIR
34 # define FNM_LEADING_DIR 0
35 #endif
36
37 char const * const exclude_keywords[] = {
38 "noescape",
39 "pathname",
40 "period",
41 "leading_dir",
42 "casefold",
43 "anchored",
44 "include",
45 "wildcards",
46 NULL
47 };
48
49 int exclude_flags[] = {
50 FNM_NOESCAPE,
51 FNM_PATHNAME,
52 FNM_PERIOD,
53 FNM_LEADING_DIR,
54 FNM_CASEFOLD,
55 EXCLUDE_ANCHORED,
56 EXCLUDE_INCLUDE,
57 EXCLUDE_WILDCARDS
58 };
59
60 ARGMATCH_VERIFY (exclude_keywords, exclude_flags);
61
62
63
64 #ifdef ARGMATCH_DIE_DECL
65
66 _Noreturn ARGMATCH_DIE_DECL;
67 ARGMATCH_DIE_DECL { exit (1); }
68
69 #endif
70
71 int
72 main (int argc, char **argv)
73 {
74 int exclude_options = 0;
75 struct exclude *exclude = new_exclude ();
76
77 if (argc == 1)
78 error (1, 0, "usage: %s file -- words...", argv[0]);
79
80 while (--argc)
81 {
82 char *opt = *++argv;
83 if (opt[0] == '-')
84 {
85 int neg = 0;
86 int flag;
87 char *s = opt + 1;
88
89 if (opt[1] == '-' && opt[2] == 0)
90 {
91 argc--;
92 break;
93 }
94 if (strlen (s) > 3 && memcmp (s, "no-", 3) == 0)
95 {
96 neg = 1;
97 s += 3;
98 }
99 flag = XARGMATCH (opt, s, exclude_keywords, exclude_flags);
100 if (neg)
101 exclude_options &= ~flag;
102 else
103 exclude_options |= flag;
104
105
106
107 if (strcmp (s, "leading_dir") == 0 && FNM_LEADING_DIR == 0)
108 exit (77);
109
110
111 if (strcmp (s, "casefold") == 0 && FNM_CASEFOLD == 0)
112 exit (77);
113 }
114 else if (add_exclude_file (add_exclude, exclude, opt,
115 exclude_options, '\n') != 0)
116 error (1, errno, "error loading %s", opt);
117 }
118
119 for (; argc; --argc)
120 {
121 char *word = *++argv;
122
123 printf ("%s: %d\n", word, excluded_file_name (exclude, word));
124 }
125
126 free_exclude (exclude);
127 return 0;
128 }