summaryrefslogtreecommitdiffstats
path: root/patches/source/vim/patches/7.4.016
blob: c58c605f5c15e1c9f7795f37203a2c13eb5983ec (plain) (blame)
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
To: vim_dev@googlegroups.com
Subject: Patch 7.4.016
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.4.016
Problem:    MS-Windows: File name completion doesn't work properly with
	    Chinese characters. (Yue Wu)
Solution:   Add fname_casew(). (Ken Takata)
Files:	    src/os_win32.c


*** ../vim-7.4.015/src/os_win32.c	2013-08-30 17:11:29.000000000 +0200
--- src/os_win32.c	2013-08-30 17:28:30.000000000 +0200
***************
*** 2500,2508 ****
--- 2500,2624 ----
  }
  
  
+ #ifdef FEAT_MBYTE
+ /*
+  * fname_casew(): Wide version of fname_case().  Set the case of the file name,
+  * if it already exists.  When "len" is > 0, also expand short to long
+  * filenames.
+  * Return FAIL if wide functions are not available, OK otherwise.
+  * NOTE: much of this is identical to fname_case(), keep in sync!
+  */
+     static int
+ fname_casew(
+     WCHAR	*name,
+     int		len)
+ {
+     WCHAR		szTrueName[_MAX_PATH + 2];
+     WCHAR		szTrueNameTemp[_MAX_PATH + 2];
+     WCHAR		*ptrue, *ptruePrev;
+     WCHAR		*porig, *porigPrev;
+     int			flen;
+     WIN32_FIND_DATAW	fb;
+     HANDLE		hFind;
+     int			c;
+     int			slen;
+ 
+     flen = (int)wcslen(name);
+     if (flen > _MAX_PATH)
+ 	return OK;
+ 
+     /* slash_adjust(name) not needed, already adjusted by fname_case(). */
+ 
+     /* Build the new name in szTrueName[] one component at a time. */
+     porig = name;
+     ptrue = szTrueName;
+ 
+     if (iswalpha(porig[0]) && porig[1] == L':')
+     {
+ 	/* copy leading drive letter */
+ 	*ptrue++ = *porig++;
+ 	*ptrue++ = *porig++;
+ 	*ptrue = NUL;	    /* in case nothing follows */
+     }
+ 
+     while (*porig != NUL)
+     {
+ 	/* copy \ characters */
+ 	while (*porig == psepc)
+ 	    *ptrue++ = *porig++;
+ 
+ 	ptruePrev = ptrue;
+ 	porigPrev = porig;
+ 	while (*porig != NUL && *porig != psepc)
+ 	{
+ 	    *ptrue++ = *porig++;
+ 	}
+ 	*ptrue = NUL;
+ 
+ 	/* To avoid a slow failure append "\*" when searching a directory,
+ 	 * server or network share. */
+ 	wcscpy(szTrueNameTemp, szTrueName);
+ 	slen = (int)wcslen(szTrueNameTemp);
+ 	if (*porig == psepc && slen + 2 < _MAX_PATH)
+ 	    wcscpy(szTrueNameTemp + slen, L"\\*");
+ 
+ 	/* Skip "", "." and "..". */
+ 	if (ptrue > ptruePrev
+ 		&& (ptruePrev[0] != L'.'
+ 		    || (ptruePrev[1] != NUL
+ 			&& (ptruePrev[1] != L'.' || ptruePrev[2] != NUL)))
+ 		&& (hFind = FindFirstFileW(szTrueNameTemp, &fb))
+ 						      != INVALID_HANDLE_VALUE)
+ 	{
+ 	    c = *porig;
+ 	    *porig = NUL;
+ 
+ 	    /* Only use the match when it's the same name (ignoring case) or
+ 	     * expansion is allowed and there is a match with the short name
+ 	     * and there is enough room. */
+ 	    if (_wcsicoll(porigPrev, fb.cFileName) == 0
+ 		    || (len > 0
+ 			&& (_wcsicoll(porigPrev, fb.cAlternateFileName) == 0
+ 			    && (int)(ptruePrev - szTrueName)
+ 					   + (int)wcslen(fb.cFileName) < len)))
+ 	    {
+ 		wcscpy(ptruePrev, fb.cFileName);
+ 
+ 		/* Look for exact match and prefer it if found.  Must be a
+ 		 * long name, otherwise there would be only one match. */
+ 		while (FindNextFileW(hFind, &fb))
+ 		{
+ 		    if (*fb.cAlternateFileName != NUL
+ 			    && (wcscoll(porigPrev, fb.cFileName) == 0
+ 				|| (len > 0
+ 				    && (_wcsicoll(porigPrev,
+ 						   fb.cAlternateFileName) == 0
+ 				    && (int)(ptruePrev - szTrueName)
+ 					 + (int)wcslen(fb.cFileName) < len))))
+ 		    {
+ 			wcscpy(ptruePrev, fb.cFileName);
+ 			break;
+ 		    }
+ 		}
+ 	    }
+ 	    FindClose(hFind);
+ 	    *porig = c;
+ 	    ptrue = ptruePrev + wcslen(ptruePrev);
+ 	}
+ 	else if (hFind == INVALID_HANDLE_VALUE
+ 		&& GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
+ 	    return FAIL;
+     }
+ 
+     wcscpy(name, szTrueName);
+     return OK;
+ }
+ #endif
+ 
  /*
   * fname_case(): Set the case of the file name, if it already exists.
   * When "len" is > 0, also expand short to long filenames.
+  * NOTE: much of this is identical to fname_casew(), keep in sync!
   */
      void
  fname_case(
***************
*** 2520,2530 ****
      int			slen;
  
      flen = (int)STRLEN(name);
!     if (flen == 0 || flen > _MAX_PATH)
  	return;
  
      slash_adjust(name);
  
      /* Build the new name in szTrueName[] one component at a time. */
      porig = name;
      ptrue = szTrueName;
--- 2636,2679 ----
      int			slen;
  
      flen = (int)STRLEN(name);
!     if (flen == 0)
  	return;
  
      slash_adjust(name);
  
+ #ifdef FEAT_MBYTE
+     if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
+     {
+ 	WCHAR	*p = enc_to_utf16(name, NULL);
+ 
+ 	if (p != NULL)
+ 	{
+ 	    char_u	*q;
+ 	    WCHAR	buf[_MAX_PATH + 2];
+ 
+ 	    wcscpy(buf, p);
+ 	    vim_free(p);
+ 
+ 	    if (fname_casew(buf, (len > 0) ? _MAX_PATH : 0) == OK)
+ 	    {
+ 		q = utf16_to_enc(buf, NULL);
+ 		if (q != NULL)
+ 		{
+ 		    vim_strncpy(name, q, (len > 0) ? len - 1 : flen);
+ 		    vim_free(q);
+ 		    return;
+ 		}
+ 	    }
+ 	}
+ 	/* Retry with non-wide function (for Windows 98). */
+     }
+ #endif
+ 
+     /* If 'enc' is utf-8, flen can be larger than _MAX_PATH.
+      * So we should check this after calling wide function. */
+     if (flen > _MAX_PATH)
+ 	return;
+ 
      /* Build the new name in szTrueName[] one component at a time. */
      porig = name;
      ptrue = szTrueName;
*** ../vim-7.4.015/src/version.c	2013-08-30 17:11:29.000000000 +0200
--- src/version.c	2013-08-30 17:15:06.000000000 +0200
***************
*** 740,741 ****
--- 740,743 ----
  {   /* Add new patch number below this line */
+ /**/
+     16,
  /**/

-- 
Fingers not found - Pound head on keyboard to continue.

 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///