annotate src/dired.c @ 227:0e522484dd2a r20-5b12

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