annotate src/dired-msw.c @ 450:98528da0b7fc r21-2-40

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