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