|
|
8b9a1c |
To: vim_dev@googlegroups.com
|
|
|
8b9a1c |
Subject: Patch 7.4.016
|
|
|
8b9a1c |
Fcc: outbox
|
|
|
8b9a1c |
From: Bram Moolenaar <Bram@moolenaar.net>
|
|
|
8b9a1c |
Mime-Version: 1.0
|
|
|
8b9a1c |
Content-Type: text/plain; charset=UTF-8
|
|
|
8b9a1c |
Content-Transfer-Encoding: 8bit
|
|
|
8b9a1c |
------------
|
|
|
8b9a1c |
|
|
|
8b9a1c |
Patch 7.4.016
|
|
|
8b9a1c |
Problem: MS-Windows: File name completion doesn't work properly with
|
|
|
8b9a1c |
Chinese characters. (Yue Wu)
|
|
|
8b9a1c |
Solution: Add fname_casew(). (Ken Takata)
|
|
|
8b9a1c |
Files: src/os_win32.c
|
|
|
8b9a1c |
|
|
|
8b9a1c |
|
|
|
8b9a1c |
*** ../vim-7.4.015/src/os_win32.c 2013-08-30 17:11:29.000000000 +0200
|
|
|
8b9a1c |
--- src/os_win32.c 2013-08-30 17:28:30.000000000 +0200
|
|
|
8b9a1c |
***************
|
|
|
8b9a1c |
*** 2500,2508 ****
|
|
|
8b9a1c |
--- 2500,2624 ----
|
|
|
8b9a1c |
}
|
|
|
8b9a1c |
|
|
|
8b9a1c |
|
|
|
8b9a1c |
+ #ifdef FEAT_MBYTE
|
|
|
8b9a1c |
+ /*
|
|
|
8b9a1c |
+ * fname_casew(): Wide version of fname_case(). Set the case of the file name,
|
|
|
8b9a1c |
+ * if it already exists. When "len" is > 0, also expand short to long
|
|
|
8b9a1c |
+ * filenames.
|
|
|
8b9a1c |
+ * Return FAIL if wide functions are not available, OK otherwise.
|
|
|
8b9a1c |
+ * NOTE: much of this is identical to fname_case(), keep in sync!
|
|
|
8b9a1c |
+ */
|
|
|
8b9a1c |
+ static int
|
|
|
8b9a1c |
+ fname_casew(
|
|
|
8b9a1c |
+ WCHAR *name,
|
|
|
8b9a1c |
+ int len)
|
|
|
8b9a1c |
+ {
|
|
|
8b9a1c |
+ WCHAR szTrueName[_MAX_PATH + 2];
|
|
|
8b9a1c |
+ WCHAR szTrueNameTemp[_MAX_PATH + 2];
|
|
|
8b9a1c |
+ WCHAR *ptrue, *ptruePrev;
|
|
|
8b9a1c |
+ WCHAR *porig, *porigPrev;
|
|
|
8b9a1c |
+ int flen;
|
|
|
8b9a1c |
+ WIN32_FIND_DATAW fb;
|
|
|
8b9a1c |
+ HANDLE hFind;
|
|
|
8b9a1c |
+ int c;
|
|
|
8b9a1c |
+ int slen;
|
|
|
8b9a1c |
+
|
|
|
8b9a1c |
+ flen = (int)wcslen(name);
|
|
|
8b9a1c |
+ if (flen > _MAX_PATH)
|
|
|
8b9a1c |
+ return OK;
|
|
|
8b9a1c |
+
|
|
|
8b9a1c |
+ /* slash_adjust(name) not needed, already adjusted by fname_case(). */
|
|
|
8b9a1c |
+
|
|
|
8b9a1c |
+ /* Build the new name in szTrueName[] one component at a time. */
|
|
|
8b9a1c |
+ porig = name;
|
|
|
8b9a1c |
+ ptrue = szTrueName;
|
|
|
8b9a1c |
+
|
|
|
8b9a1c |
+ if (iswalpha(porig[0]) && porig[1] == L':')
|
|
|
8b9a1c |
+ {
|
|
|
8b9a1c |
+ /* copy leading drive letter */
|
|
|
8b9a1c |
+ *ptrue++ = *porig++;
|
|
|
8b9a1c |
+ *ptrue++ = *porig++;
|
|
|
8b9a1c |
+ *ptrue = NUL; /* in case nothing follows */
|
|
|
8b9a1c |
+ }
|
|
|
8b9a1c |
+
|
|
|
8b9a1c |
+ while (*porig != NUL)
|
|
|
8b9a1c |
+ {
|
|
|
8b9a1c |
+ /* copy \ characters */
|
|
|
8b9a1c |
+ while (*porig == psepc)
|
|
|
8b9a1c |
+ *ptrue++ = *porig++;
|
|
|
8b9a1c |
+
|
|
|
8b9a1c |
+ ptruePrev = ptrue;
|
|
|
8b9a1c |
+ porigPrev = porig;
|
|
|
8b9a1c |
+ while (*porig != NUL && *porig != psepc)
|
|
|
8b9a1c |
+ {
|
|
|
8b9a1c |
+ *ptrue++ = *porig++;
|
|
|
8b9a1c |
+ }
|
|
|
8b9a1c |
+ *ptrue = NUL;
|
|
|
8b9a1c |
+
|
|
|
8b9a1c |
+ /* To avoid a slow failure append "\*" when searching a directory,
|
|
|
8b9a1c |
+ * server or network share. */
|
|
|
8b9a1c |
+ wcscpy(szTrueNameTemp, szTrueName);
|
|
|
8b9a1c |
+ slen = (int)wcslen(szTrueNameTemp);
|
|
|
8b9a1c |
+ if (*porig == psepc && slen + 2 < _MAX_PATH)
|
|
|
8b9a1c |
+ wcscpy(szTrueNameTemp + slen, L"\\*");
|
|
|
8b9a1c |
+
|
|
|
8b9a1c |
+ /* Skip "", "." and "..". */
|
|
|
8b9a1c |
+ if (ptrue > ptruePrev
|
|
|
8b9a1c |
+ && (ptruePrev[0] != L'.'
|
|
|
8b9a1c |
+ || (ptruePrev[1] != NUL
|
|
|
8b9a1c |
+ && (ptruePrev[1] != L'.' || ptruePrev[2] != NUL)))
|
|
|
8b9a1c |
+ && (hFind = FindFirstFileW(szTrueNameTemp, &fb))
|
|
|
8b9a1c |
+ != INVALID_HANDLE_VALUE)
|
|
|
8b9a1c |
+ {
|
|
|
8b9a1c |
+ c = *porig;
|
|
|
8b9a1c |
+ *porig = NUL;
|
|
|
8b9a1c |
+
|
|
|
8b9a1c |
+ /* Only use the match when it's the same name (ignoring case) or
|
|
|
8b9a1c |
+ * expansion is allowed and there is a match with the short name
|
|
|
8b9a1c |
+ * and there is enough room. */
|
|
|
8b9a1c |
+ if (_wcsicoll(porigPrev, fb.cFileName) == 0
|
|
|
8b9a1c |
+ || (len > 0
|
|
|
8b9a1c |
+ && (_wcsicoll(porigPrev, fb.cAlternateFileName) == 0
|
|
|
8b9a1c |
+ && (int)(ptruePrev - szTrueName)
|
|
|
8b9a1c |
+ + (int)wcslen(fb.cFileName) < len)))
|
|
|
8b9a1c |
+ {
|
|
|
8b9a1c |
+ wcscpy(ptruePrev, fb.cFileName);
|
|
|
8b9a1c |
+
|
|
|
8b9a1c |
+ /* Look for exact match and prefer it if found. Must be a
|
|
|
8b9a1c |
+ * long name, otherwise there would be only one match. */
|
|
|
8b9a1c |
+ while (FindNextFileW(hFind, &fb))
|
|
|
8b9a1c |
+ {
|
|
|
8b9a1c |
+ if (*fb.cAlternateFileName != NUL
|
|
|
8b9a1c |
+ && (wcscoll(porigPrev, fb.cFileName) == 0
|
|
|
8b9a1c |
+ || (len > 0
|
|
|
8b9a1c |
+ && (_wcsicoll(porigPrev,
|
|
|
8b9a1c |
+ fb.cAlternateFileName) == 0
|
|
|
8b9a1c |
+ && (int)(ptruePrev - szTrueName)
|
|
|
8b9a1c |
+ + (int)wcslen(fb.cFileName) < len))))
|
|
|
8b9a1c |
+ {
|
|
|
8b9a1c |
+ wcscpy(ptruePrev, fb.cFileName);
|
|
|
8b9a1c |
+ break;
|
|
|
8b9a1c |
+ }
|
|
|
8b9a1c |
+ }
|
|
|
8b9a1c |
+ }
|
|
|
8b9a1c |
+ FindClose(hFind);
|
|
|
8b9a1c |
+ *porig = c;
|
|
|
8b9a1c |
+ ptrue = ptruePrev + wcslen(ptruePrev);
|
|
|
8b9a1c |
+ }
|
|
|
8b9a1c |
+ else if (hFind == INVALID_HANDLE_VALUE
|
|
|
8b9a1c |
+ && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
|
|
|
8b9a1c |
+ return FAIL;
|
|
|
8b9a1c |
+ }
|
|
|
8b9a1c |
+
|
|
|
8b9a1c |
+ wcscpy(name, szTrueName);
|
|
|
8b9a1c |
+ return OK;
|
|
|
8b9a1c |
+ }
|
|
|
8b9a1c |
+ #endif
|
|
|
8b9a1c |
+
|
|
|
8b9a1c |
/*
|
|
|
8b9a1c |
* fname_case(): Set the case of the file name, if it already exists.
|
|
|
8b9a1c |
* When "len" is > 0, also expand short to long filenames.
|
|
|
8b9a1c |
+ * NOTE: much of this is identical to fname_casew(), keep in sync!
|
|
|
8b9a1c |
*/
|
|
|
8b9a1c |
void
|
|
|
8b9a1c |
fname_case(
|
|
|
8b9a1c |
***************
|
|
|
8b9a1c |
*** 2520,2530 ****
|
|
|
8b9a1c |
int slen;
|
|
|
8b9a1c |
|
|
|
8b9a1c |
flen = (int)STRLEN(name);
|
|
|
8b9a1c |
! if (flen == 0 || flen > _MAX_PATH)
|
|
|
8b9a1c |
return;
|
|
|
8b9a1c |
|
|
|
8b9a1c |
slash_adjust(name);
|
|
|
8b9a1c |
|
|
|
8b9a1c |
/* Build the new name in szTrueName[] one component at a time. */
|
|
|
8b9a1c |
porig = name;
|
|
|
8b9a1c |
ptrue = szTrueName;
|
|
|
8b9a1c |
--- 2636,2679 ----
|
|
|
8b9a1c |
int slen;
|
|
|
8b9a1c |
|
|
|
8b9a1c |
flen = (int)STRLEN(name);
|
|
|
8b9a1c |
! if (flen == 0)
|
|
|
8b9a1c |
return;
|
|
|
8b9a1c |
|
|
|
8b9a1c |
slash_adjust(name);
|
|
|
8b9a1c |
|
|
|
8b9a1c |
+ #ifdef FEAT_MBYTE
|
|
|
8b9a1c |
+ if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
|
|
|
8b9a1c |
+ {
|
|
|
8b9a1c |
+ WCHAR *p = enc_to_utf16(name, NULL);
|
|
|
8b9a1c |
+
|
|
|
8b9a1c |
+ if (p != NULL)
|
|
|
8b9a1c |
+ {
|
|
|
8b9a1c |
+ char_u *q;
|
|
|
8b9a1c |
+ WCHAR buf[_MAX_PATH + 2];
|
|
|
8b9a1c |
+
|
|
|
8b9a1c |
+ wcscpy(buf, p);
|
|
|
8b9a1c |
+ vim_free(p);
|
|
|
8b9a1c |
+
|
|
|
8b9a1c |
+ if (fname_casew(buf, (len > 0) ? _MAX_PATH : 0) == OK)
|
|
|
8b9a1c |
+ {
|
|
|
8b9a1c |
+ q = utf16_to_enc(buf, NULL);
|
|
|
8b9a1c |
+ if (q != NULL)
|
|
|
8b9a1c |
+ {
|
|
|
8b9a1c |
+ vim_strncpy(name, q, (len > 0) ? len - 1 : flen);
|
|
|
8b9a1c |
+ vim_free(q);
|
|
|
8b9a1c |
+ return;
|
|
|
8b9a1c |
+ }
|
|
|
8b9a1c |
+ }
|
|
|
8b9a1c |
+ }
|
|
|
8b9a1c |
+ /* Retry with non-wide function (for Windows 98). */
|
|
|
8b9a1c |
+ }
|
|
|
8b9a1c |
+ #endif
|
|
|
8b9a1c |
+
|
|
|
8b9a1c |
+ /* If 'enc' is utf-8, flen can be larger than _MAX_PATH.
|
|
|
8b9a1c |
+ * So we should check this after calling wide function. */
|
|
|
8b9a1c |
+ if (flen > _MAX_PATH)
|
|
|
8b9a1c |
+ return;
|
|
|
8b9a1c |
+
|
|
|
8b9a1c |
/* Build the new name in szTrueName[] one component at a time. */
|
|
|
8b9a1c |
porig = name;
|
|
|
8b9a1c |
ptrue = szTrueName;
|
|
|
8b9a1c |
*** ../vim-7.4.015/src/version.c 2013-08-30 17:11:29.000000000 +0200
|
|
|
8b9a1c |
--- src/version.c 2013-08-30 17:15:06.000000000 +0200
|
|
|
8b9a1c |
***************
|
|
|
8b9a1c |
*** 740,741 ****
|
|
|
8b9a1c |
--- 740,743 ----
|
|
|
8b9a1c |
{ /* Add new patch number below this line */
|
|
|
8b9a1c |
+ /**/
|
|
|
8b9a1c |
+ 16,
|
|
|
8b9a1c |
/**/
|
|
|
8b9a1c |
|
|
|
8b9a1c |
--
|
|
|
8b9a1c |
Fingers not found - Pound head on keyboard to continue.
|
|
|
8b9a1c |
|
|
|
8b9a1c |
/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
|
|
|
8b9a1c |
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
|
|
|
8b9a1c |
\\\ an exciting new programming language -- http://www.Zimbu.org ///
|
|
|
8b9a1c |
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
|