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