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