annotate src/dired.c @ 276:6330739388db r21-0b36

Import from CVS: tag r21-0b36
author cvs
date Mon, 13 Aug 2007 10:30:37 +0200
parents c5d627a313b1
children 7df0dd720c89
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* Lisp functions for making directory listings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Copyright (C) 1985, 1986, 1992, 1993, 1994 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 /* Synched up with: FSF 19.30. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 #include "lisp.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 #include "buffer.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 #include "commands.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 #include "elhash.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 #include "regex.h"
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
30 #include "opaque.h"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 #include "sysfile.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 #include "sysdir.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 Lisp_Object Vcompletion_ignored_extensions;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 Lisp_Object Qdirectory_files;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 Lisp_Object Qfile_name_completion;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 Lisp_Object Qfile_name_all_completions;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 Lisp_Object Qfile_attributes;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
40 static Lisp_Object
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 195
diff changeset
41 close_directory_unwind (Lisp_Object unwind_obj)
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
42 {
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
43 DIR *d = (DIR *)get_opaque_ptr (unwind_obj);
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
44 closedir (d);
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
45 free_opaque_ptr (unwind_obj);
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
46 return Qnil;
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
47 }
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
48
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
49 DEFUN ("directory-files", Fdirectory_files, 1, 5, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 Return a list of names of files in DIRECTORY.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 There are four optional arguments:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 If FULL is non-nil, absolute pathnames of the files are returned.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 If MATCH is non-nil, only pathnames containing that regexp are returned.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 If NOSORT is non-nil, the list is not sorted--its order is unpredictable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 NOSORT is useful if you plan to sort the result yourself.
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
56 If FILES-ONLY is the symbol t, then only the "files" in the directory
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 will be returned; subdirectories will be excluded. If FILES-ONLY is not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 nil and not t, then only the subdirectories will be returned. Otherwise,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 if FILES-ONLY is nil (the default) then both files and subdirectories will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 be returned.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
61 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
62 (dirname, full, match, nosort, files_only))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 {
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
64 /* This function can GC */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 DIR *d;
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
66 Lisp_Object list = Qnil;
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
67 Bytecount dirnamelen;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 Lisp_Object handler;
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 120
diff changeset
69 struct re_pattern_buffer *bufp = NULL;
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
70 int speccount = specpdl_depth ();
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
71 char *statbuf, *statbuf_tail;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
73 struct gcpro gcpro1, gcpro2;
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
74 GCPRO2 (dirname, list);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 /* If the file name has special constructs in it,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 call the corresponding file handler. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 handler = Ffind_file_name_handler (dirname, Qdirectory_files);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 if (!NILP (handler))
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
80 {
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
81 UNGCPRO;
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
82 if (!NILP (files_only))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
83 return call6 (handler, Qdirectory_files, dirname, full, match, nosort,
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
84 files_only);
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
85 else
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
86 return call5 (handler, Qdirectory_files, dirname, full, match,
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
87 nosort);
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
88 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
90 /* #### why do we do Fexpand_file_name after file handlers here,
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
91 but earlier everywhere else? */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 dirname = Fexpand_file_name (dirname, Qnil);
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
93 dirname = Ffile_name_as_directory (dirname);
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
94 dirnamelen = XSTRING_LENGTH (dirname);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
96 statbuf = (char *)alloca (dirnamelen + MAXNAMLEN + 1);
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
97 memcpy (statbuf, XSTRING_DATA (dirname), dirnamelen);
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
98 statbuf_tail = statbuf + dirnamelen;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 /* XEmacs: this should come after Ffile_name_as_directory() to avoid
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
101 potential regexp cache smashage. It comes before the opendir()
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
102 because it might signal an error. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 if (!NILP (match))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 CHECK_STRING (match);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 /* MATCH might be a flawed regular expression. Rather than
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 catching and signalling our own errors, we just call
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 compile_pattern to do the work for us. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 bufp = compile_pattern (match, 0, 0, 0, ERROR_ME);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 /* Now *bufp is the compiled form of MATCH; don't call anything
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 which might compile a new regexp until we're done with the loop! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
116 /* Do this opendir after anything which might signal an error.
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
117 NOTE: the above comment is old; previosly, there was no
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
118 unwind-protection in case of error, but now there is. */
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
119 d = opendir ((char *) XSTRING_DATA (dirname));
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
120 if (!d)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 report_file_error ("Opening directory", list1 (dirname));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 195
diff changeset
123 record_unwind_protect (close_directory_unwind, make_opaque_ptr ((void *)d));
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
124
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 /* Loop reading blocks */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 DIRENTRY *dp = readdir (d);
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
129 Lisp_Object name;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 int len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
132 if (!dp)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
133 break;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 len = NAMLEN (dp);
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
135 if (DIRENTRY_NONEMPTY (dp)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
136 && (NILP (match)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
137 || (0 <= re_search (bufp, dp->d_name, len, 0, len, 0))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 {
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
139 if (!NILP (files_only))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 {
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
141 int dir_p;
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
142 struct stat st;
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
143 char *cur_statbuf = statbuf;
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
144 char *cur_statbuf_tail = statbuf_tail;
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
145
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
146 /* #### I don't think the code under `if' is necessary
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
147 anymore. The crashes in this function were reported
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
148 because MAXNAMLEN was used to remember the *whole*
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
149 statbuf, instead of using MAXPATHLEN. This should be
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 272
diff changeset
150 tested after 21.0 is released. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
152 /* We normally use the buffer created by alloca.
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
153 However, if the file name we get too big, we'll use a
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
154 malloced buffer, and free it. It is undefined how
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
155 stat() will react to this, but we avoid a buffer
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
156 overrun. */
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
157 if (len > MAXNAMLEN)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
158 {
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
159 cur_statbuf = (char *)xmalloc (dirnamelen + len + 1);
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
160 memcpy (cur_statbuf, statbuf, dirnamelen);
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
161 cur_statbuf_tail = cur_statbuf + dirnamelen;
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
162 }
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
163 memcpy (cur_statbuf_tail, dp->d_name, len);
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
164 cur_statbuf_tail[len] = 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
166 if (stat (cur_statbuf, &st) < 0)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
167 dir_p = 0;
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
168 else
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
169 dir_p = ((st.st_mode & S_IFMT) == S_IFDIR);
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
170
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
171 if (cur_statbuf != statbuf)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
172 xfree (cur_statbuf);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
174 if (EQ (files_only, Qt) && dir_p)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
175 continue;
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
176 else if (!EQ (files_only, Qt) && !dir_p)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
177 continue;
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
178 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
180 if (!NILP (full))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
181 name = concat2 (dirname, make_ext_string ((Bufbyte *)dp->d_name,
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
182 len, FORMAT_FILENAME));
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
183 else
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
184 name = make_ext_string ((Bufbyte *)dp->d_name,
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
185 len, FORMAT_FILENAME);
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
186
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
187 list = Fcons (name, list);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 }
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
190 unbind_to (speccount, Qnil); /* This will close the dir */
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
191
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 if (!NILP (nosort))
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
193 RETURN_UNGCPRO (list);
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
194 else
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
195 RETURN_UNGCPRO (Fsort (Fnreverse (list), Qstring_lessp));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
198 static Lisp_Object file_name_completion (Lisp_Object file,
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
199 Lisp_Object dirname,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 int all_flag, int ver_flag);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
202 DEFUN ("file-name-completion", Ffile_name_completion, 2, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 Complete file name FILE in directory DIR.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 Returns the longest string common to all filenames in DIR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 that start with FILE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 If there is only one and FILE matches it exactly, returns t.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 Returns nil if DIR contains no name starting with FILE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 Filenames which end with any member of `completion-ignored-extensions'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 are not considered as possible completions for FILE unless there is no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 other possible completion. `completion-ignored-extensions' is not applied
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 to the names of directories.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
213 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
214 (file, dirname))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 {
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
216 /* This function can GC. GC checked 1996.04.06. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 Lisp_Object handler;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 /* If the directory name has special constructs in it,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 call the corresponding file handler. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 handler = Ffind_file_name_handler (dirname, Qfile_name_completion);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 if (!NILP (handler))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 return call3 (handler, Qfile_name_completion, file, dirname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 /* If the file name has special constructs in it,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 call the corresponding file handler. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 handler = Ffind_file_name_handler (file, Qfile_name_completion);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 if (!NILP (handler))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 return call3 (handler, Qfile_name_completion, file, dirname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 return file_name_completion (file, dirname, 0, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
234 DEFUN ("file-name-all-completions", Ffile_name_all_completions, 2, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 Return a list of all completions of file name FILE in directory DIR.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 These are all file names in directory DIR which begin with FILE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 Filenames which end with any member of `completion-ignored-extensions'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 are not considered as possible completions for FILE unless there is no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 other possible completion. `completion-ignored-extensions' is not applied
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 to the names of directories.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
242 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
243 (file, dirname))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 {
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
245 /* This function can GC. GC checked 1997.06.04. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 Lisp_Object handler;
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
247 struct gcpro gcpro1;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
249 GCPRO1 (dirname);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
250 dirname = Fexpand_file_name (dirname, Qnil);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 /* If the file name has special constructs in it,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 call the corresponding file handler. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 handler = Ffind_file_name_handler (dirname, Qfile_name_all_completions);
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
254 UNGCPRO;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 if (!NILP (handler))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 return call3 (handler, Qfile_name_all_completions, file,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 dirname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 return file_name_completion (file, dirname, 1, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 file_name_completion_stat (Lisp_Object dirname, DIRENTRY *dp,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 struct stat *st_addr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 Bytecount len = NAMLEN (dp);
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
267 Bytecount pos = XSTRING_LENGTH (dirname);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 int value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 char *fullname = (char *) alloca (len + pos + 2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
271 memcpy (fullname, XSTRING_DATA (dirname), pos);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 if (!IS_DIRECTORY_SEP (fullname[pos - 1]))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 fullname[pos++] = DIRECTORY_SEP;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 memcpy (fullname + pos, dp->d_name, len);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 fullname[pos + len] = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 #ifdef S_IFLNK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 /* We want to return success if a link points to a nonexistent file,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 but we want to return the status for what the link points to,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 in case it is a directory. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 value = lstat (fullname, st_addr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 if (S_ISLNK (st_addr->st_mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 stat (fullname, st_addr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 value = stat (fullname, st_addr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 #endif
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 120
diff changeset
288 return value;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 static Lisp_Object
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
292 file_name_completion_unwind (Lisp_Object locative)
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
293 {
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
294 DIR *d;
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
295 Lisp_Object obj = XCAR (locative);
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
296
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
297 if (NILP (obj))
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
298 return Qnil;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
299 d = (DIR *)get_opaque_ptr (obj);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
300 closedir (d);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
301 free_opaque_ptr (obj);
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
302 free_cons (XCONS (locative));
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
303 return Qnil;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
304 }
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
305
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
306 static Lisp_Object
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 file_name_completion (Lisp_Object file, Lisp_Object dirname, int all_flag,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 int ver_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 DIR *d = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 int matchcount = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 Lisp_Object bestmatch = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 Charcount bestmatchsize = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 struct stat st;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 int passcount;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 int speccount = specpdl_depth ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 Charcount file_name_length;
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
319 Lisp_Object locative;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 struct gcpro gcpro1, gcpro2, gcpro3;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 GCPRO3 (file, dirname, bestmatch);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 CHECK_STRING (file);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
326 #ifdef WINDOWSNT
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
327 /* Filename completion on Windows ignores case, since Windows
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
328 filesystems do. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 specbind (Qcompletion_ignore_case, Qt);
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
330 #endif /* WINDOWSNT */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 #ifdef FILE_SYSTEM_CASE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 file = FILE_SYSTEM_CASE (file);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 dirname = Fexpand_file_name (dirname, Qnil);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
336 file_name_length = XSTRING_CHAR_LENGTH (file);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 /* With passcount = 0, ignore files that end in an ignored extension.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 If nothing found then try again with passcount = 1, don't ignore them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 If looking for all completions, start with passcount = 1,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 so always take even the ignored ones.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 ** It would not actually be helpful to the user to ignore any possible
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 completions when making a list of them.** */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
346 /* We cannot use close_directory_unwind() because we change the
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
347 directory. The old code used to just avoid signaling errors, and
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
348 call closedir, but it was wrong, because it made sane handling of
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
349 QUIT impossible and, besides, various utility functions like
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
350 regexp_ignore_completion_p can signal errors. */
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
351 locative = noseeum_cons (Qnil, Qnil);
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
352 record_unwind_protect (file_name_completion_unwind, locative);
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
353
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 for (passcount = !!all_flag; NILP (bestmatch) && passcount < 2; passcount++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 {
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
356 d = opendir ((char *) XSTRING_DATA (Fdirectory_file_name (dirname)));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 if (!d)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 report_file_error ("Opening directory", list1 (dirname));
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
359 XCAR (locative) = make_opaque_ptr ((void *)d);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 /* Loop reading blocks */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 DIRENTRY *dp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 Bytecount len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 /* scmp() works in characters, not bytes, so we have to compute
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 this value: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 Charcount cclen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 int directoryp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 int ignored_extension_p = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 Bufbyte *d_name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
373 dp = readdir (d);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 if (!dp) break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
376 /* #### This is a bad idea, because d_name can contain
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
377 control characters, which can make XEmacs crash. This
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
378 should be handled properly with FORMAT_FILENAME. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 d_name = (Bufbyte *) dp->d_name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 len = NAMLEN (dp);
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
381 cclen = bytecount_to_charcount (d_name, len);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
383 QUIT;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 if (! DIRENTRY_NONEMPTY (dp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 || cclen < file_name_length
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
387 || 0 <= scmp (d_name, XSTRING_DATA (file), file_name_length))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 if (file_name_completion_stat (dirname, dp, &st) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 directoryp = ((st.st_mode & S_IFMT) == S_IFDIR);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 if (directoryp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 #ifndef TRIVIAL_DIRECTORY_ENTRY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 #define TRIVIAL_DIRECTORY_ENTRY(n) (!strcmp (n, ".") || !strcmp (n, ".."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 /* "." and ".." are never interesting as completions, but are
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
400 actually in the way in a directory containing only one file. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 if (!passcount && TRIVIAL_DIRECTORY_ENTRY (dp->d_name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 /* Compare extensions-to-be-ignored against end of this file name */
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
407 /* if name is not an exact match against specified string. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 if (!passcount && cclen > file_name_length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 Lisp_Object tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 /* and exit this for loop if a match is found */
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
412 EXTERNAL_LIST_LOOP (tem, Vcompletion_ignored_extensions)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 Lisp_Object elt = XCAR (tem);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 Charcount skip;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
417 CHECK_STRING (elt);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
418
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
419 skip = cclen - XSTRING_CHAR_LENGTH (elt);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 if (skip < 0) continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 if (0 > scmp (charptr_n_addr (d_name, skip),
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
423 XSTRING_DATA (elt),
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
424 XSTRING_CHAR_LENGTH (elt)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 ignored_extension_p = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 /* If an ignored-extensions match was found,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 don't process this name as a completion. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 if (!passcount && ignored_extension_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
438 if (!passcount && regexp_ignore_completion_p (d_name, Qnil, 0, cclen))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 /* Update computation of how much all possible completions match */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 matchcount++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 if (all_flag || NILP (bestmatch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 Lisp_Object name = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 struct gcpro ngcpro1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 NGCPRO1 (name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 /* This is a possible completion */
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
450 name = make_string (d_name, len);
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
451 if (directoryp) /* Completion is a directory; end it with '/' */
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
452 name = Ffile_name_as_directory (name);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 if (all_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 bestmatch = Fcons (name, bestmatch);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 bestmatch = name;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
460 bestmatchsize = XSTRING_CHAR_LENGTH (name);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 NUNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 Charcount compare = min (bestmatchsize, cclen);
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
467 Bufbyte *p1 = XSTRING_DATA (bestmatch);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 Bufbyte *p2 = d_name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 Charcount matchsize = scmp (p1, p2, compare);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 if (matchsize < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 matchsize = compare;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 if (completion_ignore_case)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 /* If this is an exact match except for case,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 use it as the best match rather than one that is not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 an exact match. This way, we get the case pattern
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 of the actual match. */
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
479 if ((matchsize == cclen
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
480 && matchsize + !!directoryp
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
481 < XSTRING_CHAR_LENGTH (bestmatch))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 /* If there is no exact match ignoring case,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 prefer a match that does not change the case
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 of the input. */
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
486 (((matchsize == cclen)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 ==
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
488 (matchsize + !!directoryp
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
489 == XSTRING_CHAR_LENGTH (bestmatch)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 /* If there is more than one exact match aside from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 case, and one of them is exact including case,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 prefer that one. */
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
493 && 0 > scmp_1 (p2, XSTRING_DATA (file),
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 file_name_length, 0)
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
495 && 0 <= scmp_1 (p1, XSTRING_DATA (file),
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 file_name_length, 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 {
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
498 bestmatch = make_string (d_name, len);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 if (directoryp)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
500 bestmatch = Ffile_name_as_directory (bestmatch);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 /* If this dirname all matches,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 see if implicit following slash does too. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 if (directoryp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 && compare == matchsize
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 && bestmatchsize > matchsize
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 && IS_ANY_SEP (charptr_emchar_n (p1, matchsize)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 matchsize++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 bestmatchsize = matchsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 closedir (d);
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
515 free_opaque_ptr (XCAR (locative));
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
516 XCAR (locative) = Qnil;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 unbind_to (speccount, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 if (all_flag || NILP (bestmatch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 return bestmatch;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 if (matchcount == 1 && bestmatchsize == file_name_length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 return Qt;
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 219
diff changeset
527 return Fsubstring (bestmatch, Qzero, make_int (bestmatchsize));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 make_directory_hash_table (char *path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 DIR *d;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 DIRENTRY *dp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 Bytecount len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 Lisp_Object hash = make_lisp_hashtable (100, HASHTABLE_NONWEAK,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 HASHTABLE_EQUAL);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 if ((d = opendir (path)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 while ((dp = readdir (d)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 len = NAMLEN (dp);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 if (DIRENTRY_NONEMPTY (dp))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 195
diff changeset
545 Fputhash (make_ext_string ((Bufbyte *) dp->d_name, len,
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
546 FORMAT_FILENAME), Qt, hash);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 closedir (d);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 return hash;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 wasteful_word_to_lisp (unsigned int item)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 /* Compatibility: in other versions, file-attributes returns a LIST
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 of two 16 bit integers... */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 Lisp_Object cons = word_to_lisp (item);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 XCDR (cons) = Fcons (XCDR (cons), Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 return cons;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
563 DEFUN ("file-attributes", Ffile_attributes, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 Return a list of attributes of file FILENAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 Value is nil if specified file cannot be opened.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 Otherwise, list elements are:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 0. t for directory, string (name linked to) for symbolic link, or nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 1. Number of links to file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 2. File uid.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 3. File gid.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 4. Last access time, as a list of two integers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 First integer has high-order 16 bits of time, second has low 16 bits.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 5. Last modification time, likewise.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 6. Last status change time, likewise.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 7. Size in bytes. (-1, if number is out of range).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 8. File modes, as a string of ten letters or dashes as in ls -l.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 9. t iff file's gid would change if file were deleted and recreated.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 10. inode number.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 11. Device number.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 If file does not exist, returns nil.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
582 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
583 (filename))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 {
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
585 /* This function can GC. GC checked 1997.06.04. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 Lisp_Object values[12];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 Lisp_Object dirname = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 struct stat s;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 char modes[10];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 Lisp_Object handler;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 struct gcpro gcpro1, gcpro2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
593 GCPRO2 (filename, dirname);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 filename = Fexpand_file_name (filename, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 /* If the file name has special constructs in it,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 call the corresponding file handler. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 handler = Ffind_file_name_handler (filename, Qfile_attributes);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 if (!NILP (handler))
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
600 {
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
601 UNGCPRO;
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
602 return call2 (handler, Qfile_attributes, filename);
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
603 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
605 if (lstat ((char *) XSTRING_DATA (filename), &s) < 0)
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
606 {
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
607 UNGCPRO;
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
608 return Qnil;
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
609 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 #ifdef BSD4_2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 dirname = Ffile_name_directory (filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 #ifdef MSDOS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 {
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
617 char *tmpnam = (char *) XSTRING_DATA (Ffile_name_nondirectory (filename));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 int l = strlen (tmpnam);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
620 if (l >= 5
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 && S_ISREG (s.st_mode)
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
622 && (stricmp (&tmpnam[l - 4], ".com") == 0 ||
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
623 stricmp (&tmpnam[l - 4], ".exe") == 0 ||
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
624 stricmp (&tmpnam[l - 4], ".bat") == 0))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 s.st_mode |= S_IEXEC;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 #endif /* MSDOS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 switch (s.st_mode & S_IFMT)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 values[0] = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 case S_IFDIR:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 values[0] = Qt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 #ifdef S_IFLNK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 case S_IFLNK:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 values[0] = Ffile_symlink_p (filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 values[1] = make_int (s.st_nlink);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 values[2] = make_int (s.st_uid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 values[3] = make_int (s.st_gid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 values[4] = wasteful_word_to_lisp (s.st_atime);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 values[5] = wasteful_word_to_lisp (s.st_mtime);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 values[6] = wasteful_word_to_lisp (s.st_ctime);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 values[7] = make_int ((EMACS_INT) s.st_size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 /* If the size is out of range, give back -1. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 /* #### Fix when Emacs gets bignums! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 if (XINT (values[7]) != s.st_size)
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
655 values[7] = make_int (-1);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 filemodestring (&s, modes);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 values[8] = make_string ((Bufbyte *) modes, 10);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 #if defined (BSD4_2) || defined (BSD4_3) /* file gid will be dir gid */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 struct stat sdir;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
662 if (!NILP (dirname) && stat ((char *) XSTRING_DATA (dirname), &sdir) == 0)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 values[9] = (sdir.st_gid != s.st_gid) ? Qt : Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 else /* if we can't tell, assume worst */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 values[9] = Qt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 #else /* file gid will be egid */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 values[9] = (s.st_gid != getegid ()) ? Qt : Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 #endif /* BSD4_2 or BSD4_3 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 values[10] = make_int (s.st_ino);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 values[11] = make_int (s.st_dev);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 return Flist (countof (values), values);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 /* initialization */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 syms_of_dired (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 defsymbol (&Qdirectory_files, "directory-files");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 defsymbol (&Qfile_name_completion, "file-name-completion");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 defsymbol (&Qfile_name_all_completions, "file-name-all-completions");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 defsymbol (&Qfile_attributes, "file-attributes");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
689 DEFSUBR (Fdirectory_files);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
690 DEFSUBR (Ffile_name_completion);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
691 DEFSUBR (Ffile_name_all_completions);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
692 DEFSUBR (Ffile_attributes);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 vars_of_dired (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 DEFVAR_LISP ("completion-ignored-extensions", &Vcompletion_ignored_extensions /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 *Completion ignores filenames ending in any string in this list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 This variable does not affect lists of possible completions,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 but does affect the commands that actually do completions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 It is used by the functions `file-name-completion' and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 `file-name-all-completions'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 Vcompletion_ignored_extensions = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 }