annotate src/dired-msw.c @ 563:183866b06e0b

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