annotate src/dired.c @ 5936:574f0cded429 cygwin

try to replace all nnnL or nnnUL constants with EMACS_[U]INT
author Henry Thompson <ht@markup.co.uk>
date Sun, 13 Dec 2015 13:22:58 +0000
parents 427a72c6ee17
children
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.
5733
c30fdcab7bc8 Added optional argument ID-FORMAT to file-attributes for GNU compatibility.
Mats Lidell <mats.lidell@cag.se>
parents: 5727
diff changeset
2 Copyright (C) 1985, 1986, 1992, 1993, 1994, 2013 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
5405
2aa9cd456ae7 Move src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 5211
diff changeset
7 XEmacs is free software: you can redistribute it and/or modify it
428
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
5405
2aa9cd456ae7 Move src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 5211
diff changeset
9 Free Software Foundation, either version 3 of the License, or (at your
2aa9cd456ae7 Move src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 5211
diff changeset
10 option) any later version.
428
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
5405
2aa9cd456ae7 Move src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 5211
diff changeset
18 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 /* Synched up with: FSF 19.30. */
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 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 #include "lisp.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 #include "buffer.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 #include "commands.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 #include "elhash.h"
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 771
diff changeset
28 #include "opaque.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 #include "regex.h"
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
30 #include "syntax.h"
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 771
diff changeset
31 #include "sysdep.h"
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 771
diff changeset
32
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 771
diff changeset
33 #include "sysdir.h"
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 771
diff changeset
34 #include "sysfile.h"
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 771
diff changeset
35 #include "syspwd.h"
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 771
diff changeset
36 #include "systime.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37
528
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
38 #ifdef WIN32_NATIVE
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
39 #include "syswindows.h"
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
40 #endif
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
41
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 Lisp_Object Vcompletion_ignored_extensions;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 Lisp_Object Qdirectory_files;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 Lisp_Object Qfile_name_completion;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 Lisp_Object Qfile_name_all_completions;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 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
47 Lisp_Object Qfile_system_ignore_case_p;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 close_directory_unwind (Lisp_Object unwind_obj)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 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
53 qxe_closedir (d);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 free_opaque_ptr (unwind_obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 DEFUN ("directory-files", Fdirectory_files, 1, 5, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 Return a list of names of files in DIRECTORY.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 There are four optional arguments:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 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
62 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
63 returned.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 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
65 NOSORT is useful if you plan to sort the result yourself.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 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
67 will be returned; subdirectories will be excluded. If FILES-ONLY is not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 nil and not t, then only the subdirectories will be returned. Otherwise,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 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
70 be returned.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 (directory, full, match, nosort, files_only))
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 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 DIR *d;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 Lisp_Object list = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 Bytecount directorylen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 Lisp_Object handler;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 struct re_pattern_buffer *bufp = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 int speccount = specpdl_depth ();
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
81 Ibyte *statbuf, *statbuf_tail;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 struct gcpro gcpro1, gcpro2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 GCPRO2 (directory, list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 /* If the file name has special constructs in it,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 call the corresponding file handler. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 handler = Ffind_file_name_handler (directory, Qdirectory_files);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 if (!NILP (handler))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 if (!NILP (files_only))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 return call6 (handler, Qdirectory_files, directory, full, match,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 nosort, files_only);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 return call5 (handler, Qdirectory_files, directory, full, match,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 nosort);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 /* #### why do we do Fexpand_file_name after file handlers here,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 but earlier everywhere else? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 directory = Fexpand_file_name (directory, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 directory = Ffile_name_as_directory (directory);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 directorylen = XSTRING_LENGTH (directory);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
106 statbuf = alloca_ibytes (directorylen + MAXNAMLEN + 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 memcpy (statbuf, XSTRING_DATA (directory), directorylen);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 statbuf_tail = statbuf + directorylen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 /* XEmacs: this should come after Ffile_name_as_directory() to avoid
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 potential regexp cache smashage. It comes before the opendir()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 because it might signal an error. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 if (!NILP (match))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 CHECK_STRING (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 /* MATCH might be a flawed regular expression. Rather than
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 catching and signalling our own errors, we just call
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 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
120 bufp = compile_pattern (match, 0, Qnil, Qnil, 0, 0, ERROR_ME);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 /* Now *bufp is the compiled form of MATCH; don't call anything
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 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
125
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 /* Do this opendir after anything which might signal an error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 NOTE: the above comment is old; previously, there was no
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 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
129 d = qxe_opendir (XSTRING_DATA (directory));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 if (!d)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 546
diff changeset
131 report_file_error ("Opening directory", directory);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 record_unwind_protect (close_directory_unwind, make_opaque_ptr ((void *)d));
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 /* Loop reading blocks */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
138 DIRENTRY *dp = qxe_readdir (d);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 int len;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
140 struct syntax_cache scache_struct;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
141 struct syntax_cache *scache = &scache_struct;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 if (!dp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 len = NAMLEN (dp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 if (DIRENTRY_NONEMPTY (dp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 && (NILP (match)
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
148 || (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
149 scache))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 if (!NILP (files_only))
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 struct stat st;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 int dir_p = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 memcpy (statbuf_tail, dp->d_name, len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 statbuf_tail[len] = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
159 if (qxe_stat (statbuf, &st) == 0
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 && (st.st_mode & S_IFMT) == S_IFDIR)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 dir_p = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 if (EQ (files_only, Qt) && dir_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 else 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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168
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 Lisp_Object name =
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
171 make_string ((Ibyte *)dp->d_name, len);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 if (!NILP (full))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 name = concat2 (directory, name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 list = Fcons (name, list);
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
179 unbind_to (speccount); /* This will close the dir */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 if (NILP (nosort))
5350
94bbd4792049 Have #'sort*, #'merge use the same test approach as functions from cl-seq.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5211
diff changeset
182 list = list_sort (Fnreverse (list), check_string_lessp_nokey, Qnil, Qnil);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 RETURN_UNGCPRO (list);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 static Lisp_Object file_name_completion (Lisp_Object file,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 Lisp_Object directory,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 int all_flag, int ver_flag);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 DEFUN ("file-name-completion", Ffile_name_completion, 2, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
192 Complete file name PARTIAL-FILENAME in directory DIRECTORY.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
193 Return the longest prefix common to all file names in DIRECTORY
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
194 that start with PARTIAL-FILENAME.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
195 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
196 Return nil if DIRECTORY contains no name starting with PARTIAL-FILENAME.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
198 File names which end with any member of `completion-ignored-extensions'
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
199 are not considered as possible completions for PARTIAL-FILENAME unless
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
200 there is no other possible completion. `completion-ignored-extensions'
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
201 is not applied to the names of directories.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
203 (partial_filename, directory))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 /* This function can GC. GC checked 1996.04.06. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 Lisp_Object handler;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 /* If the directory name has special constructs in it,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 call the corresponding file handler. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 handler = Ffind_file_name_handler (directory, Qfile_name_completion);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 if (!NILP (handler))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
212 return call3 (handler, Qfile_name_completion, partial_filename, directory);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 /* If the file name has special constructs in it,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 call the corresponding file handler. */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
216 handler = Ffind_file_name_handler (partial_filename, Qfile_name_completion);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 if (!NILP (handler))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
218 return call3 (handler, Qfile_name_completion, partial_filename, directory);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
220 return file_name_completion (partial_filename, directory, 0, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 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
224 Return a list of all completions of PARTIAL-FILENAME in DIRECTORY.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
225 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
226 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
227 (partial_filename, directory))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 /* This function can GC. GC checked 1997.06.04. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 Lisp_Object handler;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 struct gcpro gcpro1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 GCPRO1 (directory);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 directory = Fexpand_file_name (directory, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 /* If the file name has special constructs in it,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 call the corresponding file handler. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 handler = Ffind_file_name_handler (directory, Qfile_name_all_completions);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 if (!NILP (handler))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
240 return call3 (handler, Qfile_name_all_completions, partial_filename,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 directory);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
243 return file_name_completion (partial_filename, directory, 1, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 file_name_completion_stat (Lisp_Object directory, DIRENTRY *dp,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 struct stat *st_addr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 Bytecount len = NAMLEN (dp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 Bytecount pos = XSTRING_LENGTH (directory);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 int value;
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
253 Ibyte *fullname = alloca_ibytes (len + pos + 2);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 memcpy (fullname, XSTRING_DATA (directory), pos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 if (!IS_DIRECTORY_SEP (fullname[pos - 1]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 fullname[pos++] = DIRECTORY_SEP;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 memcpy (fullname + pos, dp->d_name, len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 fullname[pos + len] = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 #ifdef S_IFLNK
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 /* 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
264 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
265 in case it is a directory. */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
266 value = qxe_lstat (fullname, st_addr);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 if (S_ISLNK (st_addr->st_mode))
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
268 qxe_stat (fullname, st_addr);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 #else
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
270 value = qxe_stat (fullname, st_addr);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 return value;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 file_name_completion_unwind (Lisp_Object locative)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 DIR *d;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 Lisp_Object obj = XCAR (locative);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 if (!NILP (obj))
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 d = (DIR *)get_opaque_ptr (obj);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
284 qxe_closedir (d);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 free_opaque_ptr (obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 }
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
287 free_cons (locative);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 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
293 int UNUSED (ver_flag))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 DIR *d = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 int matchcount = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 Lisp_Object bestmatch = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 Charcount bestmatchsize = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 struct stat st;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 int passcount;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 int speccount = specpdl_depth ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 Charcount file_name_length;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 Lisp_Object locative;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 struct gcpro gcpro1, gcpro2, gcpro3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 GCPRO3 (file, directory, bestmatch);
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 CHECK_STRING (file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
311 #ifdef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 /* Filename completion on Windows ignores case, since Windows
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 filesystems do. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 specbind (Qcompletion_ignore_case, Qt);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
315 #endif /* WIN32_NATIVE */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 #ifdef FILE_SYSTEM_CASE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 file = FILE_SYSTEM_CASE (file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 directory = Fexpand_file_name (directory, Qnil);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
321 file_name_length = string_char_length (file);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 /* With passcount = 0, ignore files that end in an ignored extension.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 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
325 If looking for all completions, start with passcount = 1,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 so always take even the ignored ones.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 ** 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
329 completions when making a list of them.** */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 /* We cannot use close_directory_unwind() because we change the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 directory. The old code used to just avoid signaling errors, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 call closedir, but it was wrong, because it made sane handling of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 QUIT impossible and, besides, various utility functions like
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 regexp_ignore_completion_p can signal errors. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 locative = noseeum_cons (Qnil, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 record_unwind_protect (file_name_completion_unwind, locative);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 for (passcount = !!all_flag; NILP (bestmatch) && passcount < 2; passcount++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
341 d = qxe_opendir (XSTRING_DATA (Fdirectory_file_name (directory)));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 if (!d)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 546
diff changeset
343 report_file_error ("Opening directory", directory);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 XCAR (locative) = make_opaque_ptr ((void *)d);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 /* Loop reading blocks */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 DIRENTRY *dp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 Bytecount len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 /* scmp() works in characters, not bytes, so we have to compute
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 this value: */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 Charcount cclen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 int directoryp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 int ignored_extension_p = 0;
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
356 Ibyte *d_name;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
358 dp = qxe_readdir (d);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 if (!dp) break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
361 /* 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
362 d_name = (Ibyte *) dp->d_name;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 len = NAMLEN (dp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 cclen = bytecount_to_charcount (d_name, len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 QUIT;
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 if (! DIRENTRY_NONEMPTY (dp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 || cclen < file_name_length
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 || 0 <= scmp (d_name, XSTRING_DATA (file), file_name_length))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372
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
373 /* 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
374 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
375 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
376 continue;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 directoryp = ((st.st_mode & S_IFMT) == S_IFDIR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 if (directoryp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 #ifndef TRIVIAL_DIRECTORY_ENTRY
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 #define TRIVIAL_DIRECTORY_ENTRY(n) (!strcmp (n, ".") || !strcmp (n, ".."))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 /* "." and ".." are never interesting as completions, but are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 actually in the way in a directory containing only one file. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 if (!passcount && TRIVIAL_DIRECTORY_ENTRY (dp->d_name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 else
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 /* Compare extensions-to-be-ignored against end of this file name */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 /* if name is not an exact match against specified string. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 if (!passcount && cclen > file_name_length)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 /* 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
396 EXTERNAL_LIST_LOOP_2 (elt, Vcompletion_ignored_extensions)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 Charcount skip;
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 CHECK_STRING (elt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
402 skip = cclen - string_char_length (elt);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 if (skip < 0) continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
405 if (0 > scmp (itext_n_addr (d_name, skip),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 XSTRING_DATA (elt),
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
407 string_char_length (elt)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 ignored_extension_p = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 }
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 /* If an ignored-extensions match was found,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 don't process this name as a completion. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 if (!passcount && ignored_extension_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 800
diff changeset
421 if (!passcount && regexp_ignore_completion_p (d_name, Qnil, 0, len))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 /* Update computation of how much all possible completions match */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 matchcount++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 if (all_flag || NILP (bestmatch))
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 Lisp_Object name = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 struct gcpro ngcpro1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 NGCPRO1 (name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 /* This is a possible completion */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 name = make_string (d_name, len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 if (directoryp) /* Completion is a directory; end it with '/' */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 name = Ffile_name_as_directory (name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 if (all_flag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 bestmatch = Fcons (name, bestmatch);
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 else
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 bestmatch = name;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
443 bestmatchsize = string_char_length (name);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 NUNGCPRO;
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 else
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 Charcount compare = min (bestmatchsize, cclen);
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
450 Ibyte *p1 = XSTRING_DATA (bestmatch);
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
451 Ibyte *p2 = d_name;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 Charcount matchsize = scmp (p1, p2, compare);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 if (matchsize < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 matchsize = compare;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 if (completion_ignore_case)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 /* If this is an exact match except for case,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 use it as the best match rather than one that is not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 an exact match. This way, we get the case pattern
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 of the actual match. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 if ((matchsize == cclen
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 && matchsize + !!directoryp
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
464 < string_char_length (bestmatch))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 /* If there is no exact match ignoring case,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 prefer a match that does not change the case
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 of the input. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 (((matchsize == cclen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 ==
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 (matchsize + !!directoryp
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
472 == string_char_length (bestmatch)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 /* If there is more than one exact match aside from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 case, and one of them is exact including case,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 prefer that one. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 && 0 > scmp_1 (p2, XSTRING_DATA (file),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 file_name_length, 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 && 0 <= scmp_1 (p1, 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 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 bestmatch = make_string (d_name, len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 if (directoryp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 bestmatch = Ffile_name_as_directory (bestmatch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 }
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 /* If this directory all matches,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 see if implicit following slash does too. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 if (directoryp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 && compare == matchsize
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 && bestmatchsize > matchsize
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
492 && IS_ANY_SEP (itext_ichar_n (p1, matchsize)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 matchsize++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 bestmatchsize = matchsize;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
497 qxe_closedir (d);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 free_opaque_ptr (XCAR (locative));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 XCAR (locative) = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
502 unbind_to (speccount);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 UNGCPRO;
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 if (all_flag || NILP (bestmatch))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 return bestmatch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 if (matchcount == 1 && bestmatchsize == file_name_length)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 return Qt;
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5495
diff changeset
510 return Fsubseq (bestmatch, Qzero, make_fixnum (bestmatchsize));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512
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 static Lisp_Object user_name_completion (Lisp_Object user,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 int all_flag,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 int *uniq);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 DEFUN ("user-name-completion", Fuser_name_completion, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
519 Complete user name from PARTIAL-USERNAME.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
520 Return the longest prefix common to all user names starting with
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
521 PARTIAL-USERNAME. If there is only one and PARTIAL-USERNAME matches
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
522 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
523 with PARTIAL-USERNAME.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
525 (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 return user_name_completion (partial_username, 0, NULL);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 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
531 Complete user name from PARTIAL-USERNAME.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 This function is identical to `user-name-completion', except that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 the cons of the completion and an indication of whether the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 completion was unique is returned.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
537 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
538 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
539 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
540 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
541 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
542 was unique.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
544 (partial_username))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 int uniq;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
547 Lisp_Object completed = user_name_completion (partial_username, 0, &uniq);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 return Fcons (completed, uniq ? Qt : Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 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
552 Return a list of all user name completions from PARTIAL-USERNAME.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
553 These are all the user names which begin with PARTIAL-USERNAME.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
555 (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 return user_name_completion (partial_username, 1, NULL);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
560 struct user_name
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
561 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
562 Ibyte *ptr;
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
563 Bytecount len;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
564 };
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
565
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
566 struct user_cache
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_name *user_names;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 int length;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 int size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 EMACS_TIME last_rebuild_time;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 static struct user_cache user_cache;
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 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 free_user_cache (struct user_cache *cache)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 for (i = 0; i < cache->length; i++)
4976
16112448d484 Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents: 4808
diff changeset
580 xfree (cache->user_names[i].ptr);
16112448d484 Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents: 4808
diff changeset
581 xfree (cache->user_names);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
582 xzero (*cache);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 static Lisp_Object
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
586 user_name_completion_unwind (Lisp_Object cache_incomplete_p)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 {
528
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
588 #ifndef WIN32_NATIVE
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
589 endpwent ();
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
590 speed_up_interrupts ();
528
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
591 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
593 if (! NILP (XCAR (cache_incomplete_p)))
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
594 free_user_cache (&user_cache);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
595
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
596 free_cons (cache_incomplete_p);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 return Qnil;
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
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
601 #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
602
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 user_name_completion (Lisp_Object user, int all_flag, int *uniq)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 int matchcount = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 Lisp_Object bestmatch = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 Charcount bestmatchsize = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 Charcount user_name_length;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 EMACS_TIME t;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 struct gcpro gcpro1, gcpro2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 GCPRO2 (user, bestmatch);
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 CHECK_STRING (user);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
619 user_name_length = string_char_length (user);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 /* Cache user name lookups because it tends to be quite slow.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 * Rebuild the cache occasionally to catch changes */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 EMACS_GET_TIME (t);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
624 if (user_cache.user_names &&
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 (EMACS_SECS (t) - EMACS_SECS (user_cache.last_rebuild_time)
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
626 > USER_CACHE_TTL))
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
627 free_user_cache (&user_cache);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
629 if (!user_cache.user_names)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 {
528
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
631 #ifndef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 struct passwd *pwd;
528
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
633 #else
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
634 DWORD entriesread;
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
635 DWORD totalentries;
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
636 DWORD resume_handle = 0;
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
637 #endif
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
638
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
639 Lisp_Object cache_incomplete_p = noseeum_cons (Qt, Qnil);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
640 int speccount = specpdl_depth ();
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
641
528
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
642 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
643 #ifndef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 slow_down_interrupts ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 setpwent ();
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
646 while ((pwd = qxe_getpwent ()))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 QUIT;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
649 DO_REALLOC (user_cache.user_names, user_cache.size,
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
650 user_cache.length + 1, struct user_name);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
651 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
652 (Ibyte *) xstrdup (pwd->pw_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].len = strlen (pwd->pw_name);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
654 user_cache.length++;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 }
528
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
656 #else
531
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
657 if (xNetUserEnum)
528
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
658 {
531
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
659 do
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 USER_INFO_0 *bufptr;
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
662 NET_API_STATUS status_status_statui_statum_statu;
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
663 int i;
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
664
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
665 QUIT;
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
666 status_status_statui_statum_statu =
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
667 xNetUserEnum (NULL, 0, 0, (LPBYTE *) &bufptr, 1024,
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
668 &entriesread, &totalentries, &resume_handle);
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
669 if (status_status_statui_statum_statu != NERR_Success &&
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
670 status_status_statui_statum_statu != ERROR_MORE_DATA)
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
671 invalid_operation ("Error enumerating users",
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5495
diff changeset
672 make_fixnum (GetLastError ()));
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
673 for (i = 0; i < (int) entriesread; i++)
531
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
674 {
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
675 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
676 user_cache.length + 1, struct user_name);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
677 TO_INTERNAL_FORMAT (C_STRING,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
678 bufptr[i].usri0_name,
531
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
679 MALLOC,
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
680 (user_cache.
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
681 user_names[user_cache.length].ptr,
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].len),
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
684 Qmswindows_unicode);
531
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
685 user_cache.length++;
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
686 }
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
687 xNetApiBufferFree (bufptr);
528
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
688 }
531
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
689 while (entriesread != totalentries);
528
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
690 }
546
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
691 else /* Win 9x */
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
692 {
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
693 Extbyte name[2 * (UNLEN + 1)];
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
694 DWORD length = sizeof (name);
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
695
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
696 if (qxeGetUserName (name, &length))
546
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
697 {
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
698 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
699 user_cache.length + 1, struct user_name);
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
700 TO_INTERNAL_FORMAT (C_STRING, name,
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
701 MALLOC,
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
702 (user_cache.
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
703 user_names[user_cache.length].ptr,
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].len),
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
706 Qmswindows_tstr);
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
707 user_cache.length++;
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
708 }
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
709 }
528
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
710 #endif
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
711
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
712 XCAR (cache_incomplete_p) = Qnil;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
713 unbind_to (speccount);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
714
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 EMACS_GET_TIME (user_cache.last_rebuild_time);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718 for (i = 0; i < user_cache.length; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
720 Ibyte *u_name = user_cache.user_names[i].ptr;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
721 Bytecount len = user_cache.user_names[i].len;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 /* scmp() works in chars, not bytes, so we have to compute this: */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 Charcount cclen = bytecount_to_charcount (u_name, len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 QUIT;
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 if (cclen < user_name_length
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 || 0 <= scmp_1 (u_name, XSTRING_DATA (user), user_name_length, 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 matchcount++; /* count matching completions */
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 if (all_flag || NILP (bestmatch))
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 Lisp_Object name = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 struct gcpro ngcpro1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 NGCPRO1 (name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 /* This is a possible completion */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739 name = make_string (u_name, len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 if (all_flag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 bestmatch = Fcons (name, bestmatch);
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 else
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 bestmatch = name;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
747 bestmatchsize = string_char_length (name);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 NUNGCPRO;
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 else
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 Charcount compare = min (bestmatchsize, cclen);
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
754 Ibyte *p1 = XSTRING_DATA (bestmatch);
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
755 Ibyte *p2 = u_name;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 Charcount matchsize = scmp_1 (p1, p2, compare, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 if (matchsize < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 matchsize = compare;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 bestmatchsize = matchsize;
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 }
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 UNGCPRO;
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 if (uniq)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 *uniq = (matchcount == 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 if (all_flag || NILP (bestmatch))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 return bestmatch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 if (matchcount == 1 && bestmatchsize == user_name_length)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 return Qt;
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5495
diff changeset
774 return Fsubseq (bestmatch, Qzero, make_fixnum (bestmatchsize));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776
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 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
779 make_directory_hash_table (Lisp_Object path)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 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
782 if ((d = qxe_opendir (XSTRING_DATA (path))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 {
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 Lisp_Object hash_table_test = Qequal, hash = Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 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
786
cdca98f2d36f Move `default-file-system-ignore-case' to C; fix bug in directory hash tables
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
787 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
788 && !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
789 {
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 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
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
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 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
794
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
795 while ((dp = qxe_readdir (d)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 Bytecount len = NAMLEN (dp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 if (DIRENTRY_NONEMPTY (dp))
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
799 /* 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
800 Fputhash (make_string ((Ibyte *) dp->d_name, len), Qt, hash);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
802 qxe_closedir (d);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 return hash;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808
707
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
809 #if 0
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
810 /* ... never used ... should use list2 directly anyway ... */
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
811 /* NOTE: This function can never return a negative value. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813 wasteful_word_to_lisp (unsigned int item)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 /* Compatibility: in other versions, file-attributes returns a LIST
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 of two 16 bit integers... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 Lisp_Object cons = word_to_lisp (item);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 XCDR (cons) = Fcons (XCDR (cons), Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 return cons;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 }
707
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
821 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822
5733
c30fdcab7bc8 Added optional argument ID-FORMAT to file-attributes for GNU compatibility.
Mats Lidell <mats.lidell@cag.se>
parents: 5727
diff changeset
823 DEFUN ("file-attributes", Ffile_attributes, 1, 2, 0, /*
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 Return a list of attributes of file FILENAME.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 Value is nil if specified file cannot be opened.
5733
c30fdcab7bc8 Added optional argument ID-FORMAT to file-attributes for GNU compatibility.
Mats Lidell <mats.lidell@cag.se>
parents: 5727
diff changeset
826
c30fdcab7bc8 Added optional argument ID-FORMAT to file-attributes for GNU compatibility.
Mats Lidell <mats.lidell@cag.se>
parents: 5727
diff changeset
827 ID-FORMAT specifies the preferred format of attributes uid and gid (see
c30fdcab7bc8 Added optional argument ID-FORMAT to file-attributes for GNU compatibility.
Mats Lidell <mats.lidell@cag.se>
parents: 5727
diff changeset
828 below) - valid values are 'string and 'integer. The latter is the
c30fdcab7bc8 Added optional argument ID-FORMAT to file-attributes for GNU compatibility.
Mats Lidell <mats.lidell@cag.se>
parents: 5727
diff changeset
829 default.
c30fdcab7bc8 Added optional argument ID-FORMAT to file-attributes for GNU compatibility.
Mats Lidell <mats.lidell@cag.se>
parents: 5727
diff changeset
830
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 Otherwise, list elements are:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 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
833 1. Number of links to file.
5733
c30fdcab7bc8 Added optional argument ID-FORMAT to file-attributes for GNU compatibility.
Mats Lidell <mats.lidell@cag.se>
parents: 5727
diff changeset
834 2. File uid as a string or a number. If a string value cannot be
c30fdcab7bc8 Added optional argument ID-FORMAT to file-attributes for GNU compatibility.
Mats Lidell <mats.lidell@cag.se>
parents: 5727
diff changeset
835 looked up, a numeric value, either an integer or a float, is returned.
c30fdcab7bc8 Added optional argument ID-FORMAT to file-attributes for GNU compatibility.
Mats Lidell <mats.lidell@cag.se>
parents: 5727
diff changeset
836 3. File gid, likewise.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837 4. Last access time, as a list of two integers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 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
839 5. Last modification time, likewise.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 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
841 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
842 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
843 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
844 10. inode number.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 11. Device number.
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 If file does not exist, returns nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 */
5733
c30fdcab7bc8 Added optional argument ID-FORMAT to file-attributes for GNU compatibility.
Mats Lidell <mats.lidell@cag.se>
parents: 5727
diff changeset
849 (filename, id_format))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 /* This function can GC. GC checked 1997.06.04. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 Lisp_Object directory = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 struct stat s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854 char modes[10];
5386
af961911bcb2 Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents: 5350
diff changeset
855 Lisp_Object handler, mode, modestring = Qnil, size, gid;
af961911bcb2 Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents: 5350
diff changeset
856 struct gcpro gcpro1, gcpro2, gcpro3;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857
5733
c30fdcab7bc8 Added optional argument ID-FORMAT to file-attributes for GNU compatibility.
Mats Lidell <mats.lidell@cag.se>
parents: 5727
diff changeset
858 Lisp_Object uidInfo = Qnil;
c30fdcab7bc8 Added optional argument ID-FORMAT to file-attributes for GNU compatibility.
Mats Lidell <mats.lidell@cag.se>
parents: 5727
diff changeset
859 Lisp_Object gidInfo = Qnil;
c30fdcab7bc8 Added optional argument ID-FORMAT to file-attributes for GNU compatibility.
Mats Lidell <mats.lidell@cag.se>
parents: 5727
diff changeset
860
5386
af961911bcb2 Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents: 5350
diff changeset
861 GCPRO3 (filename, directory, modestring);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 filename = Fexpand_file_name (filename, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 /* If the file name has special constructs in it,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 call the corresponding file handler. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866 handler = Ffind_file_name_handler (filename, Qfile_attributes);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 if (!NILP (handler))
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;
5733
c30fdcab7bc8 Added optional argument ID-FORMAT to file-attributes for GNU compatibility.
Mats Lidell <mats.lidell@cag.se>
parents: 5727
diff changeset
870 if (NILP(id_format))
c30fdcab7bc8 Added optional argument ID-FORMAT to file-attributes for GNU compatibility.
Mats Lidell <mats.lidell@cag.se>
parents: 5727
diff changeset
871 return call2 (handler, Qfile_attributes, filename);
c30fdcab7bc8 Added optional argument ID-FORMAT to file-attributes for GNU compatibility.
Mats Lidell <mats.lidell@cag.se>
parents: 5727
diff changeset
872 else
c30fdcab7bc8 Added optional argument ID-FORMAT to file-attributes for GNU compatibility.
Mats Lidell <mats.lidell@cag.se>
parents: 5727
diff changeset
873 return call3 (handler, Qfile_attributes, filename, id_format);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
876 if (qxe_lstat (XSTRING_DATA (filename), &s) < 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880 }
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 #ifdef BSD4_2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 directory = Ffile_name_directory (filename);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
886 #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
887 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
888 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
889 Bytecount l = qxestrlen (tmpnam);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891 if (l >= 5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892 && S_ISREG (s.st_mode)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
893 && (qxestrcasecmp (&tmpnam[l - 4], ".com") == 0 ||
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
894 qxestrcasecmp (&tmpnam[l - 4], ".exe") == 0 ||
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
895 qxestrcasecmp (&tmpnam[l - 4], ".bat") == 0))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 s.st_mode |= S_IEXEC;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899 }
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
900 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 switch (s.st_mode & S_IFMT)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 default:
5386
af961911bcb2 Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents: 5350
diff changeset
905 mode = Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 case S_IFDIR:
5386
af961911bcb2 Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents: 5350
diff changeset
908 mode = Qt;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 #ifdef S_IFLNK
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911 case S_IFLNK:
5386
af961911bcb2 Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents: 5350
diff changeset
912 mode = Ffile_symlink_p (filename);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 }
4406
5998e37dc35e Use bignums if necessary for file size in #'file-attributes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 2367
diff changeset
916
5998e37dc35e Use bignums if necessary for file size in #'file-attributes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 2367
diff changeset
917 #ifndef HAVE_BIGNUM
5736
3192994c49ca Convert C (un)signed long long values to bignums properly.
Jerry James <james@xemacs.org>
parents: 5735
diff changeset
918 size = make_fixnum (NUMBER_FITS_IN_A_FIXNUM (s.st_size) ?
3192994c49ca Convert C (un)signed long long values to bignums properly.
Jerry James <james@xemacs.org>
parents: 5735
diff changeset
919 (EMACS_INT)s.st_size : -1);
4406
5998e37dc35e Use bignums if necessary for file size in #'file-attributes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 2367
diff changeset
920 #else
5386
af961911bcb2 Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents: 5350
diff changeset
921 size = make_integer (s.st_size);
af961911bcb2 Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents: 5350
diff changeset
922 #endif
4406
5998e37dc35e Use bignums if necessary for file size in #'file-attributes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 2367
diff changeset
923
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924 filemodestring (&s, modes);
5389
f560f6608937 Typo fix: use a semicolon instead of a comma at the end of a statement.
Jerry James <james@xemacs.org>
parents: 5386
diff changeset
925 modestring = make_string ((Ibyte *) modes, 10);
5386
af961911bcb2 Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents: 5350
diff changeset
926
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927 #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
928 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929 struct stat sdir;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
931 if (!NILP (directory) && qxe_stat (XSTRING_DATA (directory), &sdir) == 0)
5386
af961911bcb2 Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents: 5350
diff changeset
932 gid = (sdir.st_gid != s.st_gid) ? Qt : Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933 else /* if we can't tell, assume worst */
5386
af961911bcb2 Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents: 5350
diff changeset
934 gid = Qt;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936 #else /* file gid will be egid */
5386
af961911bcb2 Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents: 5350
diff changeset
937 gid = (s.st_gid != getegid ()) ? Qt : Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938 #endif /* BSD4_2 or BSD4_3 */
5386
af961911bcb2 Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents: 5350
diff changeset
939
5733
c30fdcab7bc8 Added optional argument ID-FORMAT to file-attributes for GNU compatibility.
Mats Lidell <mats.lidell@cag.se>
parents: 5727
diff changeset
940 if (NILP(id_format) || EQ (id_format, Qinteger))
c30fdcab7bc8 Added optional argument ID-FORMAT to file-attributes for GNU compatibility.
Mats Lidell <mats.lidell@cag.se>
parents: 5727
diff changeset
941 {
5762
427a72c6ee17 Eliminate several compiler (clang) warnings.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5736
diff changeset
942 uidInfo = make_unsigned_integer ((EMACS_UINT) s.st_uid);
427a72c6ee17 Eliminate several compiler (clang) warnings.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5736
diff changeset
943 gidInfo = make_unsigned_integer ((EMACS_UINT) s.st_gid);
5733
c30fdcab7bc8 Added optional argument ID-FORMAT to file-attributes for GNU compatibility.
Mats Lidell <mats.lidell@cag.se>
parents: 5727
diff changeset
944 }
c30fdcab7bc8 Added optional argument ID-FORMAT to file-attributes for GNU compatibility.
Mats Lidell <mats.lidell@cag.se>
parents: 5727
diff changeset
945 else
c30fdcab7bc8 Added optional argument ID-FORMAT to file-attributes for GNU compatibility.
Mats Lidell <mats.lidell@cag.se>
parents: 5727
diff changeset
946 {
c30fdcab7bc8 Added optional argument ID-FORMAT to file-attributes for GNU compatibility.
Mats Lidell <mats.lidell@cag.se>
parents: 5727
diff changeset
947 struct passwd *pw = qxe_getpwuid (s.st_uid);
c30fdcab7bc8 Added optional argument ID-FORMAT to file-attributes for GNU compatibility.
Mats Lidell <mats.lidell@cag.se>
parents: 5727
diff changeset
948 struct group *gr = qxe_getgrgid (s.st_gid);
c30fdcab7bc8 Added optional argument ID-FORMAT to file-attributes for GNU compatibility.
Mats Lidell <mats.lidell@cag.se>
parents: 5727
diff changeset
949
c30fdcab7bc8 Added optional argument ID-FORMAT to file-attributes for GNU compatibility.
Mats Lidell <mats.lidell@cag.se>
parents: 5727
diff changeset
950 uidInfo = build_istring (pw ? (Ibyte *) pw->pw_name : NULL);
5735
ff13c44ce0d9 Hack in rudimentary group support for WIN32 in support of Mats ID-FORMAT patch
Vin Shelton <acs@xemacs.org>
parents: 5733
diff changeset
951 #ifndef WIN32_NATIVE
5733
c30fdcab7bc8 Added optional argument ID-FORMAT to file-attributes for GNU compatibility.
Mats Lidell <mats.lidell@cag.se>
parents: 5727
diff changeset
952 gidInfo = build_istring (gr ? (Ibyte *) gr->gr_name : NULL);
5735
ff13c44ce0d9 Hack in rudimentary group support for WIN32 in support of Mats ID-FORMAT patch
Vin Shelton <acs@xemacs.org>
parents: 5733
diff changeset
953 #else
ff13c44ce0d9 Hack in rudimentary group support for WIN32 in support of Mats ID-FORMAT patch
Vin Shelton <acs@xemacs.org>
parents: 5733
diff changeset
954 gidInfo = build_istring (NULL);
ff13c44ce0d9 Hack in rudimentary group support for WIN32 in support of Mats ID-FORMAT patch
Vin Shelton <acs@xemacs.org>
parents: 5733
diff changeset
955 #endif //WIN32_NATIVE
5733
c30fdcab7bc8 Added optional argument ID-FORMAT to file-attributes for GNU compatibility.
Mats Lidell <mats.lidell@cag.se>
parents: 5727
diff changeset
956 }
c30fdcab7bc8 Added optional argument ID-FORMAT to file-attributes for GNU compatibility.
Mats Lidell <mats.lidell@cag.se>
parents: 5727
diff changeset
957
5386
af961911bcb2 Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents: 5350
diff changeset
958 RETURN_UNGCPRO (listn (12,
af961911bcb2 Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents: 5350
diff changeset
959 mode,
5762
427a72c6ee17 Eliminate several compiler (clang) warnings.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5736
diff changeset
960 make_unsigned_integer ((EMACS_UINT) s.st_nlink),
5733
c30fdcab7bc8 Added optional argument ID-FORMAT to file-attributes for GNU compatibility.
Mats Lidell <mats.lidell@cag.se>
parents: 5727
diff changeset
961 uidInfo,
c30fdcab7bc8 Added optional argument ID-FORMAT to file-attributes for GNU compatibility.
Mats Lidell <mats.lidell@cag.se>
parents: 5727
diff changeset
962 gidInfo,
5386
af961911bcb2 Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents: 5350
diff changeset
963 make_time (s.st_atime),
af961911bcb2 Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents: 5350
diff changeset
964 make_time (s.st_mtime),
af961911bcb2 Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents: 5350
diff changeset
965 make_time (s.st_ctime),
af961911bcb2 Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents: 5350
diff changeset
966 size,
af961911bcb2 Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents: 5350
diff changeset
967 modestring,
af961911bcb2 Make listu() and listn() assemble lists in forward order. Use them.
Jerry James <james@xemacs.org>
parents: 5350
diff changeset
968 gid,
5736
3192994c49ca Convert C (un)signed long long values to bignums properly.
Jerry James <james@xemacs.org>
parents: 5735
diff changeset
969 make_unsigned_integer (s.st_ino),
5762
427a72c6ee17 Eliminate several compiler (clang) warnings.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5736
diff changeset
970 make_unsigned_integer ((EMACS_UINT) s.st_dev)));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971 }
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
975 /* initialization */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
976 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
979 syms_of_dired (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 546
diff changeset
981 DEFSYMBOL (Qdirectory_files);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 546
diff changeset
982 DEFSYMBOL (Qfile_name_completion);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 546
diff changeset
983 DEFSYMBOL (Qfile_name_all_completions);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 546
diff changeset
984 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
985 DEFSYMBOL (Qfile_system_ignore_case_p);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
987 DEFSUBR (Fdirectory_files);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988 DEFSUBR (Ffile_name_completion);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
989 DEFSUBR (Ffile_name_all_completions);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
990 DEFSUBR (Fuser_name_completion);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
991 DEFSUBR (Fuser_name_completion_1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
992 DEFSUBR (Fuser_name_all_completions);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
993 DEFSUBR (Ffile_attributes);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
994 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
995
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
996 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
997 vars_of_dired (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
998 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
999 DEFVAR_LISP ("completion-ignored-extensions", &Vcompletion_ignored_extensions /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1000 *Completion ignores filenames ending in any string in this list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1001 This variable does not affect lists of possible completions,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1002 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
1003 It is used by the function `file-name-completion'.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1004 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1005 Vcompletion_ignored_extensions = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1006 }