(syms_of_dired): staticpro Qdirectory_files, Qfile_name_completion,
[bpt/emacs.git] / src / dired.c
index 15e969b..a8468c0 100644 (file)
@@ -15,7 +15,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, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
 
 
 #include <config.h>
@@ -105,8 +106,9 @@ Lisp_Object Qfile_attributes;
 DEFUN ("directory-files", Fdirectory_files, Sdirectory_files, 1, 4, 0,
   "Return a list of names of files in DIRECTORY.\n\
 There are three optional arguments:\n\
-If FULL is non-nil, absolute pathnames of the files are returned.\n\
-If MATCH is non-nil, only pathnames containing that regexp are returned.\n\
+If FULL is non-nil, return absolute file names.  Otherwise return names\n\
+ that are relative to the specified directory.\n\
+If MATCH is non-nil, mention only file names that match the regexp MATCH.\n\
 If NOSORT is non-nil, the list is not sorted--its order is unpredictable.\n\
  NOSORT is useful if you plan to sort the result yourself.")
   (directory, full, match, nosort)
@@ -228,7 +230,7 @@ DEFUN ("file-name-completion", Ffile_name_completion, Sfile_name_completion,
   2, 2, 0,
   "Complete file name FILE in directory DIRECTORY.\n\
 Returns the longest string\n\
-common to all filenames in DIRECTORY that start with FILE.\n\
+common to all file names in DIRECTORY that start with FILE.\n\
 If there is only one and FILE matches it exactly, returns t.\n\
 Returns nil if DIR contains no name starting with FILE.")
   (file, directory)
@@ -293,6 +295,19 @@ file_name_completion (file, dirname, all_flag, ver_flag)
   int count = specpdl_ptr - specpdl;
   struct gcpro gcpro1, gcpro2, gcpro3;
 
+#ifdef MSDOS
+#if __DJGPP__ > 1
+  /* Some fields of struct stat are *very* expensive to compute on MS-DOS,
+     but aren't required here.  Avoid computing the following fields:
+     st_inode, st_size and st_nlink for directories, and the execute bits
+     in st_mode for non-directory files with non-standard extensions.  */
+
+  unsigned short save_djstat_flags = _djstat_flags;
+
+  _djstat_flags = _STAT_INODE | _STAT_EXEC_MAGIC | _STAT_DIRSIZE;
+#endif
+#endif
+
 #ifdef VMS
   extern DIRENTRY * readdirver ();
 
@@ -451,6 +466,8 @@ file_name_completion (file, dirname, all_flag, ver_flag)
                     use it as the best match rather than one that is not
                     an exact match.  This way, we get the case pattern
                     of the actual match.  */
+                 /* This tests that the current file is an exact match
+                    but BESTMATCH is not (it is too long).  */
                  if ((matchsize == len
                       && matchsize + !!directoryp 
                          < XSTRING (bestmatch)->size)
@@ -458,13 +475,15 @@ file_name_completion (file, dirname, all_flag, ver_flag)
                      /* If there is no exact match ignoring case,
                         prefer a match that does not change the case
                         of the input.  */
+                     /* If there is more than one exact match aside from
+                        case, and one of them is exact including case,
+                        prefer that one.  */
+                     /* This == checks that, of current file and BESTMATCH,
+                        either both or neither are exact.  */
                      (((matchsize == len)
                        ==
                        (matchsize + !!directoryp 
                         == XSTRING (bestmatch)->size))
-                      /* If there is more than one exact match aside from
-                         case, and one of them is exact including case,
-                         prefer that one.  */
                       && !bcmp (p2, XSTRING (file)->data, XSTRING (file)->size)
                       && bcmp (p1, XSTRING (file)->data, XSTRING (file)->size)))
                    {
@@ -490,6 +509,12 @@ file_name_completion (file, dirname, all_flag, ver_flag)
   UNGCPRO;
   bestmatch = unbind_to (count, bestmatch);
 
+#ifdef MSDOS
+#if __DJGPP__ > 1
+  _djstat_flags = save_djstat_flags;
+#endif
+#endif
+
   if (all_flag || NILP (bestmatch))
     return bestmatch;
   if (matchcount == 1 && bestmatchsize == XSTRING (file)->size)
@@ -654,24 +679,13 @@ If file does not exist, returns nil.")
   else                                 /* if we can't tell, assume worst */
     values[9] = Qt;
 #else                                  /* file gid will be egid */
-#ifdef WINDOWSNT
-  values[9] = Qnil;    /* sorry, no group IDs on NT */
-#else  /* not WINDOWSNT */
   values[9] = (s.st_gid != getegid ()) ? Qt : Qnil;
-#endif /* not WINDOWSNT */
 #endif /* BSD4_2 (or BSD4_3) */
 #ifdef BSD4_3
 #undef BSD4_2 /* ok, you can look again without throwing up */
 #endif
-#ifdef WINDOWSNT
-  /* Fill in the inode and device values specially...see nt.c.  */
-  if (!get_inode_and_device_vals (filename, &values[10], &values[11])) {
-      return Qnil;
-  }
-#else  /* not WINDOWSNT */
   values[10] = make_number (s.st_ino);
   values[11] = make_number (s.st_dev);
-#endif /* not WINDOWSNT */
   return Flist (sizeof(values) / sizeof(values[0]), values);
 }
 \f
@@ -682,6 +696,11 @@ syms_of_dired ()
   Qfile_name_all_completions = intern ("file-name-all-completions");
   Qfile_attributes = intern ("file-attributes");
 
+  staticpro (&Qdirectory_files);
+  staticpro (&Qfile_name_completion);
+  staticpro (&Qfile_name_all_completions);
+  staticpro (&Qfile_attributes);
+
   defsubr (&Sdirectory_files);
   defsubr (&Sfile_name_completion);
 #ifdef VMS