]> code.delx.au - gnu-emacs/blobdiff - src/dired.c
(PURESIZE_RATIO): Reduce to 10/6.
[gnu-emacs] / src / dired.c
index 52a19f4fdc62afbffd372067134de822e64a237c..8c7c7fd5ac68c374c63d71989008be46b7f7237c 100644 (file)
@@ -1,6 +1,6 @@
 /* Lisp functions for making directory listings.
-   Copyright (C) 1985, 1986, 1993, 1994, 1999, 2000, 2001
-     Free Software Foundation, Inc.
+   Copyright (C) 1985, 1986, 1993, 1994, 1999, 2000, 2001, 2002, 2003,
+                 2004, 2005, 2006 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -16,8 +16,8 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with GNU Emacs; see the file COPYING.  If not, write to
-the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.  */
 
 
 #include <config.h>
@@ -26,14 +26,13 @@ Boston, MA 02111-1307, USA.  */
 #include <sys/types.h>
 #include <sys/stat.h>
 
-#ifdef VMS
-#include "vms-pwd.h"
-#else
+#ifdef HAVE_PWD_H
 #include <pwd.h>
+#endif
+#ifndef VMS
 #include <grp.h>
 #endif
 
-#include "systime.h"
 #include <errno.h>
 
 #ifdef VMS
@@ -86,13 +85,15 @@ extern struct direct *readdir ();
 #endif /* not MSDOS */
 #endif /* not SYSV_SYSTEM_DIR */
 
-#ifdef MSDOS
+/* Some versions of Cygwin don't have d_ino in `struct dirent'.  */
+#if defined(MSDOS) || defined(__CYGWIN__)
 #define DIRENTRY_NONEMPTY(p) ((p)->d_name[0] != 0)
 #else
 #define DIRENTRY_NONEMPTY(p) ((p)->d_ino)
 #endif
 
 #include "lisp.h"
+#include "systime.h"
 #include "buffer.h"
 #include "commands.h"
 #include "charset.h"
@@ -114,7 +115,6 @@ extern void filemodestring P_ ((struct stat *, char *));
 
 extern int completion_ignore_case;
 extern Lisp_Object Vcompletion_regexp_list;
-extern Lisp_Object Vfile_name_coding_system, Vdefault_file_name_coding_system;
 
 Lisp_Object Vcompletion_ignored_extensions;
 Lisp_Object Qcompletion_ignore_case;
@@ -132,7 +132,7 @@ Lisp_Object
 directory_files_internal_unwind (dh)
      Lisp_Object dh;
 {
-  DIR *d = (DIR *) ((XINT (XCAR (dh)) << 16) + XINT (XCDR (dh)));
+  DIR *d = (DIR *) XSAVE_VALUE (dh)->pointer;
   closedir (d);
   return Qnil;
 }
@@ -156,7 +156,6 @@ directory_files_internal (directory, full, match, nosort, attrs, id_format)
   int count = SPECPDL_INDEX ();
   struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
   DIRENTRY *dp;
-  int retry_p;
 
   /* Because of file name handlers, these functions might call
      Ffuncall, and cause a GC.  */
@@ -190,12 +189,6 @@ directory_files_internal (directory, full, match, nosort, attrs, id_format)
   /* Now *bufp is the compiled form of MATCH; don't call anything
      which might compile a new regexp until we're done with the loop!  */
 
-  /* Do this opendir after anything which might signal an error; if
-     an error is signaled while the directory stream is open, we
-     have to make sure it gets closed, and setting up an
-     unwind_protect to do so would be a pain.  */
- retry:
-
   d = opendir (SDATA (dirfilename));
   if (d == NULL)
     report_file_error ("Opening directory", Fcons (directory, Qnil));
@@ -204,8 +197,7 @@ directory_files_internal (directory, full, match, nosort, attrs, id_format)
      file-attributes on filenames, both of which can throw, so we must
      do a proper unwind-protect.  */
   record_unwind_protect (directory_files_internal_unwind,
-                        Fcons (make_number (((unsigned long) d) >> 16),
-                               make_number (((unsigned long) d) & 0xffff)));
+                        make_save_value (d, 0));
 
   directory_nbytes = SBYTES (directory);
   re_match_object = Qt;
@@ -223,10 +215,15 @@ directory_files_internal (directory, full, match, nosort, attrs, id_format)
       errno = 0;
       dp = readdir (d);
 
+      if (dp == NULL && (0
 #ifdef EAGAIN
-      if (dp == NULL && errno == EAGAIN)
-       continue;
+                        || errno == EAGAIN
+#endif
+#ifdef EINTR
+                        || errno == EINTR
 #endif
+                        ))
+       { QUIT; continue; }
 
       if (dp == NULL)
        break;
@@ -317,22 +314,11 @@ directory_files_internal (directory, full, match, nosort, attrs, id_format)
        }
     }
 
-  retry_p = 0;
-#ifdef EINTR
-  retry_p |= errno == EINTR;
-#endif
-
   closedir (d);
 
   /* Discard the unwind protect.  */
   specpdl_ptr = specpdl + count;
 
-  if (retry_p)
-    {
-      list = Qnil;
-      goto retry;
-    }
-
   if (NILP (nosort))
     list = Fsort (Fnreverse (list),
                  attrs ? Qfile_attributes_lessp : Qstring_lessp);
