components/vim/vim72-patches/7.2.244
changeset 379 c6a17bba1da3
parent 378 f0b61ed1d10d
child 380 e92b3b4a1c66
equal deleted inserted replaced
378:f0b61ed1d10d 379:c6a17bba1da3
     1 To: [email protected]
       
     2 Subject: Patch 7.2.244
       
     3 Fcc: outbox
       
     4 From: Bram Moolenaar <[email protected]>
       
     5 Mime-Version: 1.0
       
     6 Content-Type: text/plain; charset=UTF-8
       
     7 Content-Transfer-Encoding: 8bit
       
     8 ------------
       
     9 
       
    10 Patch 7.2.244
       
    11 Problem:    When 'enc' is utf-8 and 'fenc' is latin1, writing a non-latin1
       
    12 	    character gives a conversion error without any hint what is wrong.
       
    13 Solution:   When known add the line number to the error message.
       
    14 Files:	    src/fileio.c
       
    15 
       
    16 
       
    17 *** ../vim-7.2.243/src/fileio.c	2009-07-29 12:09:49.000000000 +0200
       
    18 --- src/fileio.c	2009-07-29 17:04:06.000000000 +0200
       
    19 ***************
       
    20 *** 121,126 ****
       
    21 --- 121,128 ----
       
    22       char_u	*bw_conv_buf;	/* buffer for writing converted chars */
       
    23       int		bw_conv_buflen; /* size of bw_conv_buf */
       
    24       int		bw_conv_error;	/* set for conversion error */
       
    25 +     linenr_T	bw_conv_error_lnum;  /* first line with error or zero */
       
    26 +     linenr_T	bw_start_lnum;  /* line number at start of buffer */
       
    27   # ifdef USE_ICONV
       
    28       iconv_t	bw_iconv_fd;	/* descriptor for iconv() or -1 */
       
    29   # endif
       
    30 ***************
       
    31 *** 2924,2929 ****
       
    32 --- 2925,2931 ----
       
    33       linenr_T	    lnum;
       
    34       long	    nchars;
       
    35       char_u	    *errmsg = NULL;
       
    36 +     int		    errmsg_allocated = FALSE;
       
    37       char_u	    *errnum = NULL;
       
    38       char_u	    *buffer;
       
    39       char_u	    smallbuf[SMBUFSIZE];
       
    40 ***************
       
    41 *** 2987,2992 ****
       
    42 --- 2989,2995 ----
       
    43       /* must init bw_conv_buf and bw_iconv_fd before jumping to "fail" */
       
    44       write_info.bw_conv_buf = NULL;
       
    45       write_info.bw_conv_error = FALSE;
       
    46 +     write_info.bw_conv_error_lnum = 0;
       
    47       write_info.bw_restlen = 0;
       
    48   # ifdef USE_ICONV
       
    49       write_info.bw_iconv_fd = (iconv_t)-1;
       
    50 ***************
       
    51 *** 4243,4248 ****
       
    52 --- 4245,4251 ----
       
    53   		nchars += write_info.bw_len;
       
    54   	}
       
    55       }
       
    56 +     write_info.bw_start_lnum = start;
       
    57   #endif
       
    58   
       
    59       write_info.bw_len = bufsize;
       
    60 ***************
       
    61 *** 4278,4283 ****
       
    62 --- 4281,4289 ----
       
    63   	    nchars += bufsize;
       
    64   	    s = buffer;
       
    65   	    len = 0;
       
    66 + #ifdef FEAT_MBYTE
       
    67 + 	    write_info.bw_start_lnum = lnum;
       
    68 + #endif
       
    69   	}
       
    70   	/* write failed or last line has no EOL: stop here */
       
    71   	if (end == 0
       
    72 ***************
       
    73 *** 4474,4480 ****
       
    74   	{
       
    75   #ifdef FEAT_MBYTE
       
    76   	    if (write_info.bw_conv_error)
       
    77 ! 		errmsg = (char_u *)_("E513: write error, conversion failed (make 'fenc' empty to override)");
       
    78   	    else
       
    79   #endif
       
    80   		if (got_int)
       
    81 --- 4480,4496 ----
       
    82   	{
       
    83   #ifdef FEAT_MBYTE
       
    84   	    if (write_info.bw_conv_error)
       
    85 ! 	    {
       
    86 ! 		if (write_info.bw_conv_error_lnum == 0)
       
    87 ! 		    errmsg = (char_u *)_("E513: write error, conversion failed (make 'fenc' empty to override)");
       
    88 ! 		else
       
    89 ! 		{
       
    90 ! 		    errmsg_allocated = TRUE;
       
    91 ! 		    errmsg = alloc(300);
       
    92 ! 		    vim_snprintf((char *)errmsg, 300, _("E513: write error, conversion failed in line %ld (make 'fenc' empty to override)"),
       
    93 ! 					 (long)write_info.bw_conv_error_lnum);
       
    94 ! 		}
       
    95 ! 	    }
       
    96   	    else
       
    97   #endif
       
    98   		if (got_int)
       
    99 ***************
       
   100 *** 4550,4555 ****
       
   101 --- 4566,4577 ----
       
   102   	{
       
   103   	    STRCAT(IObuff, _(" CONVERSION ERROR"));
       
   104   	    c = TRUE;
       
   105 + 	    if (write_info.bw_conv_error_lnum != 0)
       
   106 + 	    {
       
   107 + 		int l = STRLEN(IObuff);
       
   108 + 		vim_snprintf((char *)IObuff + l, IOSIZE - l, _(" in line %ld;"),
       
   109 + 			(long)write_info.bw_conv_error_lnum);
       
   110 + 	    }
       
   111   	}
       
   112   	else if (notconverted)
       
   113   	{
       
   114 ***************
       
   115 *** 4746,4751 ****
       
   116 --- 4768,4775 ----
       
   117   	}
       
   118   	STRCAT(IObuff, errmsg);
       
   119   	emsg(IObuff);
       
   120 + 	if (errmsg_allocated)
       
   121 + 	    vim_free(errmsg);
       
   122   
       
   123   	retval = FAIL;
       
   124   	if (end == 0)
       
   125 ***************
       
   126 *** 5105,5111 ****
       
   127   			c = buf[wlen];
       
   128   		}
       
   129   
       
   130 ! 		ip->bw_conv_error |= ucs2bytes(c, &p, flags);
       
   131   	    }
       
   132   	    if (flags & FIO_LATIN1)
       
   133   		len = (int)(p - buf);
       
   134 --- 5129,5141 ----
       
   135   			c = buf[wlen];
       
   136   		}
       
   137   
       
   138 ! 		if (ucs2bytes(c, &p, flags) && !ip->bw_conv_error)
       
   139 ! 		{
       
   140 ! 		    ip->bw_conv_error = TRUE;
       
   141 ! 		    ip->bw_conv_error_lnum = ip->bw_start_lnum;
       
   142 ! 		}
       
   143 ! 		if (c == NL)
       
   144 ! 		    ++ip->bw_start_lnum;
       
   145   	    }
       
   146   	    if (flags & FIO_LATIN1)
       
   147   		len = (int)(p - buf);
       
   148 ***************
       
   149 *** 5386,5391 ****
       
   150 --- 5416,5422 ----
       
   151   #ifdef FEAT_MBYTE
       
   152   /*
       
   153    * Convert a Unicode character to bytes.
       
   154 +  * Return TRUE for an error, FALSE when it's OK.
       
   155    */
       
   156       static int
       
   157   ucs2bytes(c, pp, flags)
       
   158 *** ../vim-7.2.243/src/version.c	2009-07-29 16:13:35.000000000 +0200
       
   159 --- src/version.c	2009-07-29 18:01:27.000000000 +0200
       
   160 ***************
       
   161 *** 678,679 ****
       
   162 --- 678,681 ----
       
   163   {   /* Add new patch number below this line */
       
   164 + /**/
       
   165 +     244,
       
   166   /**/
       
   167 
       
   168 -- 
       
   169 Support your right to bare arms!  Wear short sleeves!
       
   170 
       
   171  /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
       
   172 ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
       
   173 \\\        download, build and distribute -- http://www.A-A-P.org        ///
       
   174  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///