annotate src/dired-msw.c @ 819:6504113e7c2d

[xemacs-hg @ 2002-04-25 18:03:23 by andyp] sync up windows branch from 21.4
author andyp
date Thu, 25 Apr 2002 18:04:24 +0000
parents a5954632b187
children 6728e641994e
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>
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 771
diff changeset
4 Copyright (C) 2000, 2001, 2002 Ben Wing.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 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
10 Free Software Foundation; either version 2, or (at your option) any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 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
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 along with XEmacs; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 Boston, MA 02111-1307, USA. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 /* Synched up with: Not in FSF. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
25
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 * Parts of this code (& comments) were taken from ls-lisp.el
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 * Author: Sebastian Kremer <sk@thp.uni-koeln.de>
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 * insert-directory
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 * - must insert _exactly_one_line_ describing FILE if WILDCARD and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 * FULL-DIRECTORY-P is nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 * 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
36 * given, namely, an absolute path name.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 * - must insert exactly one line for each file if WILDCARD or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 * FULL-DIRECTORY-P is t, plus one optional "total" line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 * before the file lines, plus optional text after the file lines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 * Lines are delimited by "\n", so filenames containing "\n" are not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 * allowed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 * File lines should display the basename.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 * - must be consistent with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 * - 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
45 * dired-move-to-end-of-filename,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 * dired-between-files, (shortcut for (not (dired-move-to-filename)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 * dired-insert-headerline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 * dired-after-subdir-garbage (defines what a "total" line is)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 * - variable dired-subdir-regexp
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 * Insert directory listing for FILE, formatted according to SWITCHES.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 * Leaves point after the inserted text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 * SWITCHES may be a string of options, or a list of strings.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 * Optional third arg WILDCARD means treat FILE as shell wildcard.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 * Optional fourth arg FULL-DIRECTORY-P means file is a directory and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 * switches do not contain `d', so that a full listing is expected.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 * This works by running a directory listing program
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 * whose name is in the variable `insert-directory-program'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 * If WILDCARD, it also runs the shell specified by `shell-file-name'."
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 * 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
67 * over by two spaces.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
69 #define INDENT_LISTING 0
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
71 #define ROUND_FILE_SIZES 4096
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 #include "lisp.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 #include "buffer.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 #include "regex.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 #include "sysdir.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"
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
83 #include "sysproc.h"
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
84 #include "syspwd.h"
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
85 #include "systime.h"
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
86 #include "syswindows.h"
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 static int mswindows_ls_sort_case_insensitive;
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 446
diff changeset
89 static Fixnum mswindows_ls_round_file_size;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
91 Lisp_Object Qmswindows_insert_directory;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
92 Lisp_Object Qwildcard_to_regexp;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
94 extern Lisp_Object Vmswindows_downcase_file_names; /* in device-msw.c */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95
558
ed498ef2108b [xemacs-hg @ 2001-05-23 09:59:33 by ben]
ben
parents: 458
diff changeset
96 enum mswindows_sortby
ed498ef2108b [xemacs-hg @ 2001-05-23 09:59:33 by ben]
ben
parents: 458
diff changeset
97 {
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 MSWINDOWS_SORT_BY_NAME,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 MSWINDOWS_SORT_BY_NAME_NOCASE,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 MSWINDOWS_SORT_BY_MOD_DATE,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 MSWINDOWS_SORT_BY_SIZE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 };
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
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
105 static enum mswindows_sortby mswindows_sort_method;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
106 static int mswindows_reverse_sort;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
107
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
108 /* We create our own structure because the cFileName field in
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
109 WIN32_FIND_DATA is in external format and of fixed size, which we
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
110 may exceed when translating. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
111
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
112 typedef struct
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
113 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
114 DWORD dwFileAttributes;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
115 FILETIME ftCreationTime;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
116 FILETIME ftLastAccessTime;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
117 FILETIME ftLastWriteTime;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
118 DWORD nFileSizeHigh;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
119 DWORD nFileSizeLow;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
120 Intbyte *cFileName;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
121 } Win32_file;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
122
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
123 typedef struct
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
124 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
125 Dynarr_declare (Win32_file);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
126 } Win32_file_dynarr;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
127
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 #define CMPDWORDS(t1a, t1b, t2a, t2b) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 (((t1a) == (t2a)) ? (((t1b) == (t2b)) ? 0 : (((t1b) < (t2b)) ? -1 : 1)) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 : (((t1a) < (t2a)) ? -1 : 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 mswindows_ls_sort_fcn (const void *elem1, const void *elem2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
138 Win32_file *e1, *e2;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
139 int status;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
141 e1 = (Win32_file *) elem1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
142 e2 = (Win32_file *) elem2;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
143
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 switch (mswindows_sort_method)
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 case MSWINDOWS_SORT_BY_NAME:
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
147 status = strcmp (e1->cFileName, e2->cFileName);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 case MSWINDOWS_SORT_BY_NAME_NOCASE:
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
150 status = qxestrcasecmp (e1->cFileName, e2->cFileName);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 case MSWINDOWS_SORT_BY_MOD_DATE:
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
153 status = CMPDWORDS (e1->ftLastWriteTime.dwHighDateTime,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
154 e1->ftLastWriteTime.dwLowDateTime,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
155 e2->ftLastWriteTime.dwHighDateTime,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
156 e2->ftLastWriteTime.dwLowDateTime);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 case MSWINDOWS_SORT_BY_SIZE:
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
159 status = CMPDWORDS (e1->nFileSizeHigh, e1->nFileSizeLow,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
160 e2->nFileSizeHigh, e2->nFileSizeLow);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 status = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 if (mswindows_reverse_sort)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 status = -status;
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 return (status);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 }
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 static void
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
174 mswindows_sort_files (Win32_file_dynarr *files,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 enum mswindows_sortby sort_by, int reverse)
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 mswindows_sort_method = sort_by;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 mswindows_reverse_sort = reverse;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
179 qsort (Dynarr_atp (files, 0), Dynarr_length (files),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
180 sizeof (Win32_file), mswindows_ls_sort_fcn);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
183 static Win32_file_dynarr *
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
184 mswindows_get_files (Lisp_Object dirfile, int nowild, Lisp_Object pattern,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
185 int hide_dot, int hide_system)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
187 Win32_file_dynarr *files = Dynarr_new (Win32_file);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
188 struct re_pattern_buffer *bufp = NULL;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
189 int findex;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
190 DECLARE_EISTRING (win32pattern);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
191 HANDLE fh;
819
6504113e7c2d [xemacs-hg @ 2002-04-25 18:03:23 by andyp]
andyp
parents: 800
diff changeset
192 int errm;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
196 if (!NILP (pattern))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 /* PATTERN might be a flawed regular expression. Rather than
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 catching and signalling our own errors, we just call
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 compile_pattern to do the work for us. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
201 bufp = compile_pattern (pattern, 0, Qnil, 0, ERROR_ME);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 /* Now *bufp is the compiled form of PATTERN; don't call anything
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 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
205
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 /* for Win32, we need to insure that the pathname ends with "\*". */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
207 eicpy_lstr (win32pattern, dirfile);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 if (!nowild)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
210 Charcount len = eicharlen (win32pattern) - 1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
211 if (!IS_DIRECTORY_SEP (eigetch_char (win32pattern, len)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
212 eicat_c (win32pattern, "\\");
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
213 eicat_c (win32pattern, "*");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
215 eito_external (win32pattern, Qmswindows_tstr);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216
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 * Here, we use FindFirstFile()/FindNextFile() instead of opendir(),
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
219 * qxe_stat(), & friends, because qxe_stat() is VERY expensive in
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
220 * terms of time. Hence, we take the time to write complicated
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
221 * Win32-specific code, instead of simple Unix-style stuff.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 findex = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 fh = INVALID_HANDLE_VALUE;
819
6504113e7c2d [xemacs-hg @ 2002-04-25 18:03:23 by andyp]
andyp
parents: 800
diff changeset
225 errm = SetErrorMode (SEM_FAILCRITICALERRORS
6504113e7c2d [xemacs-hg @ 2002-04-25 18:03:23 by andyp]
andyp
parents: 800
diff changeset
226 | SEM_NOOPENFILEERRORBOX);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
230 Bytecount len;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
231 DECLARE_EISTRING (filename);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
232 int result;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
233 WIN32_FIND_DATAW finddat;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
234 Win32_file file;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 if (fh == INVALID_HANDLE_VALUE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
238 fh = qxeFindFirstFile (eiextdata (win32pattern), &finddat);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 if (fh == INVALID_HANDLE_VALUE)
819
6504113e7c2d [xemacs-hg @ 2002-04-25 18:03:23 by andyp]
andyp
parents: 800
diff changeset
240 {
6504113e7c2d [xemacs-hg @ 2002-04-25 18:03:23 by andyp]
andyp
parents: 800
diff changeset
241 SetErrorMode (errm);
6504113e7c2d [xemacs-hg @ 2002-04-25 18:03:23 by andyp]
andyp
parents: 800
diff changeset
242 report_file_error ("Opening directory", dirfile);
6504113e7c2d [xemacs-hg @ 2002-04-25 18:03:23 by andyp]
andyp
parents: 800
diff changeset
243 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
247 if (! qxeFindNextFile (fh, &finddat))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 {
819
6504113e7c2d [xemacs-hg @ 2002-04-25 18:03:23 by andyp]
andyp
parents: 800
diff changeset
249 if (GetLastError() == ERROR_NO_MORE_FILES)
6504113e7c2d [xemacs-hg @ 2002-04-25 18:03:23 by andyp]
andyp
parents: 800
diff changeset
250 {
6504113e7c2d [xemacs-hg @ 2002-04-25 18:03:23 by andyp]
andyp
parents: 800
diff changeset
251 break;
6504113e7c2d [xemacs-hg @ 2002-04-25 18:03:23 by andyp]
andyp
parents: 800
diff changeset
252 }
6504113e7c2d [xemacs-hg @ 2002-04-25 18:03:23 by andyp]
andyp
parents: 800
diff changeset
253 FindClose(fh);
6504113e7c2d [xemacs-hg @ 2002-04-25 18:03:23 by andyp]
andyp
parents: 800
diff changeset
254 SetErrorMode (errm);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
255 report_file_error ("Reading directory", dirfile);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 }
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
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
259 file.dwFileAttributes = finddat.dwFileAttributes;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
260 file.ftCreationTime = finddat.ftCreationTime;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
261 file.ftLastAccessTime = finddat.ftLastAccessTime;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
262 file.ftLastWriteTime = finddat.ftLastWriteTime;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
263 file.nFileSizeHigh = finddat.nFileSizeHigh;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
264 file.nFileSizeLow = finddat.nFileSizeLow;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
265 eicpy_ext (filename, (Extbyte *) finddat.cFileName,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
266 Qmswindows_tstr);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
267
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
268 if (!NILP (Vmswindows_downcase_file_names))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
269 eilwr (filename);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
270 len = eilen (filename);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
271 result = (NILP (pattern)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
272 || (0 <= re_search (bufp, eidata (filename),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 len, 0, len, 0)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 if (result)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
276 if ( ! (eigetch_char (filename, 0) == '.' &&
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
277 ((hide_system &&
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
278 (eigetch_char (filename, 1) == '\0' ||
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
279 (eigetch_char (filename, 1) == '.' &&
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
280 eigetch_char (filename, 2) == '\0'))) ||
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 hide_dot)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
283 file.cFileName =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
284 (Intbyte *) xmalloc (sizeof (Intbyte) * (1 + len));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
285 memcpy (file.cFileName, eidata (filename), len);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
286 file.cFileName[len] = '\0';
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
287 Dynarr_add (files, file);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 if (fh != INVALID_HANDLE_VALUE)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
292 FindClose (fh);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 }
819
6504113e7c2d [xemacs-hg @ 2002-04-25 18:03:23 by andyp]
andyp
parents: 800
diff changeset
295
6504113e7c2d [xemacs-hg @ 2002-04-25 18:03:23 by andyp]
andyp
parents: 800
diff changeset
296 SetErrorMode (errm);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 return (files);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
300 static Lisp_Object
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
301 mswindows_format_file (Win32_file *file, int display_size, int add_newline)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
303 Lisp_Object luser;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
304 double file_size;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
305 DECLARE_EISTRING (puta);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
306 CIntbyte buf[666];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 file_size =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 file->nFileSizeHigh * (double)UINT_MAX + file->nFileSizeLow;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 #if INDENT_LISTING
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
311 eicat_c (puta, " ");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 if (display_size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
315 sprintf (buf, "%6d ", (int)((file_size + 1023.) / 1024.));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
316 eicat_c (puta, buf);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 if (file->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
319 eicat_c (puta, "d");
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
320 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
321 eicat_c (puta, "-");
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
322 buf[0] = buf[3] = buf[6] = 'r';
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 if (file->dwFileAttributes & FILE_ATTRIBUTE_READONLY)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
324 buf[1] = buf[4] = buf[7] = '-';
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
325 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
326 buf[1] = buf[4] = buf[7] = 'w';
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
327 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
328 int is_executable = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
330 if (file->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
331 is_executable = 1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
332 else if (qxestrcharlen (file->cFileName) > 4)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
333 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
334 Intbyte *end = file->cFileName + qxestrlen (file->cFileName);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
335 DEC_CHARPTR (end);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
336 DEC_CHARPTR (end);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
337 DEC_CHARPTR (end);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
338 DEC_CHARPTR (end);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
339 if (qxestrcasecmp (end, ".exe") == 0
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
340 || qxestrcasecmp (end, ".com") == 0
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
341 || qxestrcasecmp (end, ".bat") == 0
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 #if 0
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
343 || qxestrcasecmp (end, ".pif") == 0
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 #endif
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
345 )
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
346 is_executable = 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
348 if (is_executable)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
349 buf[2] = buf[5] = buf[8] = 'x';
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
350 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
351 buf[2] = buf[5] = buf[8] = '-';
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
353 buf[9] = '\0';
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
354 eicat_c (puta, buf);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
355 if (file->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
356 eicat_c (puta, " 2 ");
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
357 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
358 eicat_c (puta, " 1 ");
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
359 luser = Fuser_login_name (Qnil);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
360 if (!STRINGP (luser))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
361 sprintf (buf, "%-9d", 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
364 Intbyte *str;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
365
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
366 str = XSTRING_DATA (luser);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
367 sprintf (buf, "%-8s ", str);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
369 eicat_raw (puta, (Intbyte *) buf, strlen (buf));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
370 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
371 CIntbyte *cptr = buf;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
372 sprintf (buf, "%-8d ", getgid ());
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
373 cptr += 9;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
374 if (file_size > 99999999.0)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
375 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
376 file_size = (file_size + 1023.0) / 1024.;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
377 if (file_size > 999999.0)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
378 sprintf (cptr, "%6.0fMB ", (file_size + 1023.0) / 1024.);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
379 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
380 sprintf (cptr, "%6.0fKB ", file_size);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
381 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
382 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
383 sprintf (cptr, "%8.0f ", file_size);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
384 while (*cptr)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
385 ++cptr;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
386 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
387 time_t t, now;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
388 Intbyte *ctimebuf;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
389
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
390 if (
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
391 #if 0
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
392 /*
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
393 * This doesn't work.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
394 * This code should be correct ...
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
395 */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
396 FileTimeToLocalFileTime (&file->ftLastWriteTime, &localtime) &&
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
397 ((t = mswindows_convert_time (localtime)) != 0) &&
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
398 #else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
399 /*
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
400 * But this code "works" ...
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
401 */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
402 ((t = mswindows_convert_time (file->ftLastWriteTime)) != 0) &&
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
403 #endif
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
404 ((ctimebuf = qxe_ctime (&t)) != NULL))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
405 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
406 memcpy (cptr, &ctimebuf[4], 7);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
407 now = time (NULL);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
408 if (now - t > (365. / 2.0) * 86400.)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
409 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
410 /* more than 6 months */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
411 cptr[7] = ' ';
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
412 memcpy (&cptr[8], &ctimebuf[20], 4);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
413 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
414 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
415 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
416 /* less than 6 months */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
417 memcpy (&cptr[7], &ctimebuf[11], 5);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
418 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
419 cptr += 12;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
420 *cptr++ = ' ';
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
421 *cptr++ = '\0';
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
422 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
423 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
424 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
425
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
426 eicat_c (puta, buf);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
427 eicat_raw (puta, file->cFileName, qxestrlen (file->cFileName));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
428 if (add_newline)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
429 eicat_c (puta, "\n");
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
430
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
431 return eimake_string (puta);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 DEFUN ("mswindows-insert-directory", Fmswindows_insert_directory, 2, 4, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 Insert directory listing for FILE, formatted according to SWITCHES.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 Leaves point after the inserted text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 SWITCHES may be a string of options, or a list of strings.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 Optional third arg WILDCARD means treat FILE as shell wildcard.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 Optional fourth arg FULL-DIRECTORY-P means file is a directory and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 switches do not contain `d', so that a full listing is expected.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 (file, switches, wildcard, full_directory_p))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
445 Lisp_Object handler, wildpat = Qnil, basename = Qnil;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
446 int nfiles = 0, i;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
447 int hide_system = 1, hide_dot = 1, reverse = 0, display_size = 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
448 Win32_file_dynarr *files;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
449 enum mswindows_sortby sort_by =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
450 (mswindows_ls_sort_case_insensitive ? MSWINDOWS_SORT_BY_NAME_NOCASE
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
451 : MSWINDOWS_SORT_BY_NAME);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
452 struct gcpro gcpro1, gcpro2, gcpro3;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
453
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
454 GCPRO3 (file, wildpat, basename);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
455
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
456 CHECK_STRING (file);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
457 if (!NILP (wildpat))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
458 CHECK_STRING (wildpat);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
460 handler = Ffind_file_name_handler (file, Qmswindows_insert_directory);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
461 if (!NILP (handler))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
462 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
463 UNGCPRO;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
464 return call5 (handler, Qmswindows_insert_directory, file, switches,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
465 wildcard, full_directory_p);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
466 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
467
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
468 if (!NILP (switches))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
470 Intbyte *cptr, *cptr_end;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
471
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
472 CHECK_STRING (switches);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
473 cptr = XSTRING_DATA (switches);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
474 cptr_end = cptr + XSTRING_LENGTH (switches);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
475 while (cptr < cptr_end)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
477 Emchar ch = charptr_emchar (cptr);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
478 switch (ch)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
480 case 'A':
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
481 hide_dot = 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
482 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
483 case 'a':
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
484 hide_system = 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
485 hide_dot = 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
486 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
487 case 'r':
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
488 reverse = 1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
489 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
490 case 's':
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
491 display_size = 1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
492 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
493 case 'S':
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
494 sort_by = MSWINDOWS_SORT_BY_SIZE;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
495 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
496 case 't':
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
497 sort_by = MSWINDOWS_SORT_BY_MOD_DATE;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
500 INC_CHARPTR (cptr);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
502 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
503
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
504 if (!NILP (wildcard))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
505 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
506 Lisp_Object newfile;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
507
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
508 file = Fdirectory_file_name (file);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
509 basename = Ffile_name_nondirectory (file);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
510 wildpat = call1 (Qwildcard_to_regexp, basename);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
511 newfile = Ffile_name_directory (file);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
512 if (NILP (newfile))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
513 newfile = Ffile_name_directory (Fexpand_file_name (file, Qnil));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
514 file = newfile;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
515 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
516
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
517 files = mswindows_get_files (file,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
518 NILP (wildcard) && NILP (full_directory_p),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
519 wildpat, hide_dot, hide_system);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
520
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
521 if (Dynarr_length (files) > 1)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
522 mswindows_sort_files (files, sort_by, reverse);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
523 if (!NILP (wildcard) || !NILP (full_directory_p))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
524 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
525 /*
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
526 * By using doubles, we can handle files up to 2^53 bytes in
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
527 * size (IEEE doubles have 53 bits of resolution). However,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
528 * as we divide by 1024 (or 2^10), the total size is
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
529 * accurate up to 2^(53+10) --> 2^63 bytes.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
530 *
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
531 * Hopefully, we won't have to handle these file sizes anytime
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
532 * soon.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
533 */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
534 double total_size, file_size, block_size;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
536 if ((block_size = mswindows_ls_round_file_size) <= 0)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
537 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
538 block_size = 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
539 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
540 total_size = 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
541 for (i = 0; i < Dynarr_length (files); ++i)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
542 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
543 Win32_file *file = Dynarr_atp (files, i);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
544 file_size =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
545 file->nFileSizeHigh * (double)UINT_MAX +
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
546 file->nFileSizeLow;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
547 if (block_size > 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
549 /*
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
550 * Round file_size up to the next nearest block size.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
551 */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 file_size =
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
553 floor ((file_size + block_size - 1) / block_size)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
554 * block_size;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
556 /* Here, we round to the nearest 1K */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
557 total_size += floor ((file_size + 512.) / 1024.);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
559 {
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 771
diff changeset
560 write_fmt_string (wrap_buffer (current_buffer),
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
561 #if INDENT_LISTING
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 771
diff changeset
562 /* ANSI C compilers auto-concatenate adjacent
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 771
diff changeset
563 strings */
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 771
diff changeset
564 " "
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
565 #endif
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 771
diff changeset
566 "total %.0f\n", total_size);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
567 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
569 for (i = 0; i < Dynarr_length (files); ++i)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
571 struct gcpro ngcpro1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
572 Lisp_Object fmtfile =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
573 mswindows_format_file (Dynarr_atp (files, i), display_size, TRUE);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
574 NGCPRO1 (fmtfile);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
575 buffer_insert1 (current_buffer, fmtfile);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
576 NUNGCPRO;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
578 for (i = 0; i < Dynarr_length (files); ++i)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
579 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
580 Win32_file *file = Dynarr_atp (files, i);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
581 xfree (file->cFileName);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
582 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
583 Dynarr_free (files);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
584
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 UNGCPRO;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
586 return Qnil;
428
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589
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 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 /* initialization */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 /************************************************************************/
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 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 syms_of_dired_mswindows (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 558
diff changeset
598 DEFSYMBOL (Qmswindows_insert_directory);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
599 DEFSYMBOL (Qwildcard_to_regexp);
428
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 DEFSUBR (Fmswindows_insert_directory);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 }
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 vars_of_dired_mswindows (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
608 DEFVAR_BOOL ("mswindows-ls-sort-case-insensitive",
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 622
diff changeset
609 &mswindows_ls_sort_case_insensitive /*
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 *Non-nil means filenames are sorted in a case-insensitive fashion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 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
612 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 mswindows_ls_sort_case_insensitive = 1;
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 DEFVAR_INT ("mswindows-ls-round-file-size", &mswindows_ls_round_file_size /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 *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
617 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
618 accurate estimate of allocated disk space. Note that this only affects
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 the total size calculation; the individual displayed file sizes are not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 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
621 enforced), as filesystem block (cluster) sizes are typically powers-of-2.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 * 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
625 * and NTFS (?). This is probably much too small for people using
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 * plain FAT, but, hopefully, plain FAT will go away someday.
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 * We should allow something like a alist here, to make the size
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 * dependent on the drive letter, etc..
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 mswindows_ls_round_file_size = 4096;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 }