changeset 50196:320721ae5978

(Ffile_name_directory): Reconstruct file name by make_specified_string. (Ffile_name_nondirectory, Ffile_name_as_directory) (Fdirectory_file_name, Fexpand_file_name) (Fsubstitute_in_file_name): Likewise. (Fread_file_name): Compare decoded homedir with DIR and DEFAULT_FILENAME.
author Kenichi Handa <handa@m17n.org>
date Wed, 19 Mar 2003 11:54:57 +0000
parents a75ad7d5fdc9
children ecb46e1986f0
files src/fileio.c
diffstat 1 files changed, 40 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/src/fileio.c	Wed Mar 19 11:37:35 2003 +0000
+++ b/src/fileio.c	Wed Mar 19 11:54:57 2003 +0000
@@ -447,9 +447,7 @@
   CORRECT_DIR_SEPS (beg);
 #endif /* DOS_NT */
 
-  if (STRING_MULTIBYTE (filename))
-    return make_string (beg, p - beg);
-  return make_unibyte_string (beg, p - beg);
+  return make_specified_string (beg, -1, p - beg, STRING_MULTIBYTE (filename));
 }
 
 DEFUN ("file-name-nondirectory", Ffile_name_nondirectory,
@@ -488,9 +486,7 @@
 	 )
     p--;
 
-  if (STRING_MULTIBYTE (filename))
-    return make_string (p, end - p);
-  return make_unibyte_string (p, end - p);
+  return make_specified_string (p, -1, end - p, STRING_MULTIBYTE (filename));
 }
 
 DEFUN ("unhandled-file-name-directory", Funhandled_file_name_directory,
@@ -631,7 +627,9 @@
     return call2 (handler, Qfile_name_as_directory, file);
 
   buf = (char *) alloca (SBYTES (file) + 10);
-  return build_string (file_name_as_directory (buf, SDATA (file)));
+  file_name_as_directory (buf, SDATA (file));
+  return make_specified_string (buf, -1, strlen (buf),
+				STRING_MULTIBYTE (file));
 }
 
 /*
@@ -831,7 +829,8 @@
   buf = (char *) alloca (SBYTES (directory) + 20);
 #endif
   directory_file_name (SDATA (directory), buf);
-  return build_string (buf);
+  return make_specified_string (buf, -1, strlen (buf),
+				STRING_MULTIBYTE (directory));
 }
 
 static char make_temp_name_tbl[64] =
@@ -1275,7 +1274,11 @@
 	{
 #ifdef VMS
 	  if (index (nm, '/'))
-	    return build_string (sys_translate_unix (nm));
+	    {
+	      nm = sys_translate_unix (nm);
+	      return make_specified_string (nm, -1, strlen (nm),
+					    STRING_MULTIBYTE (name));
+	    }
 #endif /* VMS */
 #ifdef DOS_NT
 	  /* Make sure directories are all separated with / or \ as
@@ -1286,14 +1289,18 @@
 	  if (IS_DIRECTORY_SEP (nm[1]))
 	    {
 	      if (strcmp (nm, SDATA (name)) != 0)
-		name = build_string (nm);
+		name
+		  = make_specified_string (nm, -1, strlen (nm),
+					   STRING_MULTIBYTE (name));
 	    }
 	  else
 #endif
 	  /* drive must be set, so this is okay */
 	  if (strcmp (nm - 2, SDATA (name)) != 0)
 	    {
-	      name = make_string (nm - 2, p - nm + 2);
+	      name
+		= make_specified_string (nm, -1, strlen (nm),
+					 STRING_MULTIBYTE (name));
 	      SSET (name, 0, DRIVE_LETTER (drive));
 	      SSET (name, 1, ':');
 	    }
@@ -1301,7 +1308,8 @@
 #else /* not DOS_NT */
 	  if (nm == SDATA (name))
 	    return name;
-	  return build_string (nm);
+	  return make_specified_string (nm, -1, strlen (nm),
+					STRING_MULTIBYTE (name));
 #endif /* not DOS_NT */
 	}
     }
@@ -1670,7 +1678,8 @@
   CORRECT_DIR_SEPS (target);
 #endif /* DOS_NT */
 
-  return make_string (target, o - target);
+  return make_specified_string (target, -1, o - target,
+				STRING_MULTIBYTE (name));
 }
 
 #if 0
@@ -2101,7 +2110,8 @@
     }
 
 #ifdef VMS
-  return build_string (nm);
+  return make_specified_string (nm, -1, strlen (nm),
+				STRING_MULTIBYTE (filename));
 #else
 
   /* See if any variables are substituted into the string
@@ -2244,9 +2254,7 @@
       xnm = p;
 #endif
 
-  if (STRING_MULTIBYTE (filename))
-    return make_string (xnm, x - xnm);
-  return make_unibyte_string (xnm, x - xnm);
+  return make_specified_string (xnm, -1, x - xnm, STRING_MULTIBYTE (filename));
 
  badsubst:
   error ("Bad format environment-variable substitution");
@@ -6023,6 +6031,7 @@
   Lisp_Object val, insdef, tem;
   struct gcpro gcpro1, gcpro2;
   register char *homedir;
+  Lisp_Object decoded_homedir;
   int replace_in_history = 0;
   int add_to_history = 0;
   int count;
@@ -6045,25 +6054,29 @@
       CORRECT_DIR_SEPS (homedir);
     }
 #endif
+  if (homedir != 0)
+    decoded_homedir
+      = DECODE_FILE (make_unibyte_string (homedir, strlen (homedir)));
   if (homedir != 0
       && STRINGP (dir)
-      && !strncmp (homedir, SDATA (dir), strlen (homedir))
-      && IS_DIRECTORY_SEP (SREF (dir, strlen (homedir))))
+      && !strncmp (SDATA (decoded_homedir), SDATA (dir),
+		   SBYTES (decoded_homedir))
+      && IS_DIRECTORY_SEP (SREF (dir, SBYTES (decoded_homedir))))
     {
-      dir = make_string (SDATA (dir) + strlen (homedir) - 1,
-			 SBYTES (dir) - strlen (homedir) + 1);
-      SSET (dir, 0, '~');
+      dir = Fsubstring (dir, make_number (SCHARS (decoded_homedir) + 1), Qnil);
+      dir = concat2 (build_string ("~"), dir);
     }
   /* Likewise for default_filename.  */
   if (homedir != 0
       && STRINGP (default_filename)
-      && !strncmp (homedir, SDATA (default_filename), strlen (homedir))
-      && IS_DIRECTORY_SEP (SREF (default_filename, strlen (homedir))))
+      && !strncmp (SDATA (decoded_homedir), SDATA (default_filename),
+		   SBYTES (decoded_homedir))
+      && IS_DIRECTORY_SEP (SREF (default_filename, SBYTES (decoded_homedir))))
     {
       default_filename
-	= make_string (SDATA (default_filename) + strlen (homedir) - 1,
-		       SBYTES (default_filename) - strlen (homedir) + 1);
-      SSET (default_filename, 0, '~');
+	= Fsubstring (default_filename,
+		      make_number (SCHARS (decoded_homedir) + 1), Qnil);
+      default_filename = concat2 (build_string ("~"), default_filename);
     }
   if (!NILP (default_filename))
     {