annotate src/dired.c @ 28:1917ad0d78d7 r19-15b97

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