aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDaniel Colascione2018-06-16 12:43:56 -0700
committerDaniel Colascione2018-06-16 13:46:38 -0700
commit1502b377d35d6db623301829549ebcab9a2777e6 (patch)
treeabb133a89cfe7884ecee998240a106a30b1d810d /src
parent971abd6753ed0b13019e52baab862e68453c7306 (diff)
downloademacs-1502b377d35d6db623301829549ebcab9a2777e6.tar.gz
emacs-1502b377d35d6db623301829549ebcab9a2777e6.zip
Decouple dired from regex internals
* src/dired.c: Remove use of regex.h (directory_files_internal): Use higher-level regular expression functions.
Diffstat (limited to 'src')
-rw-r--r--src/dired.c37
1 files changed, 12 insertions, 25 deletions
diff --git a/src/dired.c b/src/dired.c
index a753b1930e6..5812c569fa6 100644
--- a/src/dired.c
+++ b/src/dired.c
@@ -40,7 +40,6 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
40#include "systime.h" 40#include "systime.h"
41#include "buffer.h" 41#include "buffer.h"
42#include "coding.h" 42#include "coding.h"
43#include "regex.h"
44 43
45#ifdef MSDOS 44#ifdef MSDOS
46#include "msdos.h" /* for fstatat */ 45#include "msdos.h" /* for fstatat */
@@ -171,7 +170,6 @@ directory_files_internal (Lisp_Object directory, Lisp_Object full,
171{ 170{
172 ptrdiff_t directory_nbytes; 171 ptrdiff_t directory_nbytes;
173 Lisp_Object list, dirfilename, encoded_directory; 172 Lisp_Object list, dirfilename, encoded_directory;
174 struct re_pattern_buffer *bufp = NULL;
175 bool needsep = 0; 173 bool needsep = 0;
176 ptrdiff_t count = SPECPDL_INDEX (); 174 ptrdiff_t count = SPECPDL_INDEX ();
177#ifdef WINDOWSNT 175#ifdef WINDOWSNT
@@ -187,33 +185,12 @@ directory_files_internal (Lisp_Object directory, Lisp_Object full,
187 list = encoded_directory = dirfilename = Qnil; 185 list = encoded_directory = dirfilename = Qnil;
188 dirfilename = Fdirectory_file_name (directory); 186 dirfilename = Fdirectory_file_name (directory);
189 187
190 if (!NILP (match))
191 {
192 CHECK_STRING (match);
193
194 /* MATCH might be a flawed regular expression. Rather than
195 catching and signaling our own errors, we just call
196 compile_pattern to do the work for us. */
197 /* Pass 1 for the MULTIBYTE arg
198 because we do make multibyte strings if the contents warrant. */
199# ifdef WINDOWSNT
200 /* Windows users want case-insensitive wildcards. */
201 bufp = compile_pattern (match, 0,
202 BVAR (&buffer_defaults, case_canon_table), 0, 1);
203# else /* !WINDOWSNT */
204 bufp = compile_pattern (match, 0, Qnil, 0, 1);
205# endif /* !WINDOWSNT */
206 }
207
208 /* Note: ENCODE_FILE and DECODE_FILE can GC because they can run 188 /* Note: ENCODE_FILE and DECODE_FILE can GC because they can run
209 run_pre_post_conversion_on_str which calls Lisp directly and 189 run_pre_post_conversion_on_str which calls Lisp directly and
210 indirectly. */ 190 indirectly. */
211 dirfilename = ENCODE_FILE (dirfilename); 191 dirfilename = ENCODE_FILE (dirfilename);
212 encoded_directory = ENCODE_FILE (directory); 192 encoded_directory = ENCODE_FILE (directory);
213 193
214 /* Now *bufp is the compiled form of MATCH; don't call anything
215 which might compile a new regexp until we're done with the loop! */
216
217 int fd; 194 int fd;
218 DIR *d = open_directory (dirfilename, &fd); 195 DIR *d = open_directory (dirfilename, &fd);
219 196
@@ -250,6 +227,15 @@ directory_files_internal (Lisp_Object directory, Lisp_Object full,
250 || !IS_ANY_SEP (SREF (directory, directory_nbytes - 1))) 227 || !IS_ANY_SEP (SREF (directory, directory_nbytes - 1)))
251 needsep = 1; 228 needsep = 1;
252 229
230 /* Windows users want case-insensitive wildcards. */
231 Lisp_Object case_table =
232#ifdef WINDOWSNT
233 BVAR (&buffer_defaults, case_canon_table)
234#else
235 Qnil
236#endif
237 ;
238
253 /* Loop reading directory entries. */ 239 /* Loop reading directory entries. */
254 for (struct dirent *dp; (dp = read_dirent (d, directory)); ) 240 for (struct dirent *dp; (dp = read_dirent (d, directory)); )
255 { 241 {
@@ -266,8 +252,9 @@ directory_files_internal (Lisp_Object directory, Lisp_Object full,
266 allow matching to be interrupted. */ 252 allow matching to be interrupted. */
267 maybe_quit (); 253 maybe_quit ();
268 254
269 bool wanted = (NILP (match) 255 bool wanted = (NILP (match) ||
270 || re_search (bufp, SSDATA (name), len, 0, len, 0) >= 0); 256 fast_string_match_internal (
257 match, name, case_table) >= 0);
271 258
272 if (wanted) 259 if (wanted)
273 { 260 {