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