@@ -359,17 +345,8 @@ If NOSORT is non-nil, the list is not sorted--its order is unpredictable.
      call the corresponding file handler.  */
   handler = Ffind_file_name_handler (directory, Qdirectory_files);
   if (!NILP (handler))
-    {
-      Lisp_Object args[6];
-
-      args[0] = handler;
-      args[1] = Qdirectory_files;
-      args[2] = directory;
-      args[3] = full;
-      args[4] = match;
-      args[5] = nosort;
-      return Ffuncall (6, args);
-    }
+    return call5 (handler, Qdirectory_files, directory,
+                  full, match, nosort);
 
   return directory_files_internal (directory, full, match, nosort, 0, Qnil);
 }
@@ -395,18 +372,8 @@ ID-FORMAT specifies the preferred format of attributes uid and gid, see
      call the corresponding file handler.  */
   handler = Ffind_file_name_handler (directory, Qdirectory_files_and_attributes);
   if (!NILP (handler))
-    {
-      Lisp_Object args[7];
-
-      args[0] = handler;
-      args[1] = Qdirectory_files_and_attributes;
-      args[2] = directory;
-      args[3] = full;
-      args[4] = match;
-      args[5] = nosort;
-      args[6] = id_format;
-      return Ffuncall (7, args);
-    }
+    return call6 (handler, Qdirectory_files_and_attributes,
+                  directory, full, match, nosort, id_format);
 
   return directory_files_internal (directory, full, match, nosort, 1, id_format);
 }
@@ -420,7 +387,7 @@ DEFUN ("file-name-completion", Ffile_name_completion, Sfile_name_completion,
 Returns the longest string
 common to all file names in DIRECTORY that start with FILE.
 If there is only one and FILE matches it exactly, returns t.
-Returns nil if DIR contains no name starting with FILE.
+Returns nil if DIRECTORY contains no name starting with FILE.
 
 This function ignores some of the possible completions as
 determined by the variable `completion-ignored-extensions', which see.  */)
@@ -539,8 +506,7 @@ file_name_completion (file, dirname, all_flag, ver_flag)
        report_file_error ("Opening directory", Fcons (dirname, Qnil));
 
       record_unwind_protect (directory_files_internal_unwind,
-                             Fcons (make_number (((unsigned long) d) >> 16),
-                                    make_number (((unsigned long) d) & 0xffff)));
+                             make_save_value (d, 0));
 
       /* Loop reading blocks */
       /* (att3b compiler bug requires do a null comparison this way) */
@@ -552,8 +518,19 @@ file_name_completion (file, dirname, all_flag, ver_flag)
 #ifdef VMS
          dp = (*readfunc) (d);
 #else
+         errno = 0;
          dp = readdir (d);
+         if (dp == NULL && (0
+# ifdef EAGAIN
+                            || errno == EAGAIN
+# endif
+# ifdef EINTR
+                            || errno == EINTR
+# endif
+                            ))
+           { QUIT; continue; }
 #endif
+
          if (!dp) break;
 
          len = NAMLEN (dp);
@@ -926,6 +903,7 @@ Elements of the attribute list are:
 #endif
   char modes[10];
   Lisp_Object handler;
+  struct gcpro gcpro1;
 
   filename = Fexpand_file_name (filename, Qnil);
 
@@ -933,9 +911,17 @@ Elements of the attribute list are:
      call the corresponding file handler.  */
   handler = Ffind_file_name_handler (filename, Qfile_attributes);
   if (!NILP (handler))
-    return call3 (handler, Qfile_attributes, filename, id_format);
+    { /* Only pass the extra arg if it is used to help backward compatibility
+        with old file handlers which do not implement the new arg.  --Stef  */
+      if (NILP (id_format))
+       return call2 (handler, Qfile_attributes, filename);
+      else
+       return call3 (handler, Qfile_attributes, filename, id_format);
+    }
 
+  GCPRO1 (filename);
   encoded = ENCODE_FILE (filename);
+  UNGCPRO;
 
   if (lstat (SDATA (encoded), &s) < 0)
     return Qnil;
@@ -960,9 +946,9 @@ Elements of the attribute list are:
   else
     {
       pw = (struct passwd *) getpwuid (s.st_uid);
-      values[2] = (pw ? build_string (pw->pw_name) : s.st_uid);
+      values[2] = (pw ? build_string (pw->pw_name) : make_number (s.st_uid));
       gr = (struct group *) getgrgid (s.st_gid);
-      values[3] = (gr ? build_string (gr->gr_name) : s.st_gid);
+      values[3] = (gr ? build_string (gr->gr_name) : make_number (s.st_gid));
     }
   values[4] = make_time (s.st_atime);
   values[5] = make_time (s.st_mtime);
@@ -1051,11 +1037,11 @@ syms_of_dired ()
 #endif /* VMS */
 
   DEFVAR_LISP ("completion-ignored-extensions", &Vcompletion_ignored_extensions,
-              doc: /* *Completion ignores filenames ending in any string in this list.
-Directories are ignored if they match any string in this list which
-ends in a slash.
-This variable does not affect lists of possible completions,
-but does affect the commands that actually do completions.  */);
+              doc: /* Completion ignores file names ending in any string in this list.
+It does not ignore them if all possible completions end in one of
+these strings or when displaying a list of completions.
+It ignores directory names if they match any string in this list which
+ends in a slash.  */);
   Vcompletion_ignored_extensions = Qnil;
 }