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