annotate src/dired.c @ 5314:596011a8bf8f

= < > <= >=: it's OK to use the compiler macro when first, last args side effect 2010-12-29 Aidan Kehoe <kehoea@parhasard.net> * cl-macs.el (= < > <= >=): For these functions' compiler macros, the optimisation is safe even if the first and the last arguments have side effects, since they're only used the once.
author Aidan Kehoe <kehoea@parhasard.net>
date Wed, 29 Dec 2010 23:47:30 +0000
parents cdca98f2d36f
children 94bbd4792049 2aa9cd456ae7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 /* Lisp functions for making directory listings.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 Copyright (C) 1985, 1986, 1992, 1993, 1994 Free Software Foundation, Inc.
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3 Copyright (C) 2001, 2002 Ben Wing.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 /* Synched up with: FSF 19.30. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 #include "lisp.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 #include "buffer.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 #include "commands.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 #include "elhash.h"
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 771
diff changeset
30 #include "opaque.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 #include "regex.h"
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
32 #include "syntax.h"
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 771
diff changeset
33 #include "sysdep.h"
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 771
diff changeset
34
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 771
diff changeset
35 #include "sysdir.h"
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 771
diff changeset
36 #include "sysfile.h"
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 771
diff changeset
37 #include "syspwd.h"
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 771
diff changeset
38 #include "systime.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39
528
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
40 #ifdef WIN32_NATIVE
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
41 #include "syswindows.h"
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
42 #endif
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
43
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 Lisp_Object Vcompletion_ignored_extensions;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 Lisp_Object Qdirectory_files;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 Lisp_Object Qfile_name_completion;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 Lisp_Object Qfile_name_all_completions;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 Lisp_Object Qfile_attributes;
5211
cdca98f2d36f Move `default-file-system-ignore-case' to C; fix bug in directory hash tables
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
49 Lisp_Object Qfile_system_ignore_case_p;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 close_directory_unwind (Lisp_Object unwind_obj)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 DIR *d = (DIR *)get_opaque_ptr (unwind_obj);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
55 qxe_closedir (d);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 free_opaque_ptr (unwind_obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 DEFUN ("directory-files", Fdirectory_files, 1, 5, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 Return a list of names of files in DIRECTORY.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 There are four optional arguments:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 If FULL is non-nil, absolute pathnames of the files are returned.
2297
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 2286
diff changeset
64 If MATCH is non-nil, only pathnames whose basename contain that regexp are
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 2286
diff changeset
65 returned.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 If NOSORT is non-nil, the list is not sorted--its order is unpredictable.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 NOSORT is useful if you plan to sort the result yourself.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 If FILES-ONLY is the symbol t, then only the "files" in the directory
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 will be returned; subdirectories will be excluded. If FILES-ONLY is not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 nil and not t, then only the subdirectories will be returned. Otherwise,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 if FILES-ONLY is nil (the default) then both files and subdirectories will
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 be returned.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 (directory, full, match, nosort, files_only))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 DIR *d;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 Lisp_Object list = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 Bytecount directorylen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 Lisp_Object handler;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 struct re_pattern_buffer *bufp = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 int speccount = specpdl_depth ();
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
83 Ibyte *statbuf, *statbuf_tail;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 struct gcpro gcpro1, gcpro2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 GCPRO2 (directory, list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 /* If the file name has special constructs in it,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 call the corresponding file handler. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 handler = Ffind_file_name_handler (directory, Qdirectory_files);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 if (!NILP (handler))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 if (!NILP (files_only))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 return call6 (handler, Qdirectory_files, directory, full, match,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 nosort, files_only);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 return call5 (handler, Qdirectory_files, directory, full, match,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 nosort);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 /* #### why do we do Fexpand_file_name after file handlers here,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 but earlier everywhere else? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 directory = Fexpand_file_name (directory, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 directory = Ffile_name_as_directory (directory);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 directorylen = XSTRING_LENGTH (directory);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
108 statbuf = alloca_ibytes (directorylen + MAXNAMLEN + 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 memcpy (statbuf, XSTRING_DATA (directory), directorylen);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 statbuf_tail = statbuf + directorylen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 /* XEmacs: this should come after Ffile_name_as_directory() to avoid
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 potential regexp cache smashage. It comes before the opendir()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 because it might signal an error. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 if (!NILP (match))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 CHECK_STRING (match);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 /* MATCH might be a flawed regular expression. Rather than
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 catching and signalling our own errors, we just call
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 compile_pattern to do the work for us. */
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
122 bufp = compile_pattern (match, 0, Qnil, Qnil, 0, 0, ERROR_ME);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 /* Now *bufp is the compiled form of MATCH; don't call anything
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 which might compile a new regexp until we're done with the loop! */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 /* Do this opendir after anything which might signal an error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 NOTE: the above comment is old; previously, there was no
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 unwind-protection in case of error, but now there is. */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
131 d = qxe_opendir (XSTRING_DATA (directory));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 if (!d)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 546
diff changeset
133 report_file_error ("Opening directory", directory);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 record_unwind_protect (close_directory_unwind, make_opaque_ptr ((void *)d));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 /* Loop reading blocks */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
140 DIRENTRY *dp = qxe_readdir (d);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 int len;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
142 struct syntax_cache scache_struct;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
143 struct syntax_cache *scache = &scache_struct;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 if (!dp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 len = NAMLEN (dp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 if (DIRENTRY_NONEMPTY (dp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 && (NILP (match)
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
150 || (0 <= re_search (bufp, dp->d_name, len, 0, len, 0, Qnil, 0,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
151 scache))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 if (!NILP (files_only))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 struct stat st;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 int dir_p = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 memcpy (statbuf_tail, dp->d_name, len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 statbuf_tail[len] = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
161 if (qxe_stat (statbuf, &st) == 0
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 && (st.st_mode & S_IFMT) == S_IFDIR)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 dir_p = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 if (EQ (files_only, Qt) && dir_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 else if (!EQ (files_only, Qt) && !dir_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 Lisp_Object name =
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
173 make_string ((Ibyte *)dp->d_name, len);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 if (!NILP (full))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 name = concat2 (directory, name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 list = Fcons (name, list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
181 unbind_to (speccount); /* This will close the dir */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 if (NILP (nosort))
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5089
diff changeset
184 list = list_sort (Fnreverse (list), NULL, Qstring_lessp, Qidentity);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 RETURN_UNGCPRO (list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 static Lisp_Object file_name_completion (Lisp_Object file,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 Lisp_Object directory,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 int all_flag, int ver_flag);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 DEFUN ("file-name-completion", Ffile_name_completion, 2, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
194 Complete file name PARTIAL-FILENAME in directory DIRECTORY.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
195 Return the longest prefix common to all file names in DIRECTORY
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
196 that start with PARTIAL-FILENAME.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
197 If there is only one and PARTIAL-FILENAME matches it exactly, return t.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
198 Return nil if DIRECTORY contains no name starting with PARTIAL-FILENAME.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
200 File names which end with any member of `completion-ignored-extensions'
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
201 are not considered as possible completions for PARTIAL-FILENAME unless
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
202 there is no other possible completion. `completion-ignored-extensions'
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
203 is not applied to the names of directories.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
205 (partial_filename, directory))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 /* This function can GC. GC checked 1996.04.06. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 Lisp_Object handler;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 /* If the directory name has special constructs in it,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 call the corresponding file handler. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 handler = Ffind_file_name_handler (directory, Qfile_name_completion);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 if (!NILP (handler))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
214 return call3 (handler, Qfile_name_completion, partial_filename, directory);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 /* If the file name has special constructs in it,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 call the corresponding file handler. */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
218 handler = Ffind_file_name_handler (partial_filename, Qfile_name_completion);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 if (!NILP (handler))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
220 return call3 (handler, Qfile_name_completion, partial_filename, directory);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
222 return file_name_completion (partial_filename, directory, 0, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 DEFUN ("file-name-all-completions", Ffile_name_all_completions, 2, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
226 Return a list of all completions of PARTIAL-FILENAME in DIRECTORY.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
227 These are all file names in DIRECTORY which begin with PARTIAL-FILENAME.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
229 (partial_filename, directory))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 /* This function can GC. GC checked 1997.06.04. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 Lisp_Object handler;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 struct gcpro gcpro1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 GCPRO1 (directory);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 directory = Fexpand_file_name (directory, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 /* If the file name has special constructs in it,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 call the corresponding file handler. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 handler = Ffind_file_name_handler (directory, Qfile_name_all_completions);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 if (!NILP (handler))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
242 return call3 (handler, Qfile_name_all_completions, partial_filename,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 directory);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
245 return file_name_completion (partial_filename, directory, 1, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 file_name_completion_stat (Lisp_Object directory, DIRENTRY *dp,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 struct stat *st_addr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 Bytecount len = NAMLEN (dp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 Bytecount pos = XSTRING_LENGTH (directory);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 int value;
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
255 Ibyte *fullname = alloca_ibytes (len + pos + 2);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 memcpy (fullname, XSTRING_DATA (directory), pos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 if (!IS_DIRECTORY_SEP (fullname[pos - 1]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 fullname[pos++] = DIRECTORY_SEP;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 memcpy (fullname + pos, dp->d_name, len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 fullname[pos + len] = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 #ifdef S_IFLNK
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 /* We want to return success if a link points to a nonexistent file,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 but we want to return the status for what the link points to,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 in case it is a directory. */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
268 value = qxe_lstat (fullname, st_addr);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 if (S_ISLNK (st_addr->st_mode))
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
270 qxe_stat (fullname, st_addr);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 #else
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
272 value = qxe_stat (fullname, st_addr);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 return value;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 file_name_completion_unwind (Lisp_Object locative)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 DIR *d;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 Lisp_Object obj = XCAR (locative);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 if (!NILP (obj))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 d = (DIR *)get_opaque_ptr (obj);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
286 qxe_closedir (d);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 free_opaque_ptr (obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 }
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
289 free_cons (locative);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 file_name_completion (Lisp_Object file, Lisp_Object directory, int all_flag,
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 1726
diff changeset
295 int UNUSED (ver_flag))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 DIR *d = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 int matchcount = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 Lisp_Object bestmatch = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 Charcount bestmatchsize = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 struct stat st;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 int passcount;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 int speccount = specpdl_depth ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 Charcount file_name_length;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 Lisp_Object locative;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 struct gcpro gcpro1, gcpro2, gcpro3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 GCPRO3 (file, directory, bestmatch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 CHECK_STRING (file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
313 #ifdef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 /* Filename completion on Windows ignores case, since Windows
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 filesystems do. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 specbind (Qcompletion_ignore_case, Qt);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
317 #endif /* WIN32_NATIVE */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 #ifdef FILE_SYSTEM_CASE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 file = FILE_SYSTEM_CASE (file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 directory = Fexpand_file_name (directory, Qnil);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
323 file_name_length = string_char_length (file);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 /* With passcount = 0, ignore files that end in an ignored extension.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 If nothing found then try again with passcount = 1, don't ignore them.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 If looking for all completions, start with passcount = 1,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 so always take even the ignored ones.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 ** It would not actually be helpful to the user to ignore any possible
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 completions when making a list of them.** */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 /* We cannot use close_directory_unwind() because we change the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 directory. The old code used to just avoid signaling errors, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 call closedir, but it was wrong, because it made sane handling of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 QUIT impossible and, besides, various utility functions like
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 regexp_ignore_completion_p can signal errors. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 locative = noseeum_cons (Qnil, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 record_unwind_protect (file_name_completion_unwind, locative);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 for (passcount = !!all_flag; NILP (bestmatch) && passcount < 2; passcount++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
343 d = qxe_opendir (XSTRING_DATA (Fdirectory_file_name (directory)));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 if (!d)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 546
diff changeset
345 report_file_error ("Opening directory", directory);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 XCAR (locative) = make_opaque_ptr ((void *)d);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 /* Loop reading blocks */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 DIRENTRY *dp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 Bytecount len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 /* scmp() works in characters, not bytes, so we have to compute
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 this value: */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 Charcount cclen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 int directoryp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 int ignored_extension_p = 0;
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
358 Ibyte *d_name;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
360 dp = qxe_readdir (d);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 if (!dp) break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
363 /* Cast to Ibyte* is OK, as qxe_readdir() Mule-encapsulates. */
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
364 d_name = (Ibyte *) dp->d_name;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 len = NAMLEN (dp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 cclen = bytecount_to_charcount (d_name, len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 if (! DIRENTRY_NONEMPTY (dp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 || cclen < file_name_length
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 || 0 <= scmp (d_name, XSTRING_DATA (file), file_name_length))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374
4808
53071486ff7a Ignore file-too-large conditions when stat()ing a file for dired. The size
Jerry James <james@xemacs.org>
parents: 4406
diff changeset
375 /* Ignore file-too-large conditions; the mode is still filled in. */
53071486ff7a Ignore file-too-large conditions when stat()ing a file for dired. The size
Jerry James <james@xemacs.org>
parents: 4406
diff changeset
376 if (file_name_completion_stat (directory, dp, &st) < 0 &&
53071486ff7a Ignore file-too-large conditions when stat()ing a file for dired. The size
Jerry James <james@xemacs.org>
parents: 4406
diff changeset
377 errno != EOVERFLOW)
53071486ff7a Ignore file-too-large conditions when stat()ing a file for dired. The size
Jerry James <james@xemacs.org>
parents: 4406
diff changeset
378 continue;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 directoryp = ((st.st_mode & S_IFMT) == S_IFDIR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 if (directoryp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 #ifndef TRIVIAL_DIRECTORY_ENTRY
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 #define TRIVIAL_DIRECTORY_ENTRY(n) (!strcmp (n, ".") || !strcmp (n, ".."))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 /* "." and ".." are never interesting as completions, but are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 actually in the way in a directory containing only one file. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 if (!passcount && TRIVIAL_DIRECTORY_ENTRY (dp->d_name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 /* Compare extensions-to-be-ignored against end of this file name */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 /* if name is not an exact match against specified string. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 if (!passcount && cclen > file_name_length)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 /* and exit this for loop if a match is found */
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
398 EXTERNAL_LIST_LOOP_2 (elt, Vcompletion_ignored_extensions)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 Charcount skip;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 CHECK_STRING (elt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
404 skip = cclen - string_char_length (elt);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 if (skip < 0) continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
407 if (0 > scmp (itext_n_addr (d_name, skip),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 XSTRING_DATA (elt),
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
409 string_char_length (elt)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 ignored_extension_p = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 /* If an ignored-extensions match was found,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 don't process this name as a completion. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 if (!passcount && ignored_extension_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 800
diff changeset
423 if (!passcount && regexp_ignore_completion_p (d_name, Qnil, 0, len))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 /* Update computation of how much all possible completions match */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 matchcount++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 if (all_flag || NILP (bestmatch))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 Lisp_Object name = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 struct gcpro ngcpro1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 NGCPRO1 (name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 /* This is a possible completion */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 name = make_string (d_name, len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 if (directoryp) /* Completion is a directory; end it with '/' */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 name = Ffile_name_as_directory (name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 if (all_flag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 bestmatch = Fcons (name, bestmatch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 bestmatch = name;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
445 bestmatchsize = string_char_length (name);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 NUNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 Charcount compare = min (bestmatchsize, cclen);
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
452 Ibyte *p1 = XSTRING_DATA (bestmatch);
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
453 Ibyte *p2 = d_name;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 Charcount matchsize = scmp (p1, p2, compare);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 if (matchsize < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 matchsize = compare;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 if (completion_ignore_case)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 /* If this is an exact match except for case,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 use it as the best match rather than one that is not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 an exact match. This way, we get the case pattern
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 of the actual match. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 if ((matchsize == cclen
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 && matchsize + !!directoryp
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
466 < string_char_length (bestmatch))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 /* If there is no exact match ignoring case,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 prefer a match that does not change the case
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 of the input. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 (((matchsize == cclen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 ==
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 (matchsize + !!directoryp
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
474 == string_char_length (bestmatch)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 /* If there is more than one exact match aside from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 case, and one of them is exact including case,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 prefer that one. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 && 0 > scmp_1 (p2, XSTRING_DATA (file),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 file_name_length, 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 && 0 <= scmp_1 (p1, XSTRING_DATA (file),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 file_name_length, 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 bestmatch = make_string (d_name, len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 if (directoryp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 bestmatch = Ffile_name_as_directory (bestmatch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 /* If this directory all matches,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 see if implicit following slash does too. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 if (directoryp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 && compare == matchsize
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 && bestmatchsize > matchsize
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
494 && IS_ANY_SEP (itext_ichar_n (p1, matchsize)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 matchsize++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 bestmatchsize = matchsize;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
499 qxe_closedir (d);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 free_opaque_ptr (XCAR (locative));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 XCAR (locative) = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
504 unbind_to (speccount);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 if (all_flag || NILP (bestmatch))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 return bestmatch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 if (matchcount == 1 && bestmatchsize == file_name_length)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 return Qt;
5089
99f8ebc082d9 Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4976
diff changeset
512 return Fsubseq (bestmatch, Qzero, make_int (bestmatchsize));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 static Lisp_Object user_name_completion (Lisp_Object user,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 int all_flag,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 int *uniq);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 DEFUN ("user-name-completion", Fuser_name_completion, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
521 Complete user name from PARTIAL-USERNAME.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
522 Return the longest prefix common to all user names starting with
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
523 PARTIAL-USERNAME. If there is only one and PARTIAL-USERNAME matches
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
524 it exactly, returns t. Return nil if there is no user name starting
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
525 with PARTIAL-USERNAME.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
527 (partial_username))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
529 return user_name_completion (partial_username, 0, NULL);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 DEFUN ("user-name-completion-1", Fuser_name_completion_1, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
533 Complete user name from PARTIAL-USERNAME.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 This function is identical to `user-name-completion', except that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 the cons of the completion and an indication of whether the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 completion was unique is returned.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
539 The car of the returned value is the longest prefix common to all user
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
540 names that start with PARTIAL-USERNAME. If there is only one and
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
541 PARTIAL-USERNAME matches it exactly, the car is t. The car is nil if
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
542 there is no user name starting with PARTIAL-USERNAME. The cdr of the
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
543 result is non-nil if and only if the completion returned in the car
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
544 was unique.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
546 (partial_username))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 int uniq;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
549 Lisp_Object completed = user_name_completion (partial_username, 0, &uniq);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 return Fcons (completed, uniq ? Qt : Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 DEFUN ("user-name-all-completions", Fuser_name_all_completions, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
554 Return a list of all user name completions from PARTIAL-USERNAME.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
555 These are all the user names which begin with PARTIAL-USERNAME.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
557 (partial_username))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
559 return user_name_completion (partial_username, 1, NULL);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
562 struct user_name
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
563 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
564 Ibyte *ptr;
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
565 Bytecount len;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
566 };
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
567
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
568 struct user_cache
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
569 {
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
570 struct user_name *user_names;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 int length;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 int size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 EMACS_TIME last_rebuild_time;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 static struct user_cache user_cache;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 free_user_cache (struct user_cache *cache)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 for (i = 0; i < cache->length; i++)
4976
16112448d484 Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents: 4808
diff changeset
582 xfree (cache->user_names[i].ptr);
16112448d484 Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents: 4808
diff changeset
583 xfree (cache->user_names);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
584 xzero (*cache);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 static Lisp_Object
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
588 user_name_completion_unwind (Lisp_Object cache_incomplete_p)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 {
528
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
590 #ifndef WIN32_NATIVE
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
591 endpwent ();
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
592 speed_up_interrupts ();
528
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
593 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
595 if (! NILP (XCAR (cache_incomplete_p)))
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
596 free_user_cache (&user_cache);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
597
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
598 free_cons (cache_incomplete_p);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
603 #define USER_CACHE_TTL (24*60*60) /* Time to live: 1 day, in seconds */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 user_name_completion (Lisp_Object user, int all_flag, int *uniq)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 int matchcount = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 Lisp_Object bestmatch = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 Charcount bestmatchsize = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 Charcount user_name_length;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 EMACS_TIME t;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 struct gcpro gcpro1, gcpro2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 GCPRO2 (user, bestmatch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 CHECK_STRING (user);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
621 user_name_length = string_char_length (user);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 /* Cache user name lookups because it tends to be quite slow.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 * Rebuild the cache occasionally to catch changes */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 EMACS_GET_TIME (t);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
626 if (user_cache.user_names &&
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 (EMACS_SECS (t) - EMACS_SECS (user_cache.last_rebuild_time)
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
628 > USER_CACHE_TTL))
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
629 free_user_cache (&user_cache);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
631 if (!user_cache.user_names)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 {
528
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
633 #ifndef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 struct passwd *pwd;
528
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
635 #else
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
636 DWORD entriesread;
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
637 DWORD totalentries;
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
638 DWORD resume_handle = 0;
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
639 #endif
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
640
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
641 Lisp_Object cache_incomplete_p = noseeum_cons (Qt, Qnil);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
642 int speccount = specpdl_depth ();
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
643
528
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
644 record_unwind_protect (user_name_completion_unwind, cache_incomplete_p);
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
645 #ifndef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 slow_down_interrupts ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 setpwent ();
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
648 while ((pwd = qxe_getpwent ()))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 QUIT;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
651 DO_REALLOC (user_cache.user_names, user_cache.size,
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
652 user_cache.length + 1, struct user_name);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
653 user_cache.user_names[user_cache.length].ptr =
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
654 (Ibyte *) xstrdup (pwd->pw_name);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
655 user_cache.user_names[user_cache.length].len = strlen (pwd->pw_name);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
656 user_cache.length++;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 }
528
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
658 #else
531
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
659 if (xNetUserEnum)
528
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
660 {
531
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
661 do
528
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
662 {
531
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
663 USER_INFO_0 *bufptr;
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
664 NET_API_STATUS status_status_statui_statum_statu;
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
665 int i;
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
666
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
667 QUIT;
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
668 status_status_statui_statum_statu =
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
669 xNetUserEnum (NULL, 0, 0, (LPBYTE *) &bufptr, 1024,
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
670 &entriesread, &totalentries, &resume_handle);
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
671 if (status_status_statui_statum_statu != NERR_Success &&
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
672 status_status_statui_statum_statu != ERROR_MORE_DATA)
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
673 invalid_operation ("Error enumerating users",
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
674 make_int (GetLastError ()));
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
675 for (i = 0; i < (int) entriesread; i++)
531
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
676 {
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
677 DO_REALLOC (user_cache.user_names, user_cache.size,
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
678 user_cache.length + 1, struct user_name);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
679 TO_INTERNAL_FORMAT (C_STRING,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
680 bufptr[i].usri0_name,
531
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
681 MALLOC,
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
682 (user_cache.
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
683 user_names[user_cache.length].ptr,
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
684 user_cache.
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
685 user_names[user_cache.length].len),
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
686 Qmswindows_unicode);
531
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
687 user_cache.length++;
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
688 }
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
689 xNetApiBufferFree (bufptr);
528
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
690 }
531
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
691 while (entriesread != totalentries);
528
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
692 }
546
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
693 else /* Win 9x */
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
694 {
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
695 Extbyte name[2 * (UNLEN + 1)];
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
696 DWORD length = sizeof (name);
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
697
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
698 if (qxeGetUserName (name, &length))
546
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
699 {
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
700 DO_REALLOC (user_cache.user_names, user_cache.size,
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
701 user_cache.length + 1, struct user_name);
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
702 TO_INTERNAL_FORMAT (C_STRING, name,
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
703 MALLOC,
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
704 (user_cache.
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
705 user_names[user_cache.length].ptr,
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
706 user_cache.
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
707 user_names[user_cache.length].len),
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
708 Qmswindows_tstr);
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
709 user_cache.length++;
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
710 }
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
711 }
528
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
712 #endif
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
713
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
714 XCAR (cache_incomplete_p) = Qnil;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
715 unbind_to (speccount);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
716
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 EMACS_GET_TIME (user_cache.last_rebuild_time);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 for (i = 0; i < user_cache.length; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
722 Ibyte *u_name = user_cache.user_names[i].ptr;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
723 Bytecount len = user_cache.user_names[i].len;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 /* scmp() works in chars, not bytes, so we have to compute this: */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 Charcount cclen = bytecount_to_charcount (u_name, len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 if (cclen < user_name_length
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 || 0 <= scmp_1 (u_name, XSTRING_DATA (user), user_name_length, 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 matchcount++; /* count matching completions */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 if (all_flag || NILP (bestmatch))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 Lisp_Object name = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 struct gcpro ngcpro1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739 NGCPRO1 (name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 /* This is a possible completion */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 name = make_string (u_name, len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 if (all_flag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 bestmatch = Fcons (name, bestmatch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 bestmatch = name;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
749 bestmatchsize = string_char_length (name);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 NUNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 Charcount compare = min (bestmatchsize, cclen);
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
756 Ibyte *p1 = XSTRING_DATA (bestmatch);
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
757 Ibyte *p2 = u_name;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 Charcount matchsize = scmp_1 (p1, p2, compare, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 if (matchsize < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 matchsize = compare;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 bestmatchsize = matchsize;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 if (uniq)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 *uniq = (matchcount == 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 if (all_flag || NILP (bestmatch))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 return bestmatch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 if (matchcount == 1 && bestmatchsize == user_name_length)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 return Qt;
5089
99f8ebc082d9 Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4976
diff changeset
776 return Fsubseq (bestmatch, Qzero, make_int (bestmatchsize));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 Lisp_Object
5211
cdca98f2d36f Move `default-file-system-ignore-case' to C; fix bug in directory hash tables
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
781 make_directory_hash_table (Lisp_Object path)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 DIR *d;
5211
cdca98f2d36f Move `default-file-system-ignore-case' to C; fix bug in directory hash tables
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
784 if ((d = qxe_opendir (XSTRING_DATA (path))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 {
5211
cdca98f2d36f Move `default-file-system-ignore-case' to C; fix bug in directory hash tables
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
786 Lisp_Object hash_table_test = Qequal, hash = Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 DIRENTRY *dp;
5211
cdca98f2d36f Move `default-file-system-ignore-case' to C; fix bug in directory hash tables
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
788
cdca98f2d36f Move `default-file-system-ignore-case' to C; fix bug in directory hash tables
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
789 if (!UNBOUNDP (XSYMBOL_FUNCTION (Qfile_system_ignore_case_p))
cdca98f2d36f Move `default-file-system-ignore-case' to C; fix bug in directory hash tables
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
790 && !NILP (call1 (Qfile_system_ignore_case_p, path)))
cdca98f2d36f Move `default-file-system-ignore-case' to C; fix bug in directory hash tables
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
791 {
cdca98f2d36f Move `default-file-system-ignore-case' to C; fix bug in directory hash tables
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
792 hash_table_test = Qequalp;
cdca98f2d36f Move `default-file-system-ignore-case' to C; fix bug in directory hash tables
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
793 }
cdca98f2d36f Move `default-file-system-ignore-case' to C; fix bug in directory hash tables
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
794
cdca98f2d36f Move `default-file-system-ignore-case' to C; fix bug in directory hash tables
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
795 hash = make_lisp_hash_table (20, HASH_TABLE_NON_WEAK, hash_table_test);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
797 while ((dp = qxe_readdir (d)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 Bytecount len = NAMLEN (dp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 if (DIRENTRY_NONEMPTY (dp))
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
801 /* Cast to Ibyte* is OK, as qxe_readdir() Mule-encapsulates. */
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
802 Fputhash (make_string ((Ibyte *) dp->d_name, len), Qt, hash);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
804 qxe_closedir (d);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 return hash;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810
707
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
811 #if 0
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
812 /* ... never used ... should use list2 directly anyway ... */
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
813 /* NOTE: This function can never return a negative value. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 wasteful_word_to_lisp (unsigned int item)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 /* Compatibility: in other versions, file-attributes returns a LIST
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 of two 16 bit integers... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 Lisp_Object cons = word_to_lisp (item);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 XCDR (cons) = Fcons (XCDR (cons), Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 return cons;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 }
707
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
823 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 DEFUN ("file-attributes", Ffile_attributes, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 Return a list of attributes of file FILENAME.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 Value is nil if specified file cannot be opened.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 Otherwise, list elements are:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 0. t for directory, string (name linked to) for symbolic link, or nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 1. Number of links to file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 2. File uid.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 3. File gid.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 4. Last access time, as a list of two integers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 First integer has high-order 16 bits of time, second has low 16 bits.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 5. Last modification time, likewise.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 6. Last status change time, likewise.
4406
5998e37dc35e Use bignums if necessary for file size in #'file-attributes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 2367
diff changeset
837 7. Size in bytes. (-1, if number out of range and no bignum support.)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 8. File modes, as a string of ten letters or dashes as in ls -l.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 9. t iff file's gid would change if file were deleted and recreated.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 10. inode number.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 11. Device number.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 If file does not exist, returns nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 (filename))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 /* This function can GC. GC checked 1997.06.04. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 Lisp_Object values[12];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 Lisp_Object directory = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 struct stat s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 char modes[10];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 Lisp_Object handler;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 struct gcpro gcpro1, gcpro2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 GCPRO2 (filename, directory);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 filename = Fexpand_file_name (filename, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858 /* If the file name has special constructs in it,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 call the corresponding file handler. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 handler = Ffind_file_name_handler (filename, Qfile_attributes);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861 if (!NILP (handler))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 return call2 (handler, Qfile_attributes, filename);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
867 if (qxe_lstat (XSTRING_DATA (filename), &s) < 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873 #ifdef BSD4_2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 directory = Ffile_name_directory (filename);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
877 #if 0 /* #### shouldn't this apply to WIN32_NATIVE and maybe CYGWIN? */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
879 Ibyte *tmpnam = XSTRING_DATA (Ffile_name_nondirectory (filename));
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
880 Bytecount l = qxestrlen (tmpnam);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882 if (l >= 5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 && S_ISREG (s.st_mode)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
884 && (qxestrcasecmp (&tmpnam[l - 4], ".com") == 0 ||
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
885 qxestrcasecmp (&tmpnam[l - 4], ".exe") == 0 ||
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
886 qxestrcasecmp (&tmpnam[l - 4], ".bat") == 0))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888 s.st_mode |= S_IEXEC;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 }
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
891 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 switch (s.st_mode & S_IFMT)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 values[0] = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898 case S_IFDIR:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899 values[0] = Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 #ifdef S_IFLNK
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 case S_IFLNK:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 values[0] = Ffile_symlink_p (filename);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 values[1] = make_int (s.st_nlink);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908 values[2] = make_int (s.st_uid);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 values[3] = make_int (s.st_gid);
707
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
910 values[4] = make_time (s.st_atime);
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
911 values[5] = make_time (s.st_mtime);
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
912 values[6] = make_time (s.st_ctime);
4406
5998e37dc35e Use bignums if necessary for file size in #'file-attributes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 2367
diff changeset
913
5998e37dc35e Use bignums if necessary for file size in #'file-attributes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 2367
diff changeset
914 #ifndef HAVE_BIGNUM
5998e37dc35e Use bignums if necessary for file size in #'file-attributes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 2367
diff changeset
915 values[7] = make_integer (NUMBER_FITS_IN_AN_EMACS_INT (s.st_size) ?
5998e37dc35e Use bignums if necessary for file size in #'file-attributes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 2367
diff changeset
916 (EMACS_INT)s.st_size : -1);
5998e37dc35e Use bignums if necessary for file size in #'file-attributes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 2367
diff changeset
917 #else
5998e37dc35e Use bignums if necessary for file size in #'file-attributes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 2367
diff changeset
918 values[7] = make_integer (s.st_size);
5998e37dc35e Use bignums if necessary for file size in #'file-attributes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 2367
diff changeset
919 #endif
5998e37dc35e Use bignums if necessary for file size in #'file-attributes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 2367
diff changeset
920
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921 filemodestring (&s, modes);
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
922 values[8] = make_string ((Ibyte *) modes, 10);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923 #if defined (BSD4_2) || defined (BSD4_3) /* file gid will be dir gid */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 struct stat sdir;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
927 if (!NILP (directory) && qxe_stat (XSTRING_DATA (directory), &sdir) == 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928 values[9] = (sdir.st_gid != s.st_gid) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929 else /* if we can't tell, assume worst */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930 values[9] = Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932 #else /* file gid will be egid */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933 values[9] = (s.st_gid != getegid ()) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 #endif /* BSD4_2 or BSD4_3 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935 values[10] = make_int (s.st_ino);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936 values[11] = make_int (s.st_dev);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938 return Flist (countof (values), values);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943 /* initialization */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947 syms_of_dired (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 546
diff changeset
949 DEFSYMBOL (Qdirectory_files);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 546
diff changeset
950 DEFSYMBOL (Qfile_name_completion);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 546
diff changeset
951 DEFSYMBOL (Qfile_name_all_completions);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 546
diff changeset
952 DEFSYMBOL (Qfile_attributes);
5211
cdca98f2d36f Move `default-file-system-ignore-case' to C; fix bug in directory hash tables
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
953 DEFSYMBOL (Qfile_system_ignore_case_p);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955 DEFSUBR (Fdirectory_files);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956 DEFSUBR (Ffile_name_completion);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
957 DEFSUBR (Ffile_name_all_completions);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958 DEFSUBR (Fuser_name_completion);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 DEFSUBR (Fuser_name_completion_1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960 DEFSUBR (Fuser_name_all_completions);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961 DEFSUBR (Ffile_attributes);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965 vars_of_dired (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967 DEFVAR_LISP ("completion-ignored-extensions", &Vcompletion_ignored_extensions /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968 *Completion ignores filenames ending in any string in this list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
969 This variable does not affect lists of possible completions,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
970 but does affect the commands that actually do completions.
770
336a418893b5 [xemacs-hg @ 2002-03-08 13:33:12 by adrian]
adrian
parents: 707
diff changeset
971 It is used by the function `file-name-completion'.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 Vcompletion_ignored_extensions = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974 }