4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
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.
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
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 */
28 iconv_t bw_iconv_fd; /* descriptor for iconv() or -1 */
35 char_u *errmsg = NULL;
36 + int errmsg_allocated = FALSE;
37 char_u *errnum = NULL;
39 char_u smallbuf[SMBUFSIZE];
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;
49 write_info.bw_iconv_fd = (iconv_t)-1;
53 nchars += write_info.bw_len;
56 + write_info.bw_start_lnum = start;
59 write_info.bw_len = bufsize;
67 + write_info.bw_start_lnum = lnum;
70 /* write failed or last line has no EOL: stop here */
76 if (write_info.bw_conv_error)
77 ! errmsg = (char_u *)_("E513: write error, conversion failed (make 'fenc' empty to override)");
84 if (write_info.bw_conv_error)
86 ! if (write_info.bw_conv_error_lnum == 0)
87 ! errmsg = (char_u *)_("E513: write error, conversion failed (make 'fenc' empty to override)");
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);
103 STRCAT(IObuff, _(" CONVERSION ERROR"));
105 + if (write_info.bw_conv_error_lnum != 0)
107 + int l = STRLEN(IObuff);
108 + vim_snprintf((char *)IObuff + l, IOSIZE - l, _(" in line %ld;"),
109 + (long)write_info.bw_conv_error_lnum);
112 else if (notconverted)
118 STRCAT(IObuff, errmsg);
120 + if (errmsg_allocated)
130 ! ip->bw_conv_error |= ucs2bytes(c, &p, flags);
132 if (flags & FIO_LATIN1)
133 len = (int)(p - buf);
138 ! if (ucs2bytes(c, &p, flags) && !ip->bw_conv_error)
140 ! ip->bw_conv_error = TRUE;
141 ! ip->bw_conv_error_lnum = ip->bw_start_lnum;
144 ! ++ip->bw_start_lnum;
146 if (flags & FIO_LATIN1)
147 len = (int)(p - buf);
153 * Convert a Unicode character to bytes.
154 + * Return TRUE for an error, FALSE when it's OK.
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
163 { /* Add new patch number below this line */
169 Support your right to bare arms! Wear short sleeves!
171 /// Bram Moolenaar -- Bram@Moolenaar.net -- 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 ///