annotate src/dired-msw.c @ 694:561ad704dc70

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