annotate lib/exclude.c @ 17907:0a1c2535cad9

euidaccess: Fix Android build * modules/euidaccess (Depends-on): Add fcntl-h to ensure that AT_EACCESS gets declared.
author Kevin Cernekee <cernekee@google.com>
date Wed, 11 Feb 2015 15:22:54 -0800
parents ab58d4870664
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1171
Jim Meyering <jim@meyering.net>
parents:
diff changeset
1 /* exclude.c -- exclude file names
3398
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
2
17848
ab58d4870664 version-etc: new year
Paul Eggert <eggert@cs.ucla.edu>
parents: 17765
diff changeset
3 Copyright (C) 1992-1994, 1997, 1999-2007, 2009-2015 Free Software
14079
97fc9a21a8fb maint: update almost all copyright ranges to include 2011
Jim Meyering <meyering@redhat.com>
parents: 13479
diff changeset
4 Foundation, Inc.
1171
Jim Meyering <jim@meyering.net>
parents:
diff changeset
5
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8155
diff changeset
6 This program is free software: you can redistribute it and/or modify
1171
Jim Meyering <jim@meyering.net>
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8155
diff changeset
8 the Free Software Foundation; either version 3 of the License, or
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8155
diff changeset
9 (at your option) any later version.
1171
Jim Meyering <jim@meyering.net>
parents:
diff changeset
10
Jim Meyering <jim@meyering.net>
parents:
diff changeset
11 This program is distributed in the hope that it will be useful,
Jim Meyering <jim@meyering.net>
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
Jim Meyering <jim@meyering.net>
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Jim Meyering <jim@meyering.net>
parents:
diff changeset
14 GNU General Public License for more details.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
15
Jim Meyering <jim@meyering.net>
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8155
diff changeset
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
1171
Jim Meyering <jim@meyering.net>
parents:
diff changeset
18
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
19 /* Written by Paul Eggert <eggert@twinsun.com>
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
20 and Sergey Poznyakoff <gray@gnu.org>.
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
21 Thanks to Phil Proudman <phil@proudman51.freeserve.co.uk>
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
22 for improvement suggestions. */
1171
Jim Meyering <jim@meyering.net>
parents:
diff changeset
23
7302
8a1a9361108c * _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents: 6927
diff changeset
24 #include <config.h>
1171
Jim Meyering <jim@meyering.net>
parents:
diff changeset
25
4333
fcd34d3861a4 in lib:
Paul Eggert <eggert@cs.ucla.edu>
parents: 4292
diff changeset
26 #include <stdbool.h>
3398
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
27
4537
940fdf291f5b Ignore trailing white space and empty lines
Paul Eggert <eggert@cs.ucla.edu>
parents: 4350
diff changeset
28 #include <ctype.h>
1171
Jim Meyering <jim@meyering.net>
parents:
diff changeset
29 #include <errno.h>
4347
df44e79ce676 .h files should stand alone, but we shouldn't include <sys/types.h>
Paul Eggert <eggert@cs.ucla.edu>
parents: 4333
diff changeset
30 #include <stddef.h>
3398
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
31 #include <stdio.h>
4638
652159397a1d Remove K&R cruft.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4538
diff changeset
32 #include <stdlib.h>
652159397a1d Remove K&R cruft.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4538
diff changeset
33 #include <string.h>
11959
610ed34b4298 exclude: minor fix
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 11856
diff changeset
34 #include <wctype.h>
17625
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
35 #include <regex.h>
3398
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
36
3436
da0f25c86213 Use `""', not `<>' to #include non-system header files.
Jim Meyering <jim@meyering.net>
parents: 3398
diff changeset
37 #include "exclude.h"
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
38 #include "hash.h"
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
39 #include "mbuiter.h"
3436
da0f25c86213 Use `""', not `<>' to #include non-system header files.
Jim Meyering <jim@meyering.net>
parents: 3398
diff changeset
40 #include "fnmatch.h"
da0f25c86213 Use `""', not `<>' to #include non-system header files.
Jim Meyering <jim@meyering.net>
parents: 3398
diff changeset
41 #include "xalloc.h"
6323
af09cfa36fd5 * modules/exclude (Depends-on): Depend on verify.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6275
diff changeset
42 #include "verify.h"
17625
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
43 #include "filename.h"
3398
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
44
5318
7c24a825b51d Remove dependencies on unlocked-io.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5159
diff changeset
45 #if USE_UNLOCKED_IO
7c24a825b51d Remove dependencies on unlocked-io.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5159
diff changeset
46 # include "unlocked-io.h"
7c24a825b51d Remove dependencies on unlocked-io.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5159
diff changeset
47 #endif
7c24a825b51d Remove dependencies on unlocked-io.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5159
diff changeset
48
4077
62c996889465 (FNM_CASEFOLD, FNM_LEADING_DIR): Define to 0 if not
Paul Eggert <eggert@cs.ucla.edu>
parents: 3618
diff changeset
49 /* Non-GNU systems lack these options, so we don't need to check them. */
62c996889465 (FNM_CASEFOLD, FNM_LEADING_DIR): Define to 0 if not
Paul Eggert <eggert@cs.ucla.edu>
parents: 3618
diff changeset
50 #ifndef FNM_CASEFOLD
62c996889465 (FNM_CASEFOLD, FNM_LEADING_DIR): Define to 0 if not
Paul Eggert <eggert@cs.ucla.edu>
parents: 3618
diff changeset
51 # define FNM_CASEFOLD 0
62c996889465 (FNM_CASEFOLD, FNM_LEADING_DIR): Define to 0 if not
Paul Eggert <eggert@cs.ucla.edu>
parents: 3618
diff changeset
52 #endif
8155
eca0a6359ada * lib/exclude.c (FNM_EXTMATCH): Define if system does not.
Paul Eggert <eggert@cs.ucla.edu>
parents: 7944
diff changeset
53 #ifndef FNM_EXTMATCH
eca0a6359ada * lib/exclude.c (FNM_EXTMATCH): Define if system does not.
Paul Eggert <eggert@cs.ucla.edu>
parents: 7944
diff changeset
54 # define FNM_EXTMATCH 0
eca0a6359ada * lib/exclude.c (FNM_EXTMATCH): Define if system does not.
Paul Eggert <eggert@cs.ucla.edu>
parents: 7944
diff changeset
55 #endif
4077
62c996889465 (FNM_CASEFOLD, FNM_LEADING_DIR): Define to 0 if not
Paul Eggert <eggert@cs.ucla.edu>
parents: 3618
diff changeset
56 #ifndef FNM_LEADING_DIR
62c996889465 (FNM_CASEFOLD, FNM_LEADING_DIR): Define to 0 if not
Paul Eggert <eggert@cs.ucla.edu>
parents: 3618
diff changeset
57 # define FNM_LEADING_DIR 0
62c996889465 (FNM_CASEFOLD, FNM_LEADING_DIR): Define to 0 if not
Paul Eggert <eggert@cs.ucla.edu>
parents: 3618
diff changeset
58 #endif
62c996889465 (FNM_CASEFOLD, FNM_LEADING_DIR): Define to 0 if not
Paul Eggert <eggert@cs.ucla.edu>
parents: 3618
diff changeset
59
6323
af09cfa36fd5 * modules/exclude (Depends-on): Depend on verify.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6275
diff changeset
60 verify (((EXCLUDE_ANCHORED | EXCLUDE_INCLUDE | EXCLUDE_WILDCARDS)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
61 & (FNM_PATHNAME | FNM_NOESCAPE | FNM_PERIOD | FNM_LEADING_DIR
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
62 | FNM_CASEFOLD | FNM_EXTMATCH))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
63 == 0);
1171
Jim Meyering <jim@meyering.net>
parents:
diff changeset
64
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
65
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
66 /* Exclusion patterns are grouped into a singly-linked list of
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
67 "exclusion segments". Each segment represents a set of patterns
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
68 that can be matches using the same algorithm. Non-wildcard
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
69 patterns are kept in hash tables, to speed up searches. Wildcard
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
70 patterns are stored as arrays of patterns. */
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
71
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
72
3398
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
73 /* An exclude pattern-options pair. The options are fnmatch options
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
74 ORed with EXCLUDE_* options. */
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
75
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
76 struct patopts
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
77 {
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
78 int options;
17625
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
79 union
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
80 {
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
81 char const *pattern;
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
82 regex_t re;
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
83 } v;
3398
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
84 };
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
85
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
86 /* An array of pattern-options pairs. */
1171
Jim Meyering <jim@meyering.net>
parents:
diff changeset
87
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
88 struct exclude_pattern
1171
Jim Meyering <jim@meyering.net>
parents:
diff changeset
89 {
3398
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
90 struct patopts *exclude;
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
91 size_t exclude_alloc;
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
92 size_t exclude_count;
1171
Jim Meyering <jim@meyering.net>
parents:
diff changeset
93 };
Jim Meyering <jim@meyering.net>
parents:
diff changeset
94
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
95 enum exclude_type
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
96 {
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
97 exclude_hash, /* a hash table of excluded names */
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
98 exclude_pattern /* an array of exclude patterns */
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
99 };
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
100
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
101 struct exclude_segment
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
102 {
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
103 struct exclude_segment *next; /* next segment in list */
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
104 enum exclude_type type; /* type of this segment */
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
105 int options; /* common options for this segment */
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
106 union
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
107 {
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
108 Hash_table *table; /* for type == exclude_hash */
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
109 struct exclude_pattern pat; /* for type == exclude_pattern */
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
110 } v;
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
111 };
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
112
17625
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
113 struct pattern_buffer
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
114 {
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
115 struct pattern_buffer *next;
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
116 char *base;
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
117 };
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
118
16806
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
119 /* The exclude structure keeps a singly-linked list of exclude segments,
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
120 maintained in reverse order. */
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
121 struct exclude
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
122 {
16806
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
123 struct exclude_segment *head;
17625
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
124 struct pattern_buffer *patbuf;
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
125 };
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
126
17625
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
127 /* Register BUF in the pattern buffer list of EX. ADD_FUNC (see
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
128 add_exclude_file and add_exclude_fp below) can use this function
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
129 if it modifies the pattern, to ensure the allocated memory will be
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
130 properly reclaimed upon calling free_exclude. */
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
131 void
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
132 exclude_add_pattern_buffer (struct exclude *ex, char *buf)
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
133 {
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
134 struct pattern_buffer *pbuf = xmalloc (sizeof *pbuf);
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
135 pbuf->base = buf;
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
136 pbuf->next = ex->patbuf;
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
137 ex->patbuf = pbuf;
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
138 }
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
139
16803
50f45dd3bacf exclude: handle wildcards with FNM_EXTMATCH
Paul Eggert <eggert@cs.ucla.edu>
parents: 16201
diff changeset
140 /* Return true if STR has or may have wildcards, when matched with OPTIONS.
50f45dd3bacf exclude: handle wildcards with FNM_EXTMATCH
Paul Eggert <eggert@cs.ucla.edu>
parents: 16201
diff changeset
141 Return false if STR definitely does not have wildcards. */
14612
6ef4f1f39105 Revert "use _GL_ATTRIBUTE_CONST and _GL_ATTRIBUTE_PURE"
Jim Meyering <meyering@redhat.com>
parents: 14610
diff changeset
142 bool
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
143 fnmatch_pattern_has_wildcards (const char *str, int options)
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
144 {
16803
50f45dd3bacf exclude: handle wildcards with FNM_EXTMATCH
Paul Eggert <eggert@cs.ucla.edu>
parents: 16201
diff changeset
145 while (1)
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
146 {
16803
50f45dd3bacf exclude: handle wildcards with FNM_EXTMATCH
Paul Eggert <eggert@cs.ucla.edu>
parents: 16201
diff changeset
147 switch (*str++)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
148 {
17625
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
149 case '.':
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
150 case '{':
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
151 case '}':
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
152 case '(':
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
153 case ')':
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
154 if (options & EXCLUDE_REGEX)
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
155 return true;
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
156 break;
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
157
16803
50f45dd3bacf exclude: handle wildcards with FNM_EXTMATCH
Paul Eggert <eggert@cs.ucla.edu>
parents: 16201
diff changeset
158 case '\\':
17625
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
159 if (options & EXCLUDE_REGEX)
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
160 continue;
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
161 else
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
162 str += ! (options & FNM_NOESCAPE) && *str;
16803
50f45dd3bacf exclude: handle wildcards with FNM_EXTMATCH
Paul Eggert <eggert@cs.ucla.edu>
parents: 16201
diff changeset
163 break;
50f45dd3bacf exclude: handle wildcards with FNM_EXTMATCH
Paul Eggert <eggert@cs.ucla.edu>
parents: 16201
diff changeset
164
50f45dd3bacf exclude: handle wildcards with FNM_EXTMATCH
Paul Eggert <eggert@cs.ucla.edu>
parents: 16201
diff changeset
165 case '+': case '@': case '!':
50f45dd3bacf exclude: handle wildcards with FNM_EXTMATCH
Paul Eggert <eggert@cs.ucla.edu>
parents: 16201
diff changeset
166 if (options & FNM_EXTMATCH && *str == '(')
50f45dd3bacf exclude: handle wildcards with FNM_EXTMATCH
Paul Eggert <eggert@cs.ucla.edu>
parents: 16201
diff changeset
167 return true;
50f45dd3bacf exclude: handle wildcards with FNM_EXTMATCH
Paul Eggert <eggert@cs.ucla.edu>
parents: 16201
diff changeset
168 break;
50f45dd3bacf exclude: handle wildcards with FNM_EXTMATCH
Paul Eggert <eggert@cs.ucla.edu>
parents: 16201
diff changeset
169
50f45dd3bacf exclude: handle wildcards with FNM_EXTMATCH
Paul Eggert <eggert@cs.ucla.edu>
parents: 16201
diff changeset
170 case '?': case '*': case '[':
50f45dd3bacf exclude: handle wildcards with FNM_EXTMATCH
Paul Eggert <eggert@cs.ucla.edu>
parents: 16201
diff changeset
171 return true;
50f45dd3bacf exclude: handle wildcards with FNM_EXTMATCH
Paul Eggert <eggert@cs.ucla.edu>
parents: 16201
diff changeset
172
50f45dd3bacf exclude: handle wildcards with FNM_EXTMATCH
Paul Eggert <eggert@cs.ucla.edu>
parents: 16201
diff changeset
173 case '\0':
50f45dd3bacf exclude: handle wildcards with FNM_EXTMATCH
Paul Eggert <eggert@cs.ucla.edu>
parents: 16201
diff changeset
174 return false;
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
175 }
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
176 }
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
177 }
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
178
13320
4e283fd1efe9 exclude: Unescape hashed patterns in wildcard mode.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 13086
diff changeset
179 static void
4e283fd1efe9 exclude: Unescape hashed patterns in wildcard mode.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 13086
diff changeset
180 unescape_pattern (char *str)
4e283fd1efe9 exclude: Unescape hashed patterns in wildcard mode.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 13086
diff changeset
181 {
16805
e437afafc0dc exclude: handle wildcards with FNM_NOESCAPE and with trailing \
Paul Eggert <eggert@cs.ucla.edu>
parents: 16803
diff changeset
182 char const *q = str;
13320
4e283fd1efe9 exclude: Unescape hashed patterns in wildcard mode.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 13086
diff changeset
183 do
16805
e437afafc0dc exclude: handle wildcards with FNM_NOESCAPE and with trailing \
Paul Eggert <eggert@cs.ucla.edu>
parents: 16803
diff changeset
184 q += *q == '\\' && q[1];
13320
4e283fd1efe9 exclude: Unescape hashed patterns in wildcard mode.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 13086
diff changeset
185 while ((*str++ = *q++));
4e283fd1efe9 exclude: Unescape hashed patterns in wildcard mode.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 13086
diff changeset
186 }
4e283fd1efe9 exclude: Unescape hashed patterns in wildcard mode.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 13086
diff changeset
187
3398
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
188 /* Return a newly allocated and empty exclude list. */
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
189
1171
Jim Meyering <jim@meyering.net>
parents:
diff changeset
190 struct exclude *
Jim Meyering <jim@meyering.net>
parents:
diff changeset
191 new_exclude (void)
Jim Meyering <jim@meyering.net>
parents:
diff changeset
192 {
4820
559c5f9c9e45 Modify exclude.c to use new xalloc primitives, for simplicity.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4790
diff changeset
193 return xzalloc (sizeof *new_exclude ());
1171
Jim Meyering <jim@meyering.net>
parents:
diff changeset
194 }
Jim Meyering <jim@meyering.net>
parents:
diff changeset
195
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
196 /* Calculate the hash of string. */
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
197 static size_t
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
198 string_hasher (void const *data, size_t n_buckets)
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
199 {
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
200 char const *p = data;
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
201 return hash_string (p, n_buckets);
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
202 }
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
203
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
204 /* Ditto, for case-insensitive hashes */
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
205 static size_t
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
206 string_hasher_ci (void const *data, size_t n_buckets)
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
207 {
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
208 char const *p = data;
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
209 mbui_iterator_t iter;
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
210 size_t value = 0;
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
211
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
212 for (mbui_init (iter, p); mbui_avail (iter); mbui_advance (iter))
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
213 {
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
214 mbchar_t m = mbui_cur (iter);
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
215 wchar_t wc;
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
216
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
217 if (m.wc_valid)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
218 wc = towlower (m.wc);
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
219 else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
220 wc = *m.ptr;
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
221
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
222 value = (value * 31 + wc) % n_buckets;
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
223 }
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
224
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
225 return value;
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
226 }
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
227
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
228 /* compare two strings for equality */
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
229 static bool
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
230 string_compare (void const *data1, void const *data2)
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
231 {
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
232 char const *p1 = data1;
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
233 char const *p2 = data2;
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
234 return strcmp (p1, p2) == 0;
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
235 }
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
236
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
237 /* compare two strings for equality, case-insensitive */
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
238 static bool
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
239 string_compare_ci (void const *data1, void const *data2)
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
240 {
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
241 char const *p1 = data1;
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
242 char const *p2 = data2;
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
243 return mbscasecmp (p1, p2) == 0;
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
244 }
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
245
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
246 static void
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
247 string_free (void *data)
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
248 {
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
249 free (data);
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
250 }
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
251
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
252 /* Create new exclude segment of given TYPE and OPTIONS, and attach it
16806
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
253 to the head of EX. */
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
254 static void
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
255 new_exclude_segment (struct exclude *ex, enum exclude_type type, int options)
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
256 {
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
257 struct exclude_segment *sp = xzalloc (sizeof (struct exclude_segment));
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
258 sp->type = type;
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
259 sp->options = options;
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
260 switch (type)
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
261 {
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
262 case exclude_pattern:
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
263 break;
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
264
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
265 case exclude_hash:
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
266 sp->v.table = hash_initialize (0, NULL,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
267 (options & FNM_CASEFOLD) ?
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
268 string_hasher_ci
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
269 : string_hasher,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
270 (options & FNM_CASEFOLD) ?
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
271 string_compare_ci
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
272 : string_compare,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
273 string_free);
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
274 break;
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
275 }
16806
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
276 sp->next = ex->head;
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
277 ex->head = sp;
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
278 }
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
279
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
280 /* Free a single exclude segment */
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
281 static void
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
282 free_exclude_segment (struct exclude_segment *seg)
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
283 {
17625
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
284 size_t i;
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
285
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
286 switch (seg->type)
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
287 {
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
288 case exclude_pattern:
17625
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
289 for (i = 0; i < seg->v.pat.exclude_count; i++)
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
290 {
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
291 if (seg->v.pat.exclude[i].options & EXCLUDE_REGEX)
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
292 regfree (&seg->v.pat.exclude[i].v.re);
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
293 }
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
294 free (seg->v.pat.exclude);
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
295 break;
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
296
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
297 case exclude_hash:
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
298 hash_free (seg->v.table);
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
299 break;
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
300 }
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
301 free (seg);
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
302 }
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
303
3398
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
304 /* Free the storage associated with an exclude list. */
1171
Jim Meyering <jim@meyering.net>
parents:
diff changeset
305 void
3398
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
306 free_exclude (struct exclude *ex)
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
307 {
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
308 struct exclude_segment *seg;
17625
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
309 struct pattern_buffer *pbuf;
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
310
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
311 for (seg = ex->head; seg; )
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
312 {
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
313 struct exclude_segment *next = seg->next;
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
314 free_exclude_segment (seg);
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
315 seg = next;
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
316 }
17625
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
317
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
318 for (pbuf = ex->patbuf; pbuf; )
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
319 {
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
320 struct pattern_buffer *next = pbuf->next;
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
321 free (pbuf->base);
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
322 free (pbuf);
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
323 pbuf = next;
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
324 }
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
325
3398
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
326 free (ex);
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
327 }
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
328
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
329 /* Return zero if PATTERN matches F, obeying OPTIONS, except that
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
330 (unlike fnmatch) wildcards are disabled in PATTERN. */
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
331
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
332 static int
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
333 fnmatch_no_wildcards (char const *pattern, char const *f, int options)
1171
Jim Meyering <jim@meyering.net>
parents:
diff changeset
334 {
3459
616b1a72ff28 (fnmatch_no_wildcards): Fix confusion between
Jim Meyering <jim@meyering.net>
parents: 3436
diff changeset
335 if (! (options & FNM_LEADING_DIR))
616b1a72ff28 (fnmatch_no_wildcards): Fix confusion between
Jim Meyering <jim@meyering.net>
parents: 3436
diff changeset
336 return ((options & FNM_CASEFOLD)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
337 ? mbscasecmp (pattern, f)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
338 : strcmp (pattern, f));
8155
eca0a6359ada * lib/exclude.c (FNM_EXTMATCH): Define if system does not.
Paul Eggert <eggert@cs.ucla.edu>
parents: 7944
diff changeset
339 else if (! (options & FNM_CASEFOLD))
3398
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
340 {
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
341 size_t patlen = strlen (pattern);
8155
eca0a6359ada * lib/exclude.c (FNM_EXTMATCH): Define if system does not.
Paul Eggert <eggert@cs.ucla.edu>
parents: 7944
diff changeset
342 int r = strncmp (pattern, f, patlen);
3398
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
343 if (! r)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
344 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
345 r = f[patlen];
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
346 if (r == '/')
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
347 r = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
348 }
3398
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
349 return r;
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
350 }
8155
eca0a6359ada * lib/exclude.c (FNM_EXTMATCH): Define if system does not.
Paul Eggert <eggert@cs.ucla.edu>
parents: 7944
diff changeset
351 else
eca0a6359ada * lib/exclude.c (FNM_EXTMATCH): Define if system does not.
Paul Eggert <eggert@cs.ucla.edu>
parents: 7944
diff changeset
352 {
eca0a6359ada * lib/exclude.c (FNM_EXTMATCH): Define if system does not.
Paul Eggert <eggert@cs.ucla.edu>
parents: 7944
diff changeset
353 /* Walk through a copy of F, seeing whether P matches any prefix
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
354 of F.
8155
eca0a6359ada * lib/exclude.c (FNM_EXTMATCH): Define if system does not.
Paul Eggert <eggert@cs.ucla.edu>
parents: 7944
diff changeset
355
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
356 FIXME: This is an O(N**2) algorithm; it should be O(N).
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
357 Also, the copy should not be necessary. However, fixing this
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
358 will probably involve a change to the mbs* API. */
8155
eca0a6359ada * lib/exclude.c (FNM_EXTMATCH): Define if system does not.
Paul Eggert <eggert@cs.ucla.edu>
parents: 7944
diff changeset
359
eca0a6359ada * lib/exclude.c (FNM_EXTMATCH): Define if system does not.
Paul Eggert <eggert@cs.ucla.edu>
parents: 7944
diff changeset
360 char *fcopy = xstrdup (f);
eca0a6359ada * lib/exclude.c (FNM_EXTMATCH): Define if system does not.
Paul Eggert <eggert@cs.ucla.edu>
parents: 7944
diff changeset
361 char *p;
eca0a6359ada * lib/exclude.c (FNM_EXTMATCH): Define if system does not.
Paul Eggert <eggert@cs.ucla.edu>
parents: 7944
diff changeset
362 int r;
eca0a6359ada * lib/exclude.c (FNM_EXTMATCH): Define if system does not.
Paul Eggert <eggert@cs.ucla.edu>
parents: 7944
diff changeset
363 for (p = fcopy; ; *p++ = '/')
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
364 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
365 p = strchr (p, '/');
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
366 if (p)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
367 *p = '\0';
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
368 r = mbscasecmp (pattern, fcopy);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
369 if (!p || r <= 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
370 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
371 }
8155
eca0a6359ada * lib/exclude.c (FNM_EXTMATCH): Define if system does not.
Paul Eggert <eggert@cs.ucla.edu>
parents: 7944
diff changeset
372 free (fcopy);
eca0a6359ada * lib/exclude.c (FNM_EXTMATCH): Define if system does not.
Paul Eggert <eggert@cs.ucla.edu>
parents: 7944
diff changeset
373 return r;
eca0a6359ada * lib/exclude.c (FNM_EXTMATCH): Define if system does not.
Paul Eggert <eggert@cs.ucla.edu>
parents: 7944
diff changeset
374 }
1171
Jim Meyering <jim@meyering.net>
parents:
diff changeset
375 }
Jim Meyering <jim@meyering.net>
parents:
diff changeset
376
6803
ef94ee751cba (exclude_fnmatch): New function.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 6323
diff changeset
377 bool
ef94ee751cba (exclude_fnmatch): New function.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 6323
diff changeset
378 exclude_fnmatch (char const *pattern, char const *f, int options)
ef94ee751cba (exclude_fnmatch): New function.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 6323
diff changeset
379 {
ef94ee751cba (exclude_fnmatch): New function.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 6323
diff changeset
380 int (*matcher) (char const *, char const *, int) =
ef94ee751cba (exclude_fnmatch): New function.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 6323
diff changeset
381 (options & EXCLUDE_WILDCARDS
ef94ee751cba (exclude_fnmatch): New function.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 6323
diff changeset
382 ? fnmatch
ef94ee751cba (exclude_fnmatch): New function.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 6323
diff changeset
383 : fnmatch_no_wildcards);
ef94ee751cba (exclude_fnmatch): New function.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 6323
diff changeset
384 bool matched = ((*matcher) (pattern, f, options) == 0);
ef94ee751cba (exclude_fnmatch): New function.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 6323
diff changeset
385 char const *p;
ef94ee751cba (exclude_fnmatch): New function.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 6323
diff changeset
386
ef94ee751cba (exclude_fnmatch): New function.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 6323
diff changeset
387 if (! (options & EXCLUDE_ANCHORED))
ef94ee751cba (exclude_fnmatch): New function.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 6323
diff changeset
388 for (p = f; *p && ! matched; p++)
ef94ee751cba (exclude_fnmatch): New function.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 6323
diff changeset
389 if (*p == '/' && p[1] != '/')
17625
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
390 matched = ((*matcher) (pattern, p + 1, options) == 0);
6803
ef94ee751cba (exclude_fnmatch): New function.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 6323
diff changeset
391
ef94ee751cba (exclude_fnmatch): New function.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 6323
diff changeset
392 return matched;
ef94ee751cba (exclude_fnmatch): New function.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 6323
diff changeset
393 }
ef94ee751cba (exclude_fnmatch): New function.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 6323
diff changeset
394
17765
6dafc9cb43ae exclude: declare exclude_patopts static
Jim Meyering <meyering@fb.com>
parents: 17658
diff changeset
395 static bool
17625
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
396 exclude_patopts (struct patopts const *opts, char const *f)
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
397 {
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
398 int options = opts->options;
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
399
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
400 return (options & EXCLUDE_REGEX)
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
401 ? regexec (&opts->v.re, f, 0, NULL, 0) == 0
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
402 : exclude_fnmatch (opts->v.pattern, f, options);
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
403 }
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
404
16806
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
405 /* Return true if the exclude_pattern segment SEG matches F. */
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
406
11856
8b0d11ca9d01 build: avoid some compiler warnings
Eric Blake <ebb9@byu.net>
parents: 11811
diff changeset
407 static bool
16806
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
408 file_pattern_matches (struct exclude_segment const *seg, char const *f)
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
409 {
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
410 size_t exclude_count = seg->v.pat.exclude_count;
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
411 struct patopts const *exclude = seg->v.pat.exclude;
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
412 size_t i;
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
413
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
414 for (i = 0; i < exclude_count; i++)
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
415 {
17625
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
416 if (exclude_patopts (exclude + i, f))
16806
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
417 return true;
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
418 }
16806
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
419 return false;
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
420 }
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
421
16806
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
422 /* Return true if the exclude_hash segment SEG matches F.
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
423 BUFFER is an auxiliary storage of the same length as F (with nul
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
424 terminator included) */
11856
8b0d11ca9d01 build: avoid some compiler warnings
Eric Blake <ebb9@byu.net>
parents: 11811
diff changeset
425 static bool
16806
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
426 file_name_matches (struct exclude_segment const *seg, char const *f,
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
427 char *buffer)
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
428 {
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
429 int options = seg->options;
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
430 Hash_table *table = seg->v.table;
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
431
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
432 do
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
433 {
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
434 /* initialize the pattern */
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
435 strcpy (buffer, f);
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
436
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
437 while (1)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
438 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
439 if (hash_lookup (table, buffer))
16806
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
440 return true;
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
441 if (options & FNM_LEADING_DIR)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
442 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
443 char *p = strrchr (buffer, '/');
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
444 if (p)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
445 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
446 *p = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
447 continue;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
448 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
449 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
450 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
451 }
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
452
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
453 if (!(options & EXCLUDE_ANCHORED))
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
454 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
455 f = strchr (f, '/');
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
456 if (f)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
457 f++;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
458 }
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
459 else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
460 break;
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
461 }
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
462 while (f);
16806
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
463
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
464 return false;
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
465 }
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
466
3398
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
467 /* Return true if EX excludes F. */
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
468
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
469 bool
5907
c47674a83a78 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
470 excluded_file_name (struct exclude const *ex, char const *f)
3398
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
471 {
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
472 struct exclude_segment *seg;
16806
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
473 bool invert = false;
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
474 char *filename = NULL;
3398
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
475
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
476 /* If no patterns are given, the default is to include. */
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
477 if (!ex->head)
3535
c08cb8ae6c9c (excluded_filename): 0 -> false, since it's a boolean context.
Jim Meyering <jim@meyering.net>
parents: 3459
diff changeset
478 return false;
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
479
16806
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
480 /* Scan through the segments, reporting the status of the first match.
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
481 The segments are in reverse order, so this reports the status of
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
482 the last match in the original option list. */
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
483 for (seg = ex->head; ; seg = seg->next)
3398
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
484 {
16806
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
485 if (seg->type == exclude_hash)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
486 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
487 if (!filename)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
488 filename = xmalloc (strlen (f) + 1);
16806
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
489 if (file_name_matches (seg, f, filename))
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
490 break;
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
491 }
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
492 else
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
493 {
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
494 if (file_pattern_matches (seg, f))
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
495 break;
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
496 }
12218
751d5b272c72 exclude: make more robust
Eric Blake <ebb9@byu.net>
parents: 12203
diff changeset
497
16806
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
498 if (! seg->next)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
499 {
16806
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
500 /* If patterns are given but none match, the default is the
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
501 opposite of the last segment (i.e., the first in the
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
502 original option list). For example, in the command
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
503 'grep -r --exclude="a*" --include="*b" pat dir', the
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
504 first option is --exclude so any file name matching
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
505 neither a* nor *b is included. */
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
506 invert = true;
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
507 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
508 }
3398
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
509 }
16806
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
510
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
511 free (filename);
16806
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
512 return invert ^ ! (seg->options & EXCLUDE_INCLUDE);
3398
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
513 }
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
514
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
515 /* Append to EX the exclusion PATTERN with OPTIONS. */
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
516
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
517 void
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
518 add_exclude (struct exclude *ex, char const *pattern, int options)
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
519 {
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
520 struct exclude_segment *seg;
17625
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
521 struct exclude_pattern *pat;
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
522 struct patopts *patopts;
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
523
17625
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
524 if ((options & (EXCLUDE_REGEX|EXCLUDE_WILDCARDS))
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
525 && fnmatch_pattern_has_wildcards (pattern, options))
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
526 {
17625
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
527 if (! (ex->head && ex->head->type == exclude_pattern
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
528 && ((ex->head->options & EXCLUDE_INCLUDE)
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
529 == (options & EXCLUDE_INCLUDE))))
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
530 new_exclude_segment (ex, exclude_pattern, options);
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
531
16806
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
532 seg = ex->head;
3398
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
533
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
534 pat = &seg->v.pat;
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
535 if (pat->exclude_count == pat->exclude_alloc)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
536 pat->exclude = x2nrealloc (pat->exclude, &pat->exclude_alloc,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
537 sizeof *pat->exclude);
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
538 patopts = &pat->exclude[pat->exclude_count++];
17625
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
539
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
540 patopts->options = options;
17625
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
541 if (options & EXCLUDE_REGEX)
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
542 {
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
543 int rc;
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
544 int cflags = REG_NOSUB|REG_EXTENDED|
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
545 ((options & FNM_CASEFOLD) ? REG_ICASE : 0);
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
546
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
547 if (options & FNM_LEADING_DIR)
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
548 {
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
549 char *tmp;
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
550 size_t len = strlen (pattern);
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
551
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
552 while (len > 0 && ISSLASH (pattern[len-1]))
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
553 --len;
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
554
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
555 if (len == 0)
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
556 rc = 1;
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
557 else
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
558 {
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
559 tmp = xmalloc (len + 7);
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
560 memcpy (tmp, pattern, len);
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
561 strcpy (tmp + len, "(/.*)?");
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
562 rc = regcomp (&patopts->v.re, tmp, cflags);
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
563 free (tmp);
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
564 }
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
565 }
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
566 else
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
567 rc = regcomp (&patopts->v.re, pattern, cflags);
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
568
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
569 if (rc)
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
570 {
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
571 pat->exclude_count--;
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
572 return;
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
573 }
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
574 }
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
575 else
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
576 {
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
577 if (options & EXCLUDE_ALLOC)
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
578 {
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
579 pattern = xstrdup (pattern);
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
580 exclude_add_pattern_buffer (ex, (char*) pattern);
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
581 }
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
582 patopts->v.pattern = pattern;
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
583 }
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
584 }
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
585 else
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
586 {
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
587 char *str, *p;
16806
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
588 int exclude_hash_flags = (EXCLUDE_INCLUDE | EXCLUDE_ANCHORED
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
589 | FNM_LEADING_DIR | FNM_CASEFOLD);
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
590 if (! (ex->head && ex->head->type == exclude_hash
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
591 && ((ex->head->options & exclude_hash_flags)
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
592 == (options & exclude_hash_flags))))
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
593 new_exclude_segment (ex, exclude_hash, options);
babe19575e66 exclude: process exclude and include directives in order
Paul Eggert <eggert@cs.ucla.edu>
parents: 16805
diff changeset
594 seg = ex->head;
3398
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
595
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
596 str = xstrdup (pattern);
16805
e437afafc0dc exclude: handle wildcards with FNM_NOESCAPE and with trailing \
Paul Eggert <eggert@cs.ucla.edu>
parents: 16803
diff changeset
597 if ((options & (EXCLUDE_WILDCARDS | FNM_NOESCAPE)) == EXCLUDE_WILDCARDS)
13479
8a0b8adde2be Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 13320
diff changeset
598 unescape_pattern (str);
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
599 p = hash_insert (seg->v.table, str);
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
600 if (p != str)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
601 free (str);
11811
451cf730f520 Optimize exclude: use hash tables for non-wildcard patterns.
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 9309
diff changeset
602 }
3398
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
603 }
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
604
5907
c47674a83a78 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
605 /* Use ADD_FUNC to append to EX the patterns in FILE_NAME, each with
4537
940fdf291f5b Ignore trailing white space and empty lines
Paul Eggert <eggert@cs.ucla.edu>
parents: 4350
diff changeset
606 OPTIONS. LINE_END terminates each pattern in the file. If
940fdf291f5b Ignore trailing white space and empty lines
Paul Eggert <eggert@cs.ucla.edu>
parents: 4350
diff changeset
607 LINE_END is a space character, ignore trailing spaces and empty
17625
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
608 lines in FP. Return -1 on failure, 0 on success. */
3398
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
609
1171
Jim Meyering <jim@meyering.net>
parents:
diff changeset
610 int
17625
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
611 add_exclude_fp (void (*add_func) (struct exclude *, char const *, int, void *),
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
612 struct exclude *ex, FILE *fp, int options,
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
613 char line_end,
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
614 void *data)
1171
Jim Meyering <jim@meyering.net>
parents:
diff changeset
615 {
4820
559c5f9c9e45 Modify exclude.c to use new xalloc primitives, for simplicity.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4790
diff changeset
616 char *buf = NULL;
1171
Jim Meyering <jim@meyering.net>
parents:
diff changeset
617 char *p;
17625
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
618 char *pattern;
1171
Jim Meyering <jim@meyering.net>
parents:
diff changeset
619 char const *lim;
4820
559c5f9c9e45 Modify exclude.c to use new xalloc primitives, for simplicity.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4790
diff changeset
620 size_t buf_alloc = 0;
1171
Jim Meyering <jim@meyering.net>
parents:
diff changeset
621 size_t buf_count = 0;
Jim Meyering <jim@meyering.net>
parents:
diff changeset
622 int c;
Jim Meyering <jim@meyering.net>
parents:
diff changeset
623 int e = 0;
Jim Meyering <jim@meyering.net>
parents:
diff changeset
624
17625
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
625 while ((c = getc (fp)) != EOF)
1171
Jim Meyering <jim@meyering.net>
parents:
diff changeset
626 {
4820
559c5f9c9e45 Modify exclude.c to use new xalloc primitives, for simplicity.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4790
diff changeset
627 if (buf_count == buf_alloc)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
628 buf = x2realloc (buf, &buf_alloc);
1171
Jim Meyering <jim@meyering.net>
parents:
diff changeset
629 buf[buf_count++] = c;
Jim Meyering <jim@meyering.net>
parents:
diff changeset
630 }
Jim Meyering <jim@meyering.net>
parents:
diff changeset
631
17625
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
632 if (ferror (fp))
1171
Jim Meyering <jim@meyering.net>
parents:
diff changeset
633 e = errno;
Jim Meyering <jim@meyering.net>
parents:
diff changeset
634
3398
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
635 buf = xrealloc (buf, buf_count + 1);
4538
e05e3087e98a Fix typo in previous change; it mishandled the case when line_end was
Paul Eggert <eggert@cs.ucla.edu>
parents: 4537
diff changeset
636 buf[buf_count] = line_end;
e05e3087e98a Fix typo in previous change; it mishandled the case when line_end was
Paul Eggert <eggert@cs.ucla.edu>
parents: 4537
diff changeset
637 lim = buf + buf_count + ! (buf_count == 0 || buf[buf_count - 1] == line_end);
17625
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
638
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
639 exclude_add_pattern_buffer (ex, buf);
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
640
4538
e05e3087e98a Fix typo in previous change; it mishandled the case when line_end was
Paul Eggert <eggert@cs.ucla.edu>
parents: 4537
diff changeset
641 pattern = buf;
3398
1beac6d79e51 Merge 'exclude' changes from tar 1.13.22.
Jim Meyering <jim@meyering.net>
parents: 2108
diff changeset
642
4538
e05e3087e98a Fix typo in previous change; it mishandled the case when line_end was
Paul Eggert <eggert@cs.ucla.edu>
parents: 4537
diff changeset
643 for (p = buf; p < lim; p++)
e05e3087e98a Fix typo in previous change; it mishandled the case when line_end was
Paul Eggert <eggert@cs.ucla.edu>
parents: 4537
diff changeset
644 if (*p == line_end)
1171
Jim Meyering <jim@meyering.net>
parents:
diff changeset
645 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
646 char *pattern_end = p;
4538
e05e3087e98a Fix typo in previous change; it mishandled the case when line_end was
Paul Eggert <eggert@cs.ucla.edu>
parents: 4537
diff changeset
647
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
648 if (isspace ((unsigned char) line_end))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
649 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
650 for (; ; pattern_end--)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
651 if (pattern_end == pattern)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
652 goto next_pattern;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
653 else if (! isspace ((unsigned char) pattern_end[-1]))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
654 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
655 }
4537
940fdf291f5b Ignore trailing white space and empty lines
Paul Eggert <eggert@cs.ucla.edu>
parents: 4350
diff changeset
656
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
657 *pattern_end = '\0';
17625
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
658 (*add_func) (ex, pattern, options, data);
4537
940fdf291f5b Ignore trailing white space and empty lines
Paul Eggert <eggert@cs.ucla.edu>
parents: 4350
diff changeset
659
940fdf291f5b Ignore trailing white space and empty lines
Paul Eggert <eggert@cs.ucla.edu>
parents: 4350
diff changeset
660 next_pattern:
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12218
diff changeset
661 pattern = p + 1;
1171
Jim Meyering <jim@meyering.net>
parents:
diff changeset
662 }
Jim Meyering <jim@meyering.net>
parents:
diff changeset
663
Jim Meyering <jim@meyering.net>
parents:
diff changeset
664 errno = e;
Jim Meyering <jim@meyering.net>
parents:
diff changeset
665 return e ? -1 : 0;
Jim Meyering <jim@meyering.net>
parents:
diff changeset
666 }
17625
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
667
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
668 static void
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
669 call_addfn (struct exclude *ex, char const *pattern, int options, void *data)
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
670 {
17658
8d4f74d33135 exclude: port to strict C99
Paul Eggert <eggert@cs.ucla.edu>
parents: 17625
diff changeset
671 void (**addfnptr) (struct exclude *, char const *, int) = data;
8d4f74d33135 exclude: port to strict C99
Paul Eggert <eggert@cs.ucla.edu>
parents: 17625
diff changeset
672 (*addfnptr) (ex, pattern, options);
17625
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
673 }
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
674
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
675 int
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
676 add_exclude_file (void (*add_func) (struct exclude *, char const *, int),
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
677 struct exclude *ex, char const *file_name, int options,
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
678 char line_end)
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
679 {
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
680 bool use_stdin = file_name[0] == '-' && !file_name[1];
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
681 FILE *in;
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
682 int rc = 0;
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
683
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
684 if (use_stdin)
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
685 in = stdin;
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
686 else if (! (in = fopen (file_name, "r")))
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
687 return -1;
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
688
17658
8d4f74d33135 exclude: port to strict C99
Paul Eggert <eggert@cs.ucla.edu>
parents: 17625
diff changeset
689 rc = add_exclude_fp (call_addfn, ex, in, options, line_end, &add_func);
17625
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
690
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
691 if (!use_stdin && fclose (in) != 0)
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
692 rc = -1;
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
693
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
694 return rc;
ab0ca58c72b1 exclude: add support for posix regexps
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 17587
diff changeset
695 }