[Message Prev][Message Next][Thread Prev][Thread Next][Message Index][Thread Index]

Re: [MD:4288] Re: Write file: ダイアログボックスで文字欠落?



At Sun, 09 Mar 2003 01:58:42 +0900,
MIYOSHI Masanori wrote:

> 本格的には、
> Lisp_Object から取り出した文字列を C で操作するのではなくて、
> Lisp_Object のまま操作した後で、最後に文字列を取り出すのがいいん
> でしょうか?

その通りです。それが出来ない場合、w32.cのように、かなり面倒なprogramが必要になります。
(Emacs Lisp側のほうが、多言語文字列処理関係のAPIは圧倒的に充実していますし、
 behaviorが保存しない恐れがありますからね。)
良い手本にもなりそうなので、以下のように修正しておきました。
必ず、TCHARで取り扱い、TCHARのサイズを仮定しないようなコードを書くように心がけてください。

from himi

*** mw32fns.c.~1.91.~	Sun Mar 02 17:49:31 2003
--- mw32fns.c	Sun Mar 09 05:48:45 2003
***************
*** 8931,8938 ****
    Lisp_Object file = Qnil;
    int count = specpdl_ptr - specpdl;
    struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
!   char filename[MAX_PATH + 1];
!   char init_dir[MAX_PATH + 1];
    int use_dialog_p = 1;
  
    GCPRO5 (prompt, dir, default_filename, mustmatch, file);
--- 8931,8938 ----
    Lisp_Object file = Qnil;
    int count = specpdl_ptr - specpdl;
    struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
!   LPTSTR init_dir;
!   TCHAR filename[MAX_PATH + 1];
    int use_dialog_p = 1;
  
    GCPRO5 (prompt, dir, default_filename, mustmatch, file);
***************
*** 8942,8974 ****
    /* Create the dialog with PROMPT as title, using DIR as initial
       directory and using "*" as pattern.  */
    dir = Fexpand_file_name (dir, Qnil);
!   strncpy (init_dir, XSTRING (dir)->data, MAX_PATH);
!   init_dir[MAX_PATH] = '\0';
!   unixtodos_filename (init_dir);
  
    if (STRINGP (default_filename))
      {
!       char *file_name_only;
!       char *full_path_name = XSTRING (ENCODE_FILE (default_filename))->data;
! 
!       unixtodos_filename (full_path_name);
  
!       file_name_only = strrchr (full_path_name, '\\');
!       if (!file_name_only)
!         file_name_only = full_path_name;
        else
!         {
!           file_name_only++;
! 
!           /* If default_file_name is a directory, don't use the open
!              file dialog, as it does not support selecting
!              directories. */
!           if (!(*file_name_only))
!             use_dialog_p = 0;
!         }
! 
!       strncpy (filename, file_name_only, MAX_PATH);
!       filename[MAX_PATH] = '\0';
      }
    else
      filename[0] = '\0';
--- 8942,8969 ----
    /* Create the dialog with PROMPT as title, using DIR as initial
       directory and using "*" as pattern.  */
    dir = Fexpand_file_name (dir, Qnil);
!   init_dir = mw32_encode_lispy_string (Vw32_system_coding_system,
! 				       Funix_to_dos_filename (dir), NULL);
  
    if (STRINGP (default_filename))
      {
!       file = Ffile_name_nondirectory (Funix_to_dos_filename (default_filename));
!       if (LISPY_STRING_BYTES(file) > 0)
! 	{
! 	  int size;
! 	  LPTSTR filename_tmp;
  
! 	  filename_tmp = mw32_encode_lispy_string (Vw32_system_coding_system, file, &size);
! 	  memcpy (filename, filename_tmp, size);
! 	  filename[size / sizeof(filename[0])] = '\0';
! 	}
        else
! 	{
! 	  /* If default_file_name is a directory, don't use the open
! 	     file dialog, as it does not support selecting
! 	     directories. */
! 	  use_dialog_p = 0;
! 	}
      }
    else
      filename[0] = '\0';
***************
*** 8985,8991 ****
        file_details.lStructSize = sizeof (file_details);
        file_details.hwndOwner = FRAME_MW32_WINDOW (f);
        file_details.lpstrFile = filename;
!       file_details.nMaxFile = sizeof (filename);
        file_details.lpstrInitialDir = init_dir;
        file_details.lpstrTitle = XSTRING (prompt)->data;
        file_details.Flags = OFN_HIDEREADONLY | OFN_NOCHANGEDIR;
--- 8980,8986 ----
        file_details.lStructSize = sizeof (file_details);
        file_details.hwndOwner = FRAME_MW32_WINDOW (f);
        file_details.lpstrFile = filename;
!       file_details.nMaxFile = sizeof (filename) / sizeof (filename[0]);
        file_details.lpstrInitialDir = init_dir;
        file_details.lpstrTitle = XSTRING (prompt)->data;
        file_details.Flags = OFN_HIDEREADONLY | OFN_NOCHANGEDIR;
***************
*** 8995,9005 ****
  
        if (GetOpenFileName (&file_details))
  	{
!           dostounix_filename (filename);
! 	  file = DECODE_FILE (build_string (filename));
          }
        else
!         file = Qnil;
  
        UNBLOCK_INPUT;
        file = unbind_to (count, file);
--- 8990,9001 ----
  
        if (GetOpenFileName (&file_details))
  	{
! 	  file = mw32_decode_lispy_string (Vw32_system_coding_system,
! 					   filename, 0);
!           file = Fdos_to_unix_filename (file);
          }
        else
! 	file = Qnil;
  
        UNBLOCK_INPUT;
        file = unbind_to (count, file);