annotate src/dired-msw.c @ 353:3b3709405255 r21-1-6

Import from CVS: tag r21-1-6
author cvs
date Mon, 13 Aug 2007 10:55:33 +0200
parents e11d67e05968
children 74fd4e045ea6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1 /* fast dired replacement routines for mswindows.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
2 Copyright (C) 1998 Darryl Okahata
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
3 Portions Copyright (C) 1992, 1994 by Sebastian Kremer <sk@thp.uni-koeln.de>
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
4
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
5 This file is part of XEmacs.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
6
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
10 later version.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
11
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
15 for more details.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
16
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
21
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
22 /* Synched up with: Not in FSF. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
23
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
24 /*
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
25 * Parts of this code (& comments) were taken from ls-lisp.el
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
26 * Author: Sebastian Kremer <sk@thp.uni-koeln.de>
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
27 */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
28
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
29 /*
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
30 * insert-directory
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
31 * - must insert _exactly_one_line_ describing FILE if WILDCARD and
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
32 * FULL-DIRECTORY-P is nil.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
33 * The single line of output must display FILE's name as it was
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
34 * given, namely, an absolute path name.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
35 * - must insert exactly one line for each file if WILDCARD or
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
36 * FULL-DIRECTORY-P is t, plus one optional "total" line
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
37 * before the file lines, plus optional text after the file lines.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
38 * Lines are delimited by "\n", so filenames containing "\n" are not
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
39 * allowed.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
40 * File lines should display the basename.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
41 * - must be consistent with
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
42 * - functions dired-move-to-filename, (these two define what a file line is)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
43 * dired-move-to-end-of-filename,
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
44 * dired-between-files, (shortcut for (not (dired-move-to-filename)))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
45 * dired-insert-headerline
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
46 * dired-after-subdir-garbage (defines what a "total" line is)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
47 * - variable dired-subdir-regexp
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
48 */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
49
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
50 /*
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
51 * Insert directory listing for FILE, formatted according to SWITCHES.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
52 * Leaves point after the inserted text.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
53 * SWITCHES may be a string of options, or a list of strings.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
54 * Optional third arg WILDCARD means treat FILE as shell wildcard.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
55 * Optional fourth arg FULL-DIRECTORY-P means file is a directory and
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
56 * switches do not contain `d', so that a full listing is expected.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
57 *
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
58 * This works by running a directory listing program
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
59 * whose name is in the variable `insert-directory-program'.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
60 * If WILDCARD, it also runs the shell specified by `shell-file-name'."
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
61 */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
62
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
63 /*
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
64 * Set INDENT_LISTING to non-zero if the inserted text should be shifted
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
65 * over by two spaces.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
66 */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
67 #define INDENT_LISTING 0
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
68
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
69 #define ROUND_FILE_SIZES 4096
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
70
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
71
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
72 #include <config.h>
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
73 #include "lisp.h"
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
74
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
75 #include "buffer.h"
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
76 #include "regex.h"
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
77
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 282
diff changeset
78 #include "sysdir.h"
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
79 #include "sysfile.h"
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 282
diff changeset
80 #include "sysproc.h"
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
81
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
82 #include <windows.h>
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
83 #include <limits.h>
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 282
diff changeset
84 #include <time.h>
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 282
diff changeset
85
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 282
diff changeset
86 #include <winsock.h> /* To make nt.h happy */
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 282
diff changeset
87 #include "nt.h" /* For prototypes */
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
88
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
89 #if ROUND_FILE_SIZES > 0
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
90 #include <math.h> /* for floor() */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
91 #endif
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
92
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
93
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 272
diff changeset
94 static int mswindows_ls_sort_case_insensitive;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 272
diff changeset
95 static int mswindows_ls_round_file_size;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 272
diff changeset
96
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
97 Lisp_Object Qmswindows_insert_directory;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
98
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
99 extern Lisp_Object Vmswindows_downcase_file_names; /* in device-msw.c */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
100
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
101
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 272
diff changeset
102
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
103 enum mswindows_sortby {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
104 MSWINDOWS_SORT_BY_NAME,
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
105 MSWINDOWS_SORT_BY_NAME_NOCASE,
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
106 MSWINDOWS_SORT_BY_MOD_DATE,
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
107 MSWINDOWS_SORT_BY_SIZE
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
108 };
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
109
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
110
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
111 static enum mswindows_sortby mswindows_sort_method;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
112 static int mswindows_reverse_sort;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
113
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
114
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
115 #define CMPDWORDS(t1a, t1b, t2a, t2b) \
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
116 (((t1a) == (t2a)) ? (((t1b) == (t2b)) ? 0 : (((t1b) < (t2b)) ? -1 : 1)) \
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
117 : (((t1a) < (t2a)) ? -1 : 1))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
118
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
119
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
120 static int
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
121 mswindows_ls_sort_fcn (const void *elem1, const void *elem2)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
122 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
123 WIN32_FIND_DATA *e1, *e2;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
124 int status;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
125
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
126 e1 = *(WIN32_FIND_DATA **)elem1;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
127 e2 = *(WIN32_FIND_DATA **)elem2;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
128 switch (mswindows_sort_method)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
129 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
130 case MSWINDOWS_SORT_BY_NAME:
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
131 status = strcmp(e1->cFileName, e2->cFileName);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
132 break;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
133 case MSWINDOWS_SORT_BY_NAME_NOCASE:
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
134 status = _stricmp(e1->cFileName, e2->cFileName);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
135 break;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
136 case MSWINDOWS_SORT_BY_MOD_DATE:
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
137 status = CMPDWORDS(e1->ftLastWriteTime.dwHighDateTime,
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
138 e1->ftLastWriteTime.dwLowDateTime,
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
139 e2->ftLastWriteTime.dwHighDateTime,
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
140 e2->ftLastWriteTime.dwLowDateTime);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
141 break;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
142 case MSWINDOWS_SORT_BY_SIZE:
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
143 status = CMPDWORDS(e1->nFileSizeHigh, e1->nFileSizeLow,
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
144 e2->nFileSizeHigh, e2->nFileSizeLow);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
145 break;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
146 default:
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
147 status = 0;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
148 break;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
149 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
150 if (mswindows_reverse_sort)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
151 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
152 status = -status;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
153 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
154 return (status);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
155 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
156
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
157
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
158 static void
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
159 mswindows_sort_files (WIN32_FIND_DATA **files, int nfiles,
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
160 enum mswindows_sortby sort_by, int reverse)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
161 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
162 mswindows_sort_method = sort_by;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
163 mswindows_reverse_sort = reverse;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
164 qsort(files, nfiles, sizeof(WIN32_FIND_DATA *), mswindows_ls_sort_fcn);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
165 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
166
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
167
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
168 static WIN32_FIND_DATA *
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
169 mswindows_get_files (char *dirfile, int nowild, Lisp_Object pattern,
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
170 int hide_dot, int hide_system, int *nfiles)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
171 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
172 WIN32_FIND_DATA *files;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
173 int array_size;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
174 struct re_pattern_buffer *bufp = NULL;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
175 int findex, len;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
176 char win32pattern[MAXNAMLEN+3];
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
177 HANDLE fh;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
178
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
179 /*
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
180 * Much of the following code and comments were taken from dired.c.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
181 * Yes, this is something of a waste, but we want speed, speed, SPEED.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
182 */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
183 files = NULL;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
184 array_size = *nfiles = 0;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
185 while (1)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
186 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
187 if (!NILP(pattern))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
188 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
189 /* PATTERN might be a flawed regular expression. Rather than
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
190 catching and signalling our own errors, we just call
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
191 compile_pattern to do the work for us. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
192 bufp = compile_pattern (pattern, 0, 0, 0, ERROR_ME);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
193 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
194 /* Now *bufp is the compiled form of PATTERN; don't call anything
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
195 which might compile a new regexp until we're done with the loop! */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
196
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
197 /* Initialize file info array */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
198 array_size = 100; /* initial size */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
199 files = xmalloc(array_size * sizeof (WIN32_FIND_DATA));
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
200
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
201 /* for Win32, we need to insure that the pathname ends with "\*". */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
202 strcpy (win32pattern, dirfile);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
203 if (!nowild)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
204 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
205 len = strlen (win32pattern) - 1;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
206 if (!IS_DIRECTORY_SEP (win32pattern[len]))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
207 strcat (win32pattern, "\\");
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
208 strcat (win32pattern, "*");
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
209 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
210
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
211 /*
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
212 * Here, we use FindFirstFile()/FindNextFile() instead of opendir(),
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
213 * stat(), & friends, because stat() is VERY expensive in terms of
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
214 * time. Hence, we take the time to write complicated Win32-specific
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
215 * code, instead of simple Unix-style stuff.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
216 */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
217 findex = 0;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
218 fh = INVALID_HANDLE_VALUE;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
219
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
220 while (1)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
221 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
222 int len;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
223 char *filename;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
224 int result;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
225
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
226 if (fh == INVALID_HANDLE_VALUE)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
227 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
228 fh = FindFirstFile(win32pattern, &files[findex]);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
229 if (fh == INVALID_HANDLE_VALUE)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
230 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
231 report_file_error ("Opening directory",
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
232 list1(build_string(dirfile)));
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
233 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
234 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
235 else
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
236 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
237 if (!FindNextFile(fh, &files[findex]))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
238 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
239 if (GetLastError() == ERROR_NO_MORE_FILES)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
240 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
241 break;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
242 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
243 FindClose(fh);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
244 report_file_error ("Reading directory",
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
245 list1(build_string(dirfile)));
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
246 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
247 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
248
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
249 filename = files[findex].cFileName;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
250 if (!NILP(Vmswindows_downcase_file_names))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
251 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
252 strlwr(filename);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
253 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
254 len = strlen(filename);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
255 result = (NILP(pattern)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
256 || (0 <= re_search (bufp, filename,
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
257 len, 0, len, 0)));
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
258 if (result)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
259 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
260 if ( ! (filename[0] == '.' &&
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
261 ((hide_system && (filename[1] == '\0' ||
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
262 (filename[1] == '.' &&
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
263 filename[2] == '\0'))) ||
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
264 hide_dot)))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
265 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
266 if (++findex >= array_size)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
267 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
268 array_size = findex * 2;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
269 files = xrealloc(files,
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
270 array_size * sizeof(WIN32_FIND_DATA));
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
271 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
272 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
273 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
274 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
275 if (fh != INVALID_HANDLE_VALUE)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
276 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
277 FindClose (fh);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
278 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
279 *nfiles = findex;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
280 break;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
281 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
282 return (files);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
283 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
284
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
285
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
286 static void
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
287 mswindows_format_file (WIN32_FIND_DATA *file, char *buf, int display_size,
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
288 int add_newline)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
289 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
290 char *cptr;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
291 int len;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
292 Lisp_Object luser;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
293 double file_size;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
294
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
295 len = strlen(file->cFileName);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
296 file_size =
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
297 file->nFileSizeHigh * (double)UINT_MAX + file->nFileSizeLow;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
298 cptr = buf;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
299 #if INDENT_LISTING
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
300 *cptr++ = ' ';
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
301 *cptr++ = ' ';
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
302 #endif
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
303 if (display_size)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
304 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
305 sprintf(cptr, "%6d ", (int)((file_size + 1023.) / 1024.));
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
306 cptr += 7;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
307 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
308 if (file->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
309 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
310 *cptr++ = 'd';
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
311 } else {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
312 *cptr++ = '-';
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
313 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
314 cptr[0] = cptr[3] = cptr[6] = 'r';
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
315 if (file->dwFileAttributes & FILE_ATTRIBUTE_READONLY)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
316 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
317 cptr[1] = cptr[4] = cptr[7] = '-';
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
318 } else {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
319 cptr[1] = cptr[4] = cptr[7] = 'w';
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
320 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
321 if ((file->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
322 len > 4 &&
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
323 (_stricmp(&file->cFileName[len - 4], ".exe") == 0
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
324 || _stricmp(&file->cFileName[len - 4], ".com") == 0
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
325 || _stricmp(&file->cFileName[len - 4], ".bat") == 0
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
326 #if 0
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
327 || _stricmp(&file->cFileName[len - 4], ".pif") == 0
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
328 #endif
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
329 ))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
330 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
331 cptr[2] = cptr[5] = cptr[8] = 'x';
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
332 } else {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
333 cptr[2] = cptr[5] = cptr[8] = '-';
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
334 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
335 cptr += 9;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
336 if (file->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
337 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
338 strcpy(cptr, " 2 ");
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
339 } else {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
340 strcpy(cptr, " 1 ");
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
341 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
342 cptr += 5;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
343 luser = Fuser_login_name(Qnil);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
344 if (!STRINGP(luser))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
345 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
346 sprintf(cptr, "%-9d", 0);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
347 } else {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
348 char *str;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
349
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
350 str = XSTRING_DATA(luser);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
351 sprintf(cptr, "%-8s ", str);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
352 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
353 while (*cptr)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
354 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
355 ++cptr;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
356 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
357 sprintf(cptr, "%-8d ", getgid());
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
358 cptr += 9;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
359 if (file_size > 99999999.0)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
360 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
361 file_size = (file_size + 1023.0) / 1024.;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
362 if (file_size > 999999.0)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
363 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
364 sprintf(cptr, "%6.0fMB ", (file_size + 1023.0) / 1024.);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
365 } else {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
366 sprintf(cptr, "%6.0fKB ", file_size);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
367 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
368 } else {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
369 sprintf(cptr, "%8.0f ", file_size);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
370 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
371 while (*cptr)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
372 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
373 ++cptr;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
374 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
375 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
376 time_t t, now;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
377 char *ctimebuf;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
378 extern char *sys_ctime(const time_t *t); /* in nt.c */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
379
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
380 if (
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
381 #if 0
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
382 /*
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
383 * This doesn't work.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
384 * This code should be correct ...
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
385 */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
386 FileTimeToLocalFileTime(&file->ftLastWriteTime, &localtime) &&
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
387 ((t = convert_time(localtime)) != 0) &&
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
388 #else
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
389 /*
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
390 * But this code "works" ...
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
391 */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
392 ((t = convert_time(file->ftLastWriteTime)) != 0) &&
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
393 #endif
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
394 ((ctimebuf = sys_ctime(&t)) != NULL))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
395 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
396 memcpy(cptr, &ctimebuf[4], 7);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
397 now = time(NULL);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
398 if (now - t > (365. / 2.0) * 86400.)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
399 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
400 /* more than 6 months */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
401 cptr[7] = ' ';
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
402 memcpy(&cptr[8], &ctimebuf[20], 4);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
403 } else {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
404 /* less than 6 months */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
405 memcpy(&cptr[7], &ctimebuf[11], 5);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
406 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
407 cptr += 12;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
408 *cptr++ = ' ';
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
409 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
410 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
411 if (add_newline)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
412 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
413 sprintf(cptr, "%s\n", file->cFileName);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
414 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
415 else
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
416 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
417 strcpy(cptr, file->cFileName);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
418 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
419 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
420
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
421
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
422 DEFUN ("mswindows-insert-directory", Fmswindows_insert_directory, 2, 4, 0, /*
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
423 Insert directory listing for FILE, formatted according to SWITCHES.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
424 Leaves point after the inserted text.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
425 SWITCHES may be a string of options, or a list of strings.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
426 Optional third arg WILDCARD means treat FILE as shell wildcard.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
427 Optional fourth arg FULL-DIRECTORY-P means file is a directory and
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
428 switches do not contain `d', so that a full listing is expected.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
429 */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
430 (file, switches, wildcard, full_directory_p))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
431 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
432 Lisp_Object result, handler, wildpat, fns, basename;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
433 char *filename;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
434 char *switchstr;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
435 int len, nfiles, i;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
436 int hide_system, hide_dot, reverse, display_size;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
437 WIN32_FIND_DATA *files, **sorted_files;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
438 enum mswindows_sortby sort_by;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
439 char fmtbuf[MAXNAMLEN+100]; /* larger than necessary */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
440 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
441
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
442 result = Qnil;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
443 wildpat = Qnil;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
444 fns = Qnil;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
445 basename = Qnil;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
446 GCPRO5(result, file, wildpat, fns, basename);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
447 sorted_files = NULL;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
448 switchstr = NULL;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
449 hide_system = 1;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
450 hide_dot = 1;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
451 display_size = 0;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
452 reverse = 0;
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 272
diff changeset
453 sort_by = (mswindows_ls_sort_case_insensitive
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 272
diff changeset
454 ? MSWINDOWS_SORT_BY_NAME_NOCASE
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 272
diff changeset
455 : MSWINDOWS_SORT_BY_NAME);
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
456 nfiles = 0;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
457 while (1)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
458 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
459 handler = Ffind_file_name_handler (file, Qmswindows_insert_directory);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
460 if (!NILP(handler))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
461 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
462 result = call5(handler, Qmswindows_insert_directory, file, switches,
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
463 wildcard, full_directory_p);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
464 break;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
465 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
466 CHECK_STRING (file);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
467 if (!NILP(switches))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
468 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
469 char *cptr;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
470
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
471 CHECK_STRING (switches);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
472 switchstr = XSTRING_DATA(switches);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
473 for (cptr = switchstr; *cptr; ++cptr)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
474 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
475 switch (*cptr)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
476 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
477 case 'A':
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
478 hide_dot = 0;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
479 break;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
480 case 'a':
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
481 hide_system = 0;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
482 hide_dot = 0;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
483 break;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
484 case 'r':
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
485 reverse = 1;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
486 break;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
487 case 's':
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
488 display_size = 1;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
489 break;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
490 case 'S':
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
491 sort_by = MSWINDOWS_SORT_BY_SIZE;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
492 break;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
493 case 't':
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
494 sort_by = MSWINDOWS_SORT_BY_MOD_DATE;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
495 break;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
496 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
497 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
498 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
499
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
500 /*
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
501 * Sometimes we get ".../foo* /" as FILE (without the space).
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
502 * While the shell and `ls' don't mind, we certainly do,
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
503 * because it makes us think there is no wildcard, only a
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
504 * directory name.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
505 */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
506 if (!NILP(Fstring_match(build_string("[[?*]"), file, Qnil, Qnil)))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
507 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
508 wildcard = Qt;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
509 filename = XSTRING_DATA(file);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
510 len = strlen(filename);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
511 if (len > 0 && (filename[len - 1] == '\\' ||
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
512 filename[len - 1] == '/'))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
513 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
514 filename[len - 1] = '\0';
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
515 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
516 file = build_string(filename);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
517 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
518 if (!NILP(wildcard))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
519 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
520 Lisp_Object newfile;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
521
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
522 basename = Ffile_name_nondirectory(file);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
523 fns = intern("wildcard-to-regexp");
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
524 wildpat = call1(fns, basename);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
525 newfile = Ffile_name_directory(file);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
526 if (NILP(newfile))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
527 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
528 /* Ffile_name_directory() can GC */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
529 newfile = Ffile_name_directory(Fexpand_file_name(file, Qnil));
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
530 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
531 file = newfile;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
532 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
533 if (!NILP(wildcard) || !NILP(full_directory_p))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
534 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
535 CHECK_STRING(file);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
536 if (!NILP(wildpat))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
537 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
538 CHECK_STRING(wildpat);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
539 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
540
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
541 files = mswindows_get_files(XSTRING_DATA(file), FALSE, wildpat,
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
542 hide_dot, hide_system, &nfiles);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
543 if (files == NULL || nfiles == 0)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
544 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
545 break;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
546 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
547 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
548 else
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
549 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
550 files = mswindows_get_files(XSTRING_DATA(file), TRUE, wildpat,
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
551 hide_dot, hide_system, &nfiles);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
552 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
553 if ((sorted_files = xmalloc(nfiles * sizeof(WIN32_FIND_DATA *)))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
554 == NULL)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
555 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
556 break;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
557 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
558 for (i = 0; i < nfiles; ++i)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
559 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
560 sorted_files[i] = &files[i];
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
561 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
562 if (nfiles > 1)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
563 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
564 mswindows_sort_files(sorted_files, nfiles, sort_by, reverse);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
565 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
566 if (!NILP(wildcard) || !NILP(full_directory_p))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
567 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
568 /*
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
569 * By using doubles, we can handle files up to 2^53 bytes in
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
570 * size (IEEE doubles have 53 bits of resolution). However,
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
571 * as we divide by 1024 (or 2^10), the total size is
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
572 * accurate up to 2^(53+10) --> 2^63 bytes.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
573 *
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
574 * Hopefully, we won't have to handle these file sizes anytime
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
575 * soon.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
576 */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
577 double total_size, file_size, block_size;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
578
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 272
diff changeset
579 if ((block_size = mswindows_ls_round_file_size) <= 0)
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
580 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
581 block_size = 0;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
582 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
583 total_size = 0;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
584 for (i = 0; i < nfiles; ++i)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
585 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
586 file_size =
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
587 sorted_files[i]->nFileSizeHigh * (double)UINT_MAX +
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
588 sorted_files[i]->nFileSizeLow;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
589 if (block_size > 0)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
590 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
591 /*
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
592 * Round file_size up to the next nearest block size.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
593 */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
594 file_size =
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
595 floor((file_size + block_size - 1) / block_size)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
596 * block_size;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
597 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
598 /* Here, we round to the nearest 1K */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
599 total_size += floor((file_size + 512.) / 1024.);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
600 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
601 sprintf(fmtbuf,
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
602 #if INDENT_LISTING
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
603 /* ANSI C compilers auto-concatenate adjacent strings */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
604 " "
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
605 #endif
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
606 "total %.0f\n", total_size);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
607 buffer_insert1(current_buffer, build_string(fmtbuf));
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
608 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
609 for (i = 0; i < nfiles; ++i)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
610 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
611 mswindows_format_file(sorted_files[i], fmtbuf, display_size, TRUE);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
612 buffer_insert1(current_buffer, build_string(fmtbuf));
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
613 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
614 break;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
615 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
616 if (sorted_files)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
617 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
618 xfree(sorted_files);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
619 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
620 UNGCPRO;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
621 return (result);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
622 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
623
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
624
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
625
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
626 /************************************************************************/
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
627 /* initialization */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
628 /************************************************************************/
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
629
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
630 void
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
631 syms_of_dired_mswindows (void)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
632 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
633 defsymbol (&Qmswindows_insert_directory, "mswindows-insert-directory");
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
634
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
635 DEFSUBR (Fmswindows_insert_directory);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
636 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
637
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
638
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
639 void
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
640 vars_of_dired_mswindows (void)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
641 {
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 272
diff changeset
642 DEFVAR_BOOL ("mswindows-ls-sort-case-insensitive", &mswindows_ls_sort_case_insensitive, /*
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
643 *Non-nil means filenames are sorted in a case-insensitive fashion.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
644 Nil means filenames are sorted in a case-sensitive fashion, just like Unix.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
645 */ );
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 272
diff changeset
646 mswindows_ls_sort_case_insensitive = 1;
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
647
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 272
diff changeset
648 DEFVAR_INT ("mswindows-ls-round-file-size", &mswindows_ls_round_file_size /*
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
649 *If non-zero, file sizes are rounded in terms of this block size when
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
650 the file totals are being calculated. This is useful for getting a more
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
651 accurate estimate of allocated disk space. Note that this only affects
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
652 the total size calculation; the individual displayed file sizes are not
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
653 changed. This block size should also be a power of 2 (but this is not
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
654 enforced), as filesystem block (cluster) sizes are typically powers-of-2.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
655 */ );
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
656 /*
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
657 * Here, we choose 4096 because it's the cluster size for both FAT32
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
658 * and NTFS (?). This is probably much too small for people using
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
659 * plain FAT, but, hopefully, plain FAT will go away someday.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
660 *
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
661 * We should allow something like a alist here, to make the size
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
662 * dependent on the drive letter, etc..
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
663 */
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 272
diff changeset
664 mswindows_ls_round_file_size = 4096;
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
665 }