annotate src/dired.c @ 195:a2f645c6b9f8 r20-3b24

Import from CVS: tag r20-3b24
author cvs
date Mon, 13 Aug 2007 09:59:05 +0200
parents 3d6bfa290dbd
children 41ff10fd062f
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
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
43 close_directory_fd (Lisp_Object unwind_obj)
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
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
127 record_unwind_protect (close_directory_fd, make_opaque_ptr ((void *)d));
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
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
154 alloca. However, if the filename is too big
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
155 (meaning MAXNAMLEN lies on the system), we'll use
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
156 a malloced buffer, and free it. */
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
157 if (len > MAXNAMLEN)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
158 {
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
159 cur_statbuf = (char *) xmalloc (name_as_dir_length
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
160 + len + 1);
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
161 memcpy (cur_statbuf, statbuf, name_as_dir_length);
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
162 cur_statbuf_tail = cur_statbuf + name_as_dir_length;
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
163 }
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
164 memcpy (cur_statbuf_tail, dp->d_name, len);
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
165 cur_statbuf_tail [len] = 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
167 if (stat (cur_statbuf, &st) < 0)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 dir_p = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 dir_p = ((st.st_mode & S_IFMT) == S_IFDIR);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
172 if (cur_statbuf != statbuf)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
173 xfree (cur_statbuf);
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
174
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 if (EQ (files_only, Qt) && dir_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 else if (!EQ (files_only, Qt) && !dir_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 if (!NILP (full))
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
182 name = concat2 (name_as_dir,
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
183 make_string ((Bufbyte *)dp->d_name, len));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 else
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
185 name = make_string ((Bufbyte *)dp->d_name, len);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
187 list = Fcons (name, list);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 }
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
191 unbind_to (speccount, Qnil); /* This will close the dir */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 if (!NILP (nosort))
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
193 RETURN_UNGCPRO (list);
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
194 else
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
195 RETURN_UNGCPRO (Fsort (Fnreverse (list), Qstring_lessp));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
198 static Lisp_Object file_name_completion (Lisp_Object file,
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
199 Lisp_Object dirname,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 int all_flag, int ver_flag);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
202 DEFUN ("file-name-completion", Ffile_name_completion, 2, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 Complete file name FILE in directory DIR.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 Returns the longest string common to all filenames in DIR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 that start with FILE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 If there is only one and FILE matches it exactly, returns t.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 Returns nil if DIR contains no name starting with FILE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 Filenames which end with any member of `completion-ignored-extensions'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 are not considered as possible completions for FILE unless there is no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 other possible completion. `completion-ignored-extensions' is not applied
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 to the names of directories.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
213 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
214 (file, dirname))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 {
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
216 /* This function can GC. GC checked 1996.04.06. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 Lisp_Object handler;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 /* If the directory name has special constructs in it,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 call the corresponding file handler. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 handler = Ffind_file_name_handler (dirname, Qfile_name_completion);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 if (!NILP (handler))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 return call3 (handler, Qfile_name_completion, file, dirname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 /* If the file name has special constructs in it,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 call the corresponding file handler. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 handler = Ffind_file_name_handler (file, Qfile_name_completion);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 if (!NILP (handler))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 return call3 (handler, Qfile_name_completion, file, dirname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 return file_name_completion (file, dirname, 0, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
234 DEFUN ("file-name-all-completions", Ffile_name_all_completions, 2, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 Return a list of all completions of file name FILE in directory DIR.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 These are all file names in directory DIR which begin with FILE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 Filenames which end with any member of `completion-ignored-extensions'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 are not considered as possible completions for FILE unless there is no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 other possible completion. `completion-ignored-extensions' is not applied
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 to the names of directories.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
242 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
243 (file, dirname))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 {
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
245 /* This function can GC. GC checked 1997.06.04. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 Lisp_Object handler;
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
247 struct gcpro gcpro1;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
249 GCPRO1 (dirname);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
250 dirname = Fexpand_file_name (dirname, Qnil);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 /* If the file name has special constructs in it,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 call the corresponding file handler. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 handler = Ffind_file_name_handler (dirname, Qfile_name_all_completions);
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
254 UNGCPRO;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 if (!NILP (handler))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 return call3 (handler, Qfile_name_all_completions, file,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 dirname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 return file_name_completion (file, dirname, 1, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 file_name_completion_stat (Lisp_Object dirname, DIRENTRY *dp,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 struct stat *st_addr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 Bytecount len = NAMLEN (dp);
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
267 Bytecount pos = XSTRING_LENGTH (dirname);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 int value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 char *fullname = (char *) alloca (len + pos + 2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
271 memcpy (fullname, XSTRING_DATA (dirname), pos);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 #ifndef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 if (!IS_DIRECTORY_SEP (fullname[pos - 1]))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 fullname[pos++] = DIRECTORY_SEP;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 memcpy (fullname + pos, dp->d_name, len);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 fullname[pos + len] = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 #ifdef S_IFLNK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 /* We want to return success if a link points to a nonexistent file,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 but we want to return the status for what the link points to,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 in case it is a directory. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 value = lstat (fullname, st_addr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 if (S_ISLNK (st_addr->st_mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 stat (fullname, st_addr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 value = stat (fullname, st_addr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 #endif
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 120
diff changeset
290 return value;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 file_name_completion (Lisp_Object file, Lisp_Object dirname, int all_flag,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 int ver_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 DIR *d = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 int matchcount = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 Lisp_Object bestmatch = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 Charcount bestmatchsize = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 struct stat st;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 int passcount;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 int speccount = specpdl_depth ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 Charcount file_name_length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 DIRENTRY *((*readfunc) (DIR *)) = readdir;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 struct gcpro gcpro1, gcpro2, gcpro3;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 GCPRO3 (file, dirname, bestmatch);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 CHECK_STRING (file);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 #ifdef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 /* Filename completion on VMS ignores case, since VMS filesys does. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 specbind (Qcompletion_ignore_case, Qt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 if (ver_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 readfunc = readdirver;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 #endif /* VMS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 #ifdef FILE_SYSTEM_CASE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 file = FILE_SYSTEM_CASE (file);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 dirname = Fexpand_file_name (dirname, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 file_name_length = string_char_length (XSTRING (file));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 /* With passcount = 0, ignore files that end in an ignored extension.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 If nothing found then try again with passcount = 1, don't ignore them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 If looking for all completions, start with passcount = 1,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 so always take even the ignored ones.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 ** It would not actually be helpful to the user to ignore any possible
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 completions when making a list of them.** */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 for (passcount = !!all_flag; NILP (bestmatch) && passcount < 2; passcount++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 {
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
337 d = opendir ((char *) XSTRING_DATA (Fdirectory_file_name (dirname)));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 if (!d)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 report_file_error ("Opening directory", list1 (dirname));
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 dp = (*readfunc) (d);
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 d_name = (Bufbyte *) dp->d_name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 len = NAMLEN (dp);
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
358 cclen = bytecount_to_charcount (d_name, len);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 /* Can't just use QUIT because we have to make sure the file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 descriptor gets closed. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 if (QUITP)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 closedir (d);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 signal_quit ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 if (! DIRENTRY_NONEMPTY (dp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 || cclen < file_name_length
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
370 || 0 <= scmp (d_name, XSTRING_DATA (file), file_name_length))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 if (file_name_completion_stat (dirname, dp, &st) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 directoryp = ((st.st_mode & S_IFMT) == S_IFDIR);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 if (directoryp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 #ifndef TRIVIAL_DIRECTORY_ENTRY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 #define TRIVIAL_DIRECTORY_ENTRY(n) (!strcmp (n, ".") || !strcmp (n, ".."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 /* "." and ".." are never interesting as completions, but are
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
383 actually in the way in a directory containing only one file. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 if (!passcount && TRIVIAL_DIRECTORY_ENTRY (dp->d_name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 /* Compare extensions-to-be-ignored against end of this file name */
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
390 /* if name is not an exact match against specified string. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 if (!passcount && cclen > file_name_length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 Lisp_Object tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 /* and exit this for loop if a match is found */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 for (tem = Vcompletion_ignored_extensions;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 CONSP (tem);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 tem = XCDR (tem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 Lisp_Object elt = XCAR (tem);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 Charcount skip;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 if (!STRINGP (elt)) continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 skip = cclen - string_char_length (XSTRING (elt));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 if (skip < 0) continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 if (0 > scmp (charptr_n_addr (d_name, skip),
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
407 XSTRING_DATA (elt),
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 string_char_length (XSTRING (elt))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 ignored_extension_p = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 /* If an ignored-extensions match was found,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 don't process this name as a completion. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 if (!passcount && ignored_extension_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
422 if (!passcount && regexp_ignore_completion_p (d_name, Qnil, 0, cclen))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 /* Update computation of how much all possible completions match */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 matchcount++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 if (all_flag || NILP (bestmatch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 Lisp_Object name = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 struct gcpro ngcpro1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 NGCPRO1 (name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 /* This is a possible completion */
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
434 name = make_string (d_name, len);
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
435 if (directoryp) /* Completion is a directory; end it with '/' */
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
436 name = Ffile_name_as_directory (name);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 if (all_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 bestmatch = Fcons (name, bestmatch);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 bestmatch = name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 bestmatchsize = string_char_length (XSTRING (name));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 NUNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 Charcount compare = min (bestmatchsize, cclen);
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
451 Bufbyte *p1 = XSTRING_DATA (bestmatch);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 Bufbyte *p2 = d_name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 Charcount matchsize = scmp (p1, p2, compare);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 if (matchsize < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 matchsize = compare;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 if (completion_ignore_case)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 /* If this is an exact match except for case,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 use it as the best match rather than one that is not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 an exact match. This way, we get the case pattern
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 of the actual match. */
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
463 if ((matchsize == cclen
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
464 && matchsize + !!directoryp
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 < string_char_length (XSTRING (bestmatch)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 /* If there is no exact match ignoring case,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 prefer a match that does not change the case
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 of the input. */
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
470 (((matchsize == cclen)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 ==
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
472 (matchsize + !!directoryp
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 == string_char_length (XSTRING (bestmatch))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 /* If there is more than one exact match aside from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 case, and one of them is exact including case,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 prefer that one. */
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
477 && 0 > scmp_1 (p2, XSTRING_DATA (file),
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 file_name_length, 0)
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
479 && 0 <= scmp_1 (p1, XSTRING_DATA (file),
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 file_name_length, 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 {
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
482 bestmatch = make_string (d_name, len);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 if (directoryp)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
484 bestmatch = Ffile_name_as_directory (bestmatch);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 /* If this dirname all matches,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 see if implicit following slash does too. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 if (directoryp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 && compare == matchsize
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 && bestmatchsize > matchsize
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 && IS_ANY_SEP (charptr_emchar_n (p1, matchsize)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 matchsize++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 bestmatchsize = matchsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 closedir (d);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 unbind_to (speccount, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 if (all_flag || NILP (bestmatch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 return bestmatch;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 if (matchcount == 1 && bestmatchsize == file_name_length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 return Qt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 return Fsubstring (bestmatch, make_int (0), make_int (bestmatchsize));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 make_directory_hash_table (char *path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 DIR *d;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 DIRENTRY *dp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 Bytecount len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 Lisp_Object hash = make_lisp_hashtable (100, HASHTABLE_NONWEAK,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 HASHTABLE_EQUAL);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 if ((d = opendir (path)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 while ((dp = readdir (d)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 len = NAMLEN (dp);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 if (DIRENTRY_NONEMPTY (dp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 Fputhash (make_string ((Bufbyte *) dp->d_name, len), Qt, hash);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 closedir (d);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 return hash;
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 #ifdef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
536 DEFUN ("file-name-all-versions", Ffile_name_all_versions, 2, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 Return a list of all versions of file name FILE in directory DIR.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
538 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
539 (file, dirname))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 return file_name_completion (file, dirname, 1, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
545 DEFUN ("file-version-limit", Ffile_version_limit, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 Return the maximum number of versions allowed for FILE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 Returns nil if the file cannot be opened or if there is no version limit.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
548 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
549 (filename))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 Lisp_Object retval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 struct FAB fab;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 struct RAB rab;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 struct XABFHC xabfhc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 int status;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 filename = Fexpand_file_name (filename, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 CHECK_STRING (filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 fab = cc$rms_fab;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 xabfhc = cc$rms_xabfhc;
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
562 fab.fab$l_fna = XSTRING_DATA (filename);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 fab.fab$b_fns = strlen (fab.fab$l_fna);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 fab.fab$l_xab = (char *) &xabfhc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 status = sys$open (&fab, 0, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 if (status != RMS$_NORMAL) /* Probably non-existent file */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 sys$close (&fab, 0, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 if (xabfhc.xab$w_verlimit == 32767)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 return Qnil; /* No version limit */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 return make_int (xabfhc.xab$w_verlimit);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 #endif /* VMS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 wasteful_word_to_lisp (unsigned int item)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 /* Compatibility: in other versions, file-attributes returns a LIST
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 of two 16 bit integers... */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 Lisp_Object cons = word_to_lisp (item);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 XCDR (cons) = Fcons (XCDR (cons), Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 return cons;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
588 DEFUN ("file-attributes", Ffile_attributes, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 Return a list of attributes of file FILENAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 Value is nil if specified file cannot be opened.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 Otherwise, list elements are:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 0. t for directory, string (name linked to) for symbolic link, or nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 1. Number of links to file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 2. File uid.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 3. File gid.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 4. Last access time, as a list of two integers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 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
598 5. Last modification time, likewise.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 6. Last status change time, likewise.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 7. Size in bytes. (-1, if number is out of range).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 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
602 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
603 10. inode number.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 11. Device number.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 If file does not exist, returns nil.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
607 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
608 (filename))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 {
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
610 /* This function can GC. GC checked 1997.06.04. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 Lisp_Object values[12];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 Lisp_Object dirname = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 struct stat s;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 char modes[10];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 Lisp_Object handler;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 struct gcpro gcpro1, gcpro2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
618 GCPRO2 (filename, dirname);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 filename = Fexpand_file_name (filename, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 /* If the file name has special constructs in it,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 call the corresponding file handler. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 handler = Ffind_file_name_handler (filename, Qfile_attributes);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 if (!NILP (handler))
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
625 {
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
626 UNGCPRO;
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
627 return call2 (handler, Qfile_attributes, filename);
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
628 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
630 if (lstat ((char *) XSTRING_DATA (filename), &s) < 0)
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
631 {
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
632 UNGCPRO;
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
633 return Qnil;
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
634 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 #ifdef BSD4_2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 dirname = Ffile_name_directory (filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 #ifdef MSDOS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 {
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
642 char *tmpnam = (char *) XSTRING_DATA (Ffile_name_nondirectory (filename));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 int l = strlen (tmpnam);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
645 if (l >= 5
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 && S_ISREG (s.st_mode)
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
647 && (stricmp (&tmpnam[l - 4], ".com") == 0 ||
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
648 stricmp (&tmpnam[l - 4], ".exe") == 0 ||
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
649 stricmp (&tmpnam[l - 4], ".bat") == 0))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 s.st_mode |= S_IEXEC;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 #endif /* MSDOS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 switch (s.st_mode & S_IFMT)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 values[0] = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 case S_IFDIR:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 values[0] = Qt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 #ifdef S_IFLNK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 case S_IFLNK:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 values[0] = Ffile_symlink_p (filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 values[1] = make_int (s.st_nlink);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 values[2] = make_int (s.st_uid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 values[3] = make_int (s.st_gid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 values[4] = wasteful_word_to_lisp (s.st_atime);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 values[5] = wasteful_word_to_lisp (s.st_mtime);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 values[6] = wasteful_word_to_lisp (s.st_ctime);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 values[7] = make_int ((EMACS_INT) s.st_size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 /* If the size is out of range, give back -1. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 /* #### Fix when Emacs gets bignums! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 if (XINT (values[7]) != s.st_size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 XSETINT (values[7], -1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 filemodestring (&s, modes);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 values[8] = make_string ((Bufbyte *) modes, 10);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 #if defined (BSD4_2) || defined (BSD4_3) /* file gid will be dir gid */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 struct stat sdir;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
687 if (!NILP (dirname) && stat ((char *) XSTRING_DATA (dirname), &sdir) == 0)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 values[9] = (sdir.st_gid != s.st_gid) ? Qt : Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 else /* if we can't tell, assume worst */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 values[9] = Qt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 #else /* file gid will be egid */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 values[9] = (s.st_gid != getegid ()) ? Qt : Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 #endif /* BSD4_2 or BSD4_3 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 values[10] = make_int (s.st_ino);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 values[11] = make_int (s.st_dev);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 return Flist (countof (values), values);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 /* initialization */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 syms_of_dired (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 defsymbol (&Qdirectory_files, "directory-files");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 defsymbol (&Qfile_name_completion, "file-name-completion");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 defsymbol (&Qfile_name_all_completions, "file-name-all-completions");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 defsymbol (&Qfile_attributes, "file-attributes");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
714 DEFSUBR (Fdirectory_files);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
715 DEFSUBR (Ffile_name_completion);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 #ifdef VMS
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
717 DEFSUBR (Ffile_name_all_versions);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
718 DEFSUBR (Ffile_version_limit);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 #endif /* VMS */
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
720 DEFSUBR (Ffile_name_all_completions);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
721 DEFSUBR (Ffile_attributes);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 vars_of_dired (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 DEFVAR_LISP ("completion-ignored-extensions", &Vcompletion_ignored_extensions /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 *Completion ignores filenames ending in any string in this list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 This variable does not affect lists of possible completions,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 but does affect the commands that actually do completions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 It is used by the functions `file-name-completion' and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 `file-name-all-completions'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 Vcompletion_ignored_extensions = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 }