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