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