annotate src/dired.c @ 398:74fd4e045ea6 r21-2-29

Import from CVS: tag r21-2-29
author cvs
date Mon, 13 Aug 2007 11:13:30 +0200
parents 6719134a07c2
children 2f8bb876ab1d
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"
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
33 #include "systime.h"
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
34 #include "sysdep.h"
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
35 #include "syspwd.h"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 Lisp_Object Vcompletion_ignored_extensions;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 Lisp_Object Qdirectory_files;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 Lisp_Object Qfile_name_completion;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 Lisp_Object Qfile_name_all_completions;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 Lisp_Object Qfile_attributes;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
43 static Lisp_Object
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 195
diff changeset
44 close_directory_unwind (Lisp_Object unwind_obj)
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
45 {
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
46 DIR *d = (DIR *)get_opaque_ptr (unwind_obj);
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
47 closedir (d);
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
48 free_opaque_ptr (unwind_obj);
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
49 return Qnil;
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
50 }
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
51
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
52 DEFUN ("directory-files", Fdirectory_files, 1, 5, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 Return a list of names of files in DIRECTORY.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 There are four optional arguments:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 If FULL is non-nil, absolute pathnames of the files are returned.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 If MATCH is non-nil, only pathnames containing that regexp are returned.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 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
58 NOSORT is useful if you plan to sort the result yourself.
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
59 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
60 will be returned; subdirectories will be excluded. If FILES-ONLY is not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 nil and not t, then only the subdirectories will be returned. Otherwise,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 if FILES-ONLY is nil (the default) then both files and subdirectories will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 be returned.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
64 */
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
65 (directory, full, match, nosort, files_only))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 {
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
67 /* This function can GC */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 DIR *d;
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
69 Lisp_Object list = Qnil;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
70 Bytecount directorylen;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 Lisp_Object handler;
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 120
diff changeset
72 struct re_pattern_buffer *bufp = NULL;
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
73 int speccount = specpdl_depth ();
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
74 char *statbuf, *statbuf_tail;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
76 struct gcpro gcpro1, gcpro2;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
77 GCPRO2 (directory, list);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 /* If the file name has special constructs in it,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 call the corresponding file handler. */
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
81 handler = Ffind_file_name_handler (directory, Qdirectory_files);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 if (!NILP (handler))
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
83 {
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
84 UNGCPRO;
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
85 if (!NILP (files_only))
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
86 return call6 (handler, Qdirectory_files, directory, full, match,
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
87 nosort, files_only);
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
88 else
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
89 return call5 (handler, Qdirectory_files, directory, full, match,
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
90 nosort);
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
91 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
93 /* #### why do we do Fexpand_file_name after file handlers here,
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
94 but earlier everywhere else? */
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
95 directory = Fexpand_file_name (directory, Qnil);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
96 directory = Ffile_name_as_directory (directory);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
97 directorylen = XSTRING_LENGTH (directory);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
99 statbuf = (char *)alloca (directorylen + MAXNAMLEN + 1);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
100 memcpy (statbuf, XSTRING_DATA (directory), directorylen);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
101 statbuf_tail = statbuf + directorylen;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 /* XEmacs: this should come after Ffile_name_as_directory() to avoid
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
104 potential regexp cache smashage. It comes before the opendir()
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
105 because it might signal an error. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 if (!NILP (match))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 CHECK_STRING (match);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 /* MATCH might be a flawed regular expression. Rather than
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 catching and signalling our own errors, we just call
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 compile_pattern to do the work for us. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 bufp = compile_pattern (match, 0, 0, 0, ERROR_ME);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 /* Now *bufp is the compiled form of MATCH; don't call anything
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 which might compile a new regexp until we're done with the loop! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
119 /* Do this opendir after anything which might signal an error.
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
120 NOTE: the above comment is old; previously, there was no
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
121 unwind-protection in case of error, but now there is. */
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
122 d = opendir ((char *) XSTRING_DATA (directory));
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
123 if (!d)
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
124 report_file_error ("Opening directory", list1 (directory));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 195
diff changeset
126 record_unwind_protect (close_directory_unwind, make_opaque_ptr ((void *)d));
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
127
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 /* Loop reading blocks */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 DIRENTRY *dp = readdir (d);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 int len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
134 if (!dp)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
135 break;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 len = NAMLEN (dp);
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
137 if (DIRENTRY_NONEMPTY (dp)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
138 && (NILP (match)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
139 || (0 <= re_search (bufp, dp->d_name, len, 0, len, 0))))
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 if (!NILP (files_only))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 {
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
143 struct stat st;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
144 int dir_p = 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
146 memcpy (statbuf_tail, dp->d_name, len);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
147 statbuf_tail[len] = 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
149 if (stat (statbuf, &st) == 0
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
150 && (st.st_mode & S_IFMT) == S_IFDIR)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
151 dir_p = 1;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
153 if (EQ (files_only, Qt) && dir_p)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
154 continue;
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
155 else if (!EQ (files_only, Qt) && !dir_p)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
156 continue;
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
157 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
159 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
160 Lisp_Object name =
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 382
diff changeset
161 make_string ((Bufbyte *)dp->d_name, len);
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
162 if (!NILP (full))
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
163 name = concat2 (directory, name);
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
164
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
165 list = Fcons (name, list);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
166 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 }
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
169 unbind_to (speccount, Qnil); /* This will close the dir */
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
170
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
171 if (NILP (nosort))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
172 list = Fsort (Fnreverse (list), Qstring_lessp);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
173
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
174 RETURN_UNGCPRO (list);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
177 static Lisp_Object file_name_completion (Lisp_Object file,
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
178 Lisp_Object directory,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 int all_flag, int ver_flag);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
181 DEFUN ("file-name-completion", Ffile_name_completion, 2, 2, 0, /*
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
182 Complete file name FILE in directory DIRECTORY.
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
183 Returns the longest string common to all filenames in DIRECTORY
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 that start with FILE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 If there is only one and FILE matches it exactly, returns t.
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
186 Returns nil if DIRECTORY contains no name starting with FILE.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 Filenames which end with any member of `completion-ignored-extensions'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 are not considered as possible completions for FILE unless there is no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 other possible completion. `completion-ignored-extensions' is not applied
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 to the names of directories.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
192 */
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
193 (file, directory))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 {
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
195 /* This function can GC. GC checked 1996.04.06. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 Lisp_Object handler;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 /* If the directory name has special constructs in it,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 call the corresponding file handler. */
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
200 handler = Ffind_file_name_handler (directory, Qfile_name_completion);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 if (!NILP (handler))
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
202 return call3 (handler, Qfile_name_completion, file, directory);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 /* If the file name has special constructs in it,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 call the corresponding file handler. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 handler = Ffind_file_name_handler (file, Qfile_name_completion);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 if (!NILP (handler))
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
208 return call3 (handler, Qfile_name_completion, file, directory);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
210 return file_name_completion (file, directory, 0, 0);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
213 DEFUN ("file-name-all-completions", Ffile_name_all_completions, 2, 2, 0, /*
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
214 Return a list of all completions of file name FILE in directory DIRECTORY.
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
215 These are all file names in directory DIRECTORY which begin with FILE.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
217 File names which end with any member of `completion-ignored-extensions'
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 are not considered as possible completions for FILE unless there is no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 other possible completion. `completion-ignored-extensions' is not applied
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 to the names of directories.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
221 */
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
222 (file, directory))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 {
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
224 /* This function can GC. GC checked 1997.06.04. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 Lisp_Object handler;
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
226 struct gcpro gcpro1;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
228 GCPRO1 (directory);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
229 directory = Fexpand_file_name (directory, Qnil);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 /* If the file name has special constructs in it,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 call the corresponding file handler. */
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
232 handler = Ffind_file_name_handler (directory, Qfile_name_all_completions);
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
233 UNGCPRO;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 if (!NILP (handler))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 return call3 (handler, Qfile_name_all_completions, file,
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
236 directory);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
238 return file_name_completion (file, directory, 1, 0);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 static int
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
242 file_name_completion_stat (Lisp_Object directory, DIRENTRY *dp,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 struct stat *st_addr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 Bytecount len = NAMLEN (dp);
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
246 Bytecount pos = XSTRING_LENGTH (directory);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 int value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 char *fullname = (char *) alloca (len + pos + 2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
250 memcpy (fullname, XSTRING_DATA (directory), pos);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 if (!IS_DIRECTORY_SEP (fullname[pos - 1]))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 fullname[pos++] = DIRECTORY_SEP;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 memcpy (fullname + pos, dp->d_name, len);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 fullname[pos + len] = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 #ifdef S_IFLNK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 /* We want to return success if a link points to a nonexistent file,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 but we want to return the status for what the link points to,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 in case it is a directory. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 value = lstat (fullname, st_addr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 if (S_ISLNK (st_addr->st_mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 stat (fullname, st_addr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 value = stat (fullname, st_addr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 #endif
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 120
diff changeset
267 return value;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 static Lisp_Object
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
271 file_name_completion_unwind (Lisp_Object locative)
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
272 {
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
273 DIR *d;
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
274 Lisp_Object obj = XCAR (locative);
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
275
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
276 if (!NILP (obj))
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
277 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
278 d = (DIR *)get_opaque_ptr (obj);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
279 closedir (d);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
280 free_opaque_ptr (obj);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
281 }
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
282 free_cons (XCONS (locative));
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
283 return Qnil;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
284 }
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
285
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
286 static Lisp_Object
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
287 file_name_completion (Lisp_Object file, Lisp_Object directory, int all_flag,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 int ver_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 DIR *d = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 int matchcount = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 Lisp_Object bestmatch = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 Charcount bestmatchsize = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 struct stat st;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 int passcount;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 int speccount = specpdl_depth ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 Charcount file_name_length;
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
299 Lisp_Object locative;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 struct gcpro gcpro1, gcpro2, gcpro3;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
302 GCPRO3 (file, directory, bestmatch);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 CHECK_STRING (file);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
306 #ifdef WINDOWSNT
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
307 /* Filename completion on Windows ignores case, since Windows
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
308 filesystems do. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 specbind (Qcompletion_ignore_case, Qt);
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
310 #endif /* WINDOWSNT */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 #ifdef FILE_SYSTEM_CASE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 file = FILE_SYSTEM_CASE (file);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 #endif
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
315 directory = Fexpand_file_name (directory, Qnil);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
316 file_name_length = XSTRING_CHAR_LENGTH (file);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 /* With passcount = 0, ignore files that end in an ignored extension.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 If nothing found then try again with passcount = 1, don't ignore them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 If looking for all completions, start with passcount = 1,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 so always take even the ignored ones.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 ** It would not actually be helpful to the user to ignore any possible
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 completions when making a list of them.** */
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 /* We cannot use close_directory_unwind() because we change the
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
327 directory. The old code used to just avoid signaling errors, and
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
328 call closedir, but it was wrong, because it made sane handling of
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
329 QUIT impossible and, besides, various utility functions like
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
330 regexp_ignore_completion_p can signal errors. */
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
331 locative = noseeum_cons (Qnil, Qnil);
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
332 record_unwind_protect (file_name_completion_unwind, locative);
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
333
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 for (passcount = !!all_flag; NILP (bestmatch) && passcount < 2; passcount++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 {
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
336 d = opendir ((char *) XSTRING_DATA (Fdirectory_file_name (directory)));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 if (!d)
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
338 report_file_error ("Opening directory", list1 (directory));
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
339 XCAR (locative) = make_opaque_ptr ((void *)d);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 /* Loop reading blocks */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 DIRENTRY *dp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 Bytecount len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 /* scmp() works in characters, not bytes, so we have to compute
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 this value: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 Charcount cclen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 int directoryp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 int ignored_extension_p = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 Bufbyte *d_name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
353 dp = readdir (d);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 if (!dp) break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
356 /* Cast to Bufbyte* is OK, as readdir() Mule-encapsulates. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 d_name = (Bufbyte *) dp->d_name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 len = NAMLEN (dp);
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
359 cclen = bytecount_to_charcount (d_name, len);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
361 QUIT;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 if (! DIRENTRY_NONEMPTY (dp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 || cclen < file_name_length
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
365 || 0 <= scmp (d_name, XSTRING_DATA (file), file_name_length))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
368 if (file_name_completion_stat (directory, dp, &st) < 0)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 directoryp = ((st.st_mode & S_IFMT) == S_IFDIR);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 if (directoryp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 #ifndef TRIVIAL_DIRECTORY_ENTRY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 #define TRIVIAL_DIRECTORY_ENTRY(n) (!strcmp (n, ".") || !strcmp (n, ".."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 /* "." and ".." are never interesting as completions, but are
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
378 actually in the way in a directory containing only one file. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 if (!passcount && TRIVIAL_DIRECTORY_ENTRY (dp->d_name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 /* Compare extensions-to-be-ignored against end of this file name */
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
385 /* if name is not an exact match against specified string. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 if (!passcount && cclen > file_name_length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 Lisp_Object tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 /* and exit this for loop if a match is found */
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
390 EXTERNAL_LIST_LOOP (tem, Vcompletion_ignored_extensions)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 Lisp_Object elt = XCAR (tem);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 Charcount skip;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
395 CHECK_STRING (elt);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
396
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
397 skip = cclen - XSTRING_CHAR_LENGTH (elt);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 if (skip < 0) continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 if (0 > scmp (charptr_n_addr (d_name, skip),
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
401 XSTRING_DATA (elt),
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
402 XSTRING_CHAR_LENGTH (elt)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 ignored_extension_p = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 /* If an ignored-extensions match was found,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 don't process this name as a completion. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 if (!passcount && ignored_extension_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
416 if (!passcount && regexp_ignore_completion_p (d_name, Qnil, 0, cclen))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 /* Update computation of how much all possible completions match */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 matchcount++;
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 (all_flag || NILP (bestmatch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 Lisp_Object name = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 struct gcpro ngcpro1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 NGCPRO1 (name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 /* This is a possible completion */
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
428 name = make_string (d_name, len);
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
429 if (directoryp) /* Completion is a directory; end it with '/' */
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
430 name = Ffile_name_as_directory (name);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 if (all_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 bestmatch = Fcons (name, bestmatch);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 bestmatch = name;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
438 bestmatchsize = XSTRING_CHAR_LENGTH (name);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 NUNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 Charcount compare = min (bestmatchsize, cclen);
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
445 Bufbyte *p1 = XSTRING_DATA (bestmatch);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 Bufbyte *p2 = d_name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 Charcount matchsize = scmp (p1, p2, compare);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 if (matchsize < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 matchsize = compare;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 if (completion_ignore_case)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 /* If this is an exact match except for case,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 use it as the best match rather than one that is not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 an exact match. This way, we get the case pattern
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 of the actual match. */
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
457 if ((matchsize == cclen
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
458 && matchsize + !!directoryp
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
459 < XSTRING_CHAR_LENGTH (bestmatch))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 /* If there is no exact match ignoring case,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 prefer a match that does not change the case
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 of the input. */
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
464 (((matchsize == cclen)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 ==
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
466 (matchsize + !!directoryp
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
467 == XSTRING_CHAR_LENGTH (bestmatch)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 /* If there is more than one exact match aside from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 case, and one of them is exact including case,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 prefer that one. */
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
471 && 0 > scmp_1 (p2, XSTRING_DATA (file),
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 file_name_length, 0)
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
473 && 0 <= scmp_1 (p1, XSTRING_DATA (file),
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 file_name_length, 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 {
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
476 bestmatch = make_string (d_name, len);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 if (directoryp)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
478 bestmatch = Ffile_name_as_directory (bestmatch);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
482 /* If this directory all matches,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 see if implicit following slash does too. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 if (directoryp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 && compare == matchsize
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 && bestmatchsize > matchsize
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 && IS_ANY_SEP (charptr_emchar_n (p1, matchsize)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 matchsize++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 bestmatchsize = matchsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 closedir (d);
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
493 free_opaque_ptr (XCAR (locative));
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 263
diff changeset
494 XCAR (locative) = Qnil;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 unbind_to (speccount, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 if (all_flag || NILP (bestmatch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 return bestmatch;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 if (matchcount == 1 && bestmatchsize == file_name_length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 return Qt;
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 219
diff changeset
505 return Fsubstring (bestmatch, Qzero, make_int (bestmatchsize));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
509
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
510 /* The *pwent() functions do not exist on NT */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
511 #ifndef WINDOWSNT
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
512
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
513 static Lisp_Object user_name_completion (Lisp_Object user,
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
514 int all_flag,
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
515 int *uniq);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
516
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
517 DEFUN ("user-name-completion", Fuser_name_completion, 1, 1, 0, /*
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
518 Complete user name USER.
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
519
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
520 Returns the longest string common to all user names that start
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
521 with USER. If there is only one and USER matches it exactly,
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
522 returns t. Returns nil if there is no user name starting with USER.
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
523 */
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
524 (user))
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
525 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
526 return user_name_completion (user, 0, NULL);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
527 }
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
528
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
529 DEFUN ("user-name-completion-1", Fuser_name_completion_1, 1, 1, 0, /*
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
530 Complete user name USER.
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
531
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
532 This function is identical to `user-name-completion', except that
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
533 the cons of the completion and an indication of whether the
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
534 completion was unique is returned.
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
535
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
536 The car of the returned value is the longest string common to all
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
537 user names that start with USER. If there is only one and USER
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
538 matches it exactly, the car is t. The car is nil if there is no
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
539 user name starting with USER. The cdr of the result is non-nil
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
540 if and only if the completion returned in the car was unique.
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
541 */
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
542 (user))
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
543 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
544 int uniq;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
545 Lisp_Object completed = user_name_completion (user, 0, &uniq);
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
546 return Fcons (completed, uniq ? Qt : Qnil);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
547 }
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
548
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
549 DEFUN ("user-name-all-completions", Fuser_name_all_completions, 1, 1, 0, /*
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
550 Return a list of all completions of user name USER.
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
551 These are all user names which begin with USER.
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
552 */
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
553 (user))
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
554 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
555 return user_name_completion (user, 1, NULL);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
556 }
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
557
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
558 struct user_name
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
559 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
560 Bufbyte *ptr;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
561 size_t len;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
562 };
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
563
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
564 struct user_cache
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
565 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
566 struct user_name *user_names;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
567 int length;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
568 int size;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
569 EMACS_TIME last_rebuild_time;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
570 };
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
571 static struct user_cache user_cache;
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
572
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
573 static void
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
574 free_user_cache (struct user_cache *cache)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
575 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
576 int i;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
577 for (i = 0; i < cache->length; i++)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
578 xfree (cache->user_names[i].ptr);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
579 xfree (cache->user_names);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
580 xzero (*cache);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
581 }
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
582
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
583 static Lisp_Object
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
584 user_name_completion_unwind (Lisp_Object cache_incomplete_p)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
585 {
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
586 endpwent ();
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
587 speed_up_interrupts ();
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
588
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
589 if (! NILP (XCAR (cache_incomplete_p)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
590 free_user_cache (&user_cache);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
591
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
592 free_cons (XCONS (cache_incomplete_p));
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
593
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
594 return Qnil;
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
595 }
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
596
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
597 #define USER_CACHE_TTL (24*60*60) /* Time to live: 1 day, in seconds */
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
598
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
599 static Lisp_Object
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
600 user_name_completion (Lisp_Object user, int all_flag, int *uniq)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
601 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
602 /* This function can GC */
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
603 int matchcount = 0;
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
604 Lisp_Object bestmatch = Qnil;
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
605 Charcount bestmatchsize = 0;
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
606 Charcount user_name_length;
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
607 EMACS_TIME t;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
608 int i;
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
609 struct gcpro gcpro1, gcpro2;
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
610
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
611 GCPRO2 (user, bestmatch);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
612
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
613 CHECK_STRING (user);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
614
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
615 user_name_length = XSTRING_CHAR_LENGTH (user);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
616
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
617 /* Cache user name lookups because it tends to be quite slow.
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
618 * Rebuild the cache occasionally to catch changes */
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
619 EMACS_GET_TIME (t);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
620 if (user_cache.user_names &&
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
621 (EMACS_SECS (t) - EMACS_SECS (user_cache.last_rebuild_time)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
622 > USER_CACHE_TTL))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
623 free_user_cache (&user_cache);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
624
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
625 if (!user_cache.user_names)
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
626 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
627 struct passwd *pwd;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
628 Lisp_Object cache_incomplete_p = noseeum_cons (Qt, Qnil);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
629 int speccount = specpdl_depth ();
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
630
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
631 slow_down_interrupts ();
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
632 setpwent ();
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
633 record_unwind_protect (user_name_completion_unwind, cache_incomplete_p);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
634 while ((pwd = getpwent ()))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
635 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
636 QUIT;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
637 DO_REALLOC (user_cache.user_names, user_cache.size,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
638 user_cache.length + 1, struct user_name);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
639 TO_INTERNAL_FORMAT (C_STRING, pwd->pw_name,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
640 MALLOC,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
641 (user_cache.user_names[user_cache.length].ptr,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
642 user_cache.user_names[user_cache.length].len),
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
643 Qnative);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
644 user_cache.length++;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
645 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
646 XCAR (cache_incomplete_p) = Qnil;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
647 unbind_to (speccount, Qnil);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
648
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
649 EMACS_GET_TIME (user_cache.last_rebuild_time);
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
650 }
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
651
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
652 for (i = 0; i < user_cache.length; i++)
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
653 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
654 Bufbyte *u_name = user_cache.user_names[i].ptr;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
655 Bytecount len = user_cache.user_names[i].len;
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
656 /* scmp() works in chars, not bytes, so we have to compute this: */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
657 Charcount cclen = bytecount_to_charcount (u_name, len);
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
658
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
659 QUIT;
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
660
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
661 if (cclen < user_name_length
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
662 || 0 <= scmp_1 (u_name, XSTRING_DATA (user), user_name_length, 0))
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
663 continue;
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
664
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
665 matchcount++; /* count matching completions */
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
666
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
667 if (all_flag || NILP (bestmatch))
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
668 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
669 Lisp_Object name = Qnil;
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
670 struct gcpro ngcpro1;
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
671 NGCPRO1 (name);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
672 /* This is a possible completion */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
673 name = make_string (u_name, len);
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
674 if (all_flag)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
675 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
676 bestmatch = Fcons (name, bestmatch);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
677 }
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
678 else
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
679 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
680 bestmatch = name;
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
681 bestmatchsize = XSTRING_CHAR_LENGTH (name);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
682 }
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
683 NUNGCPRO;
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
684 }
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
685 else
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
686 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
687 Charcount compare = min (bestmatchsize, cclen);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
688 Bufbyte *p1 = XSTRING_DATA (bestmatch);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
689 Bufbyte *p2 = u_name;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
690 Charcount matchsize = scmp_1 (p1, p2, compare, 0);
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
691
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
692 if (matchsize < 0)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
693 matchsize = compare;
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
694
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
695 bestmatchsize = matchsize;
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
696 }
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
697 }
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
698
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
699 UNGCPRO;
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
700
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
701 if (uniq)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
702 *uniq = (matchcount == 1);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
703
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
704 if (all_flag || NILP (bestmatch))
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
705 return bestmatch;
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
706 if (matchcount == 1 && bestmatchsize == user_name_length)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
707 return Qt;
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
708 return Fsubstring (bestmatch, Qzero, make_int (bestmatchsize));
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
709 }
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
710 #endif /* ! defined WINDOWSNT */
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
711
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
712
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 Lisp_Object
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
714 make_directory_hash_table (const char *path)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 DIR *d;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 if ((d = opendir (path)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 {
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 276
diff changeset
719 DIRENTRY *dp;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
720 Lisp_Object hash =
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
721 make_lisp_hash_table (20, HASH_TABLE_NON_WEAK, HASH_TABLE_EQUAL);
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 276
diff changeset
722
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 while ((dp = readdir (d)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 {
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 276
diff changeset
725 Bytecount len = NAMLEN (dp);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 if (DIRENTRY_NONEMPTY (dp))
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
727 /* Cast to Bufbyte* is OK, as readdir() Mule-encapsulates. */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
728 Fputhash (make_string ((Bufbyte *) dp->d_name, len), Qt, hash);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 closedir (d);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
731 return hash;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 }
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
733 else
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
734 return Qnil;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 wasteful_word_to_lisp (unsigned int item)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 /* Compatibility: in other versions, file-attributes returns a LIST
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 of two 16 bit integers... */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 Lisp_Object cons = word_to_lisp (item);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 XCDR (cons) = Fcons (XCDR (cons), Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 return cons;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
747 DEFUN ("file-attributes", Ffile_attributes, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 Return a list of attributes of file FILENAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 Value is nil if specified file cannot be opened.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 Otherwise, list elements are:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 0. t for directory, string (name linked to) for symbolic link, or nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 1. Number of links to file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 2. File uid.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 3. File gid.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 4. Last access time, as a list of two integers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 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
757 5. Last modification time, likewise.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 6. Last status change time, likewise.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 7. Size in bytes. (-1, if number is out of range).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 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
761 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
762 10. inode number.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 11. Device number.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 If file does not exist, returns nil.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
766 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
767 (filename))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 {
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
769 /* This function can GC. GC checked 1997.06.04. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 Lisp_Object values[12];
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
771 Lisp_Object directory = Qnil;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 struct stat s;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 char modes[10];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 Lisp_Object handler;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 struct gcpro gcpro1, gcpro2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
777 GCPRO2 (filename, directory);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 filename = Fexpand_file_name (filename, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 /* If the file name has special constructs in it,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 call the corresponding file handler. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 handler = Ffind_file_name_handler (filename, Qfile_attributes);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 if (!NILP (handler))
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
784 {
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
785 UNGCPRO;
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
786 return call2 (handler, Qfile_attributes, filename);
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
787 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
789 if (lstat ((char *) XSTRING_DATA (filename), &s) < 0)
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
790 {
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
791 UNGCPRO;
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
792 return Qnil;
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
793 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 #ifdef BSD4_2
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
796 directory = Ffile_name_directory (filename);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 #ifdef MSDOS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 {
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
801 char *tmpnam = (char *) XSTRING_DATA (Ffile_name_nondirectory (filename));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 int l = strlen (tmpnam);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
804 if (l >= 5
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 && S_ISREG (s.st_mode)
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
806 && (stricmp (&tmpnam[l - 4], ".com") == 0 ||
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
807 stricmp (&tmpnam[l - 4], ".exe") == 0 ||
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
808 stricmp (&tmpnam[l - 4], ".bat") == 0))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 s.st_mode |= S_IEXEC;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 #endif /* MSDOS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 switch (s.st_mode & S_IFMT)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 values[0] = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 case S_IFDIR:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 values[0] = Qt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 #ifdef S_IFLNK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 case S_IFLNK:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 values[0] = Ffile_symlink_p (filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 values[1] = make_int (s.st_nlink);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 values[2] = make_int (s.st_uid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 values[3] = make_int (s.st_gid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 values[4] = wasteful_word_to_lisp (s.st_atime);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 values[5] = wasteful_word_to_lisp (s.st_mtime);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 values[6] = wasteful_word_to_lisp (s.st_ctime);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 values[7] = make_int ((EMACS_INT) s.st_size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 /* If the size is out of range, give back -1. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 /* #### Fix when Emacs gets bignums! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 if (XINT (values[7]) != s.st_size)
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
839 values[7] = make_int (-1);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 filemodestring (&s, modes);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 values[8] = make_string ((Bufbyte *) modes, 10);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 #if defined (BSD4_2) || defined (BSD4_3) /* file gid will be dir gid */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 struct stat sdir;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 384
diff changeset
846 if (!NILP (directory) && stat ((char *) XSTRING_DATA (directory), &sdir) == 0)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 values[9] = (sdir.st_gid != s.st_gid) ? Qt : Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 else /* if we can't tell, assume worst */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 values[9] = Qt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 #else /* file gid will be egid */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 values[9] = (s.st_gid != getegid ()) ? Qt : Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 #endif /* BSD4_2 or BSD4_3 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 values[10] = make_int (s.st_ino);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 values[11] = make_int (s.st_dev);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 return Flist (countof (values), values);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 /* initialization */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 syms_of_dired (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 defsymbol (&Qdirectory_files, "directory-files");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 defsymbol (&Qfile_name_completion, "file-name-completion");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 defsymbol (&Qfile_name_all_completions, "file-name-all-completions");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 defsymbol (&Qfile_attributes, "file-attributes");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
873 DEFSUBR (Fdirectory_files);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
874 DEFSUBR (Ffile_name_completion);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
875 DEFSUBR (Ffile_name_all_completions);
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
876 #ifndef WINDOWSNT
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
877 DEFSUBR (Fuser_name_completion);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
878 DEFSUBR (Fuser_name_completion_1);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 280
diff changeset
879 DEFSUBR (Fuser_name_all_completions);
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
880 #endif
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
881 DEFSUBR (Ffile_attributes);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 vars_of_dired (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 DEFVAR_LISP ("completion-ignored-extensions", &Vcompletion_ignored_extensions /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 *Completion ignores filenames ending in any string in this list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 This variable does not affect lists of possible completions,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 but does affect the commands that actually do completions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 It is used by the functions `file-name-completion' and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 `file-name-all-completions'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 Vcompletion_ignored_extensions = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 }