(iso-languages): For Portuguese ~c and
[bpt/emacs.git] / src / dired.c
index 4c1f62e..eb743c5 100644 (file)
@@ -31,6 +31,10 @@ Boston, MA 02111-1307, USA.  */
 #include <rmsdef.h>
 #endif
 
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
 /* The d_nameln member of a struct dirent includes the '\0' character
    on some systems, but not on others.  What's worse, you can't tell
    at compile-time which one it will be, since it really depends on
@@ -183,13 +187,13 @@ If NOSORT is non-nil, the list is not sorted--its order is unpredictable.\n\
     report_file_error ("Opening directory", Fcons (directory, Qnil));
 
   list = Qnil;
-  dirnamelen = STRING_BYTES (XSTRING (encoded_directory));
+  dirnamelen = STRING_BYTES (XSTRING (directory));
   re_match_object = Qt;
 
   /* Decide whether we need to add a directory separator.  */
 #ifndef VMS
   if (dirnamelen == 0
-      || !IS_ANY_SEP (XSTRING (encoded_directory)->data[dirnamelen - 1]))
+      || !IS_ANY_SEP (XSTRING (directory)->data[dirnamelen - 1]))
     needsep = 1;
 #endif /* not VMS */
 
@@ -199,38 +203,41 @@ If NOSORT is non-nil, the list is not sorted--its order is unpredictable.\n\
   while (1)
     {
       DIRENTRY *dp = readdir (d);
-      int len;
 
       if (!dp) break;
-      len = NAMLEN (dp);
       if (DIRENTRY_NONEMPTY (dp))
        {
+         int len;
+
+         len = NAMLEN (dp);
+         name = DECODE_FILE (make_string (dp->d_name, len));
+         len = STRING_BYTES (XSTRING (name));
+
          if (NILP (match)
-             || (0 <= re_search (bufp, dp->d_name, len, 0, len, 0)))
+             || (0 <= re_search (bufp, XSTRING (name)->data, len, 0, len, 0)))
            {
              if (!NILP (full))
                {
                  int afterdirindex = dirnamelen;
                  int total = len + dirnamelen;
                  int nchars;
+                 Lisp_Object fullname;
 
-                 name = make_uninit_multibyte_string (total + needsep,
-                                                      total + needsep);
-                 bcopy (XSTRING (encoded_directory)->data, XSTRING (name)->data,
+                 fullname = make_uninit_multibyte_string (total + needsep,
+                                                          total + needsep);
+                 bcopy (XSTRING (directory)->data, XSTRING (fullname)->data,
                         dirnamelen);
                  if (needsep)
-                   XSTRING (name)->data[afterdirindex++] = DIRECTORY_SEP;
-                 bcopy (dp->d_name,
-                        XSTRING (name)->data + afterdirindex, len);
-                 nchars = chars_in_text (XSTRING (name)->data,
+                   XSTRING (fullname)->data[afterdirindex++] = DIRECTORY_SEP;
+                 bcopy (XSTRING (name)->data,
+                        XSTRING (fullname)->data + afterdirindex, len);
+                 nchars = chars_in_text (XSTRING (fullname)->data,
                                          afterdirindex + len);
-                 XSTRING (name)->size = nchars;
-                 if (nchars == STRING_BYTES (XSTRING (name)))
-                   SET_STRING_BYTES (XSTRING (name), -1);
+                 XSTRING (fullname)->size = nchars;
+                 if (nchars == STRING_BYTES (XSTRING (fullname)))
+                   SET_STRING_BYTES (XSTRING (fullname), -1);
+                 name = fullname;
                }
-             else
-               name = make_string (dp->d_name, len);
-             name = DECODE_FILE (name);
              list = Fcons (name, list);
            }
        }
@@ -295,6 +302,8 @@ These are all file names in directory DIRECTORY which begin with FILE.")
   return file_name_completion (file, directory, 1, 0);
 }
 
+static int file_name_completion_stat ();
+
 Lisp_Object
 file_name_completion (file, dirname, all_flag, ver_flag)
      Lisp_Object file, dirname;
@@ -547,6 +556,7 @@ file_name_completion (file, dirname, all_flag, ver_flag)
   return Fsignal (Qquit, Qnil);
 }
 
+static int
 file_name_completion_stat (dirname, dp, st_addr)
      Lisp_Object dirname;
      DIRENTRY *dp;
@@ -742,6 +752,7 @@ If file does not exist, returns nil.")
   return Flist (sizeof(values) / sizeof(values[0]), values);
 }
 \f
+void
 syms_of_dired ()
 {
   Qdirectory_files = intern ("directory-files");