all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Kenichi Handa <handa@m17n.org>
Cc: emacs-devel@gnu.org
Subject: Re: expand-file-name problem for eight-bit-control/graphic
Date: Tue, 18 Mar 2003 11:03:35 +0900 (JST)	[thread overview]
Message-ID: <200303180203.LAA27619@etlken.m17n.org> (raw)
In-Reply-To: <E18u5Z4-0004yd-00@fencepost.gnu.org> (message from Richard Stallman on Sat, 15 Mar 2003 01:54:42 -0500)

In article <E18u5Z4-0004yd-00@fencepost.gnu.org>, Richard Stallman <rms@gnu.org> writes:
> I have a lot of doubts about this code, because it seems to encode and
> then decode the file name.  Since the arguments and values are both
> strings for use within Emacs, I think it is incorrect for
> expand-file-name to ever encode or decode a file name.

But, at least, we can't use build_string and make_string
blindly to reconstruct a file name.  So, how about the
attached change?

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

*** fileio.c.~1.474.~	Tue Mar 18 09:59:02 2003
--- fileio.c	Tue Mar 18 10:52:33 2003
***************
*** 992,997 ****
--- 992,1014 ----
  
  
  \f
+ /* Return a string made from NBYTES bytes at P.  If MULTIBYTE is
+    nonzero, the string is multibyte (it is assumed that the bytes are
+    in correct multibyte form).  If MULTIBYTE is zero, the string is
+    unibyte.  */
+ 
+ static Lisp_Object
+ bytes_to_string (unsigned char *p, int nbytes, int multibyte)
+ {
+   int nchars;
+ 
+   if (! multibyte)
+     return make_unibyte_string ((char *) p, nbytes);
+   nchars = multibyte_chars_in_text (p, nbytes);
+   return make_multibyte_string ((char *) p, nchars, nbytes);
+ }
+ 
+ 
  DEFUN ("expand-file-name", Fexpand_file_name, Sexpand_file_name, 1, 2, 0,
         doc: /* Convert filename NAME to absolute, and canonicalize it.
  Second arg DEFAULT-DIRECTORY is directory to start with if NAME is relative
***************
*** 1028,1033 ****
--- 1045,1051 ----
  #endif /* DOS_NT */
    int length;
    Lisp_Object handler;
+   int multibyte;
  
    CHECK_STRING (name);
  
***************
*** 1111,1116 ****
--- 1129,1135 ----
    name = FILE_SYSTEM_CASE (name);
  #endif
  
+   multibyte = STRING_MULTIBYTE (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
--- 1294,1304 ----
  	{
  #ifdef VMS
  	  if (index (nm, '/'))
! 	    {
! 	      nm = sys_translate_unix (nm);
! 	      length = strlen (nm);
! 	      return bytes_to_string (nm, length, multibyte);
! 	    }
  #endif /* VMS */
  #ifdef DOS_NT
  	  /* Make sure directories are all separated with / or \ as
***************
*** 1286,1299 ****
  	  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, ':');
  	    }
--- 1309,1322 ----
  	  if (IS_DIRECTORY_SEP (nm[1]))
  	    {
  	      if (strcmp (nm, SDATA (name)) != 0)
! 		name = bytes_to_string (nm, strlen (nm), multibyte);
  	    }
  	  else
  #endif
  	  /* drive must be set, so this is okay */
  	  if (strcmp (nm - 2, SDATA (name)) != 0)
  	    {
! 	      name = bytes_to_string (nm, strlen (nm), multibyte);
  	      SSET (name, 0, DRIVE_LETTER (drive));
  	      SSET (name, 1, ':');
  	    }
***************
*** 1301,1307 ****
  #else /* not DOS_NT */
  	  if (nm == SDATA (name))
  	    return name;
! 	  return build_string (nm);
  #endif /* not DOS_NT */
  	}
      }
--- 1324,1330 ----
  #else /* not DOS_NT */
  	  if (nm == SDATA (name))
  	    return name;
! 	  return bytes_to_string (nm, strlen (nm), multibyte);
  #endif /* not DOS_NT */
  	}
      }
***************
*** 1670,1676 ****
    CORRECT_DIR_SEPS (target);
  #endif /* DOS_NT */
  
!   return make_string (target, o - target);
  }
  
  #if 0
--- 1693,1699 ----
    CORRECT_DIR_SEPS (target);
  #endif /* DOS_NT */
  
!   return bytes_to_string (target, o - target, multibyte);
  }
  
  #if 0

  reply	other threads:[~2003-03-18  2:03 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2003-03-18 13:24     ` Kenichi Handa
2003-03-19 13:36       ` Richard Stallman
2003-03-20 18:49       ` Juanma Barranquero

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200303180203.LAA27619@etlken.m17n.org \
    --to=handa@m17n.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.