(directory_files_internal_w32_unwind) [WINDOWSNT]: New function.
[bpt/emacs.git] / src / dired.c
CommitLineData
14d55bce 1/* Lisp functions for making directory listings.
0b5538bd 2 Copyright (C) 1985, 1986, 1993, 1994, 1999, 2000, 2001, 2002, 2003,
76b6f707 3 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
14d55bce
RS
4
5This file is part of GNU Emacs.
6
9ec0b715 7GNU Emacs is free software: you can redistribute it and/or modify
14d55bce 8it under the terms of the GNU General Public License as published by
9ec0b715
GM
9the Free Software Foundation, either version 3 of the License, or
10(at your option) any later version.
14d55bce
RS
11
12GNU Emacs is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
9ec0b715 18along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
14d55bce
RS
19
20
3964b9a7
RS
21#include <config.h>
22
14d55bce
RS
23#include <stdio.h>
24#include <sys/types.h>
25#include <sys/stat.h>
26
5b9c0a1d 27#ifdef HAVE_PWD_H
6b61353c 28#include <pwd.h>
5b9c0a1d 29#endif
6b61353c 30#include <grp.h>
6b61353c 31
7cc9f69f 32#include <errno.h>
68c45bf0 33
dfcf069d
AS
34#ifdef HAVE_UNISTD_H
35#include <unistd.h>
36#endif
37
d6717cdb
JB
38/* The d_nameln member of a struct dirent includes the '\0' character
39 on some systems, but not on others. What's worse, you can't tell
40 at compile-time which one it will be, since it really depends on
41 the sort of system providing the filesystem you're reading from,
42 not the system you are running on. Paul Eggert
43 <eggert@bi.twinsun.com> says this occurs when Emacs is running on a
44 SunOS 4.1.2 host, reading a directory that is remote-mounted from a
45 Solaris 2.1 host and is in a native Solaris 2.1 filesystem.
46
47 Since applying strlen to the name always works, we'll just do that. */
48#define NAMLEN(p) strlen (p->d_name)
49
14d55bce
RS
50#ifdef SYSV_SYSTEM_DIR
51
52#include <dirent.h>
53#define DIRENTRY struct dirent
14d55bce 54
128ecc89 55#else /* not SYSV_SYSTEM_DIR */
14d55bce 56
128ecc89
RS
57#ifdef MSDOS
58#include <dirent.h>
59#else
14d55bce 60#include <sys/dir.h>
128ecc89 61#endif
14d55bce 62
851cab13
DL
63#include <sys/stat.h>
64
128ecc89 65#ifndef MSDOS
14d55bce 66#define DIRENTRY struct direct
14d55bce
RS
67
68extern DIR *opendir ();
69extern struct direct *readdir ();
70
128ecc89
RS
71#endif /* not MSDOS */
72#endif /* not SYSV_SYSTEM_DIR */
73
8f7f8c65
EZ
74/* Some versions of Cygwin don't have d_ino in `struct dirent'. */
75#if defined(MSDOS) || defined(__CYGWIN__)
128ecc89
RS
76#define DIRENTRY_NONEMPTY(p) ((p)->d_name[0] != 0)
77#else
78#define DIRENTRY_NONEMPTY(p) ((p)->d_ino)
14d55bce
RS
79#endif
80
14d55bce 81#include "lisp.h"
fa8459a3 82#include "systime.h"
14d55bce
RS
83#include "buffer.h"
84#include "commands.h"
d2f6dae8 85#include "character.h"
bd33479f
KH
86#include "charset.h"
87#include "coding.h"
14d55bce 88#include "regex.h"
8c8a7c58 89#include "blockinput.h"
14d55bce 90
e50c66d3
KH
91/* Returns a search buffer, with a fastmap allocated and ready to go. */
92extern struct re_pattern_buffer *compile_pattern ();
c7e466e1 93
851cab13
DL
94/* From filemode.c. Can't go in Lisp.h because of `stat'. */
95extern void filemodestring P_ ((struct stat *, char *));
96
14d55bce
RS
97/* if system does not have symbolic links, it does not have lstat.
98 In that case, use ordinary stat instead. */
99
100#ifndef S_IFLNK
101#define lstat stat
102#endif
103
97e98a56 104extern int completion_ignore_case;
ecd3f8b2 105extern Lisp_Object Qcompletion_ignore_case;
f676868d 106extern Lisp_Object Vcompletion_regexp_list;
65156807 107extern Lisp_Object Vw32_get_true_file_attributes;
ccbcf979 108
14d55bce 109Lisp_Object Vcompletion_ignored_extensions;
32f4334d 110Lisp_Object Qdirectory_files;
4424b255 111Lisp_Object Qdirectory_files_and_attributes;
32f4334d
RS
112Lisp_Object Qfile_name_completion;
113Lisp_Object Qfile_name_all_completions;
434e6714 114Lisp_Object Qfile_attributes;
4424b255 115Lisp_Object Qfile_attributes_lessp;
b3f04ced
RS
116
117static int scmp P_ ((unsigned char *, unsigned char *, int));
14d55bce 118\f
65156807
EZ
119#ifdef WINDOWSNT
120Lisp_Object
121directory_files_internal_w32_unwind (Lisp_Object arg)
122{
123 Vw32_get_true_file_attributes = arg;
124 return Qnil;
125}
126#endif
2488aba5
AI
127
128Lisp_Object
129directory_files_internal_unwind (dh)
130 Lisp_Object dh;
131{
9d291bdf 132 DIR *d = (DIR *) XSAVE_VALUE (dh)->pointer;
d15b573e 133 BLOCK_INPUT;
2488aba5 134 closedir (d);
d15b573e 135 UNBLOCK_INPUT;
2488aba5
AI
136 return Qnil;
137}
138
177c0ea7 139/* Function shared by Fdirectory_files and Fdirectory_files_and_attributes.
4424b255 140 When ATTRS is zero, return a list of directory filenames; when
6b61353c
KH
141 non-zero, return a list of directory filenames and their attributes.
142 In the latter case, ID_FORMAT is passed to Ffile_attributes. */
f69f9da1 143
4424b255 144Lisp_Object
6b61353c 145directory_files_internal (directory, full, match, nosort, attrs, id_format)
23bd240f 146 Lisp_Object directory, full, match, nosort;
4424b255 147 int attrs;
6b61353c 148 Lisp_Object id_format;
14d55bce
RS
149{
150 DIR *d;
388ac098
GM
151 int directory_nbytes;
152 Lisp_Object list, dirfilename, encoded_directory;
6bbd7a29 153 struct re_pattern_buffer *bufp = NULL;
96d64004 154 int needsep = 0;
aed13378 155 int count = SPECPDL_INDEX ();
388ac098 156 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
8e42f043 157 DIRENTRY *dp;
65156807
EZ
158#ifdef WINDOWSNT
159 Lisp_Object w32_save = Qnil;
160#endif
32f4334d 161
96d64004 162 /* Because of file name handlers, these functions might call
6155fae1 163 Ffuncall, and cause a GC. */
388ac098
GM
164 list = encoded_directory = dirfilename = Qnil;
165 GCPRO5 (match, directory, list, dirfilename, encoded_directory);
96d64004 166 dirfilename = Fdirectory_file_name (directory);
6155fae1 167
265a9e55 168 if (!NILP (match))
14d55bce 169 {
b7826503 170 CHECK_STRING (match);
ebb9e16f
JB
171
172 /* MATCH might be a flawed regular expression. Rather than
8e6208c5 173 catching and signaling our own errors, we just call
ebb9e16f 174 compile_pattern to do the work for us. */
c872c6b2
RS
175 /* Pass 1 for the MULTIBYTE arg
176 because we do make multibyte strings if the contents warrant. */
1a9fbabe
EZ
177# ifdef WINDOWSNT
178 /* Windows users want case-insensitive wildcards. */
179 bufp = compile_pattern (match, 0,
180 buffer_defaults.case_canon_table, 0, 1);
181# else /* !WINDOWSNT */
3e937712 182 bufp = compile_pattern (match, 0, Qnil, 0, 1);
1a9fbabe 183# endif /* !WINDOWSNT */
14d55bce
RS
184 }
185
b3edfc9b 186 /* Note: ENCODE_FILE and DECODE_FILE can GC because they can run
388ac098
GM
187 run_pre_post_conversion_on_str which calls Lisp directly and
188 indirectly. */
6c8b4f07
SM
189 if (STRING_MULTIBYTE (dirfilename))
190 dirfilename = ENCODE_FILE (dirfilename);
191 encoded_directory = (STRING_MULTIBYTE (directory)
192 ? ENCODE_FILE (directory) : directory);
24c2a54f 193
e50c66d3 194 /* Now *bufp is the compiled form of MATCH; don't call anything
6155fae1
JB
195 which might compile a new regexp until we're done with the loop! */
196
d15b573e 197 BLOCK_INPUT;
d5db4077 198 d = opendir (SDATA (dirfilename));
d15b573e 199 UNBLOCK_INPUT;
388ac098 200 if (d == NULL)
23bd240f 201 report_file_error ("Opening directory", Fcons (directory, Qnil));
14d55bce 202
2488aba5
AI
203 /* Unfortunately, we can now invoke expand-file-name and
204 file-attributes on filenames, both of which can throw, so we must
205 do a proper unwind-protect. */
206 record_unwind_protect (directory_files_internal_unwind,
9d291bdf 207 make_save_value (d, 0));
2488aba5 208
65156807
EZ
209#ifdef WINDOWSNT
210 if (attrs)
211 {
212 extern Lisp_Object Qlocal;
213 extern int is_slow_fs (const char *);
214
215 /* Do this only once to avoid doing it (in w32.c:stat) for each
216 file in the directory, when we call Ffile_attributes below. */
217 record_unwind_protect (directory_files_internal_w32_unwind,
218 Vw32_get_true_file_attributes);
219 w32_save = Vw32_get_true_file_attributes;
220 if (EQ (Vw32_get_true_file_attributes, Qlocal))
221 {
222 char *dirnm = SDATA (dirfilename);
223 char *fn = alloca (SBYTES (dirfilename) + 1);
224
225 strncpy (fn, SDATA (dirfilename), SBYTES (dirfilename));
226 fn[SBYTES (dirfilename)] = '\0';
227 /* w32.c:stat will notice these bindings and avoid calling
228 GetDriveType for each file. */
229 if (is_slow_fs (fn))
230 Vw32_get_true_file_attributes = Qnil;
231 else
232 Vw32_get_true_file_attributes = Qt;
233 }
234 }
235#endif
236
d5db4077 237 directory_nbytes = SBYTES (directory);
c81a9bdc 238 re_match_object = Qt;
14d55bce 239
96d64004 240 /* Decide whether we need to add a directory separator. */
388ac098 241 if (directory_nbytes == 0
d5db4077 242 || !IS_ANY_SEP (SREF (directory, directory_nbytes - 1)))
96d64004 243 needsep = 1;
96d64004 244
8e42f043 245 /* Loop reading blocks until EOF or error. */
f69f9da1 246 for (;;)
14d55bce 247 {
f69f9da1
GM
248 errno = 0;
249 dp = readdir (d);
250
9d291bdf 251 if (dp == NULL && (0
f69f9da1 252#ifdef EAGAIN
9d291bdf
SM
253 || errno == EAGAIN
254#endif
255#ifdef EINTR
256 || errno == EINTR
f69f9da1 257#endif
9d291bdf
SM
258 ))
259 { QUIT; continue; }
177c0ea7 260
f69f9da1
GM
261 if (dp == NULL)
262 break;
263
128ecc89 264 if (DIRENTRY_NONEMPTY (dp))
14d55bce 265 {
e23f810c 266 int len;
2488aba5 267 int wanted = 0;
388ac098
GM
268 Lisp_Object name, finalname;
269 struct gcpro gcpro1, gcpro2;
e23f810c
KH
270
271 len = NAMLEN (dp);
9ad4f3e5 272 name = finalname = make_unibyte_string (dp->d_name, len);
388ac098 273 GCPRO2 (finalname, name);
177c0ea7 274
6c8b4f07 275 /* Note: DECODE_FILE can GC; it should protect its argument,
388ac098
GM
276 though. */
277 name = DECODE_FILE (name);
d5db4077 278 len = SBYTES (name);
e23f810c 279
2488aba5
AI
280 /* Now that we have unwind_protect in place, we might as well
281 allow matching to be interrupted. */
282 immediate_quit = 1;
283 QUIT;
284
265a9e55 285 if (NILP (match)
d5db4077 286 || (0 <= re_search (bufp, SDATA (name), len, 0, len, 0)))
388ac098 287 wanted = 1;
2488aba5
AI
288
289 immediate_quit = 0;
290
291 if (wanted)
14d55bce 292 {
265a9e55 293 if (!NILP (full))
14d55bce 294 {
e23f810c 295 Lisp_Object fullname;
388ac098
GM
296 int nbytes = len + directory_nbytes + needsep;
297 int nchars;
5617588f 298
388ac098 299 fullname = make_uninit_multibyte_string (nbytes, nbytes);
d5db4077 300 bcopy (SDATA (directory), SDATA (fullname),
388ac098 301 directory_nbytes);
177c0ea7 302
5617588f 303 if (needsep)
d549c5db 304 SSET (fullname, directory_nbytes, DIRECTORY_SEP);
177c0ea7 305
d5db4077
KR
306 bcopy (SDATA (name),
307 SDATA (fullname) + directory_nbytes + needsep,
388ac098 308 len);
177c0ea7 309
d5db4077 310 nchars = chars_in_text (SDATA (fullname), nbytes);
388ac098
GM
311
312 /* Some bug somewhere. */
313 if (nchars > nbytes)
314 abort ();
177c0ea7 315
437fcd47 316 STRING_SET_CHARS (fullname, nchars);
388ac098 317 if (nchars == nbytes)
d5db4077 318 STRING_SET_UNIBYTE (fullname);
177c0ea7 319
4424b255
GV
320 finalname = fullname;
321 }
aab9c564
KH
322 else
323 finalname = name;
4424b255
GV
324
325 if (attrs)
326 {
327 /* Construct an expanded filename for the directory entry.
328 Use the decoded names for input to Ffile_attributes. */
388ac098
GM
329 Lisp_Object decoded_fullname, fileattrs;
330 struct gcpro gcpro1, gcpro2;
331
332 decoded_fullname = fileattrs = Qnil;
333 GCPRO2 (decoded_fullname, fileattrs);
4424b255 334
388ac098 335 /* Both Fexpand_file_name and Ffile_attributes can GC. */
4424b255 336 decoded_fullname = Fexpand_file_name (name, directory);
6b61353c 337 fileattrs = Ffile_attributes (decoded_fullname, id_format);
4424b255
GV
338
339 list = Fcons (Fcons (finalname, fileattrs), list);
388ac098 340 UNGCPRO;
4424b255
GV
341 }
342 else
388ac098 343 list = Fcons (finalname, list);
14d55bce 344 }
388ac098
GM
345
346 UNGCPRO;
14d55bce
RS
347 }
348 }
2488aba5 349
d15b573e 350 BLOCK_INPUT;
14d55bce 351 closedir (d);
d15b573e 352 UNBLOCK_INPUT;
65156807
EZ
353#ifdef WINDOWSNT
354 if (attrs)
355 Vw32_get_true_file_attributes = w32_save;
356#endif
2488aba5
AI
357
358 /* Discard the unwind protect. */
359 specpdl_ptr = specpdl + count;
360
388ac098
GM
361 if (NILP (nosort))
362 list = Fsort (Fnreverse (list),
363 attrs ? Qfile_attributes_lessp : Qstring_lessp);
177c0ea7 364
388ac098 365 RETURN_UNGCPRO (list);
14d55bce 366}
4424b255
GV
367
368
369DEFUN ("directory-files", Fdirectory_files, Sdirectory_files, 1, 4, 0,
335c5470
PJ
370 doc: /* Return a list of names of files in DIRECTORY.
371There are three optional arguments:
372If FULL is non-nil, return absolute file names. Otherwise return names
373 that are relative to the specified directory.
374If MATCH is non-nil, mention only file names that match the regexp MATCH.
375If NOSORT is non-nil, the list is not sorted--its order is unpredictable.
e933b15e
CY
376 Otherwise, the list returned is sorted with `stringp-lessp'.
377 NOSORT is useful if you plan to sort the result yourself. */)
335c5470 378 (directory, full, match, nosort)
4424b255
GV
379 Lisp_Object directory, full, match, nosort;
380{
381 Lisp_Object handler;
4ece81a6 382 directory = Fexpand_file_name (directory, Qnil);
4424b255
GV
383
384 /* If the file name has special constructs in it,
385 call the corresponding file handler. */
386 handler = Ffind_file_name_handler (directory, Qdirectory_files);
387 if (!NILP (handler))
6b61353c
KH
388 return call5 (handler, Qdirectory_files, directory,
389 full, match, nosort);
4424b255 390
6b61353c 391 return directory_files_internal (directory, full, match, nosort, 0, Qnil);
4424b255
GV
392}
393
335c5470 394DEFUN ("directory-files-and-attributes", Fdirectory_files_and_attributes,
6b61353c 395 Sdirectory_files_and_attributes, 1, 5, 0,
335c5470 396 doc: /* Return a list of names of files and their attributes in DIRECTORY.
6b61353c 397There are four optional arguments:
335c5470
PJ
398If FULL is non-nil, return absolute file names. Otherwise return names
399 that are relative to the specified directory.
400If MATCH is non-nil, mention only file names that match the regexp MATCH.
401If NOSORT is non-nil, the list is not sorted--its order is unpredictable.
6b61353c
KH
402 NOSORT is useful if you plan to sort the result yourself.
403ID-FORMAT specifies the preferred format of attributes uid and gid, see
6c5665e9
EZ
404`file-attributes' for further documentation.
405On MS-Windows, performance depends on `w32-get-true-file-attributes',
406which see. */)
6b61353c
KH
407 (directory, full, match, nosort, id_format)
408 Lisp_Object directory, full, match, nosort, id_format;
4424b255
GV
409{
410 Lisp_Object handler;
4ece81a6 411 directory = Fexpand_file_name (directory, Qnil);
4424b255
GV
412
413 /* If the file name has special constructs in it,
414 call the corresponding file handler. */
415 handler = Ffind_file_name_handler (directory, Qdirectory_files_and_attributes);
416 if (!NILP (handler))
6b61353c
KH
417 return call6 (handler, Qdirectory_files_and_attributes,
418 directory, full, match, nosort, id_format);
4424b255 419
6b61353c 420 return directory_files_internal (directory, full, match, nosort, 1, id_format);
4424b255
GV
421}
422
14d55bce
RS
423\f
424Lisp_Object file_name_completion ();
425
426DEFUN ("file-name-completion", Ffile_name_completion, Sfile_name_completion,
abfb1932 427 2, 3, 0,
335c5470
PJ
428 doc: /* Complete file name FILE in directory DIRECTORY.
429Returns the longest string
430common to all file names in DIRECTORY that start with FILE.
431If there is only one and FILE matches it exactly, returns t.
2f60660a 432Returns nil if DIRECTORY contains no name starting with FILE.
335c5470 433
b6ce54d6
RS
434If PREDICATE is non-nil, call PREDICATE with each possible
435completion (in absolute form) and ignore it if PREDICATE returns nil.
436
335c5470
PJ
437This function ignores some of the possible completions as
438determined by the variable `completion-ignored-extensions', which see. */)
abfb1932
RS
439 (file, directory, predicate)
440 Lisp_Object file, directory, predicate;
14d55bce 441{
32f4334d 442 Lisp_Object handler;
32f4334d 443
8436e231 444 /* If the directory name has special constructs in it,
32f4334d 445 call the corresponding file handler. */
23bd240f 446 handler = Ffind_file_name_handler (directory, Qfile_name_completion);
32f4334d 447 if (!NILP (handler))
abfb1932 448 return call4 (handler, Qfile_name_completion, file, directory, predicate);
32f4334d 449
8436e231
RS
450 /* If the file name has special constructs in it,
451 call the corresponding file handler. */
452 handler = Ffind_file_name_handler (file, Qfile_name_completion);
453 if (!NILP (handler))
abfb1932 454 return call4 (handler, Qfile_name_completion, file, directory, predicate);
8436e231 455
abfb1932 456 return file_name_completion (file, directory, 0, 0, predicate);
14d55bce
RS
457}
458
459DEFUN ("file-name-all-completions", Ffile_name_all_completions,
335c5470
PJ
460 Sfile_name_all_completions, 2, 2, 0,
461 doc: /* Return a list of all completions of file name FILE in directory DIRECTORY.
462These are all file names in directory DIRECTORY which begin with FILE. */)
463 (file, directory)
23bd240f 464 Lisp_Object file, directory;
14d55bce 465{
32f4334d
RS
466 Lisp_Object handler;
467
8436e231 468 /* If the directory name has special constructs in it,
32f4334d 469 call the corresponding file handler. */
23bd240f 470 handler = Ffind_file_name_handler (directory, Qfile_name_all_completions);
32f4334d 471 if (!NILP (handler))
23bd240f 472 return call3 (handler, Qfile_name_all_completions, file, directory);
32f4334d 473
8436e231
RS
474 /* If the file name has special constructs in it,
475 call the corresponding file handler. */
476 handler = Ffind_file_name_handler (file, Qfile_name_all_completions);
477 if (!NILP (handler))
23bd240f 478 return call3 (handler, Qfile_name_all_completions, file, directory);
8436e231 479
abfb1932 480 return file_name_completion (file, directory, 1, 0, Qnil);
14d55bce
RS
481}
482
dfcf069d 483static int file_name_completion_stat ();
01bb4018 484Lisp_Object Qdefault_directory;
dfcf069d 485
14d55bce 486Lisp_Object
abfb1932 487file_name_completion (file, dirname, all_flag, ver_flag, predicate)
14d55bce
RS
488 Lisp_Object file, dirname;
489 int all_flag, ver_flag;
abfb1932 490 Lisp_Object predicate;
14d55bce
RS
491{
492 DIR *d;
3271a8f5 493 int bestmatchsize = 0;
14d55bce 494 int matchcount = 0;
abfb1932
RS
495 /* If ALL_FLAG is 1, BESTMATCH is the list of all matches, decoded.
496 If ALL_FLAG is 0, BESTMATCH is either nil
497 or the best match so far, not decoded. */
14d55bce 498 Lisp_Object bestmatch, tem, elt, name;
24c2a54f
RS
499 Lisp_Object encoded_file;
500 Lisp_Object encoded_dir;
14d55bce
RS
501 struct stat st;
502 int directoryp;
3271a8f5
SM
503 /* If includeall is zero, exclude files in completion-ignored-extensions as
504 well as "." and "..". Until shown otherwise, assume we can't exclude
505 anything. */
506 int includeall = 1;
aed13378 507 int count = SPECPDL_INDEX ();
24c2a54f 508 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
3fcc88cc 509
6bbd7a29
GM
510 elt = Qnil;
511
b7826503 512 CHECK_STRING (file);
14d55bce 513
128ecc89
RS
514#ifdef FILE_SYSTEM_CASE
515 file = FILE_SYSTEM_CASE (file);
516#endif
14d55bce 517 bestmatch = Qnil;
24c2a54f
RS
518 encoded_file = encoded_dir = Qnil;
519 GCPRO5 (file, dirname, bestmatch, encoded_file, encoded_dir);
3fcc88cc 520 dirname = Fexpand_file_name (dirname, Qnil);
01bb4018 521 specbind (Qdefault_directory, dirname);
14d55bce 522
24c2a54f
RS
523 /* Do completion on the encoded file name
524 because the other names in the directory are (we presume)
525 encoded likewise. We decode the completed string at the end. */
2a54a229
SM
526 /* Actually, this is not quite true any more: we do most of the completion
527 work with decoded file names, but we still do some filtering based
528 on the encoded file name. */
6c8b4f07 529 encoded_file = STRING_MULTIBYTE (file) ? ENCODE_FILE (file) : file;
24c2a54f
RS
530
531 encoded_dir = ENCODE_FILE (dirname);
532
3271a8f5
SM
533 BLOCK_INPUT;
534 d = opendir (SDATA (Fdirectory_file_name (encoded_dir)));
535 UNBLOCK_INPUT;
536 if (!d)
537 report_file_error ("Opening directory", Fcons (dirname, Qnil));
14d55bce 538
3271a8f5
SM
539 record_unwind_protect (directory_files_internal_unwind,
540 make_save_value (d, 0));
14d55bce 541
3271a8f5
SM
542 /* Loop reading blocks */
543 /* (att3b compiler bug requires do a null comparison this way) */
544 while (1)
14d55bce 545 {
3271a8f5
SM
546 DIRENTRY *dp;
547 int len;
548 int canexclude = 0;
14d55bce 549
3271a8f5
SM
550 errno = 0;
551 dp = readdir (d);
552 if (dp == NULL && (0
9d291bdf 553# ifdef EAGAIN
3271a8f5 554 || errno == EAGAIN
9d291bdf
SM
555# endif
556# ifdef EINTR
3271a8f5 557 || errno == EINTR
9d291bdf 558# endif
3271a8f5
SM
559 ))
560 { QUIT; continue; }
9d291bdf 561
3271a8f5 562 if (!dp) break;
14d55bce 563
3271a8f5 564 len = NAMLEN (dp);
14d55bce 565
3271a8f5
SM
566 QUIT;
567 if (! DIRENTRY_NONEMPTY (dp)
568 || len < SCHARS (encoded_file)
569 || 0 <= scmp (dp->d_name, SDATA (encoded_file),
570 SCHARS (encoded_file)))
571 continue;
14d55bce 572
3271a8f5
SM
573 if (file_name_completion_stat (encoded_dir, dp, &st) < 0)
574 continue;
14d55bce 575
3271a8f5
SM
576 directoryp = ((st.st_mode & S_IFMT) == S_IFDIR);
577 tem = Qnil;
578 /* If all_flag is set, always include all.
579 It would not actually be helpful to the user to ignore any possible
580 completions when making a list of them. */
581 if (!all_flag)
582 {
583 int skip;
2cd298e2 584
7519c40d 585#if 0 /* FIXME: The `scmp' call compares an encoded and a decoded string. */
2cd298e2
SM
586 /* If this entry matches the current bestmatch, the only
587 thing it can do is increase matchcount, so don't bother
588 investigating it any further. */
589 if (!completion_ignore_case
590 /* The return result depends on whether it's the sole match. */
591 && matchcount > 1
592 && !includeall /* This match may allow includeall to 0. */
593 && len >= bestmatchsize
594 && 0 > scmp (dp->d_name, SDATA (bestmatch), bestmatchsize))
595 continue;
7519c40d 596#endif
2cd298e2 597
3271a8f5 598 if (directoryp)
ad456ad4
RS
599 {
600#ifndef TRIVIAL_DIRECTORY_ENTRY
601#define TRIVIAL_DIRECTORY_ENTRY(n) (!strcmp (n, ".") || !strcmp (n, ".."))
602#endif
abfb1932
RS
603 /* "." and ".." are never interesting as completions, and are
604 actually in the way in a directory with only one file. */
3271a8f5
SM
605 if (TRIVIAL_DIRECTORY_ENTRY (dp->d_name))
606 canexclude = 1;
607 else if (len > SCHARS (encoded_file))
d013f29b
EZ
608 /* Ignore directories if they match an element of
609 completion-ignored-extensions which ends in a slash. */
610 for (tem = Vcompletion_ignored_extensions;
611 CONSP (tem); tem = XCDR (tem))
612 {
613 int elt_len;
2a54a229 614 unsigned char *p1;
d013f29b
EZ
615
616 elt = XCAR (tem);
617 if (!STRINGP (elt))
618 continue;
a74aaa9d
EZ
619 /* Need to encode ELT, since scmp compares unibyte
620 strings only. */
621 elt = ENCODE_FILE (elt);
d5db4077 622 elt_len = SCHARS (elt) - 1; /* -1 for trailing / */
7a8d465a 623 if (elt_len <= 0)
d013f29b 624 continue;
d5db4077 625 p1 = SDATA (elt);
d013f29b
EZ
626 if (p1[elt_len] != '/')
627 continue;
628 skip = len - elt_len;
629 if (skip < 0)
630 continue;
631
632 if (0 <= scmp (dp->d_name + skip, p1, elt_len))
633 continue;
634 break;
635 }
ad456ad4
RS
636 }
637 else
3271a8f5 638 {
14d55bce
RS
639 /* Compare extensions-to-be-ignored against end of this file name */
640 /* if name is not an exact match against specified string */
3271a8f5 641 if (len > SCHARS (encoded_file))
14d55bce
RS
642 /* and exit this for loop if a match is found */
643 for (tem = Vcompletion_ignored_extensions;
70949dac 644 CONSP (tem); tem = XCDR (tem))
14d55bce 645 {
70949dac 646 elt = XCAR (tem);
88cf1852 647 if (!STRINGP (elt)) continue;
a74aaa9d
EZ
648 /* Need to encode ELT, since scmp compares unibyte
649 strings only. */
650 elt = ENCODE_FILE (elt);
d5db4077 651 skip = len - SCHARS (elt);
14d55bce
RS
652 if (skip < 0) continue;
653
654 if (0 <= scmp (dp->d_name + skip,
d5db4077
KR
655 SDATA (elt),
656 SCHARS (elt)))
14d55bce
RS
657 continue;
658 break;
659 }
660 }
661
f676868d
KH
662 /* If an ignored-extensions match was found,
663 don't process this name as a completion. */
3271a8f5
SM
664 if (CONSP (tem))
665 canexclude = 1;
f676868d 666
3271a8f5
SM
667 if (!includeall && canexclude)
668 /* We're not including all files and this file can be excluded. */
669 continue;
9c691c00 670
3271a8f5
SM
671 if (includeall && !canexclude)
672 { /* If we have one non-excludable file, we want to exclude the
673 excudable files. */
674 includeall = 0;
675 /* Throw away any previous excludable match found. */
676 bestmatch = Qnil;
677 bestmatchsize = 0;
678 matchcount = 0;
f676868d 679 }
3271a8f5
SM
680 }
681 /* FIXME: If we move this `decode' earlier we can eliminate
682 the repeated ENCODE_FILE on Vcompletion_ignored_extensions. */
683 name = make_unibyte_string (dp->d_name, len);
684 name = DECODE_FILE (name);
685
686 {
687 Lisp_Object regexps;
688 Lisp_Object zero;
689 XSETFASTINT (zero, 0);
690
691 /* Ignore this element if it fails to match all the regexps. */
cc524e3b
CY
692 if (completion_ignore_case)
693 {
694 for (regexps = Vcompletion_regexp_list; CONSP (regexps);
695 regexps = XCDR (regexps))
696 if (fast_string_match_ignore_case (XCAR (regexps), name) < 0)
697 break;
698 }
699 else
700 {
701 for (regexps = Vcompletion_regexp_list; CONSP (regexps);
702 regexps = XCDR (regexps))
703 if (fast_string_match (XCAR (regexps), name) < 0)
704 break;
705 }
706
3271a8f5
SM
707 if (CONSP (regexps))
708 continue;
709 }
710
711 /* This is a possible completion */
712 if (directoryp)
713 /* This completion is a directory; make it end with '/'. */
714 name = Ffile_name_as_directory (name);
715
716 /* Test the predicate, if any. */
717 if (!NILP (predicate))
718 {
719 Lisp_Object val;
720 struct gcpro gcpro1;
14d55bce 721
3271a8f5
SM
722 GCPRO1 (name);
723 val = call1 (predicate, name);
724 UNGCPRO;
c4c52bb7 725
3271a8f5
SM
726 if (NILP (val))
727 continue;
728 }
abfb1932 729
3271a8f5 730 /* Suitably record this match. */
14d55bce 731
3271a8f5 732 matchcount++;
f676868d 733
3271a8f5
SM
734 if (all_flag)
735 bestmatch = Fcons (name, bestmatch);
736 else if (NILP (bestmatch))
737 {
738 bestmatch = name;
739 bestmatchsize = SCHARS (name);
740 }
741 else
742 {
743 Lisp_Object zero = make_number (0);
744 /* FIXME: This is a copy of the code in Ftry_completion. */
745 int compare = min (bestmatchsize, SCHARS (name));
746 Lisp_Object tem
747 = Fcompare_strings (bestmatch, zero,
748 make_number (compare),
749 name, zero,
750 make_number (compare),
751 completion_ignore_case ? Qt : Qnil);
752 int matchsize
753 = (EQ (tem, Qt) ? compare
754 : XINT (tem) < 0 ? - XINT (tem) - 1
755 : XINT (tem) - 1);
756
757 if (completion_ignore_case)
f676868d 758 {
3271a8f5
SM
759 /* If this is an exact match except for case,
760 use it as the best match rather than one that is not
761 an exact match. This way, we get the case pattern
762 of the actual match. */
763 /* This tests that the current file is an exact match
764 but BESTMATCH is not (it is too long). */
765 if ((matchsize == SCHARS (name)
2cd298e2 766 && matchsize + !!directoryp < SCHARS (bestmatch))
3271a8f5
SM
767 ||
768 /* If there is no exact match ignoring case,
769 prefer a match that does not change the case
770 of the input. */
771 /* If there is more than one exact match aside from
772 case, and one of them is exact including case,
773 prefer that one. */
774 /* This == checks that, of current file and BESTMATCH,
775 either both or neither are exact. */
776 (((matchsize == SCHARS (name))
777 ==
778 (matchsize + !!directoryp == SCHARS (bestmatch)))
779 && (tem = Fcompare_strings (name, zero,
780 make_number (SCHARS (file)),
781 file, zero,
782 Qnil,
783 Qnil),
784 EQ (Qt, tem))
785 && (tem = Fcompare_strings (bestmatch, zero,
786 make_number (SCHARS (file)),
787 file, zero,
788 Qnil,
789 Qnil),
790 ! EQ (Qt, tem))))
791 bestmatch = name;
14d55bce 792 }
3271a8f5 793 bestmatchsize = matchsize;
2cd298e2
SM
794
795 /* If the best completion so far is reduced to the string
796 we're trying to complete, then we already know there's no
797 other completion, so there's no point looking any further. */
798 if (matchsize <= SCHARS (file)
799 && !includeall /* A future match may allow includeall to 0. */
800 /* If completion-ignore-case is non-nil, don't
801 short-circuit because we want to find the best
802 possible match *including* case differences. */
803 && (!completion_ignore_case || matchsize == 0)
804 /* The return value depends on whether it's the sole match. */
805 && matchcount > 1)
806 break;
807
14d55bce 808 }
14d55bce
RS
809 }
810
3fcc88cc 811 UNGCPRO;
3271a8f5 812 /* This closes the directory. */
c3a3229c 813 bestmatch = unbind_to (count, bestmatch);
14d55bce 814
265a9e55 815 if (all_flag || NILP (bestmatch))
2a54a229 816 return bestmatch;
928b5acc
SM
817 /* Return t if the supplied string is an exact match (counting case);
818 it does not require any change to be made. */
819 if (matchcount == 1 && !NILP (Fequal (bestmatch, file)))
14d55bce 820 return Qt;
24c2a54f
RS
821 bestmatch = Fsubstring (bestmatch, make_number (0),
822 make_number (bestmatchsize));
24c2a54f 823 return bestmatch;
14d55bce
RS
824}
825
b3f04ced
RS
826/* Compare exactly LEN chars of strings at S1 and S2,
827 ignoring case if appropriate.
828 Return -1 if strings match,
829 else number of chars that match at the beginning. */
830
831static int
832scmp (s1, s2, len)
833 register unsigned char *s1, *s2;
834 int len;
835{
836 register int l = len;
837
838 if (completion_ignore_case)
839 {
840 while (l && DOWNCASE (*s1++) == DOWNCASE (*s2++))
841 l--;
842 }
843 else
844 {
845 while (l && *s1++ == *s2++)
846 l--;
847 }
848 if (l == 0)
849 return -1;
850 else
851 return len - l;
852}
853
dfcf069d 854static int
14d55bce
RS
855file_name_completion_stat (dirname, dp, st_addr)
856 Lisp_Object dirname;
857 DIRENTRY *dp;
858 struct stat *st_addr;
859{
860 int len = NAMLEN (dp);
d5db4077 861 int pos = SCHARS (dirname);
7e3cf34f 862 int value;
14d55bce
RS
863 char *fullname = (char *) alloca (len + pos + 2);
864
04924ee3
RS
865#ifdef MSDOS
866#if __DJGPP__ > 1
867 /* Some fields of struct stat are *very* expensive to compute on MS-DOS,
868 but aren't required here. Avoid computing the following fields:
869 st_inode, st_size and st_nlink for directories, and the execute bits
870 in st_mode for non-directory files with non-standard extensions. */
871
872 unsigned short save_djstat_flags = _djstat_flags;
873
874 _djstat_flags = _STAT_INODE | _STAT_EXEC_MAGIC | _STAT_DIRSIZE;
875#endif /* __DJGPP__ > 1 */
876#endif /* MSDOS */
877
d5db4077 878 bcopy (SDATA (dirname), fullname, pos);
0b39d75d
RS
879 if (!IS_DIRECTORY_SEP (fullname[pos - 1]))
880 fullname[pos++] = DIRECTORY_SEP;
14d55bce
RS
881
882 bcopy (dp->d_name, fullname + pos, len);
883 fullname[pos + len] = 0;
884
a889bd0e 885#ifdef S_IFLNK
7e3cf34f
RS
886 /* We want to return success if a link points to a nonexistent file,
887 but we want to return the status for what the link points to,
888 in case it is a directory. */
889 value = lstat (fullname, st_addr);
890 stat (fullname, st_addr);
891 return value;
a889bd0e 892#else
04924ee3
RS
893 value = stat (fullname, st_addr);
894#ifdef MSDOS
895#if __DJGPP__ > 1
896 _djstat_flags = save_djstat_flags;
897#endif /* __DJGPP__ > 1 */
898#endif /* MSDOS */
899 return value;
900#endif /* S_IFLNK */
14d55bce
RS
901}
902\f
903Lisp_Object
904make_time (time)
e5124be7 905 time_t time;
14d55bce
RS
906{
907 return Fcons (make_number (time >> 16),
908 Fcons (make_number (time & 0177777), Qnil));
909}
910
8aaaec6b
EZ
911static char *
912stat_uname (struct stat *st)
913{
914#ifdef WINDOWSNT
915 return st->st_uname;
916#else
917 struct passwd *pw = (struct passwd *) getpwuid (st->st_uid);
918
919 if (pw)
920 return pw->pw_name;
921 else
922 return NULL;
923#endif
924}
925
926static char *
927stat_gname (struct stat *st)
928{
929#ifdef WINDOWSNT
930 return st->st_gname;
931#else
932 struct group *gr = (struct group *) getgrgid (st->st_gid);
933
934 if (gr)
935 return gr->gr_name;
936 else
937 return NULL;
938#endif
939}
940
51105b13
EZ
941/* Make an integer or float number for UID and GID, while being
942 careful not to produce negative numbers due to signed integer
943 overflow. */
944static Lisp_Object
945make_uid (struct stat *st)
946{
947 EMACS_INT uid = st->st_uid;
948
949 if (sizeof (st->st_uid) > sizeof (uid) || uid < 0 || FIXNUM_OVERFLOW_P (uid))
950 return make_float ((double)st->st_uid);
951 return make_number (uid);
952}
953
954static Lisp_Object
955make_gid (struct stat *st)
956{
957 EMACS_INT gid = st->st_gid;
958
959 if (sizeof (st->st_gid) > sizeof (gid) || gid < 0 || FIXNUM_OVERFLOW_P (gid))
960 return make_float ((double)st->st_gid);
961 return make_number (gid);
962}
963
6b61353c 964DEFUN ("file-attributes", Ffile_attributes, Sfile_attributes, 1, 2, 0,
335c5470
PJ
965 doc: /* Return a list of attributes of file FILENAME.
966Value is nil if specified file cannot be opened.
6b61353c
KH
967
968ID-FORMAT specifies the preferred format of attributes uid and gid (see
969below) - valid values are 'string and 'integer. The latter is the default,
970but we plan to change that, so you should specify a non-nil value for
971ID-FORMAT if you use the returned uid or gid.
972
973Elements of the attribute list are:
335c5470
PJ
974 0. t for directory, string (name linked to) for symbolic link, or nil.
975 1. Number of links to file.
78e7d1fe
EZ
976 2. File uid as a string or a number. If a string value cannot be
977 looked up, a numeric value, either an integer or a float, is returned.
6b61353c 978 3. File gid, likewise.
335c5470
PJ
979 4. Last access time, as a list of two integers.
980 First integer has high-order 16 bits of time, second has low 16 bits.
21f73755 981 (See a note below about FAT-based filesystems.)
335c5470
PJ
982 5. Last modification time, likewise.
983 6. Last status change time, likewise.
984 7. Size in bytes.
985 This is a floating point number if the size is too large for an integer.
986 8. File modes, as a string of ten letters or dashes as in ls -l.
e0f24100 987 9. t if file's gid would change if file were deleted and recreated.
335c5470 98810. inode number. If inode number is larger than the Emacs integer,
e058f331
EZ
989 but still fits into a 32-bit number, this is a cons cell containing two
990 integers: first the high part, then the low 16 bits. If the inode number
991 is wider than 32 bits, this is a cons cell containing three integers:
992 first the high 24 bits, then middle 24 bits, and finally the low 16 bits.
335c5470 99311. Device number. If it is larger than the Emacs integer, this is
6c5665e9
EZ
994 a cons cell, similar to the inode number.
995
996On MS-Windows, performance depends on `w32-get-true-file-attributes',
21f73755
EZ
997which see.
998
999On some FAT-based filesystems, only the date of last access is recorded,
1000so last access time will always be midnight of that day. */)
6b61353c
KH
1001 (filename, id_format)
1002 Lisp_Object filename, id_format;
14d55bce
RS
1003{
1004 Lisp_Object values[12];
24c2a54f 1005 Lisp_Object encoded;
14d55bce 1006 struct stat s;
0a974c85 1007#if defined (BSD4_2) || defined (BSD4_3)
b3edfc9b 1008 Lisp_Object dirname;
14d55bce 1009 struct stat sdir;
b3edfc9b 1010#endif
14d55bce 1011 char modes[10];
32f4334d 1012 Lisp_Object handler;
7435aef8 1013 struct gcpro gcpro1;
1cab27d2 1014 EMACS_INT ino, uid, gid;
51105b13 1015 char *uname = NULL, *gname = NULL;
14d55bce
RS
1016
1017 filename = Fexpand_file_name (filename, Qnil);
32f4334d
RS
1018
1019 /* If the file name has special constructs in it,
1020 call the corresponding file handler. */
a617e913 1021 handler = Ffind_file_name_handler (filename, Qfile_attributes);
32f4334d 1022 if (!NILP (handler))
6b61353c
KH
1023 { /* Only pass the extra arg if it is used to help backward compatibility
1024 with old file handlers which do not implement the new arg. --Stef */
1025 if (NILP (id_format))
1026 return call2 (handler, Qfile_attributes, filename);
1027 else
1028 return call3 (handler, Qfile_attributes, filename, id_format);
1029 }
32f4334d 1030
7435aef8 1031 GCPRO1 (filename);
24c2a54f 1032 encoded = ENCODE_FILE (filename);
7435aef8 1033 UNGCPRO;
24c2a54f 1034
d5db4077 1035 if (lstat (SDATA (encoded), &s) < 0)
14d55bce
RS
1036 return Qnil;
1037
1038 switch (s.st_mode & S_IFMT)
1039 {
1040 default:
1041 values[0] = Qnil; break;
1042 case S_IFDIR:
1043 values[0] = Qt; break;
1044#ifdef S_IFLNK
1045 case S_IFLNK:
1046 values[0] = Ffile_symlink_p (filename); break;
1047#endif
1048 }
1049 values[1] = make_number (s.st_nlink);
51105b13
EZ
1050
1051 if (!(NILP (id_format) || EQ (id_format, Qinteger)))
6b61353c 1052 {
8c8a7c58 1053 BLOCK_INPUT;
8aaaec6b 1054 uname = stat_uname (&s);
8aaaec6b 1055 gname = stat_gname (&s);
8c8a7c58 1056 UNBLOCK_INPUT;
6b61353c 1057 }
51105b13 1058 if (uname)
80904120 1059 values[2] = DECODE_SYSTEM (build_string (uname));
51105b13
EZ
1060 else
1061 values[2] = make_uid (&s);
1062 if (gname)
80904120 1063 values[3] = DECODE_SYSTEM (build_string (gname));
51105b13
EZ
1064 else
1065 values[3] = make_gid (&s);
1066
14d55bce
RS
1067 values[4] = make_time (s.st_atime);
1068 values[5] = make_time (s.st_mtime);
1069 values[6] = make_time (s.st_ctime);
68c45bf0 1070 values[7] = make_number (s.st_size);
cb1846b4 1071 /* If the size is out of range for an integer, return a float. */
60fc6069 1072 if (XINT (values[7]) != s.st_size)
cb1846b4 1073 values[7] = make_float ((double)s.st_size);
4bc12672
JR
1074 /* If the size is negative, and its type is long, convert it back to
1075 positive. */
1076 if (s.st_size < 0 && sizeof (s.st_size) == sizeof (long))
1077 values[7] = make_float ((double) ((unsigned long) s.st_size));
1078
14d55bce
RS
1079 filemodestring (&s, modes);
1080 values[8] = make_string (modes, 10);
0a974c85 1081#if defined (BSD4_2) || defined (BSD4_3) /* file gid will be dir gid */
14d55bce 1082 dirname = Ffile_name_directory (filename);
24c2a54f
RS
1083 if (! NILP (dirname))
1084 encoded = ENCODE_FILE (dirname);
d5db4077 1085 if (! NILP (dirname) && stat (SDATA (encoded), &sdir) == 0)
01388a3d 1086 values[9] = (sdir.st_gid != s.st_gid) ? Qt : Qnil;
14d55bce
RS
1087 else /* if we can't tell, assume worst */
1088 values[9] = Qt;
1089#else /* file gid will be egid */
01388a3d 1090 values[9] = (s.st_gid != getegid ()) ? Qt : Qnil;
14d55bce 1091#endif /* BSD4_2 (or BSD4_3) */
b55445d6 1092 /* Shut up GCC warnings in FIXNUM_OVERFLOW_P below. */
e058f331
EZ
1093 if (sizeof (s.st_ino) > sizeof (ino))
1094 ino = (EMACS_INT)(s.st_ino & 0xffffffff);
1095 else
1096 ino = s.st_ino;
1097 if (!FIXNUM_OVERFLOW_P (ino)
1098 && (sizeof (s.st_ino) <= sizeof (ino) || (s.st_ino & ~INTMASK) == 0))
1099 /* Keep the most common cases as integers. */
1100 values[10] = make_number (ino);
1101 else if (sizeof (s.st_ino) <= sizeof (ino)
1102 || ((s.st_ino >> 16) & ~INTMASK) == 0)
4c637faa
RS
1103 /* To allow inode numbers larger than VALBITS, separate the bottom
1104 16 bits. */
e058f331
EZ
1105 values[10] = Fcons (make_number ((EMACS_INT)(s.st_ino >> 16)),
1106 make_number ((EMACS_INT)(s.st_ino & 0xffff)));
4c637faa 1107 else
e058f331
EZ
1108 {
1109 /* To allow inode numbers beyond 32 bits, separate into 2 24-bit
ff8ddc7b 1110 high parts and a 16-bit bottom part.
25ae5671
EZ
1111 The code on the next line avoids a compiler warning on
1112 systems where st_ino is 32 bit wide. (bug#766). */
ff8ddc7b 1113 EMACS_INT high_ino = s.st_ino >> 31 >> 1;
e058f331
EZ
1114 EMACS_INT low_ino = s.st_ino & 0xffffffff;
1115
1116 values[10] = Fcons (make_number (high_ino >> 8),
1117 Fcons (make_number (((high_ino & 0xff) << 16)
1118 + (low_ino >> 16)),
1119 make_number (low_ino & 0xffff)));
1120 }
68c45bf0 1121
7412d429
EZ
1122 /* Likewise for device, but don't let it become negative. We used
1123 to use FIXNUM_OVERFLOW_P here, but that won't catch large
1124 positive numbers such as 0xFFEEDDCC. */
1125 if ((EMACS_INT)s.st_dev < 0
1126 || (EMACS_INT)s.st_dev > MOST_POSITIVE_FIXNUM)
68c45bf0
PE
1127 values[11] = Fcons (make_number (s.st_dev >> 16),
1128 make_number (s.st_dev & 0xffff));
1129 else
1130 values[11] = make_number (s.st_dev);
1131
14d55bce
RS
1132 return Flist (sizeof(values) / sizeof(values[0]), values);
1133}
4424b255
GV
1134
1135DEFUN ("file-attributes-lessp", Ffile_attributes_lessp, Sfile_attributes_lessp, 2, 2, 0,
335c5470
PJ
1136 doc: /* Return t if first arg file attributes list is less than second.
1137Comparison is in lexicographic order and case is significant. */)
1138 (f1, f2)
4424b255
GV
1139 Lisp_Object f1, f2;
1140{
1141 return Fstring_lessp (Fcar (f1), Fcar (f2));
1142}
14d55bce 1143\f
dfcf069d 1144void
14d55bce
RS
1145syms_of_dired ()
1146{
32f4334d 1147 Qdirectory_files = intern ("directory-files");
4424b255 1148 Qdirectory_files_and_attributes = intern ("directory-files-and-attributes");
32f4334d
RS
1149 Qfile_name_completion = intern ("file-name-completion");
1150 Qfile_name_all_completions = intern ("file-name-all-completions");
434e6714 1151 Qfile_attributes = intern ("file-attributes");
4424b255 1152 Qfile_attributes_lessp = intern ("file-attributes-lessp");
01bb4018 1153 Qdefault_directory = intern ("default-directory");
32f4334d 1154
a2d3836c 1155 staticpro (&Qdirectory_files);
4424b255 1156 staticpro (&Qdirectory_files_and_attributes);
a2d3836c
EN
1157 staticpro (&Qfile_name_completion);
1158 staticpro (&Qfile_name_all_completions);
1159 staticpro (&Qfile_attributes);
4424b255 1160 staticpro (&Qfile_attributes_lessp);
01bb4018 1161 staticpro (&Qdefault_directory);
a2d3836c 1162
14d55bce 1163 defsubr (&Sdirectory_files);
4424b255 1164 defsubr (&Sdirectory_files_and_attributes);
14d55bce 1165 defsubr (&Sfile_name_completion);
14d55bce
RS
1166 defsubr (&Sfile_name_all_completions);
1167 defsubr (&Sfile_attributes);
4424b255 1168 defsubr (&Sfile_attributes_lessp);
14d55bce 1169
14d55bce 1170 DEFVAR_LISP ("completion-ignored-extensions", &Vcompletion_ignored_extensions,
407a52c4
LT
1171 doc: /* Completion ignores file names ending in any string in this list.
1172It does not ignore them if all possible completions end in one of
1173these strings or when displaying a list of completions.
1174It ignores directory names if they match any string in this list which
1175ends in a slash. */);
14d55bce
RS
1176 Vcompletion_ignored_extensions = Qnil;
1177}
6b61353c
KH
1178
1179/* arch-tag: 1ac8deca-4d8f-4d41-ade9-089154d98c03
1180 (do not change this comment) */