153
|
1 /* Lisp functions for making directory listings.
|
64770
|
2 Copyright (C) 1985, 1986, 1993, 1994, 1999, 2000, 2001, 2002, 2003,
|
106815
|
3 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
|
153
|
4
|
|
5 This file is part of GNU Emacs.
|
|
6
|
94963
|
7 GNU Emacs is free software: you can redistribute it and/or modify
|
153
|
8 it under the terms of the GNU General Public License as published by
|
94963
|
9 the Free Software Foundation, either version 3 of the License, or
|
|
10 (at your option) any later version.
|
153
|
11
|
|
12 GNU Emacs is distributed in the hope that it will be useful,
|
|
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 GNU General Public License for more details.
|
|
16
|
|
17 You should have received a copy of the GNU General Public License
|
94963
|
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
|
153
|
19
|
|
20
|
7896
|
21 #include <config.h>
|
|
22
|
153
|
23 #include <stdio.h>
|
|
24 #include <sys/types.h>
|
|
25 #include <sys/stat.h>
|
105669
|
26 #include <setjmp.h>
|
153
|
27
|
61700
|
28 #ifdef HAVE_PWD_H
|
53112
b6c073b1f1c7
(Ffile_attributes): Parameter ID-FORMAT added and included in call to file
Lars Hansen <larsh@soem.dk>
diff
changeset
|
29 #include <pwd.h>
|
61700
|
30 #endif
|
53112
b6c073b1f1c7
(Ffile_attributes): Parameter ID-FORMAT added and included in call to file
Lars Hansen <larsh@soem.dk>
diff
changeset
|
31 #include <grp.h>
|
b6c073b1f1c7
(Ffile_attributes): Parameter ID-FORMAT added and included in call to file
Lars Hansen <larsh@soem.dk>
diff
changeset
|
32
|
36064
|
33 #include <errno.h>
|
26088
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
34
|
21514
|
35 #ifdef HAVE_UNISTD_H
|
|
36 #include <unistd.h>
|
|
37 #endif
|
|
38
|
2117
|
39 /* The d_nameln member of a struct dirent includes the '\0' character
|
|
40 on some systems, but not on others. What's worse, you can't tell
|
|
41 at compile-time which one it will be, since it really depends on
|
|
42 the sort of system providing the filesystem you're reading from,
|
|
43 not the system you are running on. Paul Eggert
|
|
44 <eggert@bi.twinsun.com> says this occurs when Emacs is running on a
|
|
45 SunOS 4.1.2 host, reading a directory that is remote-mounted from a
|
|
46 Solaris 2.1 host and is in a native Solaris 2.1 filesystem.
|
|
47
|
|
48 Since applying strlen to the name always works, we'll just do that. */
|
|
49 #define NAMLEN(p) strlen (p->d_name)
|
|
50
|
109585
4504e82595bb
Replace tests for SYSV_SYSTEM_DIR with HAVE_DIRENT_H, set via autoconf
Jan D <jan.h.d@swipnet.se>
diff
changeset
|
51 #ifdef HAVE_DIRENT_H
|
153
|
52
|
|
53 #include <dirent.h>
|
|
54 #define DIRENTRY struct dirent
|
|
55
|
109585
4504e82595bb
Replace tests for SYSV_SYSTEM_DIR with HAVE_DIRENT_H, set via autoconf
Jan D <jan.h.d@swipnet.se>
diff
changeset
|
56 #else /* not HAVE_DIRENT_H */
|
153
|
57
|
|
58 #include <sys/dir.h>
|
26565
|
59 #include <sys/stat.h>
|
|
60
|
153
|
61 #define DIRENTRY struct direct
|
|
62
|
109516
68ca98ae70fb
Make building under stricter warning flags somewhat cleaner.
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
63 extern DIR *opendir (char *);
|
68ca98ae70fb
Make building under stricter warning flags somewhat cleaner.
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
64 extern struct direct *readdir (DIR *);
|
153
|
65
|
109585
4504e82595bb
Replace tests for SYSV_SYSTEM_DIR with HAVE_DIRENT_H, set via autoconf
Jan D <jan.h.d@swipnet.se>
diff
changeset
|
66 #endif /* HAVE_DIRENT_H */
|
5492
|
67
|
109691
fc06750bcd9d
* dired.c (DIRENTRY_NONEMPTY) [cygwin]: Use d_ino instead of the MSDOS definition.
Ken Brown <kbrown@cornell.edu>
diff
changeset
|
68 #ifdef MSDOS
|
5492
|
69 #define DIRENTRY_NONEMPTY(p) ((p)->d_name[0] != 0)
|
|
70 #else
|
|
71 #define DIRENTRY_NONEMPTY(p) ((p)->d_ino)
|
153
|
72 #endif
|
|
73
|
|
74 #include "lisp.h"
|
65764
375ab086d366
* image.c (slurp_file, xbm_read_bitmap_data): Cast to the correct
Dan Nicolaescu <dann@ics.uci.edu>
diff
changeset
|
75 #include "systime.h"
|
153
|
76 #include "buffer.h"
|
|
77 #include "commands.h"
|
88352
|
78 #include "character.h"
|
21050
|
79 #include "charset.h"
|
|
80 #include "coding.h"
|
153
|
81 #include "regex.h"
|
71816
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
diff
changeset
|
82 #include "blockinput.h"
|
153
|
83
|
9604
d3f06c8c76a1
(Fdirectory_files): Use the new calling convention for compile_pattern.
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
84 /* Returns a search buffer, with a fastmap allocated and ready to go. */
|
109639
|
85 extern struct re_pattern_buffer *compile_pattern (Lisp_Object,
|
|
86 struct re_registers *,
|
|
87 Lisp_Object, int, int);
|
2371
|
88
|
26565
|
89 /* From filemode.c. Can't go in Lisp.h because of `stat'. */
|
109100
|
90 extern void filemodestring (struct stat *, char *);
|
26565
|
91
|
153
|
92 /* if system does not have symbolic links, it does not have lstat.
|
|
93 In that case, use ordinary stat instead. */
|
|
94
|
|
95 #ifndef S_IFLNK
|
|
96 #define lstat stat
|
|
97 #endif
|
|
98
|
103860
|
99 extern Lisp_Object Vw32_get_true_file_attributes;
|
1509
|
100
|
153
|
101 Lisp_Object Vcompletion_ignored_extensions;
|
843
|
102 Lisp_Object Qdirectory_files;
|
25192
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
103 Lisp_Object Qdirectory_files_and_attributes;
|
843
|
104 Lisp_Object Qfile_name_completion;
|
|
105 Lisp_Object Qfile_name_all_completions;
|
847
|
106 Lisp_Object Qfile_attributes;
|
25192
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
107 Lisp_Object Qfile_attributes_lessp;
|
42169
|
108
|
109555
|
109 static int scmp (const unsigned char *, const unsigned char *, int);
|
153
|
110
|
103860
|
111 #ifdef WINDOWSNT
|
|
112 Lisp_Object
|
|
113 directory_files_internal_w32_unwind (Lisp_Object arg)
|
|
114 {
|
|
115 Vw32_get_true_file_attributes = arg;
|
|
116 return Qnil;
|
|
117 }
|
|
118 #endif
|
32826
|
119
|
|
120 Lisp_Object
|
109126
|
121 directory_files_internal_unwind (Lisp_Object dh)
|
32826
|
122 {
|
65319
44f6057f47c7
(directory_files_internal_unwind, directory_files_internal)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
123 DIR *d = (DIR *) XSAVE_VALUE (dh)->pointer;
|
72538
85113179d2d1
(directory_files_internal_unwind, directory_files_internal)
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
diff
changeset
|
124 BLOCK_INPUT;
|
32826
|
125 closedir (d);
|
72538
85113179d2d1
(directory_files_internal_unwind, directory_files_internal)
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
diff
changeset
|
126 UNBLOCK_INPUT;
|
32826
|
127 return Qnil;
|
|
128 }
|
|
129
|
49600
|
130 /* Function shared by Fdirectory_files and Fdirectory_files_and_attributes.
|
25192
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
131 When ATTRS is zero, return a list of directory filenames; when
|
53112
b6c073b1f1c7
(Ffile_attributes): Parameter ID-FORMAT added and included in call to file
Lars Hansen <larsh@soem.dk>
diff
changeset
|
132 non-zero, return a list of directory filenames and their attributes.
|
b6c073b1f1c7
(Ffile_attributes): Parameter ID-FORMAT added and included in call to file
Lars Hansen <larsh@soem.dk>
diff
changeset
|
133 In the latter case, ID_FORMAT is passed to Ffile_attributes. */
|
36665
|
134
|
25192
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
135 Lisp_Object
|
109126
|
136 directory_files_internal (Lisp_Object directory, Lisp_Object full, Lisp_Object match, Lisp_Object nosort, int attrs, Lisp_Object id_format)
|
153
|
137 {
|
|
138 DIR *d;
|
33345
|
139 int directory_nbytes;
|
|
140 Lisp_Object list, dirfilename, encoded_directory;
|
31829
|
141 struct re_pattern_buffer *bufp = NULL;
|
21380
|
142 int needsep = 0;
|
46293
|
143 int count = SPECPDL_INDEX ();
|
33345
|
144 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
|
33497
|
145 DIRENTRY *dp;
|
103860
|
146 #ifdef WINDOWSNT
|
|
147 Lisp_Object w32_save = Qnil;
|
|
148 #endif
|
843
|
149
|
21380
|
150 /* Because of file name handlers, these functions might call
|
2182
|
151 Ffuncall, and cause a GC. */
|
33345
|
152 list = encoded_directory = dirfilename = Qnil;
|
|
153 GCPRO5 (match, directory, list, dirfilename, encoded_directory);
|
21380
|
154 dirfilename = Fdirectory_file_name (directory);
|
2182
|
155
|
485
|
156 if (!NILP (match))
|
153
|
157 {
|
40656
|
158 CHECK_STRING (match);
|
808
|
159
|
|
160 /* MATCH might be a flawed regular expression. Rather than
|
14036
|
161 catching and signaling our own errors, we just call
|
808
|
162 compile_pattern to do the work for us. */
|
20634
|
163 /* Pass 1 for the MULTIBYTE arg
|
|
164 because we do make multibyte strings if the contents warrant. */
|
71462
7579ed1c76f1
(directory_files_internal) [WINDOWSNT]: Find files case-insensitively.
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
165 # ifdef WINDOWSNT
|
7579ed1c76f1
(directory_files_internal) [WINDOWSNT]: Find files case-insensitively.
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
166 /* Windows users want case-insensitive wildcards. */
|
7579ed1c76f1
(directory_files_internal) [WINDOWSNT]: Find files case-insensitively.
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
167 bufp = compile_pattern (match, 0,
|
7579ed1c76f1
(directory_files_internal) [WINDOWSNT]: Find files case-insensitively.
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
168 buffer_defaults.case_canon_table, 0, 1);
|
7579ed1c76f1
(directory_files_internal) [WINDOWSNT]: Find files case-insensitively.
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
169 # else /* !WINDOWSNT */
|
20870
|
170 bufp = compile_pattern (match, 0, Qnil, 0, 1);
|
71462
7579ed1c76f1
(directory_files_internal) [WINDOWSNT]: Find files case-insensitively.
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
171 # endif /* !WINDOWSNT */
|
153
|
172 }
|
|
173
|
34970
|
174 /* Note: ENCODE_FILE and DECODE_FILE can GC because they can run
|
33345
|
175 run_pre_post_conversion_on_str which calls Lisp directly and
|
|
176 indirectly. */
|
94178
|
177 if (STRING_MULTIBYTE (dirfilename))
|
|
178 dirfilename = ENCODE_FILE (dirfilename);
|
|
179 encoded_directory = (STRING_MULTIBYTE (directory)
|
|
180 ? ENCODE_FILE (directory) : directory);
|
19816
|
181
|
9604
d3f06c8c76a1
(Fdirectory_files): Use the new calling convention for compile_pattern.
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
182 /* Now *bufp is the compiled form of MATCH; don't call anything
|
2182
|
183 which might compile a new regexp until we're done with the loop! */
|
|
184
|
72538
85113179d2d1
(directory_files_internal_unwind, directory_files_internal)
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
diff
changeset
|
185 BLOCK_INPUT;
|
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
186 d = opendir (SDATA (dirfilename));
|
72538
85113179d2d1
(directory_files_internal_unwind, directory_files_internal)
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
diff
changeset
|
187 UNBLOCK_INPUT;
|
33345
|
188 if (d == NULL)
|
14067
afef050ad4e6
(Fdirectory_files, Ffile_name_completion, Ffile_name_all_completions,
Erik Naggum <erik@naggum.no>
diff
changeset
|
189 report_file_error ("Opening directory", Fcons (directory, Qnil));
|
153
|
190
|
32826
|
191 /* Unfortunately, we can now invoke expand-file-name and
|
|
192 file-attributes on filenames, both of which can throw, so we must
|
|
193 do a proper unwind-protect. */
|
|
194 record_unwind_protect (directory_files_internal_unwind,
|
65319
44f6057f47c7
(directory_files_internal_unwind, directory_files_internal)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
195 make_save_value (d, 0));
|
32826
|
196
|
103860
|
197 #ifdef WINDOWSNT
|
|
198 if (attrs)
|
|
199 {
|
|
200 extern int is_slow_fs (const char *);
|
|
201
|
|
202 /* Do this only once to avoid doing it (in w32.c:stat) for each
|
|
203 file in the directory, when we call Ffile_attributes below. */
|
|
204 record_unwind_protect (directory_files_internal_w32_unwind,
|
|
205 Vw32_get_true_file_attributes);
|
|
206 w32_save = Vw32_get_true_file_attributes;
|
|
207 if (EQ (Vw32_get_true_file_attributes, Qlocal))
|
|
208 {
|
|
209 /* w32.c:stat will notice these bindings and avoid calling
|
|
210 GetDriveType for each file. */
|
103880
|
211 if (is_slow_fs (SDATA (dirfilename)))
|
103860
|
212 Vw32_get_true_file_attributes = Qnil;
|
|
213 else
|
|
214 Vw32_get_true_file_attributes = Qt;
|
|
215 }
|
|
216 }
|
|
217 #endif
|
|
218
|
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
219 directory_nbytes = SBYTES (directory);
|
17460
|
220 re_match_object = Qt;
|
153
|
221
|
21380
|
222 /* Decide whether we need to add a directory separator. */
|
33345
|
223 if (directory_nbytes == 0
|
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
224 || !IS_ANY_SEP (SREF (directory, directory_nbytes - 1)))
|
21380
|
225 needsep = 1;
|
|
226
|
33497
|
227 /* Loop reading blocks until EOF or error. */
|
36665
|
228 for (;;)
|
153
|
229 {
|
36665
|
230 errno = 0;
|
|
231 dp = readdir (d);
|
|
232
|
65319
44f6057f47c7
(directory_files_internal_unwind, directory_files_internal)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
233 if (dp == NULL && (0
|
36665
|
234 #ifdef EAGAIN
|
65319
44f6057f47c7
(directory_files_internal_unwind, directory_files_internal)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
235 || errno == EAGAIN
|
36665
|
236 #endif
|
65319
44f6057f47c7
(directory_files_internal_unwind, directory_files_internal)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
237 #ifdef EINTR
|
44f6057f47c7
(directory_files_internal_unwind, directory_files_internal)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
238 || errno == EINTR
|
44f6057f47c7
(directory_files_internal_unwind, directory_files_internal)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
239 #endif
|
44f6057f47c7
(directory_files_internal_unwind, directory_files_internal)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
240 ))
|
44f6057f47c7
(directory_files_internal_unwind, directory_files_internal)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
241 { QUIT; continue; }
|
49600
|
242
|
36665
|
243 if (dp == NULL)
|
|
244 break;
|
|
245
|
5492
|
246 if (DIRENTRY_NONEMPTY (dp))
|
153
|
247 {
|
22916
|
248 int len;
|
32826
|
249 int wanted = 0;
|
33345
|
250 Lisp_Object name, finalname;
|
|
251 struct gcpro gcpro1, gcpro2;
|
22916
|
252
|
|
253 len = NAMLEN (dp);
|
35353
|
254 name = finalname = make_unibyte_string (dp->d_name, len);
|
33345
|
255 GCPRO2 (finalname, name);
|
49600
|
256
|
94178
|
257 /* Note: DECODE_FILE can GC; it should protect its argument,
|
33345
|
258 though. */
|
|
259 name = DECODE_FILE (name);
|
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
260 len = SBYTES (name);
|
22916
|
261
|
32826
|
262 /* Now that we have unwind_protect in place, we might as well
|
|
263 allow matching to be interrupted. */
|
|
264 immediate_quit = 1;
|
|
265 QUIT;
|
|
266
|
485
|
267 if (NILP (match)
|
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
268 || (0 <= re_search (bufp, SDATA (name), len, 0, len, 0)))
|
33345
|
269 wanted = 1;
|
32826
|
270
|
|
271 immediate_quit = 0;
|
|
272
|
|
273 if (wanted)
|
|
274 {
|
485
|
275 if (!NILP (full))
|
153
|
276 {
|
33345
|
277 Lisp_Object fullname;
|
|
278 int nbytes = len + directory_nbytes + needsep;
|
21261
|
279 int nchars;
|
11176
07a3b9c34717
(Fdirectory_files): Fix bug in IS_ANY_SEP usage introduced in Oct 30 change.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
280
|
33345
|
281 fullname = make_uninit_multibyte_string (nbytes, nbytes);
|
109165
750db9f3e6d8
Replace bcopy, bzero, bcmp by memcpy, memmove, memset, memcmp
Andreas Schwab <schwab@linux-m68k.org>
diff
changeset
|
282 memcpy (SDATA (fullname), SDATA (directory),
|
750db9f3e6d8
Replace bcopy, bzero, bcmp by memcpy, memmove, memset, memcmp
Andreas Schwab <schwab@linux-m68k.org>
diff
changeset
|
283 directory_nbytes);
|
49600
|
284
|
11176
07a3b9c34717
(Fdirectory_files): Fix bug in IS_ANY_SEP usage introduced in Oct 30 change.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
285 if (needsep)
|
46423
|
286 SSET (fullname, directory_nbytes, DIRECTORY_SEP);
|
49600
|
287
|
109165
750db9f3e6d8
Replace bcopy, bzero, bcmp by memcpy, memmove, memset, memcmp
Andreas Schwab <schwab@linux-m68k.org>
diff
changeset
|
288 memcpy (SDATA (fullname) + directory_nbytes + needsep,
|
750db9f3e6d8
Replace bcopy, bzero, bcmp by memcpy, memmove, memset, memcmp
Andreas Schwab <schwab@linux-m68k.org>
diff
changeset
|
289 SDATA (name), len);
|
49600
|
290
|
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
291 nchars = chars_in_text (SDATA (fullname), nbytes);
|
33345
|
292
|
|
293 /* Some bug somewhere. */
|
|
294 if (nchars > nbytes)
|
|
295 abort ();
|
49600
|
296
|
46373
|
297 STRING_SET_CHARS (fullname, nchars);
|
33345
|
298 if (nchars == nbytes)
|
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
299 STRING_SET_UNIBYTE (fullname);
|
49600
|
300
|
25192
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
301 finalname = fullname;
|
153
|
302 }
|
34667
|
303 else
|
|
304 finalname = name;
|
25192
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
305
|
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
306 if (attrs)
|
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
307 {
|
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
308 /* Construct an expanded filename for the directory entry.
|
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
309 Use the decoded names for input to Ffile_attributes. */
|
33345
|
310 Lisp_Object decoded_fullname, fileattrs;
|
|
311 struct gcpro gcpro1, gcpro2;
|
25192
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
312
|
33345
|
313 decoded_fullname = fileattrs = Qnil;
|
|
314 GCPRO2 (decoded_fullname, fileattrs);
|
|
315
|
|
316 /* Both Fexpand_file_name and Ffile_attributes can GC. */
|
25192
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
317 decoded_fullname = Fexpand_file_name (name, directory);
|
53112
b6c073b1f1c7
(Ffile_attributes): Parameter ID-FORMAT added and included in call to file
Lars Hansen <larsh@soem.dk>
diff
changeset
|
318 fileattrs = Ffile_attributes (decoded_fullname, id_format);
|
25192
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
319
|
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
320 list = Fcons (Fcons (finalname, fileattrs), list);
|
33345
|
321 UNGCPRO;
|
25192
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
322 }
|
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
323 else
|
33345
|
324 list = Fcons (finalname, list);
|
153
|
325 }
|
33345
|
326
|
|
327 UNGCPRO;
|
153
|
328 }
|
|
329 }
|
32826
|
330
|
72538
85113179d2d1
(directory_files_internal_unwind, directory_files_internal)
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
diff
changeset
|
331 BLOCK_INPUT;
|
153
|
332 closedir (d);
|
72538
85113179d2d1
(directory_files_internal_unwind, directory_files_internal)
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
diff
changeset
|
333 UNBLOCK_INPUT;
|
103860
|
334 #ifdef WINDOWSNT
|
|
335 if (attrs)
|
|
336 Vw32_get_true_file_attributes = w32_save;
|
|
337 #endif
|
32826
|
338
|
|
339 /* Discard the unwind protect. */
|
|
340 specpdl_ptr = specpdl + count;
|
|
341
|
33345
|
342 if (NILP (nosort))
|
|
343 list = Fsort (Fnreverse (list),
|
|
344 attrs ? Qfile_attributes_lessp : Qstring_lessp);
|
49600
|
345
|
33345
|
346 RETURN_UNGCPRO (list);
|
153
|
347 }
|
25192
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
348
|
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
349
|
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
350 DEFUN ("directory-files", Fdirectory_files, Sdirectory_files, 1, 4, 0,
|
41001
|
351 doc: /* Return a list of names of files in DIRECTORY.
|
|
352 There are three optional arguments:
|
|
353 If FULL is non-nil, return absolute file names. Otherwise return names
|
|
354 that are relative to the specified directory.
|
|
355 If MATCH is non-nil, mention only file names that match the regexp MATCH.
|
|
356 If NOSORT is non-nil, the list is not sorted--its order is unpredictable.
|
105168
|
357 Otherwise, the list returned is sorted with `string-lessp'.
|
|
358 NOSORT is useful if you plan to sort the result yourself. */)
|
109179
|
359 (Lisp_Object directory, Lisp_Object full, Lisp_Object match, Lisp_Object nosort)
|
25192
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
360 {
|
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
361 Lisp_Object handler;
|
49922
|
362 directory = Fexpand_file_name (directory, Qnil);
|
25192
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
363
|
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
364 /* If the file name has special constructs in it,
|
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
365 call the corresponding file handler. */
|
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
366 handler = Ffind_file_name_handler (directory, Qdirectory_files);
|
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
367 if (!NILP (handler))
|
53310
|
368 return call5 (handler, Qdirectory_files, directory,
|
|
369 full, match, nosort);
|
25192
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
370
|
53112
b6c073b1f1c7
(Ffile_attributes): Parameter ID-FORMAT added and included in call to file
Lars Hansen <larsh@soem.dk>
diff
changeset
|
371 return directory_files_internal (directory, full, match, nosort, 0, Qnil);
|
25192
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
372 }
|
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
373
|
41001
|
374 DEFUN ("directory-files-and-attributes", Fdirectory_files_and_attributes,
|
53112
b6c073b1f1c7
(Ffile_attributes): Parameter ID-FORMAT added and included in call to file
Lars Hansen <larsh@soem.dk>
diff
changeset
|
375 Sdirectory_files_and_attributes, 1, 5, 0,
|
41001
|
376 doc: /* Return a list of names of files and their attributes in DIRECTORY.
|
53112
b6c073b1f1c7
(Ffile_attributes): Parameter ID-FORMAT added and included in call to file
Lars Hansen <larsh@soem.dk>
diff
changeset
|
377 There are four optional arguments:
|
41001
|
378 If FULL is non-nil, return absolute file names. Otherwise return names
|
|
379 that are relative to the specified directory.
|
|
380 If MATCH is non-nil, mention only file names that match the regexp MATCH.
|
|
381 If NOSORT is non-nil, the list is not sorted--its order is unpredictable.
|
53112
b6c073b1f1c7
(Ffile_attributes): Parameter ID-FORMAT added and included in call to file
Lars Hansen <larsh@soem.dk>
diff
changeset
|
382 NOSORT is useful if you plan to sort the result yourself.
|
b6c073b1f1c7
(Ffile_attributes): Parameter ID-FORMAT added and included in call to file
Lars Hansen <larsh@soem.dk>
diff
changeset
|
383 ID-FORMAT specifies the preferred format of attributes uid and gid, see
|
94841
|
384 `file-attributes' for further documentation.
|
|
385 On MS-Windows, performance depends on `w32-get-true-file-attributes',
|
|
386 which see. */)
|
109179
|
387 (Lisp_Object directory, Lisp_Object full, Lisp_Object match, Lisp_Object nosort, Lisp_Object id_format)
|
25192
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
388 {
|
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
389 Lisp_Object handler;
|
49922
|
390 directory = Fexpand_file_name (directory, Qnil);
|
25192
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
391
|
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
392 /* If the file name has special constructs in it,
|
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
393 call the corresponding file handler. */
|
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
394 handler = Ffind_file_name_handler (directory, Qdirectory_files_and_attributes);
|
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
395 if (!NILP (handler))
|
53310
|
396 return call6 (handler, Qdirectory_files_and_attributes,
|
|
397 directory, full, match, nosort, id_format);
|
25192
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
398
|
53112
b6c073b1f1c7
(Ffile_attributes): Parameter ID-FORMAT added and included in call to file
Lars Hansen <larsh@soem.dk>
diff
changeset
|
399 return directory_files_internal (directory, full, match, nosort, 1, id_format);
|
25192
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
400 }
|
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
401
|
153
|
402
|
109126
|
403 Lisp_Object file_name_completion (Lisp_Object file, Lisp_Object dirname, int all_flag, int ver_flag, Lisp_Object predicate);
|
153
|
404
|
|
405 DEFUN ("file-name-completion", Ffile_name_completion, Sfile_name_completion,
|
74686
|
406 2, 3, 0,
|
41001
|
407 doc: /* Complete file name FILE in directory DIRECTORY.
|
|
408 Returns the longest string
|
|
409 common to all file names in DIRECTORY that start with FILE.
|
|
410 If there is only one and FILE matches it exactly, returns t.
|
62185
633425d6cc86
(Ffile_name_completion): Make argument name match its use in docstring.
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
411 Returns nil if DIRECTORY contains no name starting with FILE.
|
41001
|
412
|
74689
|
413 If PREDICATE is non-nil, call PREDICATE with each possible
|
|
414 completion (in absolute form) and ignore it if PREDICATE returns nil.
|
|
415
|
41001
|
416 This function ignores some of the possible completions as
|
|
417 determined by the variable `completion-ignored-extensions', which see. */)
|
109179
|
418 (Lisp_Object file, Lisp_Object directory, Lisp_Object predicate)
|
153
|
419 {
|
843
|
420 Lisp_Object handler;
|
|
421
|
12984
|
422 /* If the directory name has special constructs in it,
|
|
423 call the corresponding file handler. */
|
14067
afef050ad4e6
(Fdirectory_files, Ffile_name_completion, Ffile_name_all_completions,
Erik Naggum <erik@naggum.no>
diff
changeset
|
424 handler = Ffind_file_name_handler (directory, Qfile_name_completion);
|
12984
|
425 if (!NILP (handler))
|
74686
|
426 return call4 (handler, Qfile_name_completion, file, directory, predicate);
|
12984
|
427
|
843
|
428 /* If the file name has special constructs in it,
|
|
429 call the corresponding file handler. */
|
12984
|
430 handler = Ffind_file_name_handler (file, Qfile_name_completion);
|
843
|
431 if (!NILP (handler))
|
74686
|
432 return call4 (handler, Qfile_name_completion, file, directory, predicate);
|
843
|
433
|
74686
|
434 return file_name_completion (file, directory, 0, 0, predicate);
|
153
|
435 }
|
|
436
|
|
437 DEFUN ("file-name-all-completions", Ffile_name_all_completions,
|
41001
|
438 Sfile_name_all_completions, 2, 2, 0,
|
|
439 doc: /* Return a list of all completions of file name FILE in directory DIRECTORY.
|
|
440 These are all file names in directory DIRECTORY which begin with FILE. */)
|
109179
|
441 (Lisp_Object file, Lisp_Object directory)
|
153
|
442 {
|
843
|
443 Lisp_Object handler;
|
|
444
|
12984
|
445 /* If the directory name has special constructs in it,
|
|
446 call the corresponding file handler. */
|
14067
afef050ad4e6
(Fdirectory_files, Ffile_name_completion, Ffile_name_all_completions,
Erik Naggum <erik@naggum.no>
diff
changeset
|
447 handler = Ffind_file_name_handler (directory, Qfile_name_all_completions);
|
12984
|
448 if (!NILP (handler))
|
14067
afef050ad4e6
(Fdirectory_files, Ffile_name_completion, Ffile_name_all_completions,
Erik Naggum <erik@naggum.no>
diff
changeset
|
449 return call3 (handler, Qfile_name_all_completions, file, directory);
|
12984
|
450
|
843
|
451 /* If the file name has special constructs in it,
|
|
452 call the corresponding file handler. */
|
12984
|
453 handler = Ffind_file_name_handler (file, Qfile_name_all_completions);
|
843
|
454 if (!NILP (handler))
|
14067
afef050ad4e6
(Fdirectory_files, Ffile_name_completion, Ffile_name_all_completions,
Erik Naggum <erik@naggum.no>
diff
changeset
|
455 return call3 (handler, Qfile_name_all_completions, file, directory);
|
843
|
456
|
74686
|
457 return file_name_completion (file, directory, 1, 0, Qnil);
|
153
|
458 }
|
|
459
|
109129
|
460 static int file_name_completion_stat (Lisp_Object dirname, DIRENTRY *dp, struct stat *st_addr);
|
94888
|
461 Lisp_Object Qdefault_directory;
|
21514
|
462
|
153
|
463 Lisp_Object
|
109126
|
464 file_name_completion (Lisp_Object file, Lisp_Object dirname, int all_flag, int ver_flag, Lisp_Object predicate)
|
153
|
465 {
|
|
466 DIR *d;
|
94890
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
467 int bestmatchsize = 0;
|
153
|
468 int matchcount = 0;
|
74686
|
469 /* If ALL_FLAG is 1, BESTMATCH is the list of all matches, decoded.
|
|
470 If ALL_FLAG is 0, BESTMATCH is either nil
|
|
471 or the best match so far, not decoded. */
|
153
|
472 Lisp_Object bestmatch, tem, elt, name;
|
19816
|
473 Lisp_Object encoded_file;
|
|
474 Lisp_Object encoded_dir;
|
153
|
475 struct stat st;
|
|
476 int directoryp;
|
94890
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
477 /* If includeall is zero, exclude files in completion-ignored-extensions as
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
478 well as "." and "..". Until shown otherwise, assume we can't exclude
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
479 anything. */
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
480 int includeall = 1;
|
46293
|
481 int count = SPECPDL_INDEX ();
|
19816
|
482 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
|
6559
|
483
|
31829
|
484 elt = Qnil;
|
|
485
|
40656
|
486 CHECK_STRING (file);
|
153
|
487
|
5492
|
488 #ifdef FILE_SYSTEM_CASE
|
|
489 file = FILE_SYSTEM_CASE (file);
|
|
490 #endif
|
6559
|
491 bestmatch = Qnil;
|
19816
|
492 encoded_file = encoded_dir = Qnil;
|
|
493 GCPRO5 (file, dirname, bestmatch, encoded_file, encoded_dir);
|
153
|
494 dirname = Fexpand_file_name (dirname, Qnil);
|
94888
|
495 specbind (Qdefault_directory, dirname);
|
153
|
496
|
19816
|
497 /* Do completion on the encoded file name
|
|
498 because the other names in the directory are (we presume)
|
|
499 encoded likewise. We decode the completed string at the end. */
|
94493
41892e1c80a1
(file_name_completion): Fix up the encoding/decoding issue
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
500 /* Actually, this is not quite true any more: we do most of the completion
|
41892e1c80a1
(file_name_completion): Fix up the encoding/decoding issue
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
501 work with decoded file names, but we still do some filtering based
|
41892e1c80a1
(file_name_completion): Fix up the encoding/decoding issue
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
502 on the encoded file name. */
|
94178
|
503 encoded_file = STRING_MULTIBYTE (file) ? ENCODE_FILE (file) : file;
|
19816
|
504
|
|
505 encoded_dir = ENCODE_FILE (dirname);
|
|
506
|
94890
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
507 BLOCK_INPUT;
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
508 d = opendir (SDATA (Fdirectory_file_name (encoded_dir)));
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
509 UNBLOCK_INPUT;
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
510 if (!d)
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
511 report_file_error ("Opening directory", Fcons (dirname, Qnil));
|
48906
|
512
|
94890
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
513 record_unwind_protect (directory_files_internal_unwind,
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
514 make_save_value (d, 0));
|
153
|
515
|
94890
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
516 /* Loop reading blocks */
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
517 /* (att3b compiler bug requires do a null comparison this way) */
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
518 while (1)
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
519 {
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
520 DIRENTRY *dp;
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
521 int len;
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
522 int canexclude = 0;
|
153
|
523
|
94890
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
524 errno = 0;
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
525 dp = readdir (d);
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
526 if (dp == NULL && (0
|
65319
44f6057f47c7
(directory_files_internal_unwind, directory_files_internal)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
527 # ifdef EAGAIN
|
94890
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
528 || errno == EAGAIN
|
65319
44f6057f47c7
(directory_files_internal_unwind, directory_files_internal)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
529 # endif
|
44f6057f47c7
(directory_files_internal_unwind, directory_files_internal)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
530 # ifdef EINTR
|
94890
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
531 || errno == EINTR
|
65319
44f6057f47c7
(directory_files_internal_unwind, directory_files_internal)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
532 # endif
|
94890
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
533 ))
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
534 { QUIT; continue; }
|
65319
44f6057f47c7
(directory_files_internal_unwind, directory_files_internal)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
535
|
94890
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
536 if (!dp) break;
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
537
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
538 len = NAMLEN (dp);
|
153
|
539
|
94890
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
540 QUIT;
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
541 if (! DIRENTRY_NONEMPTY (dp)
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
542 || len < SCHARS (encoded_file)
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
543 || 0 <= scmp (dp->d_name, SDATA (encoded_file),
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
544 SCHARS (encoded_file)))
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
545 continue;
|
153
|
546
|
94890
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
547 if (file_name_completion_stat (encoded_dir, dp, &st) < 0)
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
548 continue;
|
153
|
549
|
94890
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
550 directoryp = ((st.st_mode & S_IFMT) == S_IFDIR);
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
551 tem = Qnil;
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
552 /* If all_flag is set, always include all.
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
553 It would not actually be helpful to the user to ignore any possible
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
554 completions when making a list of them. */
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
555 if (!all_flag)
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
556 {
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
557 int skip;
|
102621
7183ab1b842a
(file_name_completion): Check completion-ignored-extensions
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
558
|
102622
d4e19d304e30
(file_name_completion): Disable the first optimization just
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
559 #if 0 /* FIXME: The `scmp' call compares an encoded and a decoded string. */
|
102621
7183ab1b842a
(file_name_completion): Check completion-ignored-extensions
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
560 /* If this entry matches the current bestmatch, the only
|
7183ab1b842a
(file_name_completion): Check completion-ignored-extensions
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
561 thing it can do is increase matchcount, so don't bother
|
7183ab1b842a
(file_name_completion): Check completion-ignored-extensions
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
562 investigating it any further. */
|
7183ab1b842a
(file_name_completion): Check completion-ignored-extensions
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
563 if (!completion_ignore_case
|
7183ab1b842a
(file_name_completion): Check completion-ignored-extensions
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
564 /* The return result depends on whether it's the sole match. */
|
7183ab1b842a
(file_name_completion): Check completion-ignored-extensions
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
565 && matchcount > 1
|
7183ab1b842a
(file_name_completion): Check completion-ignored-extensions
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
566 && !includeall /* This match may allow includeall to 0. */
|
7183ab1b842a
(file_name_completion): Check completion-ignored-extensions
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
567 && len >= bestmatchsize
|
7183ab1b842a
(file_name_completion): Check completion-ignored-extensions
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
568 && 0 > scmp (dp->d_name, SDATA (bestmatch), bestmatchsize))
|
7183ab1b842a
(file_name_completion): Check completion-ignored-extensions
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
569 continue;
|
102622
d4e19d304e30
(file_name_completion): Disable the first optimization just
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
570 #endif
|
102621
7183ab1b842a
(file_name_completion): Check completion-ignored-extensions
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
571
|
94890
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
572 if (directoryp)
|
9399
dfcf54257f10
(file_name_completion): Ignore files "." and ".." in first pass.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
573 {
|
dfcf54257f10
(file_name_completion): Ignore files "." and ".." in first pass.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
574 #ifndef TRIVIAL_DIRECTORY_ENTRY
|
dfcf54257f10
(file_name_completion): Ignore files "." and ".." in first pass.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
575 #define TRIVIAL_DIRECTORY_ENTRY(n) (!strcmp (n, ".") || !strcmp (n, ".."))
|
dfcf54257f10
(file_name_completion): Ignore files "." and ".." in first pass.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
576 #endif
|
74686
|
577 /* "." and ".." are never interesting as completions, and are
|
|
578 actually in the way in a directory with only one file. */
|
94890
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
579 if (TRIVIAL_DIRECTORY_ENTRY (dp->d_name))
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
580 canexclude = 1;
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
581 else if (len > SCHARS (encoded_file))
|
39878
|
582 /* Ignore directories if they match an element of
|
|
583 completion-ignored-extensions which ends in a slash. */
|
|
584 for (tem = Vcompletion_ignored_extensions;
|
|
585 CONSP (tem); tem = XCDR (tem))
|
|
586 {
|
|
587 int elt_len;
|
94493
41892e1c80a1
(file_name_completion): Fix up the encoding/decoding issue
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
588 unsigned char *p1;
|
39878
|
589
|
|
590 elt = XCAR (tem);
|
|
591 if (!STRINGP (elt))
|
|
592 continue;
|
42189
|
593 /* Need to encode ELT, since scmp compares unibyte
|
|
594 strings only. */
|
|
595 elt = ENCODE_FILE (elt);
|
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
596 elt_len = SCHARS (elt) - 1; /* -1 for trailing / */
|
39882
|
597 if (elt_len <= 0)
|
39878
|
598 continue;
|
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
599 p1 = SDATA (elt);
|
39878
|
600 if (p1[elt_len] != '/')
|
|
601 continue;
|
|
602 skip = len - elt_len;
|
|
603 if (skip < 0)
|
|
604 continue;
|
|
605
|
|
606 if (0 <= scmp (dp->d_name + skip, p1, elt_len))
|
|
607 continue;
|
|
608 break;
|
|
609 }
|
9399
dfcf54257f10
(file_name_completion): Ignore files "." and ".." in first pass.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
610 }
|
dfcf54257f10
(file_name_completion): Ignore files "." and ".." in first pass.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
611 else
|
94890
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
612 {
|
153
|
613 /* Compare extensions-to-be-ignored against end of this file name */
|
|
614 /* if name is not an exact match against specified string */
|
94890
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
615 if (len > SCHARS (encoded_file))
|
153
|
616 /* and exit this for loop if a match is found */
|
|
617 for (tem = Vcompletion_ignored_extensions;
|
25645
|
618 CONSP (tem); tem = XCDR (tem))
|
153
|
619 {
|
25645
|
620 elt = XCAR (tem);
|
9134
|
621 if (!STRINGP (elt)) continue;
|
42189
|
622 /* Need to encode ELT, since scmp compares unibyte
|
|
623 strings only. */
|
|
624 elt = ENCODE_FILE (elt);
|
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
625 skip = len - SCHARS (elt);
|
153
|
626 if (skip < 0) continue;
|
|
627
|
|
628 if (0 <= scmp (dp->d_name + skip,
|
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
629 SDATA (elt),
|
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
630 SCHARS (elt)))
|
153
|
631 continue;
|
|
632 break;
|
|
633 }
|
|
634 }
|
|
635
|
6680
|
636 /* If an ignored-extensions match was found,
|
|
637 don't process this name as a completion. */
|
94890
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
638 if (CONSP (tem))
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
639 canexclude = 1;
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
640
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
641 if (!includeall && canexclude)
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
642 /* We're not including all files and this file can be excluded. */
|
6680
|
643 continue;
|
|
644
|
94890
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
645 if (includeall && !canexclude)
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
646 { /* If we have one non-excludable file, we want to exclude the
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
647 excudable files. */
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
648 includeall = 0;
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
649 /* Throw away any previous excludable match found. */
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
650 bestmatch = Qnil;
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
651 bestmatchsize = 0;
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
652 matchcount = 0;
|
153
|
653 }
|
|
654 }
|
94890
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
655 /* FIXME: If we move this `decode' earlier we can eliminate
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
656 the repeated ENCODE_FILE on Vcompletion_ignored_extensions. */
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
657 name = make_unibyte_string (dp->d_name, len);
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
658 name = DECODE_FILE (name);
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
659
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
660 {
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
661 Lisp_Object regexps;
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
662 Lisp_Object zero;
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
663 XSETFASTINT (zero, 0);
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
664
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
665 /* Ignore this element if it fails to match all the regexps. */
|
99463
1620ef046b91
(file_name_completion): If completion_ignore_case is enabled, ignore
Chong Yidong <cyd@stupidchicken.com>
diff
changeset
|
666 if (completion_ignore_case)
|
1620ef046b91
(file_name_completion): If completion_ignore_case is enabled, ignore
Chong Yidong <cyd@stupidchicken.com>
diff
changeset
|
667 {
|
1620ef046b91
(file_name_completion): If completion_ignore_case is enabled, ignore
Chong Yidong <cyd@stupidchicken.com>
diff
changeset
|
668 for (regexps = Vcompletion_regexp_list; CONSP (regexps);
|
1620ef046b91
(file_name_completion): If completion_ignore_case is enabled, ignore
Chong Yidong <cyd@stupidchicken.com>
diff
changeset
|
669 regexps = XCDR (regexps))
|
1620ef046b91
(file_name_completion): If completion_ignore_case is enabled, ignore
Chong Yidong <cyd@stupidchicken.com>
diff
changeset
|
670 if (fast_string_match_ignore_case (XCAR (regexps), name) < 0)
|
1620ef046b91
(file_name_completion): If completion_ignore_case is enabled, ignore
Chong Yidong <cyd@stupidchicken.com>
diff
changeset
|
671 break;
|
1620ef046b91
(file_name_completion): If completion_ignore_case is enabled, ignore
Chong Yidong <cyd@stupidchicken.com>
diff
changeset
|
672 }
|
1620ef046b91
(file_name_completion): If completion_ignore_case is enabled, ignore
Chong Yidong <cyd@stupidchicken.com>
diff
changeset
|
673 else
|
1620ef046b91
(file_name_completion): If completion_ignore_case is enabled, ignore
Chong Yidong <cyd@stupidchicken.com>
diff
changeset
|
674 {
|
1620ef046b91
(file_name_completion): If completion_ignore_case is enabled, ignore
Chong Yidong <cyd@stupidchicken.com>
diff
changeset
|
675 for (regexps = Vcompletion_regexp_list; CONSP (regexps);
|
1620ef046b91
(file_name_completion): If completion_ignore_case is enabled, ignore
Chong Yidong <cyd@stupidchicken.com>
diff
changeset
|
676 regexps = XCDR (regexps))
|
1620ef046b91
(file_name_completion): If completion_ignore_case is enabled, ignore
Chong Yidong <cyd@stupidchicken.com>
diff
changeset
|
677 if (fast_string_match (XCAR (regexps), name) < 0)
|
1620ef046b91
(file_name_completion): If completion_ignore_case is enabled, ignore
Chong Yidong <cyd@stupidchicken.com>
diff
changeset
|
678 break;
|
1620ef046b91
(file_name_completion): If completion_ignore_case is enabled, ignore
Chong Yidong <cyd@stupidchicken.com>
diff
changeset
|
679 }
|
1620ef046b91
(file_name_completion): If completion_ignore_case is enabled, ignore
Chong Yidong <cyd@stupidchicken.com>
diff
changeset
|
680
|
94890
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
681 if (CONSP (regexps))
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
682 continue;
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
683 }
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
684
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
685 /* This is a possible completion */
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
686 if (directoryp)
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
687 /* This completion is a directory; make it end with '/'. */
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
688 name = Ffile_name_as_directory (name);
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
689
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
690 /* Test the predicate, if any. */
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
691 if (!NILP (predicate))
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
692 {
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
693 Lisp_Object val;
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
694 struct gcpro gcpro1;
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
695
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
696 GCPRO1 (name);
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
697 val = call1 (predicate, name);
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
698 UNGCPRO;
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
699
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
700 if (NILP (val))
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
701 continue;
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
702 }
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
703
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
704 /* Suitably record this match. */
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
705
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
706 matchcount++;
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
707
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
708 if (all_flag)
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
709 bestmatch = Fcons (name, bestmatch);
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
710 else if (NILP (bestmatch))
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
711 {
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
712 bestmatch = name;
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
713 bestmatchsize = SCHARS (name);
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
714 }
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
715 else
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
716 {
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
717 Lisp_Object zero = make_number (0);
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
718 /* FIXME: This is a copy of the code in Ftry_completion. */
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
719 int compare = min (bestmatchsize, SCHARS (name));
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
720 Lisp_Object tem
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
721 = Fcompare_strings (bestmatch, zero,
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
722 make_number (compare),
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
723 name, zero,
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
724 make_number (compare),
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
725 completion_ignore_case ? Qt : Qnil);
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
726 int matchsize
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
727 = (EQ (tem, Qt) ? compare
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
728 : XINT (tem) < 0 ? - XINT (tem) - 1
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
729 : XINT (tem) - 1);
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
730
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
731 if (completion_ignore_case)
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
732 {
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
733 /* If this is an exact match except for case,
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
734 use it as the best match rather than one that is not
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
735 an exact match. This way, we get the case pattern
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
736 of the actual match. */
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
737 /* This tests that the current file is an exact match
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
738 but BESTMATCH is not (it is too long). */
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
739 if ((matchsize == SCHARS (name)
|
102621
7183ab1b842a
(file_name_completion): Check completion-ignored-extensions
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
740 && matchsize + !!directoryp < SCHARS (bestmatch))
|
94890
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
741 ||
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
742 /* If there is no exact match ignoring case,
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
743 prefer a match that does not change the case
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
744 of the input. */
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
745 /* If there is more than one exact match aside from
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
746 case, and one of them is exact including case,
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
747 prefer that one. */
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
748 /* This == checks that, of current file and BESTMATCH,
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
749 either both or neither are exact. */
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
750 (((matchsize == SCHARS (name))
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
751 ==
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
752 (matchsize + !!directoryp == SCHARS (bestmatch)))
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
753 && (tem = Fcompare_strings (name, zero,
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
754 make_number (SCHARS (file)),
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
755 file, zero,
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
756 Qnil,
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
757 Qnil),
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
758 EQ (Qt, tem))
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
759 && (tem = Fcompare_strings (bestmatch, zero,
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
760 make_number (SCHARS (file)),
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
761 file, zero,
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
762 Qnil,
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
763 Qnil),
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
764 ! EQ (Qt, tem))))
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
765 bestmatch = name;
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
766 }
|
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
767 bestmatchsize = matchsize;
|
102621
7183ab1b842a
(file_name_completion): Check completion-ignored-extensions
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
768
|
7183ab1b842a
(file_name_completion): Check completion-ignored-extensions
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
769 /* If the best completion so far is reduced to the string
|
7183ab1b842a
(file_name_completion): Check completion-ignored-extensions
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
770 we're trying to complete, then we already know there's no
|
7183ab1b842a
(file_name_completion): Check completion-ignored-extensions
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
771 other completion, so there's no point looking any further. */
|
7183ab1b842a
(file_name_completion): Check completion-ignored-extensions
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
772 if (matchsize <= SCHARS (file)
|
7183ab1b842a
(file_name_completion): Check completion-ignored-extensions
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
773 && !includeall /* A future match may allow includeall to 0. */
|
7183ab1b842a
(file_name_completion): Check completion-ignored-extensions
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
774 /* If completion-ignore-case is non-nil, don't
|
7183ab1b842a
(file_name_completion): Check completion-ignored-extensions
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
775 short-circuit because we want to find the best
|
7183ab1b842a
(file_name_completion): Check completion-ignored-extensions
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
776 possible match *including* case differences. */
|
7183ab1b842a
(file_name_completion): Check completion-ignored-extensions
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
777 && (!completion_ignore_case || matchsize == 0)
|
7183ab1b842a
(file_name_completion): Check completion-ignored-extensions
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
778 /* The return value depends on whether it's the sole match. */
|
7183ab1b842a
(file_name_completion): Check completion-ignored-extensions
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
779 && matchcount > 1)
|
7183ab1b842a
(file_name_completion): Check completion-ignored-extensions
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
780 break;
|
7183ab1b842a
(file_name_completion): Check completion-ignored-extensions
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
781
|
94890
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
782 }
|
153
|
783 }
|
|
784
|
6559
|
785 UNGCPRO;
|
94890
907ac6ecef89
(file_name_completion): Tweak the code so as to always do it
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
786 /* This closes the directory. */
|
48906
|
787 bestmatch = unbind_to (count, bestmatch);
|
153
|
788
|
485
|
789 if (all_flag || NILP (bestmatch))
|
94493
41892e1c80a1
(file_name_completion): Fix up the encoding/decoding issue
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
790 return bestmatch;
|
95781
a17231a1f8f8
* dired.c (file_name_completion): Don't return t if the match is exact
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
791 /* Return t if the supplied string is an exact match (counting case);
|
a17231a1f8f8
* dired.c (file_name_completion): Don't return t if the match is exact
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
792 it does not require any change to be made. */
|
a17231a1f8f8
* dired.c (file_name_completion): Don't return t if the match is exact
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
793 if (matchcount == 1 && !NILP (Fequal (bestmatch, file)))
|
153
|
794 return Qt;
|
19816
|
795 bestmatch = Fsubstring (bestmatch, make_number (0),
|
|
796 make_number (bestmatchsize));
|
|
797 return bestmatch;
|
153
|
798 }
|
|
799
|
42169
|
800 /* Compare exactly LEN chars of strings at S1 and S2,
|
|
801 ignoring case if appropriate.
|
|
802 Return -1 if strings match,
|
|
803 else number of chars that match at the beginning. */
|
|
804
|
|
805 static int
|
109555
|
806 scmp (const unsigned char *s1, const unsigned char *s2, int len)
|
42169
|
807 {
|
|
808 register int l = len;
|
|
809
|
|
810 if (completion_ignore_case)
|
|
811 {
|
|
812 while (l && DOWNCASE (*s1++) == DOWNCASE (*s2++))
|
|
813 l--;
|
|
814 }
|
|
815 else
|
|
816 {
|
|
817 while (l && *s1++ == *s2++)
|
|
818 l--;
|
|
819 }
|
|
820 if (l == 0)
|
|
821 return -1;
|
|
822 else
|
|
823 return len - l;
|
|
824 }
|
|
825
|
21514
|
826 static int
|
109129
|
827 file_name_completion_stat (Lisp_Object dirname, DIRENTRY *dp, struct stat *st_addr)
|
153
|
828 {
|
|
829 int len = NAMLEN (dp);
|
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
830 int pos = SCHARS (dirname);
|
7286
|
831 int value;
|
153
|
832 char *fullname = (char *) alloca (len + pos + 2);
|
|
833
|
16246
|
834 #ifdef MSDOS
|
|
835 /* Some fields of struct stat are *very* expensive to compute on MS-DOS,
|
|
836 but aren't required here. Avoid computing the following fields:
|
|
837 st_inode, st_size and st_nlink for directories, and the execute bits
|
|
838 in st_mode for non-directory files with non-standard extensions. */
|
|
839
|
|
840 unsigned short save_djstat_flags = _djstat_flags;
|
|
841
|
|
842 _djstat_flags = _STAT_INODE | _STAT_EXEC_MAGIC | _STAT_DIRSIZE;
|
|
843 #endif /* MSDOS */
|
|
844
|
109165
750db9f3e6d8
Replace bcopy, bzero, bcmp by memcpy, memmove, memset, memcmp
Andreas Schwab <schwab@linux-m68k.org>
diff
changeset
|
845 memcpy (fullname, SDATA (dirname), pos);
|
9787
|
846 if (!IS_DIRECTORY_SEP (fullname[pos - 1]))
|
|
847 fullname[pos++] = DIRECTORY_SEP;
|
153
|
848
|
109165
750db9f3e6d8
Replace bcopy, bzero, bcmp by memcpy, memmove, memset, memcmp
Andreas Schwab <schwab@linux-m68k.org>
diff
changeset
|
849 memcpy (fullname + pos, dp->d_name, len);
|
153
|
850 fullname[pos + len] = 0;
|
|
851
|
5432
|
852 #ifdef S_IFLNK
|
7286
|
853 /* We want to return success if a link points to a nonexistent file,
|
|
854 but we want to return the status for what the link points to,
|
|
855 in case it is a directory. */
|
|
856 value = lstat (fullname, st_addr);
|
|
857 stat (fullname, st_addr);
|
|
858 return value;
|
5432
|
859 #else
|
16246
|
860 value = stat (fullname, st_addr);
|
|
861 #ifdef MSDOS
|
|
862 _djstat_flags = save_djstat_flags;
|
|
863 #endif /* MSDOS */
|
|
864 return value;
|
|
865 #endif /* S_IFLNK */
|
153
|
866 }
|
|
867
|
|
868 Lisp_Object
|
109126
|
869 make_time (time_t time)
|
153
|
870 {
|
|
871 return Fcons (make_number (time >> 16),
|
|
872 Fcons (make_number (time & 0177777), Qnil));
|
|
873 }
|
|
874
|
94814
|
875 static char *
|
|
876 stat_uname (struct stat *st)
|
|
877 {
|
|
878 #ifdef WINDOWSNT
|
|
879 return st->st_uname;
|
|
880 #else
|
|
881 struct passwd *pw = (struct passwd *) getpwuid (st->st_uid);
|
|
882
|
|
883 if (pw)
|
|
884 return pw->pw_name;
|
|
885 else
|
|
886 return NULL;
|
|
887 #endif
|
|
888 }
|
|
889
|
|
890 static char *
|
|
891 stat_gname (struct stat *st)
|
|
892 {
|
|
893 #ifdef WINDOWSNT
|
|
894 return st->st_gname;
|
|
895 #else
|
|
896 struct group *gr = (struct group *) getgrgid (st->st_gid);
|
|
897
|
|
898 if (gr)
|
|
899 return gr->gr_name;
|
|
900 else
|
|
901 return NULL;
|
|
902 #endif
|
|
903 }
|
|
904
|
53112
b6c073b1f1c7
(Ffile_attributes): Parameter ID-FORMAT added and included in call to file
Lars Hansen <larsh@soem.dk>
diff
changeset
|
905 DEFUN ("file-attributes", Ffile_attributes, Sfile_attributes, 1, 2, 0,
|
41001
|
906 doc: /* Return a list of attributes of file FILENAME.
|
|
907 Value is nil if specified file cannot be opened.
|
53112
b6c073b1f1c7
(Ffile_attributes): Parameter ID-FORMAT added and included in call to file
Lars Hansen <larsh@soem.dk>
diff
changeset
|
908
|
b6c073b1f1c7
(Ffile_attributes): Parameter ID-FORMAT added and included in call to file
Lars Hansen <larsh@soem.dk>
diff
changeset
|
909 ID-FORMAT specifies the preferred format of attributes uid and gid (see
|
107976
|
910 below) - valid values are 'string and 'integer. The latter is the
|
|
911 default, but we plan to change that, so you should specify a non-nil value
|
|
912 for ID-FORMAT if you use the returned uid or gid.
|
53112
b6c073b1f1c7
(Ffile_attributes): Parameter ID-FORMAT added and included in call to file
Lars Hansen <larsh@soem.dk>
diff
changeset
|
913
|
b6c073b1f1c7
(Ffile_attributes): Parameter ID-FORMAT added and included in call to file
Lars Hansen <larsh@soem.dk>
diff
changeset
|
914 Elements of the attribute list are:
|
41001
|
915 0. t for directory, string (name linked to) for symbolic link, or nil.
|
|
916 1. Number of links to file.
|
102632
|
917 2. File uid as a string or a number. If a string value cannot be
|
|
918 looked up, a numeric value, either an integer or a float, is returned.
|
53112
b6c073b1f1c7
(Ffile_attributes): Parameter ID-FORMAT added and included in call to file
Lars Hansen <larsh@soem.dk>
diff
changeset
|
919 3. File gid, likewise.
|
41001
|
920 4. Last access time, as a list of two integers.
|
|
921 First integer has high-order 16 bits of time, second has low 16 bits.
|
105458
|
922 (See a note below about access time on FAT-based filesystems.)
|
|
923 5. Last modification time, likewise. This is the time of the last
|
|
924 change to the file's contents.
|
|
925 6. Last status change time, likewise. This is the time of last change
|
|
926 to the file's attributes: owner and group, access mode bits, etc.
|
41001
|
927 7. Size in bytes.
|
|
928 This is a floating point number if the size is too large for an integer.
|
|
929 8. File modes, as a string of ten letters or dashes as in ls -l.
|
78501
|
930 9. t if file's gid would change if file were deleted and recreated.
|
105458
|
931 10. inode number. If inode number is larger than what Emacs integer
|
|
932 can hold, but still fits into a 32-bit number, this is a cons cell
|
|
933 containing two integers: first the high part, then the low 16 bits.
|
|
934 If the inode number is wider than 32 bits, this is of the form
|
|
935 (HIGH MIDDLE . LOW): first the high 24 bits, then middle 24 bits,
|
|
936 and finally the low 16 bits.
|
|
937 11. Filesystem device number. If it is larger than what the Emacs
|
|
938 integer can hold, this is a cons cell, similar to the inode number.
|
|
939
|
|
940 On most filesystems, the combination of the inode and the device
|
|
941 number uniquely identifies the file.
|
94841
|
942
|
|
943 On MS-Windows, performance depends on `w32-get-true-file-attributes',
|
103280
|
944 which see.
|
|
945
|
|
946 On some FAT-based filesystems, only the date of last access is recorded,
|
|
947 so last access time will always be midnight of that day. */)
|
109179
|
948 (Lisp_Object filename, Lisp_Object id_format)
|
153
|
949 {
|
|
950 Lisp_Object values[12];
|
19816
|
951 Lisp_Object encoded;
|
153
|
952 struct stat s;
|
109097
|
953 #ifdef BSD4_2
|
34970
|
954 Lisp_Object dirname;
|
153
|
955 struct stat sdir;
|
109097
|
956 #endif /* BSD4_2 */
|
153
|
957 char modes[10];
|
843
|
958 Lisp_Object handler;
|
60900
|
959 struct gcpro gcpro1;
|
102661
|
960 char *uname = NULL, *gname = NULL;
|
153
|
961
|
|
962 filename = Fexpand_file_name (filename, Qnil);
|
843
|
963
|
|
964 /* If the file name has special constructs in it,
|
|
965 call the corresponding file handler. */
|
7028
|
966 handler = Ffind_file_name_handler (filename, Qfile_attributes);
|
843
|
967 if (!NILP (handler))
|
54905
da06b9bd886b
(Ffile_attributes): Don't pass extra nil arg to file-handler.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
968 { /* Only pass the extra arg if it is used to help backward compatibility
|
da06b9bd886b
(Ffile_attributes): Don't pass extra nil arg to file-handler.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
969 with old file handlers which do not implement the new arg. --Stef */
|
da06b9bd886b
(Ffile_attributes): Don't pass extra nil arg to file-handler.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
970 if (NILP (id_format))
|
da06b9bd886b
(Ffile_attributes): Don't pass extra nil arg to file-handler.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
971 return call2 (handler, Qfile_attributes, filename);
|
da06b9bd886b
(Ffile_attributes): Don't pass extra nil arg to file-handler.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
972 else
|
da06b9bd886b
(Ffile_attributes): Don't pass extra nil arg to file-handler.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
973 return call3 (handler, Qfile_attributes, filename, id_format);
|
da06b9bd886b
(Ffile_attributes): Don't pass extra nil arg to file-handler.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
974 }
|
843
|
975
|
60900
|
976 GCPRO1 (filename);
|
19816
|
977 encoded = ENCODE_FILE (filename);
|
60900
|
978 UNGCPRO;
|
19816
|
979
|
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
980 if (lstat (SDATA (encoded), &s) < 0)
|
153
|
981 return Qnil;
|
|
982
|
|
983 switch (s.st_mode & S_IFMT)
|
|
984 {
|
|
985 default:
|
|
986 values[0] = Qnil; break;
|
|
987 case S_IFDIR:
|
|
988 values[0] = Qt; break;
|
|
989 #ifdef S_IFLNK
|
|
990 case S_IFLNK:
|
|
991 values[0] = Ffile_symlink_p (filename); break;
|
|
992 #endif
|
|
993 }
|
|
994 values[1] = make_number (s.st_nlink);
|
102661
|
995
|
|
996 if (!(NILP (id_format) || EQ (id_format, Qinteger)))
|
53112
b6c073b1f1c7
(Ffile_attributes): Parameter ID-FORMAT added and included in call to file
Lars Hansen <larsh@soem.dk>
diff
changeset
|
997 {
|
71816
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
diff
changeset
|
998 BLOCK_INPUT;
|
94814
|
999 uname = stat_uname (&s);
|
|
1000 gname = stat_gname (&s);
|
71816
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
diff
changeset
|
1001 UNBLOCK_INPUT;
|
53112
b6c073b1f1c7
(Ffile_attributes): Parameter ID-FORMAT added and included in call to file
Lars Hansen <larsh@soem.dk>
diff
changeset
|
1002 }
|
102661
|
1003 if (uname)
|
103712
87554fb2c23c
(Ffile_attributes): Decode user and group names by the locale's encoding.
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
1004 values[2] = DECODE_SYSTEM (build_string (uname));
|
102661
|
1005 else
|
105748
|
1006 values[2] = make_fixnum_or_float (s.st_uid);
|
102661
|
1007 if (gname)
|
103712
87554fb2c23c
(Ffile_attributes): Decode user and group names by the locale's encoding.
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
1008 values[3] = DECODE_SYSTEM (build_string (gname));
|
102661
|
1009 else
|
105748
|
1010 values[3] = make_fixnum_or_float (s.st_gid);
|
102661
|
1011
|
153
|
1012 values[4] = make_time (s.st_atime);
|
|
1013 values[5] = make_time (s.st_mtime);
|
|
1014 values[6] = make_time (s.st_ctime);
|
105748
|
1015 values[7] = make_fixnum_or_float (s.st_size);
|
48563
|
1016 /* If the size is negative, and its type is long, convert it back to
|
|
1017 positive. */
|
|
1018 if (s.st_size < 0 && sizeof (s.st_size) == sizeof (long))
|
|
1019 values[7] = make_float ((double) ((unsigned long) s.st_size));
|
|
1020
|
153
|
1021 filemodestring (&s, modes);
|
|
1022 values[8] = make_string (modes, 10);
|
109097
|
1023 #ifdef BSD4_2 /* file gid will be dir gid */
|
153
|
1024 dirname = Ffile_name_directory (filename);
|
19816
|
1025 if (! NILP (dirname))
|
|
1026 encoded = ENCODE_FILE (dirname);
|
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
1027 if (! NILP (dirname) && stat (SDATA (encoded), &sdir) == 0)
|
94371
436ee104782b
(Ffile_attributes) [WINDOWSNT]: Undo change from 2008-03-31, it's not needed
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
1028 values[9] = (sdir.st_gid != s.st_gid) ? Qt : Qnil;
|
153
|
1029 else /* if we can't tell, assume worst */
|
|
1030 values[9] = Qt;
|
|
1031 #else /* file gid will be egid */
|
94371
436ee104782b
(Ffile_attributes) [WINDOWSNT]: Undo change from 2008-03-31, it's not needed
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
1032 values[9] = (s.st_gid != getegid ()) ? Qt : Qnil;
|
109097
|
1033 #endif /* not BSD4_2 */
|
105748
|
1034 if (!FIXNUM_OVERFLOW_P (s.st_ino))
|
93689
|
1035 /* Keep the most common cases as integers. */
|
105748
|
1036 values[10] = make_number (s.st_ino);
|
|
1037 else if (!FIXNUM_OVERFLOW_P (s.st_ino >> 16))
|
17868
bc2cf7c40435
(Ffile_attributes): Return inode number as a cons only if necessary.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1038 /* To allow inode numbers larger than VALBITS, separate the bottom
|
bc2cf7c40435
(Ffile_attributes): Return inode number as a cons only if necessary.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1039 16 bits. */
|
93689
|
1040 values[10] = Fcons (make_number ((EMACS_INT)(s.st_ino >> 16)),
|
|
1041 make_number ((EMACS_INT)(s.st_ino & 0xffff)));
|
17868
bc2cf7c40435
(Ffile_attributes): Return inode number as a cons only if necessary.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1042 else
|
93689
|
1043 {
|
|
1044 /* To allow inode numbers beyond 32 bits, separate into 2 24-bit
|
97770
|
1045 high parts and a 16-bit bottom part.
|
97773
|
1046 The code on the next line avoids a compiler warning on
|
|
1047 systems where st_ino is 32 bit wide. (bug#766). */
|
97770
|
1048 EMACS_INT high_ino = s.st_ino >> 31 >> 1;
|
93689
|
1049 EMACS_INT low_ino = s.st_ino & 0xffffffff;
|
|
1050
|
|
1051 values[10] = Fcons (make_number (high_ino >> 8),
|
|
1052 Fcons (make_number (((high_ino & 0xff) << 16)
|
|
1053 + (low_ino >> 16)),
|
|
1054 make_number (low_ino & 0xffff)));
|
|
1055 }
|
26088
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
1056
|
105748
|
1057 /* Likewise for device. */
|
|
1058 if (FIXNUM_OVERFLOW_P (s.st_dev))
|
26088
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
1059 values[11] = Fcons (make_number (s.st_dev >> 16),
|
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
1060 make_number (s.st_dev & 0xffff));
|
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
1061 else
|
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
1062 values[11] = make_number (s.st_dev);
|
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
1063
|
153
|
1064 return Flist (sizeof(values) / sizeof(values[0]), values);
|
|
1065 }
|
25192
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
1066
|
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
1067 DEFUN ("file-attributes-lessp", Ffile_attributes_lessp, Sfile_attributes_lessp, 2, 2, 0,
|
41001
|
1068 doc: /* Return t if first arg file attributes list is less than second.
|
|
1069 Comparison is in lexicographic order and case is significant. */)
|
109179
|
1070 (Lisp_Object f1, Lisp_Object f2)
|
25192
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
1071 {
|
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
1072 return Fstring_lessp (Fcar (f1), Fcar (f2));
|
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
1073 }
|
153
|
1074
|
21514
|
1075 void
|
109126
|
1076 syms_of_dired (void)
|
153
|
1077 {
|
105877
|
1078 Qdirectory_files = intern_c_string ("directory-files");
|
|
1079 Qdirectory_files_and_attributes = intern_c_string ("directory-files-and-attributes");
|
|
1080 Qfile_name_completion = intern_c_string ("file-name-completion");
|
|
1081 Qfile_name_all_completions = intern_c_string ("file-name-all-completions");
|
|
1082 Qfile_attributes = intern_c_string ("file-attributes");
|
|
1083 Qfile_attributes_lessp = intern_c_string ("file-attributes-lessp");
|
|
1084 Qdefault_directory = intern_c_string ("default-directory");
|
843
|
1085
|
16225
|
1086 staticpro (&Qdirectory_files);
|
25192
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
1087 staticpro (&Qdirectory_files_and_attributes);
|
16225
|
1088 staticpro (&Qfile_name_completion);
|
|
1089 staticpro (&Qfile_name_all_completions);
|
|
1090 staticpro (&Qfile_attributes);
|
25192
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
1091 staticpro (&Qfile_attributes_lessp);
|
94888
|
1092 staticpro (&Qdefault_directory);
|
16225
|
1093
|
153
|
1094 defsubr (&Sdirectory_files);
|
25192
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
1095 defsubr (&Sdirectory_files_and_attributes);
|
153
|
1096 defsubr (&Sfile_name_completion);
|
|
1097 defsubr (&Sfile_name_all_completions);
|
|
1098 defsubr (&Sfile_attributes);
|
25192
03f530e858df
(directory_files_internal, Fdirectory_files_and_attributes,
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
1099 defsubr (&Sfile_attributes_lessp);
|
153
|
1100
|
|
1101 DEFVAR_LISP ("completion-ignored-extensions", &Vcompletion_ignored_extensions,
|
68323
|
1102 doc: /* Completion ignores file names ending in any string in this list.
|
|
1103 It does not ignore them if all possible completions end in one of
|
|
1104 these strings or when displaying a list of completions.
|
|
1105 It ignores directory names if they match any string in this list which
|
|
1106 ends in a slash. */);
|
153
|
1107 Vcompletion_ignored_extensions = Qnil;
|
|
1108 }
|
52401
|
1109
|
|
1110 /* arch-tag: 1ac8deca-4d8f-4d41-ade9-089154d98c03
|
|
1111 (do not change this comment) */
|