annotate src/dired.c @ 0:376386a54a3c r19-14

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