Mercurial > hg > xemacs-beta
view src/dired-msw.c @ 2367:ecf1ebac70d8
[xemacs-hg @ 2004-11-04 23:05:23 by ben]
commit mega-patch
configure.in: Turn off -Winline and -Wchar-subscripts.
Use the right set of cflags when compiling modules.
Rewrite ldap configuration to separate the inclusion of lber
(needed in recent Cygwin) from the basic checks for the
needed libraries.
add a function for MAKE_JUNK_C; initially code was added to
generate xemacs.def using this, but it will need to be rewritten.
add an rm -f for junk.c to avoid weird Cygwin bug with cp -f onto
an existing file.
Sort list of auto-detected functions and eliminate unused checks for
stpcpy, setlocale and getwd.
Add autodetection of Cygwin scanf problems
BETA: Rewrite section on configure to indicate what flags are important
and what not.
digest-doc.c, make-dump-id.c, profile.c, sorted-doc.c: Add proper decls for main().
make-msgfile.c: Document that this is old junk.
Move proposal to text.c.
make-msgfile.lex: Move proposal to text.c.
make-mswin-unicode.pl: Convert error-generating code so that the entire message will
be seen as a single unrecognized token.
mule/mule-ccl.el: Update docs.
lispref/mule.texi: Update CCL docs.
ldap/eldap.c: Mule-ize.
Use EXTERNAL_LIST_LOOP_2 instead of deleted EXTERNAL_LIST_LOOP.
* XEmacs 21.5.18 "chestnut" is released.
---------------------------------------------------------------
MULE-RELATED WORK:
---------------------------------------------------------------
---------------------------
byte-char conversion
---------------------------
buffer.c, buffer.h, insdel.c, text.c: Port FSF algorithm for byte-char conversion, replacing broken
previous version. Track the char position of the gap. Add
functions to do char-byte conversion downwards as well as upwards.
Move comments about algorithm workings to internals manual.
---------------------------
work on types
---------------------------
alloc.c, console-x-impl.h, dump-data.c, dump-data.h, dumper.c, dialog-msw.c, dired-msw.c, doc.c, editfns.c, esd.c, event-gtk.h, event-msw.c, events.c, file-coding.c, file-coding.h, fns.c, glyphs-eimage.c, glyphs-gtk.c, glyphs-msw.c, glyphs-shared.c, glyphs-x.c, glyphs.c, glyphs.h, gui.c, hpplay.c, imgproc.c, intl-win32.c, lrecord.h, lstream.c, keymap.c, lisp.h, libsst.c, linuxplay.c, miscplay.c, miscplay.h, mule-coding.c, nas.c, nt.c, ntheap.c, ntplay.c, objects-msw.c, objects-tty.c, objects-x.c, print.c, process-nt.c, process.c, redisplay.h, select-common.h, select-gtk.c, select-x.c, sgiplay.c, sound.c, sound.h, sunplay.c, sysfile.h, sysdep.c, syswindows.h, text.c, unexnt.c, win32.c, xgccache.c: Further work on types. This creates a full set of types for all
the basic semantics of `char' that I have so far identified, so that
its semantics can always be identified for the purposes of proper
Mule-safe code, and the raw use of `char' always avoided.
(1) More type renaming, for consistency of naming.
Char_ASCII -> Ascbyte
UChar_ASCII -> UAscbyte
Char_Binary -> CBinbyte
UChar_Binary -> Binbyte
SChar_Binary -> SBinbyte
(2) Introduce Rawbyte, CRawbyte, Boolbyte, Chbyte, UChbyte, and
Bitbyte and use them.
(3) New types Itext, Wexttext and Textcount for separating out
the concepts of bytes and textual units (different under UTF-16
and UTF-32, which are potential internal encodings).
(4) qxestr*_c -> qxestr*_ascii.
lisp.h: New; goes with other qxe() functions. #### Maybe goes in a
different section.
lisp.h: Group generic int-type defs together with EMACS_INT defs.
lisp.h: * lisp.h (WEXTTEXT_IS_WIDE)
New defns.
lisp.h: New type to replace places where int occurs as a boolean.
It's signed because occasionally people may want to use -1 as
an error value, and because unsigned ints are viral -- see comments
in the internals manual against using them.
dynarr.c: int -> Bytecount.
---------------------------
Mule-izing
---------------------------
device-x.c: Partially Mule-ize.
dumper.c, dumper.h: Mule-ize. Use Rawbyte. Use stderr_out not printf. Use wext_*().
sysdep.c, syswindows.h, text.c: New Wexttext API for manipulation of external text that may be
Unicode (e.g. startup code under Windows).
emacs.c: Mule-ize. Properly deal with argv in external encoding.
Use wext_*() and Wexttext. Use Rawbyte.
#if 0 some old junk on SCO that is unlikely to be correct.
Rewrite allocation code in run-temacs.
emacs.c, symsinit.h, win32.c: Rename win32 init function and call it even earlier, to
initialize mswindows_9x_p even earlier, for use in startup code
(XEUNICODE_P).
process.c: Use _wenviron not environ under Windows, to get Unicode environment
variables.
event-Xt.c: Mule-ize drag-n-drop related stuff.
dragdrop.c, dragdrop.h, frame-x.c: Mule-ize.
text.h: Add some more stand-in defines for particular kinds of conversion;
use in Mule-ization work in frame-x.c etc.
---------------------------
Freshening
---------------------------
intl-auto-encap-win32.c, intl-auto-encap-win32.h: Regenerate.
---------------------------
Unicode-work
---------------------------
intl-win32.c, syswindows.h: Factor out common options to MultiByteToWideChar and
WideCharToMultiByte. Add convert_unicode_to_multibyte_malloc()
and convert_unicode_to_multibyte_dynarr() and use. Add stuff for
alloca() conversion of multibyte/unicode.
alloc.c: Use dfc_external_data_len() in case of unicode coding system.
alloc.c, mule-charset.c: Don't zero out and reinit charset Unicode tables. This fucks up
dump-time loading. Anyway, either we load them at dump time or
run time, never both.
unicode.c: Dump the blank tables as well.
---------------------------------------------------------------
DOCUMENTATION, MOSTLY MULE-RELATED:
---------------------------------------------------------------
EmacsFrame.c, emodules.c, event-Xt.c, fileio.c, input-method-xlib.c, mule-wnnfns.c, redisplay-gtk.c, redisplay-tty.c, redisplay-x.c, regex.c, sysdep.c: Add comment about Mule work needed.
text.h: Add more documentation describing why DFC routines were not written
to return their value. Add some other DFC documentation.
console-msw.c, console-msw.h: Add pointer to docs in win32.c.
emacs.c: Add comments on sources of doc info.
text.c, charset.h, unicode.c, intl-win32.c, intl-encap-win32.c, text.h, file-coding.c, mule-coding.c: Collect background comments and related to text matters and
internationalization, and proposals for work to be done, in text.c
or Internals manual, stuff related to specific textual API's in
text.h, and stuff related to internal implementation of Unicode
conversion in unicode.c. Put lots of pointers to the comments to
make them easier to find.
s/mingw32.h, s/win32-common.h, s/win32-native.h, s/windowsnt.h, win32.c: Add bunches of new documentation on the different kinds of
builds and environments under Windows and how they work.
Collect this info in win32.c. Add pointers to these docs in
the relevant s/* files.
emacs.c: Document places with long comments.
Remove comment about exiting, move to internals manual, put
in pointer.
event-stream.c: Move docs about event queues and focus to internals manual, put
in pointer.
events.h: Move docs about event stream callbacks to internals manual, put
in pointer.
profile.c, redisplay.c, signal.c: Move documentation to the Internals manual.
process-nt.c: Add pointer to comment in win32-native.el.
lisp.h: Add comments about some comment conventions.
lisp.h: Add comment about the second argument.
device-msw.c, redisplay-msw.c: @@#### comments are out-of-date.
---------------------------------------------------------------
PDUMP WORK (MOTIVATED BY UNICODE CHANGES)
---------------------------------------------------------------
alloc.c, buffer.c, bytecode.c, console-impl.h, console.c, device.c, dumper.c, lrecord.h, elhash.c, emodules.h, events.c, extents.c, frame.c, glyphs.c, glyphs.h, mule-charset.c, mule-coding.c, objects.c, profile.c, rangetab.c, redisplay.c, specifier.c, specifier.h, window.c, lstream.c, file-coding.h, file-coding.c: PDUMP:
Properly implement dump_add_root_block(), which never worked before,
and is necessary for dumping Unicode tables.
Pdump name changes for accuracy:
XD_STRUCT_PTR -> XD_BLOCK_PTR.
XD_STRUCT_ARRAY -> XD_BLOCK_ARRAY.
XD_C_STRING -> XD_ASCII_STRING.
*_structure_* -> *_block_*.
lrecord.h: some comments added about
dump_add_root_block() vs dump_add_root_block_ptr().
extents.c: remove incorrect comment about pdump problems with gap array.
---------------------------------------------------------------
ALLOCATION
---------------------------------------------------------------
abbrev.c, alloc.c, bytecode.c, casefiddle.c, device-msw.c, device-x.c, dired-msw.c, doc.c, doprnt.c, dragdrop.c, editfns.c, emodules.c, file-coding.c, fileio.c, filelock.c, fns.c, glyphs-eimage.c, glyphs-gtk.c, glyphs-msw.c, glyphs-x.c, gui-msw.c, gui-x.c, imgproc.c, intl-win32.c, lread.c, menubar-gtk.c, menubar.c, nt.c, objects-msw.c, objects-x.c, print.c, process-nt.c, process-unix.c, process.c, realpath.c, redisplay.c, search.c, select-common.c, symbols.c, sysdep.c, syswindows.h, text.c, text.h, ui-byhand.c: New macros {alloca,xnew}_{itext,{i,ext,raw,bin,asc}bytes} for
more convenient allocation of these commonly requested items.
Modify functions to use alloca_ibytes, alloca_array, alloca_extbytes,
xnew_ibytes, etc. also XREALLOC_ARRAY, xnew.
alloc.c: Rewrite the allocation functions to factor out repeated code.
Add assertions for freeing dumped data.
lisp.h: Moved down and consolidated with other allocation stuff.
lisp.h, dynarr.c: New functions for allocation that's very efficient when mostly in
LIFO order.
lisp.h, text.c, text.h: Factor out some stuff for general use by alloca()-conversion funs.
text.h, lisp.h: Fill out convenience routines for allocating various kinds of
bytes and put them in lisp.h. Use them in place of xmalloc(),
ALLOCA().
text.h: Fill out the convenience functions so the _MALLOC() kinds match
the alloca() kinds.
---------------------------------------------------------------
ERROR-CHECKING
---------------------------------------------------------------
text.h: Create ASSERT_ASCTEXT_ASCII() and ASSERT_ASCTEXT_ASCII_LEN()
from similar Eistring checkers and change the Eistring checkers to
use them instead.
---------------------------------------------------------------
MACROS IN LISP.H
---------------------------------------------------------------
lisp.h: Redo GCPRO declarations. Create a "base" set of functions that can
be used to generate any kind of gcpro sets -- regular, ngcpro,
nngcpro, private ones used in GC_EXTERNAL_LIST_LOOP_2.
buffer.c, callint.c, chartab.c, console-msw.c, device-x.c, dialog-msw.c, dired.c, extents.c, ui-gtk.c, rangetab.c, nt.c, mule-coding.c, minibuf.c, menubar-msw.c, menubar.c, menubar-gtk.c, lread.c, lisp.h, gutter.c, glyphs.c, glyphs-widget.c, fns.c, fileio.c, file-coding.c, specifier.c: Eliminate EXTERNAL_LIST_LOOP, which does not check for circularities.
Use EXTERNAL_LIST_LOOP_2 instead or EXTERNAL_LIST_LOOP_3
or EXTERNAL_PROPERTY_LIST_LOOP_3 or GC_EXTERNAL_LIST_LOOP_2
(new macro). Removed/redid comments on EXTERNAL_LIST_LOOP.
---------------------------------------------------------------
SPACING FIXES
---------------------------------------------------------------
callint.c, hftctl.c, number-gmp.c, process-unix.c: Spacing fixes.
---------------------------------------------------------------
FIX FOR GEOMETRY PROBLEM IN FIRST FRAME
---------------------------------------------------------------
unicode.c: Add workaround for newlib bug in sscanf() [should be fixed by
release 1.5.12 of Cygwin].
toolbar.c: bug fix for problem of initial frame being 77 chars wide on Windows.
will be overridden by my other ws.
---------------------------------------------------------------
FIX FOR LEAKING PROCESS HANDLES:
---------------------------------------------------------------
process-nt.c: Fixes for leaking handles. Inspired by work done by Adrian Aichner
<adrian@xemacs.org>.
---------------------------------------------------------------
FIX FOR CYGWIN BUG (Unicode-related):
---------------------------------------------------------------
unicode.c: Add workaround for newlib bug in sscanf() [should be fixed by
release 1.5.12 of Cygwin].
---------------------------------------------------------------
WARNING FIXES:
---------------------------------------------------------------
console-stream.c: `reinit' is unused.
compiler.h, event-msw.c, frame-msw.c, intl-encap-win32.c, text.h: Add stuff to deal with ANSI-aliasing warnings I got.
regex.c: Gather includes together to avoid warning.
---------------------------------------------------------------
CHANGES TO INITIALIZATION ROUTINES:
---------------------------------------------------------------
buffer.c, emacs.c, console.c, debug.c, device-x.c, device.c, dragdrop.c, emodules.c, eval.c, event-Xt.c, event-gtk.c, event-msw.c, event-stream.c, event-tty.c, events.c, extents.c, faces.c, file-coding.c, fileio.c, font-lock.c, frame-msw.c, glyphs-widget.c, glyphs.c, gui-x.c, insdel.c, lread.c, lstream.c, menubar-gtk.c, menubar-x.c, minibuf.c, mule-wnnfns.c, objects-msw.c, objects.c, print.c, scrollbar-x.c, search.c, select-x.c, text.c, undo.c, unicode.c, window.c, symsinit.h: Call reinit_*() functions directly from emacs.c, for clarity.
Factor out some redundant init code. Move disallowed stuff
that had crept into vars_of_glyphs() into complex_vars_of_glyphs().
Call init_eval_semi_early() from eval.c not in the middle of
vars_of_() in emacs.c since there should be no order dependency
in the latter calls.
---------------------------------------------------------------
ARMAGEDDON:
---------------------------------------------------------------
alloc.c, emacs.c, lisp.h, print.c: Rename inhibit_non_essential_printing_operations to
inhibit_non_essential_conversion_operations.
text.c: Assert on !inhibit_non_essential_conversion_operations.
console-msw.c, print.c: Don't do conversion in SetConsoleTitle or FindWindow to avoid
problems during armageddon. Put #errors for NON_ASCII_INTERNAL_FORMAT
in places where problems would arise.
---------------------------------------------------------------
CHANGES TO THE BUILD PROCEDURE:
---------------------------------------------------------------
config.h.in, s/cxux.h, s/usg5-4-2.h, m/powerpc.h: Add comment about correct ordering of this file.
Rearrange everything to follow this -- put all #undefs together
and before the s&m files. Add undefs for HAVE_ALLOCA, C_ALLOCA,
BROKEN_ALLOCA_IN_FUNCTION_CALLS, STACK_DIRECTION. Remove unused
HAVE_STPCPY, HAVE_GETWD, HAVE_SETLOCALE.
m/gec63.h: Deleted; totally broken, not used at all, not in FSF.
m/7300.h, m/acorn.h, m/alliant-2800.h, m/alliant.h, m/altos.h, m/amdahl.h, m/apollo.h, m/att3b.h, m/aviion.h, m/celerity.h, m/clipper.h, m/cnvrgnt.h, m/convex.h, m/cydra5.h, m/delta.h, m/delta88k.h, m/dpx2.h, m/elxsi.h, m/ews4800r.h, m/gould.h, m/hp300bsd.h, m/hp800.h, m/hp9000s300.h, m/i860.h, m/ibmps2-aix.h, m/ibmrs6000.h, m/ibmrt-aix.h, m/ibmrt.h, m/intel386.h, m/iris4d.h, m/iris5d.h, m/iris6d.h, m/irist.h, m/isi-ov.h, m/luna88k.h, m/m68k.h, m/masscomp.h, m/mg1.h, m/mips-nec.h, m/mips-siemens.h, m/mips.h, m/news.h, m/nh3000.h, m/nh4000.h, m/ns32000.h, m/orion105.h, m/pfa50.h, m/plexus.h, m/pmax.h, m/powerpc.h, m/pyrmips.h, m/sequent-ptx.h, m/sequent.h, m/sgi-challenge.h, m/symmetry.h, m/tad68k.h, m/tahoe.h, m/targon31.h, m/tekxd88.h, m/template.h, m/tower32.h, m/tower32v3.h, m/ustation.h, m/vax.h, m/wicat.h, m/xps100.h: Delete C_ALLOCA, HAVE_ALLOCA, STACK_DIRECTION,
BROKEN_ALLOCA_IN_FUNCTION_CALLS. All of this is auto-detected.
When in doubt, I followed recent FSF sources, which also have
these things deleted.
author | ben |
---|---|
date | Thu, 04 Nov 2004 23:08:28 +0000 |
parents | a8d8f419b459 |
children | ab71ad6ff3dd |
line wrap: on
line source
/* fast dired replacement routines for mswindows. Copyright (C) 1998 Darryl Okahata Portions Copyright (C) 1992, 1994 by Sebastian Kremer <sk@thp.uni-koeln.de> Copyright (C) 2000, 2001, 2002 Ben Wing. This file is part of XEmacs. XEmacs is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. XEmacs is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with XEmacs; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Synched up with: Not in FSF. */ /* * Parts of this code (& comments) were taken from ls-lisp.el * Author: Sebastian Kremer <sk@thp.uni-koeln.de> */ /* * insert-directory * - must insert _exactly_one_line_ describing FILE if WILDCARD and * FULL-DIRECTORY-P is nil. * The single line of output must display FILE's name as it was * given, namely, an absolute path name. * - must insert exactly one line for each file if WILDCARD or * FULL-DIRECTORY-P is t, plus one optional "total" line * before the file lines, plus optional text after the file lines. * Lines are delimited by "\n", so filenames containing "\n" are not * allowed. * File lines should display the basename. * - must be consistent with * - functions dired-move-to-filename, (these two define what a file line is) * dired-move-to-end-of-filename, * dired-between-files, (shortcut for (not (dired-move-to-filename))) * dired-insert-headerline * dired-after-subdir-garbage (defines what a "total" line is) * - variable dired-subdir-regexp */ /* * Insert directory listing for FILE, formatted according to SWITCHES. * Leaves point after the inserted text. * SWITCHES may be a string of options, or a list of strings. * Optional third arg WILDCARD means treat FILE as shell wildcard. * Optional fourth arg FULL-DIRECTORY-P means file is a directory and * switches do not contain `d', so that a full listing is expected. * * This works by running a directory listing program * whose name is in the variable `insert-directory-program'. * If WILDCARD, it also runs the shell specified by `shell-file-name'." */ /* * Set INDENT_LISTING to non-zero if the inserted text should be shifted * over by two spaces. */ #define INDENT_LISTING 0 #define ROUND_FILE_SIZES 4096 #include <config.h> #include "lisp.h" #include "buffer.h" #include "regex.h" #include "syntax.h" #include "console-msw.h" #include "sysdir.h" #include "sysfile.h" #include "sysfloat.h" #include "sysproc.h" #include "syspwd.h" #include "systime.h" static int mswindows_ls_sort_case_insensitive; static Fixnum mswindows_ls_round_file_size; Lisp_Object Qmswindows_insert_directory; Lisp_Object Qwildcard_to_regexp; extern Lisp_Object Vmswindows_downcase_file_names; /* in device-msw.c */ enum mswindows_sortby { MSWINDOWS_SORT_BY_NAME, MSWINDOWS_SORT_BY_NAME_NOCASE, MSWINDOWS_SORT_BY_MOD_DATE, MSWINDOWS_SORT_BY_SIZE }; static enum mswindows_sortby mswindows_sort_method; static int mswindows_reverse_sort; /* We create our own structure because the cFileName field in WIN32_FIND_DATA is in external format and of fixed size, which we may exceed when translating. */ typedef struct { DWORD dwFileAttributes; FILETIME ftCreationTime; FILETIME ftLastAccessTime; FILETIME ftLastWriteTime; DWORD nFileSizeHigh; DWORD nFileSizeLow; Ibyte *cFileName; } Win32_file; typedef struct { Dynarr_declare (Win32_file); } Win32_file_dynarr; #define CMPDWORDS(t1a, t1b, t2a, t2b) \ (((t1a) == (t2a)) ? (((t1b) == (t2b)) ? 0 : (((t1b) < (t2b)) ? -1 : 1)) \ : (((t1a) < (t2a)) ? -1 : 1)) static int mswindows_ls_sort_fcn (const void *elem1, const void *elem2) { Win32_file *e1, *e2; int status; e1 = (Win32_file *) elem1; e2 = (Win32_file *) elem2; switch (mswindows_sort_method) { case MSWINDOWS_SORT_BY_NAME: status = qxestrcmp (e1->cFileName, e2->cFileName); break; case MSWINDOWS_SORT_BY_NAME_NOCASE: status = qxestrcasecmp (e1->cFileName, e2->cFileName); break; case MSWINDOWS_SORT_BY_MOD_DATE: status = CMPDWORDS (e1->ftLastWriteTime.dwHighDateTime, e1->ftLastWriteTime.dwLowDateTime, e2->ftLastWriteTime.dwHighDateTime, e2->ftLastWriteTime.dwLowDateTime); break; case MSWINDOWS_SORT_BY_SIZE: status = CMPDWORDS (e1->nFileSizeHigh, e1->nFileSizeLow, e2->nFileSizeHigh, e2->nFileSizeLow); break; default: status = 0; break; } if (mswindows_reverse_sort) { status = -status; } return (status); } static void mswindows_sort_files (Win32_file_dynarr *files, enum mswindows_sortby sort_by, int reverse) { mswindows_sort_method = sort_by; mswindows_reverse_sort = reverse; qsort (Dynarr_atp (files, 0), Dynarr_length (files), sizeof (Win32_file), mswindows_ls_sort_fcn); } static Win32_file_dynarr * mswindows_get_files (Lisp_Object dirfile, int nowild, Lisp_Object pattern, int hide_dot, int hide_system) { Win32_file_dynarr *files = Dynarr_new (Win32_file); struct re_pattern_buffer *bufp = NULL; int findex; DECLARE_EISTRING (win32pattern); HANDLE fh; int errm; while (1) { if (!NILP (pattern)) { /* PATTERN might be a flawed regular expression. Rather than catching and signalling our own errors, we just call compile_pattern to do the work for us. */ bufp = compile_pattern (pattern, 0, Qnil, Qnil, 0, 0, ERROR_ME); } /* Now *bufp is the compiled form of PATTERN; don't call anything which might compile a new regexp until we're done with the loop! */ /* for Win32, we need to insure that the pathname ends with "\*". */ eicpy_lstr (win32pattern, dirfile); if (!nowild) { Charcount len = eicharlen (win32pattern) - 1; if (!IS_DIRECTORY_SEP (eigetch_char (win32pattern, len))) eicat_c (win32pattern, "\\"); eicat_c (win32pattern, "*"); } eito_external (win32pattern, Qmswindows_tstr); /* * Here, we use FindFirstFile()/FindNextFile() instead of opendir(), * qxe_stat(), & friends, because qxe_stat() is VERY expensive in * terms of time. Hence, we take the time to write complicated * Win32-specific code, instead of simple Unix-style stuff. */ findex = 0; fh = INVALID_HANDLE_VALUE; errm = SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX); while (1) { Bytecount len; DECLARE_EISTRING (filename); int result; WIN32_FIND_DATAW finddat; Win32_file file; struct syntax_cache scache_struct; struct syntax_cache *scache = &scache_struct; if (fh == INVALID_HANDLE_VALUE) { fh = qxeFindFirstFile (eiextdata (win32pattern), &finddat); if (fh == INVALID_HANDLE_VALUE) { SetErrorMode (errm); report_file_error ("Opening directory", dirfile); } } else { if (! qxeFindNextFile (fh, &finddat)) { if (GetLastError() == ERROR_NO_MORE_FILES) { break; } FindClose(fh); SetErrorMode (errm); report_file_error ("Reading directory", dirfile); } } file.dwFileAttributes = finddat.dwFileAttributes; file.ftCreationTime = finddat.ftCreationTime; file.ftLastAccessTime = finddat.ftLastAccessTime; file.ftLastWriteTime = finddat.ftLastWriteTime; file.nFileSizeHigh = finddat.nFileSizeHigh; file.nFileSizeLow = finddat.nFileSizeLow; eicpy_ext (filename, (Extbyte *) finddat.cFileName, Qmswindows_tstr); if (!NILP (Vmswindows_downcase_file_names)) eilwr (filename); len = eilen (filename); result = (NILP (pattern) || (0 <= re_search (bufp, (char *) eidata (filename), len, 0, len, 0, Qnil, 0, scache))); if (result) { if ( ! (eigetch_char (filename, 0) == '.' && ((hide_system && (eigetch_char (filename, 1) == '\0' || (eigetch_char (filename, 1) == '.' && eigetch_char (filename, 2) == '\0'))) || hide_dot))) { file.cFileName = xnew_ibytes (len + ITEXT_ZTERM_SIZE); memcpy (file.cFileName, eidata (filename), len); file.cFileName[len] = '\0'; Dynarr_add (files, file); } } } if (fh != INVALID_HANDLE_VALUE) FindClose (fh); break; } SetErrorMode (errm); return (files); } static Lisp_Object mswindows_format_file (Win32_file *file, int display_size, int add_newline) { Lisp_Object luser; double file_size; DECLARE_EISTRING (puta); CIbyte buf[666]; file_size = file->nFileSizeHigh * (double)UINT_MAX + file->nFileSizeLow; #if INDENT_LISTING eicat_c (puta, " "); #endif if (display_size) { sprintf (buf, "%6d ", (int)((file_size + 1023.) / 1024.)); eicat_c (puta, buf); } if (file->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) eicat_c (puta, "d"); else eicat_c (puta, "-"); buf[0] = buf[3] = buf[6] = 'r'; if (file->dwFileAttributes & FILE_ATTRIBUTE_READONLY) buf[1] = buf[4] = buf[7] = '-'; else buf[1] = buf[4] = buf[7] = 'w'; { int is_executable = 0; if (file->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) is_executable = 1; else if (qxestrcharlen (file->cFileName) > 4) { Ibyte *end = file->cFileName + qxestrlen (file->cFileName); DEC_IBYTEPTR (end); DEC_IBYTEPTR (end); DEC_IBYTEPTR (end); DEC_IBYTEPTR (end); if (qxestrcasecmp_ascii (end, ".exe") == 0 || qxestrcasecmp_ascii (end, ".com") == 0 || qxestrcasecmp_ascii (end, ".bat") == 0 #if 0 || qxestrcasecmp_ascii (end, ".pif") == 0 #endif ) is_executable = 1; } if (is_executable) buf[2] = buf[5] = buf[8] = 'x'; else buf[2] = buf[5] = buf[8] = '-'; } buf[9] = '\0'; eicat_c (puta, buf); if (file->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) eicat_c (puta, " 2 "); else eicat_c (puta, " 1 "); luser = Fuser_login_name (Qnil); if (!STRINGP (luser)) sprintf (buf, "%-9d", 0); else { Ibyte *str; str = XSTRING_DATA (luser); sprintf (buf, "%-8s ", str); } eicat_raw (puta, (Ibyte *) buf, strlen (buf)); { CIbyte *cptr = buf; sprintf (buf, "%-8d ", getgid ()); cptr += 9; if (file_size > 99999999.0) { file_size = (file_size + 1023.0) / 1024.; if (file_size > 999999.0) sprintf (cptr, "%6.0fMB ", (file_size + 1023.0) / 1024.); else sprintf (cptr, "%6.0fKB ", file_size); } else sprintf (cptr, "%8.0f ", file_size); while (*cptr) ++cptr; { time_t t, now; Ibyte *ctimebuf; if ( #if 0 /* * This doesn't work. * This code should be correct ... */ FileTimeToLocalFileTime (&file->ftLastWriteTime, &localtime) && ((t = mswindows_convert_time (localtime)) != 0) && #else /* * But this code "works" ... */ ((t = mswindows_convert_time (file->ftLastWriteTime)) != 0) && #endif ((ctimebuf = qxe_ctime (&t)) != NULL)) { memcpy (cptr, &ctimebuf[4], 7); now = time (NULL); if (now - t > (365. / 2.0) * 86400.) { /* more than 6 months */ cptr[7] = ' '; memcpy (&cptr[8], &ctimebuf[20], 4); } else { /* less than 6 months */ memcpy (&cptr[7], &ctimebuf[11], 5); } cptr += 12; *cptr++ = ' '; *cptr++ = '\0'; } } } eicat_c (puta, buf); eicat_raw (puta, file->cFileName, qxestrlen (file->cFileName)); if (add_newline) eicat_c (puta, "\n"); return eimake_string (puta); } DEFUN ("mswindows-insert-directory", Fmswindows_insert_directory, 2, 4, 0, /* Insert directory listing for FILE, formatted according to SWITCHES. Leaves point after the inserted text. SWITCHES may be a string of options, or a list of strings. Optional third arg WILDCARD means treat FILE as shell wildcard. Optional fourth arg FULL-DIRECTORY-P means file is a directory and switches do not contain `d', so that a full listing is expected. */ (file, switches, wildcard, full_directory_p)) { Lisp_Object handler, wildpat = Qnil, basename = Qnil; int nfiles = 0, i; int hide_system = 1, hide_dot = 1, reverse = 0, display_size = 0; Win32_file_dynarr *files; enum mswindows_sortby sort_by = (mswindows_ls_sort_case_insensitive ? MSWINDOWS_SORT_BY_NAME_NOCASE : MSWINDOWS_SORT_BY_NAME); struct gcpro gcpro1, gcpro2, gcpro3; GCPRO3 (file, wildpat, basename); CHECK_STRING (file); if (!NILP (wildpat)) CHECK_STRING (wildpat); handler = Ffind_file_name_handler (file, Qmswindows_insert_directory); if (!NILP (handler)) { UNGCPRO; return call5 (handler, Qmswindows_insert_directory, file, switches, wildcard, full_directory_p); } if (!NILP (switches)) { Ibyte *cptr, *cptr_end; CHECK_STRING (switches); cptr = XSTRING_DATA (switches); cptr_end = cptr + XSTRING_LENGTH (switches); while (cptr < cptr_end) { Ichar ch = itext_ichar (cptr); switch (ch) { case 'A': hide_dot = 0; break; case 'a': hide_system = 0; hide_dot = 0; break; case 'r': reverse = 1; break; case 's': display_size = 1; break; case 'S': sort_by = MSWINDOWS_SORT_BY_SIZE; break; case 't': sort_by = MSWINDOWS_SORT_BY_MOD_DATE; break; } INC_IBYTEPTR (cptr); } } if (!NILP (wildcard)) { Lisp_Object newfile; file = Fdirectory_file_name (file); basename = Ffile_name_nondirectory (file); wildpat = call1 (Qwildcard_to_regexp, basename); newfile = Ffile_name_directory (file); if (NILP (newfile)) newfile = Ffile_name_directory (Fexpand_file_name (file, Qnil)); file = newfile; } files = mswindows_get_files (file, NILP (wildcard) && NILP (full_directory_p), wildpat, hide_dot, hide_system); if (Dynarr_length (files) > 1) mswindows_sort_files (files, sort_by, reverse); if (!NILP (wildcard) || !NILP (full_directory_p)) { /* * By using doubles, we can handle files up to 2^53 bytes in * size (IEEE doubles have 53 bits of resolution). However, * as we divide by 1024 (or 2^10), the total size is * accurate up to 2^(53+10) --> 2^63 bytes. * * Hopefully, we won't have to handle these file sizes anytime * soon. */ double total_size, file_size, block_size; if ((block_size = mswindows_ls_round_file_size) <= 0) { block_size = 0; } total_size = 0; for (i = 0; i < Dynarr_length (files); ++i) { Win32_file *file = Dynarr_atp (files, i); file_size = file->nFileSizeHigh * (double)UINT_MAX + file->nFileSizeLow; if (block_size > 0) { /* * Round file_size up to the next nearest block size. */ file_size = floor ((file_size + block_size - 1) / block_size) * block_size; } /* Here, we round to the nearest 1K */ total_size += floor ((file_size + 512.) / 1024.); } { write_fmt_string (wrap_buffer (current_buffer), #if INDENT_LISTING /* ANSI C compilers auto-concatenate adjacent strings */ " " #endif "total %.0f\n", total_size); } } for (i = 0; i < Dynarr_length (files); ++i) { struct gcpro ngcpro1; Lisp_Object fmtfile = mswindows_format_file (Dynarr_atp (files, i), display_size, TRUE); NGCPRO1 (fmtfile); buffer_insert1 (current_buffer, fmtfile); NUNGCPRO; } for (i = 0; i < Dynarr_length (files); ++i) { Win32_file *file = Dynarr_atp (files, i); xfree (file->cFileName, Ibyte *); } Dynarr_free (files); UNGCPRO; return Qnil; } /************************************************************************/ /* initialization */ /************************************************************************/ void syms_of_dired_mswindows (void) { DEFSYMBOL (Qmswindows_insert_directory); DEFSYMBOL (Qwildcard_to_regexp); DEFSUBR (Fmswindows_insert_directory); } void vars_of_dired_mswindows (void) { DEFVAR_BOOL ("mswindows-ls-sort-case-insensitive", &mswindows_ls_sort_case_insensitive /* *Non-nil means filenames are sorted in a case-insensitive fashion. Nil means filenames are sorted in a case-sensitive fashion, just like Unix. */ ); mswindows_ls_sort_case_insensitive = 1; DEFVAR_INT ("mswindows-ls-round-file-size", &mswindows_ls_round_file_size /* *If non-zero, file sizes are rounded in terms of this block size when the file totals are being calculated. This is useful for getting a more accurate estimate of allocated disk space. Note that this only affects the total size calculation; the individual displayed file sizes are not changed. This block size should also be a power of 2 (but this is not enforced), as filesystem block (cluster) sizes are typically powers-of-2. */ ); /* * Here, we choose 4096 because it's the cluster size for both FAT32 * and NTFS (?). This is probably much too small for people using * plain FAT, but, hopefully, plain FAT will go away someday. * * We should allow something like a alist here, to make the size * dependent on the drive letter, etc.. */ mswindows_ls_round_file_size = 4096; }