unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* expand-file-name problem for eight-bit-control/graphic
@ 2003-03-13  7:47 Kenichi Handa
  2003-03-15  6:54 ` Richard Stallman
  0 siblings, 1 reply; 6+ messages in thread
From: Kenichi Handa @ 2003-03-13  7:47 UTC (permalink / raw)


I've just found that expand-file-name sometimes converts
unibyte filename to multibyte, and multibyte filename to
unibyte.

Ex.1  unibyte->multibyte
(expand-file-name "~/\201\300") => "/home/handa/À"

Ex.2 multibyte->unibyte
(expand-file-name "~/À\200") => "/home/handa/\201\300\236\240"

The reason is that it uses make_string and build_string
blindly.  It seems that the attached patch fixes this bug,
but, as expand-file-name is one of heavily system-dependent
parts, and has lots of "#ifdef", I'd like to ask the other
poeple to confirm this patch doesn't cause any problem.

---
Ken'ichi HANDA
handa@m17n.org

2003-03-13  Kenichi Handa  <handa@etlken2>

	* fileio.c (Fexpand_file_name): Preserve multibyteness of NAME in
	the return value.

*** fileio.c.~1.474.~	Mon Feb  3 09:16:21 2003
--- fileio.c	Thu Mar 13 16:28:58 2003
***************
*** 1028,1033 ****
--- 1028,1034 ----
  #endif /* DOS_NT */
    int length;
    Lisp_Object handler;
+   int multibyte;
  
    CHECK_STRING (name);
  
***************
*** 1111,1116 ****
--- 1112,1123 ----
    name = FILE_SYSTEM_CASE (name);
  #endif
  
+   if (STRING_MULTIBYTE (default_directory))
+     default_directory = ENCODE_FILE (default_directory);
+   multibyte = STRING_MULTIBYTE (name);
+   if (multibyte)
+     name = ENCODE_FILE (name);
+ 
    nm = SDATA (name);
  
  #ifdef DOS_NT
***************
*** 1275,1281 ****
  	{
  #ifdef VMS
  	  if (index (nm, '/'))
! 	    return build_string (sys_translate_unix (nm));
  #endif /* VMS */
  #ifdef DOS_NT
  	  /* Make sure directories are all separated with / or \ as
--- 1282,1294 ----
  	{
  #ifdef VMS
  	  if (index (nm, '/'))
! 	    {
! 	      nm = sys_translate_unix (nm);
! 	      name = make_unibyte_string (nm, strlen (nm));
! 	      if (multibyte)
! 		name = DECODE_FILE (name);
! 	      return name;
! 	    }
  #endif /* VMS */
  #ifdef DOS_NT
  	  /* Make sure directories are all separated with / or \ as
***************
*** 1286,1307 ****
  	  if (IS_DIRECTORY_SEP (nm[1]))
  	    {
  	      if (strcmp (nm, SDATA (name)) != 0)
! 		name = build_string (nm);
  	    }
  	  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);
  	      SSET (name, 0, DRIVE_LETTER (drive));
  	      SSET (name, 1, ':');
  	    }
  	  return name;
  #else /* not DOS_NT */
! 	  if (nm == SDATA (name))
! 	    return name;
! 	  return build_string (nm);
  #endif /* not DOS_NT */
  	}
      }
--- 1299,1324 ----
  	  if (IS_DIRECTORY_SEP (nm[1]))
  	    {
  	      if (strcmp (nm, SDATA (name)) != 0)
! 		name = make_unibyte_string (nm, strlen (nm));
  	    }
  	  else
  #endif
  	  /* drive must be set, so this is okay */
  	  if (strcmp (nm - 2, SDATA (name)) != 0)
  	    {
! 	      name = make_unibyte_string (nm - 2, p - nm + 2);
  	      SSET (name, 0, DRIVE_LETTER (drive));
  	      SSET (name, 1, ':');
  	    }
+ 	  if (multibyte)
+ 	    name = DECODE_FILE (name);
  	  return name;
  #else /* not DOS_NT */
! 	  if (nm != SDATA (name))
! 	    name = make_unibyte_string (nm, strlen (nm));
! 	  if (multibyte)
! 	    name = DECODE_FILE (name);
! 	  return name;
  #endif /* not DOS_NT */
  	}
      }
***************
*** 1670,1676 ****
    CORRECT_DIR_SEPS (target);
  #endif /* DOS_NT */
  
!   return make_string (target, o - target);
  }
  
  #if 0
--- 1687,1696 ----
    CORRECT_DIR_SEPS (target);
  #endif /* DOS_NT */
  
!   name = make_unibyte_string (target, o - target);
!   if (multibyte)
!     name = DECODE_FILE (name);
!   return name;
  }
  
  #if 0

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2003-03-20 18:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-03-13  7:47 expand-file-name problem for eight-bit-control/graphic Kenichi Handa
2003-03-15  6:54 ` Richard Stallman
2003-03-18  2:03   ` Kenichi Handa
2003-03-18 13:24     ` Kenichi Handa
2003-03-19 13:36       ` Richard Stallman
2003-03-20 18:49       ` Juanma Barranquero

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).