annotate src/dired.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 13a418960a88
children 5998e37dc35e
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 /* Lisp functions for making directory listings.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 Copyright (C) 1985, 1986, 1992, 1993, 1994 Free Software Foundation, Inc.
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3 Copyright (C) 2001, 2002 Ben Wing.
428
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: FSF 19.30. */
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 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 #include "lisp.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 #include "buffer.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 #include "commands.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 #include "elhash.h"
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 771
diff changeset
30 #include "opaque.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 #include "regex.h"
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
32 #include "syntax.h"
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 771
diff changeset
33 #include "sysdep.h"
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 771
diff changeset
34
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 771
diff changeset
35 #include "sysdir.h"
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 771
diff changeset
36 #include "sysfile.h"
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 771
diff changeset
37 #include "syspwd.h"
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 771
diff changeset
38 #include "systime.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39
528
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
40 #ifdef WIN32_NATIVE
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
41 #include "syswindows.h"
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
42 #endif
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
43
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 Lisp_Object Vcompletion_ignored_extensions;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 Lisp_Object Qdirectory_files;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 Lisp_Object Qfile_name_completion;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 Lisp_Object Qfile_name_all_completions;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 Lisp_Object Qfile_attributes;
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 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 close_directory_unwind (Lisp_Object unwind_obj)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 DIR *d = (DIR *)get_opaque_ptr (unwind_obj);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
54 qxe_closedir (d);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 free_opaque_ptr (unwind_obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 return Qnil;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 DEFUN ("directory-files", Fdirectory_files, 1, 5, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 Return a list of names of files in DIRECTORY.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 There are four optional arguments:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 If FULL is non-nil, absolute pathnames of the files are returned.
2297
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 2286
diff changeset
63 If MATCH is non-nil, only pathnames whose basename contain that regexp are
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 2286
diff changeset
64 returned.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 If NOSORT is non-nil, the list is not sorted--its order is unpredictable.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 NOSORT is useful if you plan to sort the result yourself.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 If FILES-ONLY is the symbol t, then only the "files" in the directory
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 will be returned; subdirectories will be excluded. If FILES-ONLY is not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 nil and not t, then only the subdirectories will be returned. Otherwise,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 if FILES-ONLY is nil (the default) then both files and subdirectories will
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 be returned.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 (directory, full, match, nosort, files_only))
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 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 DIR *d;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 Lisp_Object list = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 Bytecount directorylen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 Lisp_Object handler;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 struct re_pattern_buffer *bufp = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 int speccount = specpdl_depth ();
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
82 Ibyte *statbuf, *statbuf_tail;
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 struct gcpro gcpro1, gcpro2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 GCPRO2 (directory, list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 /* If the file name has special constructs in it,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 call the corresponding file handler. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 handler = Ffind_file_name_handler (directory, Qdirectory_files);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 if (!NILP (handler))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 if (!NILP (files_only))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 return call6 (handler, Qdirectory_files, directory, full, match,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 nosort, files_only);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 return call5 (handler, Qdirectory_files, directory, full, match,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 nosort);
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 /* #### why do we do Fexpand_file_name after file handlers here,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 but earlier everywhere else? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 directory = Fexpand_file_name (directory, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 directory = Ffile_name_as_directory (directory);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 directorylen = XSTRING_LENGTH (directory);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
107 statbuf = alloca_ibytes (directorylen + MAXNAMLEN + 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 memcpy (statbuf, XSTRING_DATA (directory), directorylen);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 statbuf_tail = statbuf + directorylen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 /* XEmacs: this should come after Ffile_name_as_directory() to avoid
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 potential regexp cache smashage. It comes before the opendir()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 because it might signal an error. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 if (!NILP (match))
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 CHECK_STRING (match);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 /* MATCH might be a flawed regular expression. Rather than
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 catching and signalling our own errors, we just call
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 compile_pattern to do the work for us. */
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
121 bufp = compile_pattern (match, 0, Qnil, Qnil, 0, 0, ERROR_ME);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 /* Now *bufp is the compiled form of MATCH; don't call anything
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 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
126
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 /* Do this opendir after anything which might signal an error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 NOTE: the above comment is old; previously, there was no
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 unwind-protection in case of error, but now there is. */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
130 d = qxe_opendir (XSTRING_DATA (directory));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 if (!d)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 546
diff changeset
132 report_file_error ("Opening directory", directory);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 record_unwind_protect (close_directory_unwind, make_opaque_ptr ((void *)d));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 /* Loop reading blocks */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
139 DIRENTRY *dp = qxe_readdir (d);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 int len;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
141 struct syntax_cache scache_struct;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
142 struct syntax_cache *scache = &scache_struct;
428
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 if (!dp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 len = NAMLEN (dp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 if (DIRENTRY_NONEMPTY (dp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 && (NILP (match)
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
149 || (0 <= re_search (bufp, dp->d_name, len, 0, len, 0, Qnil, 0,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
150 scache))))
428
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 if (!NILP (files_only))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 struct stat st;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 int dir_p = 0;
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 memcpy (statbuf_tail, dp->d_name, len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 statbuf_tail[len] = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
160 if (qxe_stat (statbuf, &st) == 0
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 && (st.st_mode & S_IFMT) == S_IFDIR)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 dir_p = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 if (EQ (files_only, Qt) && dir_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 else if (!EQ (files_only, Qt) && !dir_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 continue;
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 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 Lisp_Object name =
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
172 make_string ((Ibyte *)dp->d_name, len);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 if (!NILP (full))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 name = concat2 (directory, name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 list = Fcons (name, list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
180 unbind_to (speccount); /* This will close the dir */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 if (NILP (nosort))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 list = Fsort (Fnreverse (list), Qstring_lessp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 RETURN_UNGCPRO (list);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 static Lisp_Object file_name_completion (Lisp_Object file,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 Lisp_Object directory,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 int all_flag, int ver_flag);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 DEFUN ("file-name-completion", Ffile_name_completion, 2, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
193 Complete file name PARTIAL-FILENAME in directory DIRECTORY.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
194 Return the longest prefix common to all file names in DIRECTORY
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
195 that start with PARTIAL-FILENAME.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
196 If there is only one and PARTIAL-FILENAME matches it exactly, return t.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
197 Return nil if DIRECTORY contains no name starting with PARTIAL-FILENAME.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
199 File names which end with any member of `completion-ignored-extensions'
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
200 are not considered as possible completions for PARTIAL-FILENAME unless
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
201 there is no other possible completion. `completion-ignored-extensions'
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
202 is not applied to the names of directories.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
204 (partial_filename, directory))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 /* This function can GC. GC checked 1996.04.06. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 Lisp_Object handler;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 /* If the directory name has special constructs in it,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 call the corresponding file handler. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 handler = Ffind_file_name_handler (directory, Qfile_name_completion);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 if (!NILP (handler))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
213 return call3 (handler, Qfile_name_completion, partial_filename, directory);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 /* If the file name has special constructs in it,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 call the corresponding file handler. */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
217 handler = Ffind_file_name_handler (partial_filename, Qfile_name_completion);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 if (!NILP (handler))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
219 return call3 (handler, Qfile_name_completion, partial_filename, directory);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
221 return file_name_completion (partial_filename, directory, 0, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 DEFUN ("file-name-all-completions", Ffile_name_all_completions, 2, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
225 Return a list of all completions of PARTIAL-FILENAME in DIRECTORY.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
226 These are all file names in DIRECTORY which begin with PARTIAL-FILENAME.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
228 (partial_filename, directory))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 /* This function can GC. GC checked 1997.06.04. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 Lisp_Object handler;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 struct gcpro gcpro1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 GCPRO1 (directory);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 directory = Fexpand_file_name (directory, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 /* If the file name has special constructs in it,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 call the corresponding file handler. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 handler = Ffind_file_name_handler (directory, Qfile_name_all_completions);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 if (!NILP (handler))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
241 return call3 (handler, Qfile_name_all_completions, partial_filename,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 directory);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
244 return file_name_completion (partial_filename, directory, 1, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 file_name_completion_stat (Lisp_Object directory, DIRENTRY *dp,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 struct stat *st_addr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 Bytecount len = NAMLEN (dp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 Bytecount pos = XSTRING_LENGTH (directory);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 int value;
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
254 Ibyte *fullname = alloca_ibytes (len + pos + 2);
428
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 memcpy (fullname, XSTRING_DATA (directory), pos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 if (!IS_DIRECTORY_SEP (fullname[pos - 1]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 fullname[pos++] = DIRECTORY_SEP;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 memcpy (fullname + pos, dp->d_name, len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 fullname[pos + len] = 0;
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 #ifdef S_IFLNK
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 /* We want to return success if a link points to a nonexistent file,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 but we want to return the status for what the link points to,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 in case it is a directory. */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
267 value = qxe_lstat (fullname, st_addr);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 if (S_ISLNK (st_addr->st_mode))
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
269 qxe_stat (fullname, st_addr);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 #else
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
271 value = qxe_stat (fullname, st_addr);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 return value;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 file_name_completion_unwind (Lisp_Object locative)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 DIR *d;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 Lisp_Object obj = XCAR (locative);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 if (!NILP (obj))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 d = (DIR *)get_opaque_ptr (obj);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
285 qxe_closedir (d);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 free_opaque_ptr (obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 }
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
288 free_cons (locative);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 file_name_completion (Lisp_Object file, Lisp_Object directory, int all_flag,
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 1726
diff changeset
294 int UNUSED (ver_flag))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 DIR *d = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 int matchcount = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 Lisp_Object bestmatch = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 Charcount bestmatchsize = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 struct stat st;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 int passcount;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 int speccount = specpdl_depth ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 Charcount file_name_length;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 Lisp_Object locative;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 struct gcpro gcpro1, gcpro2, gcpro3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 GCPRO3 (file, directory, bestmatch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 CHECK_STRING (file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
312 #ifdef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 /* Filename completion on Windows ignores case, since Windows
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 filesystems do. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 specbind (Qcompletion_ignore_case, Qt);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
316 #endif /* WIN32_NATIVE */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 #ifdef FILE_SYSTEM_CASE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 file = FILE_SYSTEM_CASE (file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 directory = Fexpand_file_name (directory, Qnil);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
322 file_name_length = string_char_length (file);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 /* With passcount = 0, ignore files that end in an ignored extension.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 If nothing found then try again with passcount = 1, don't ignore them.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 If looking for all completions, start with passcount = 1,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 so always take even the ignored ones.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 ** It would not actually be helpful to the user to ignore any possible
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 completions when making a list of them.** */
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 /* We cannot use close_directory_unwind() because we change the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 directory. The old code used to just avoid signaling errors, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 call closedir, but it was wrong, because it made sane handling of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 QUIT impossible and, besides, various utility functions like
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 regexp_ignore_completion_p can signal errors. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 locative = noseeum_cons (Qnil, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 record_unwind_protect (file_name_completion_unwind, locative);
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 for (passcount = !!all_flag; NILP (bestmatch) && passcount < 2; passcount++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
342 d = qxe_opendir (XSTRING_DATA (Fdirectory_file_name (directory)));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 if (!d)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 546
diff changeset
344 report_file_error ("Opening directory", directory);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 XCAR (locative) = make_opaque_ptr ((void *)d);
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 /* Loop reading blocks */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 DIRENTRY *dp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 Bytecount len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 /* scmp() works in characters, not bytes, so we have to compute
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 this value: */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 Charcount cclen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 int directoryp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 int ignored_extension_p = 0;
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
357 Ibyte *d_name;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
359 dp = qxe_readdir (d);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 if (!dp) break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
362 /* Cast to Ibyte* is OK, as qxe_readdir() Mule-encapsulates. */
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
363 d_name = (Ibyte *) dp->d_name;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 len = NAMLEN (dp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 cclen = bytecount_to_charcount (d_name, len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 if (! DIRENTRY_NONEMPTY (dp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 || cclen < file_name_length
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 || 0 <= scmp (d_name, XSTRING_DATA (file), file_name_length))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 if (file_name_completion_stat (directory, dp, &st) < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 directoryp = ((st.st_mode & S_IFMT) == S_IFDIR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 if (directoryp)
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 #ifndef TRIVIAL_DIRECTORY_ENTRY
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 #define TRIVIAL_DIRECTORY_ENTRY(n) (!strcmp (n, ".") || !strcmp (n, ".."))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 /* "." and ".." are never interesting as completions, but are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 actually in the way in a directory containing only one file. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 if (!passcount && TRIVIAL_DIRECTORY_ENTRY (dp->d_name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 else
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 /* Compare extensions-to-be-ignored against end of this file name */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 /* if name is not an exact match against specified string. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 if (!passcount && cclen > file_name_length)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 /* and exit this for loop if a match is found */
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
395 EXTERNAL_LIST_LOOP_2 (elt, Vcompletion_ignored_extensions)
428
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 Charcount skip;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 CHECK_STRING (elt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
401 skip = cclen - string_char_length (elt);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 if (skip < 0) continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
404 if (0 > scmp (itext_n_addr (d_name, skip),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 XSTRING_DATA (elt),
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
406 string_char_length (elt)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 ignored_extension_p = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 break;
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 /* If an ignored-extensions match was found,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 don't process this name as a completion. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 if (!passcount && ignored_extension_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 800
diff changeset
420 if (!passcount && regexp_ignore_completion_p (d_name, Qnil, 0, len))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 /* Update computation of how much all possible completions match */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 matchcount++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 if (all_flag || NILP (bestmatch))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 Lisp_Object name = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 struct gcpro ngcpro1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 NGCPRO1 (name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 /* This is a possible completion */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 name = make_string (d_name, len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 if (directoryp) /* Completion is a directory; end it with '/' */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 name = Ffile_name_as_directory (name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 if (all_flag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 bestmatch = Fcons (name, bestmatch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 bestmatch = name;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
442 bestmatchsize = string_char_length (name);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 NUNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 else
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 Charcount compare = min (bestmatchsize, cclen);
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
449 Ibyte *p1 = XSTRING_DATA (bestmatch);
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
450 Ibyte *p2 = d_name;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 Charcount matchsize = scmp (p1, p2, compare);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 if (matchsize < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 matchsize = compare;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 if (completion_ignore_case)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 /* If this is an exact match except for case,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 use it as the best match rather than one that is not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 an exact match. This way, we get the case pattern
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 of the actual match. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 if ((matchsize == cclen
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 && matchsize + !!directoryp
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
463 < string_char_length (bestmatch))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 /* If there is no exact match ignoring case,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 prefer a match that does not change the case
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 of the input. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 (((matchsize == cclen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 ==
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 (matchsize + !!directoryp
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
471 == string_char_length (bestmatch)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 /* If there is more than one exact match aside from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 case, and one of them is exact including case,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 prefer that one. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 && 0 > scmp_1 (p2, XSTRING_DATA (file),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 file_name_length, 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 && 0 <= scmp_1 (p1, XSTRING_DATA (file),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 file_name_length, 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 bestmatch = make_string (d_name, len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 if (directoryp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 bestmatch = Ffile_name_as_directory (bestmatch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 }
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 /* If this directory all matches,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 see if implicit following slash does too. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 if (directoryp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 && compare == matchsize
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 && bestmatchsize > matchsize
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
491 && IS_ANY_SEP (itext_ichar_n (p1, matchsize)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 matchsize++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 bestmatchsize = matchsize;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
496 qxe_closedir (d);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 free_opaque_ptr (XCAR (locative));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 XCAR (locative) = Qnil;
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
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
501 unbind_to (speccount);
428
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 UNGCPRO;
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 (all_flag || NILP (bestmatch))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 return bestmatch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 if (matchcount == 1 && bestmatchsize == file_name_length)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 return Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 return Fsubstring (bestmatch, Qzero, make_int (bestmatchsize));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 }
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 static Lisp_Object user_name_completion (Lisp_Object user,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 int all_flag,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 int *uniq);
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 DEFUN ("user-name-completion", Fuser_name_completion, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
518 Complete user name from PARTIAL-USERNAME.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
519 Return the longest prefix common to all user names starting with
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
520 PARTIAL-USERNAME. If there is only one and PARTIAL-USERNAME matches
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
521 it exactly, returns t. Return nil if there is no user name starting
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
522 with PARTIAL-USERNAME.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
524 (partial_username))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
526 return user_name_completion (partial_username, 0, NULL);
428
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 DEFUN ("user-name-completion-1", Fuser_name_completion_1, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
530 Complete user name from PARTIAL-USERNAME.
428
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 This function is identical to `user-name-completion', except that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 the cons of the completion and an indication of whether the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 completion was unique is returned.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
536 The car of the returned value is the longest prefix common to all user
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
537 names that start with PARTIAL-USERNAME. If there is only one and
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
538 PARTIAL-USERNAME matches it exactly, the car is t. The car is nil if
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
539 there is no user name starting with PARTIAL-USERNAME. The cdr of the
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
540 result is non-nil if and only if the completion returned in the car
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
541 was unique.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
543 (partial_username))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 int uniq;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
546 Lisp_Object completed = user_name_completion (partial_username, 0, &uniq);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 return Fcons (completed, uniq ? Qt : Qnil);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 DEFUN ("user-name-all-completions", Fuser_name_all_completions, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
551 Return a list of all user name completions from PARTIAL-USERNAME.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
552 These are all the user names which begin with PARTIAL-USERNAME.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
554 (partial_username))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
556 return user_name_completion (partial_username, 1, NULL);
428
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
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
559 struct user_name
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
560 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
561 Ibyte *ptr;
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
562 Bytecount len;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
563 };
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
564
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
565 struct user_cache
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
566 {
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
567 struct user_name *user_names;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 int length;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 int size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 EMACS_TIME last_rebuild_time;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 static struct user_cache user_cache;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 free_user_cache (struct user_cache *cache)
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 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 for (i = 0; i < cache->length; i++)
1726
a8d8f419b459 [xemacs-hg @ 2003-09-30 15:26:34 by james]
james
parents: 867
diff changeset
579 xfree (cache->user_names[i].ptr, Ibyte *);
a8d8f419b459 [xemacs-hg @ 2003-09-30 15:26:34 by james]
james
parents: 867
diff changeset
580 xfree (cache->user_names, struct user_name *);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
581 xzero (*cache);
428
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 static Lisp_Object
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
585 user_name_completion_unwind (Lisp_Object cache_incomplete_p)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 {
528
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
587 #ifndef WIN32_NATIVE
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
588 endpwent ();
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
589 speed_up_interrupts ();
528
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
590 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
592 if (! NILP (XCAR (cache_incomplete_p)))
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
593 free_user_cache (&user_cache);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
594
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
595 free_cons (cache_incomplete_p);
428
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 return Qnil;
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
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
600 #define USER_CACHE_TTL (24*60*60) /* Time to live: 1 day, in seconds */
428
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 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 user_name_completion (Lisp_Object user, int all_flag, int *uniq)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 int matchcount = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 Lisp_Object bestmatch = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 Charcount bestmatchsize = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 Charcount user_name_length;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 EMACS_TIME t;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 struct gcpro gcpro1, gcpro2;
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 GCPRO2 (user, bestmatch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 CHECK_STRING (user);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
618 user_name_length = string_char_length (user);
428
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 /* Cache user name lookups because it tends to be quite slow.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 * Rebuild the cache occasionally to catch changes */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 EMACS_GET_TIME (t);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
623 if (user_cache.user_names &&
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 (EMACS_SECS (t) - EMACS_SECS (user_cache.last_rebuild_time)
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
625 > USER_CACHE_TTL))
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
626 free_user_cache (&user_cache);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
628 if (!user_cache.user_names)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 {
528
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
630 #ifndef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 struct passwd *pwd;
528
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
632 #else
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
633 DWORD entriesread;
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
634 DWORD totalentries;
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
635 DWORD resume_handle = 0;
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
636 #endif
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
637
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
638 Lisp_Object cache_incomplete_p = noseeum_cons (Qt, Qnil);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
639 int speccount = specpdl_depth ();
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
640
528
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
641 record_unwind_protect (user_name_completion_unwind, cache_incomplete_p);
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
642 #ifndef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 slow_down_interrupts ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 setpwent ();
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
645 while ((pwd = qxe_getpwent ()))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 QUIT;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
648 DO_REALLOC (user_cache.user_names, user_cache.size,
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
649 user_cache.length + 1, struct user_name);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
650 user_cache.user_names[user_cache.length].ptr =
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
651 (Ibyte *) xstrdup (pwd->pw_name);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
652 user_cache.user_names[user_cache.length].len = strlen (pwd->pw_name);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
653 user_cache.length++;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 }
528
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
655 #else
531
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
656 if (xNetUserEnum)
528
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
657 {
531
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
658 do
528
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
659 {
531
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
660 USER_INFO_0 *bufptr;
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
661 NET_API_STATUS status_status_statui_statum_statu;
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
662 int i;
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
663
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
664 QUIT;
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
665 status_status_statui_statum_statu =
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
666 xNetUserEnum (NULL, 0, 0, (LPBYTE *) &bufptr, 1024,
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
667 &entriesread, &totalentries, &resume_handle);
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
668 if (status_status_statui_statum_statu != NERR_Success &&
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
669 status_status_statui_statum_statu != ERROR_MORE_DATA)
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
670 invalid_operation ("Error enumerating users",
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
671 make_int (GetLastError ()));
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
672 for (i = 0; i < (int) entriesread; i++)
531
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
673 {
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
674 DO_REALLOC (user_cache.user_names, user_cache.size,
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
675 user_cache.length + 1, struct user_name);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
676 TO_INTERNAL_FORMAT (C_STRING,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
677 bufptr[i].usri0_name,
531
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
678 MALLOC,
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
679 (user_cache.
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
680 user_names[user_cache.length].ptr,
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
681 user_cache.
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
682 user_names[user_cache.length].len),
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
683 Qmswindows_unicode);
531
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
684 user_cache.length++;
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
685 }
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
686 xNetApiBufferFree (bufptr);
528
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
687 }
531
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 528
diff changeset
688 while (entriesread != totalentries);
528
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
689 }
546
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
690 else /* Win 9x */
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
691 {
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
692 Extbyte name[2 * (UNLEN + 1)];
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
693 DWORD length = sizeof (name);
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
694
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
695 if (qxeGetUserName (name, &length))
546
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
696 {
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
697 DO_REALLOC (user_cache.user_names, user_cache.size,
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
698 user_cache.length + 1, struct user_name);
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
699 TO_INTERNAL_FORMAT (C_STRING, name,
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
700 MALLOC,
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
701 (user_cache.
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
702 user_names[user_cache.length].ptr,
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
703 user_cache.
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
704 user_names[user_cache.length].len),
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
705 Qmswindows_tstr);
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
706 user_cache.length++;
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
707 }
666d73d6ac56 [xemacs-hg @ 2001-05-20 01:17:07 by ben]
ben
parents: 531
diff changeset
708 }
528
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
709 #endif
ef4d2466a29c [xemacs-hg @ 2001-05-10 09:59:45 by ben]
ben
parents: 460
diff changeset
710
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
711 XCAR (cache_incomplete_p) = Qnil;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
712 unbind_to (speccount);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
713
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 EMACS_GET_TIME (user_cache.last_rebuild_time);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 for (i = 0; i < user_cache.length; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
719 Ibyte *u_name = user_cache.user_names[i].ptr;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
720 Bytecount len = user_cache.user_names[i].len;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 /* scmp() works in chars, not bytes, so we have to compute this: */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 Charcount cclen = bytecount_to_charcount (u_name, len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 if (cclen < user_name_length
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 || 0 <= scmp_1 (u_name, XSTRING_DATA (user), user_name_length, 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 matchcount++; /* count matching completions */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 if (all_flag || NILP (bestmatch))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 Lisp_Object name = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 struct gcpro ngcpro1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 NGCPRO1 (name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 /* This is a possible completion */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 name = make_string (u_name, len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739 if (all_flag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 bestmatch = Fcons (name, bestmatch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 bestmatch = name;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
746 bestmatchsize = string_char_length (name);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 NUNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 Charcount compare = min (bestmatchsize, cclen);
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
753 Ibyte *p1 = XSTRING_DATA (bestmatch);
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
754 Ibyte *p2 = u_name;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 Charcount matchsize = scmp_1 (p1, p2, compare, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 if (matchsize < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 matchsize = compare;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 bestmatchsize = matchsize;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 if (uniq)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 *uniq = (matchcount == 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 if (all_flag || NILP (bestmatch))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 return bestmatch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 if (matchcount == 1 && bestmatchsize == user_name_length)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 return Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 return Fsubstring (bestmatch, Qzero, make_int (bestmatchsize));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 Lisp_Object
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
778 make_directory_hash_table (const Ibyte *path)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 DIR *d;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
781 if ((d = qxe_opendir (path)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 DIRENTRY *dp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784 Lisp_Object hash =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 make_lisp_hash_table (20, HASH_TABLE_NON_WEAK, HASH_TABLE_EQUAL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
787 while ((dp = qxe_readdir (d)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789 Bytecount len = NAMLEN (dp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 if (DIRENTRY_NONEMPTY (dp))
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
791 /* Cast to Ibyte* is OK, as qxe_readdir() Mule-encapsulates. */
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
792 Fputhash (make_string ((Ibyte *) dp->d_name, len), Qt, hash);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
794 qxe_closedir (d);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 return hash;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800
707
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
801 #if 0
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
802 /* ... never used ... should use list2 directly anyway ... */
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
803 /* NOTE: This function can never return a negative value. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 wasteful_word_to_lisp (unsigned int item)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 /* Compatibility: in other versions, file-attributes returns a LIST
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 of two 16 bit integers... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 Lisp_Object cons = word_to_lisp (item);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 XCDR (cons) = Fcons (XCDR (cons), Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 return cons;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 }
707
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
813 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 DEFUN ("file-attributes", Ffile_attributes, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 Return a list of attributes of file FILENAME.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 Value is nil if specified file cannot be opened.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 Otherwise, list elements are:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 0. t for directory, string (name linked to) for symbolic link, or nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 1. Number of links to file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 2. File uid.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 3. File gid.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 4. Last access time, as a list of two integers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 First integer has high-order 16 bits of time, second has low 16 bits.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 5. Last modification time, likewise.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 6. Last status change time, likewise.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 7. Size in bytes. (-1, if number is out of range).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 8. File modes, as a string of ten letters or dashes as in ls -l.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 9. t iff file's gid would change if file were deleted and recreated.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 10. inode number.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 11. Device number.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 If file does not exist, returns nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 (filename))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837 /* This function can GC. GC checked 1997.06.04. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 Lisp_Object values[12];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 Lisp_Object directory = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 struct stat s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 char modes[10];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842 Lisp_Object handler;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 struct gcpro gcpro1, gcpro2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 GCPRO2 (filename, directory);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 filename = Fexpand_file_name (filename, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 /* If the file name has special constructs in it,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 call the corresponding file handler. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 handler = Ffind_file_name_handler (filename, Qfile_attributes);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 if (!NILP (handler))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854 return call2 (handler, Qfile_attributes, filename);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
857 if (qxe_lstat (XSTRING_DATA (filename), &s) < 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 #ifdef BSD4_2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 directory = Ffile_name_directory (filename);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
867 #if 0 /* #### shouldn't this apply to WIN32_NATIVE and maybe CYGWIN? */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
869 Ibyte *tmpnam = XSTRING_DATA (Ffile_name_nondirectory (filename));
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
870 Bytecount l = qxestrlen (tmpnam);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872 if (l >= 5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873 && S_ISREG (s.st_mode)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
874 && (qxestrcasecmp (&tmpnam[l - 4], ".com") == 0 ||
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
875 qxestrcasecmp (&tmpnam[l - 4], ".exe") == 0 ||
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
876 qxestrcasecmp (&tmpnam[l - 4], ".bat") == 0))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878 s.st_mode |= S_IEXEC;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880 }
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
881 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 switch (s.st_mode & S_IFMT)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 values[0] = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888 case S_IFDIR:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889 values[0] = Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891 #ifdef S_IFLNK
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892 case S_IFLNK:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 values[0] = Ffile_symlink_p (filename);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 values[1] = make_int (s.st_nlink);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898 values[2] = make_int (s.st_uid);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899 values[3] = make_int (s.st_gid);
707
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
900 values[4] = make_time (s.st_atime);
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
901 values[5] = make_time (s.st_mtime);
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
902 values[6] = make_time (s.st_ctime);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 values[7] = make_int ((EMACS_INT) s.st_size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 /* If the size is out of range, give back -1. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905 /* #### Fix when Emacs gets bignums! */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 if (XINT (values[7]) != s.st_size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 values[7] = make_int (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908 filemodestring (&s, modes);
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
909 values[8] = make_string ((Ibyte *) modes, 10);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 #if defined (BSD4_2) || defined (BSD4_3) /* file gid will be dir gid */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912 struct stat sdir;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 770
diff changeset
914 if (!NILP (directory) && qxe_stat (XSTRING_DATA (directory), &sdir) == 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 values[9] = (sdir.st_gid != s.st_gid) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916 else /* if we can't tell, assume worst */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917 values[9] = Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919 #else /* file gid will be egid */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920 values[9] = (s.st_gid != getegid ()) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921 #endif /* BSD4_2 or BSD4_3 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922 values[10] = make_int (s.st_ino);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923 values[11] = make_int (s.st_dev);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 return Flist (countof (values), values);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930 /* initialization */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 syms_of_dired (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 546
diff changeset
936 DEFSYMBOL (Qdirectory_files);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 546
diff changeset
937 DEFSYMBOL (Qfile_name_completion);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 546
diff changeset
938 DEFSYMBOL (Qfile_name_all_completions);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 546
diff changeset
939 DEFSYMBOL (Qfile_attributes);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 DEFSUBR (Fdirectory_files);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942 DEFSUBR (Ffile_name_completion);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943 DEFSUBR (Ffile_name_all_completions);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944 DEFSUBR (Fuser_name_completion);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945 DEFSUBR (Fuser_name_completion_1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946 DEFSUBR (Fuser_name_all_completions);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947 DEFSUBR (Ffile_attributes);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951 vars_of_dired (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953 DEFVAR_LISP ("completion-ignored-extensions", &Vcompletion_ignored_extensions /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 *Completion ignores filenames ending in any string in this list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955 This variable does not affect lists of possible completions,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956 but does affect the commands that actually do completions.
770
336a418893b5 [xemacs-hg @ 2002-03-08 13:33:12 by adrian]
adrian
parents: 707
diff changeset
957 It is used by the function `file-name-completion'.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 Vcompletion_ignored_extensions = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960 }