forked from aniani/vim
updated for version 7.2-049
This commit is contained in:
@@ -992,7 +992,7 @@ _WndProc(
|
|||||||
SendMessage(lpdi->hdr.hwndFrom, TTM_SETMAXTIPWIDTH,
|
SendMessage(lpdi->hdr.hwndFrom, TTM_SETMAXTIPWIDTH,
|
||||||
0, 500);
|
0, 500);
|
||||||
|
|
||||||
tt_text = enc_to_ucs2(str, NULL);
|
tt_text = enc_to_utf16(str, NULL);
|
||||||
lpdi->lpszText = tt_text;
|
lpdi->lpszText = tt_text;
|
||||||
/* can't show tooltip if failed */
|
/* can't show tooltip if failed */
|
||||||
}
|
}
|
||||||
@@ -1935,7 +1935,7 @@ GetResultStr(HWND hwnd, int GCS, int *lenp)
|
|||||||
if (buf == NULL)
|
if (buf == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
convbuf = ucs2_to_enc(buf, lenp);
|
convbuf = utf16_to_enc(buf, lenp);
|
||||||
pImmReleaseContext(hwnd, hIMC);
|
pImmReleaseContext(hwnd, hIMC);
|
||||||
vim_free(buf);
|
vim_free(buf);
|
||||||
return convbuf;
|
return convbuf;
|
||||||
@@ -2566,7 +2566,7 @@ gui_mch_add_menu(
|
|||||||
{
|
{
|
||||||
/* 'encoding' differs from active codepage: convert menu name
|
/* 'encoding' differs from active codepage: convert menu name
|
||||||
* and use wide function */
|
* and use wide function */
|
||||||
wn = enc_to_ucs2(menu->name, NULL);
|
wn = enc_to_utf16(menu->name, NULL);
|
||||||
if (wn != NULL)
|
if (wn != NULL)
|
||||||
{
|
{
|
||||||
MENUITEMINFOW infow;
|
MENUITEMINFOW infow;
|
||||||
@@ -2728,7 +2728,7 @@ gui_mch_add_menu_item(
|
|||||||
{
|
{
|
||||||
/* 'encoding' differs from active codepage: convert menu item name
|
/* 'encoding' differs from active codepage: convert menu item name
|
||||||
* and use wide function */
|
* and use wide function */
|
||||||
wn = enc_to_ucs2(menu->name, NULL);
|
wn = enc_to_utf16(menu->name, NULL);
|
||||||
if (wn != NULL)
|
if (wn != NULL)
|
||||||
{
|
{
|
||||||
n = InsertMenuW(parent->submenu_id, (UINT)idx,
|
n = InsertMenuW(parent->submenu_id, (UINT)idx,
|
||||||
@@ -3570,7 +3570,7 @@ nCopyAnsiToWideChar(
|
|||||||
if (enc_codepage == 0 && (int)GetACP() != enc_codepage)
|
if (enc_codepage == 0 && (int)GetACP() != enc_codepage)
|
||||||
{
|
{
|
||||||
/* Not a codepage, use our own conversion function. */
|
/* Not a codepage, use our own conversion function. */
|
||||||
wn = enc_to_ucs2(lpAnsiIn, NULL);
|
wn = enc_to_utf16(lpAnsiIn, NULL);
|
||||||
if (wn != NULL)
|
if (wn != NULL)
|
||||||
{
|
{
|
||||||
wcscpy(lpWCStr, wn);
|
wcscpy(lpWCStr, wn);
|
||||||
|
@@ -547,7 +547,7 @@ char_to_string(int ch, char_u *string, int slen, int had_alt)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
len = 1;
|
len = 1;
|
||||||
ws = ucs2_to_enc(wstring, &len);
|
ws = utf16_to_enc(wstring, &len);
|
||||||
if (ws == NULL)
|
if (ws == NULL)
|
||||||
len = 0;
|
len = 0;
|
||||||
else
|
else
|
||||||
@@ -2128,7 +2128,7 @@ GetTextWidthEnc(HDC hdc, char_u *str, int len)
|
|||||||
{
|
{
|
||||||
/* 'encoding' differs from active codepage: convert text and use wide
|
/* 'encoding' differs from active codepage: convert text and use wide
|
||||||
* function */
|
* function */
|
||||||
wstr = enc_to_ucs2(str, &wlen);
|
wstr = enc_to_utf16(str, &wlen);
|
||||||
if (wstr != NULL)
|
if (wstr != NULL)
|
||||||
{
|
{
|
||||||
n = GetTextExtentPointW(hdc, wstr, wlen, &size);
|
n = GetTextExtentPointW(hdc, wstr, wlen, &size);
|
||||||
@@ -2252,7 +2252,7 @@ add_tabline_popup_menu_entry(HMENU pmenu, UINT item_id, char_u *item_text)
|
|||||||
{
|
{
|
||||||
/* 'encoding' differs from active codepage: convert menu name
|
/* 'encoding' differs from active codepage: convert menu name
|
||||||
* and use wide function */
|
* and use wide function */
|
||||||
wn = enc_to_ucs2(item_text, NULL);
|
wn = enc_to_utf16(item_text, NULL);
|
||||||
if (wn != NULL)
|
if (wn != NULL)
|
||||||
{
|
{
|
||||||
MENUITEMINFOW infow;
|
MENUITEMINFOW infow;
|
||||||
@@ -2422,7 +2422,7 @@ gui_mch_update_tabline(void)
|
|||||||
if (use_unicode)
|
if (use_unicode)
|
||||||
{
|
{
|
||||||
/* Need to go through Unicode. */
|
/* Need to go through Unicode. */
|
||||||
wstr = enc_to_ucs2(NameBuff, NULL);
|
wstr = enc_to_utf16(NameBuff, NULL);
|
||||||
if (wstr != NULL)
|
if (wstr != NULL)
|
||||||
{
|
{
|
||||||
TCITEMW tiw;
|
TCITEMW tiw;
|
||||||
@@ -2521,8 +2521,8 @@ set_window_title(HWND hwnd, char *title)
|
|||||||
WCHAR *wbuf;
|
WCHAR *wbuf;
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
/* Convert the title from 'encoding' to ucs2. */
|
/* Convert the title from 'encoding' to UTF-16. */
|
||||||
wbuf = (WCHAR *)enc_to_ucs2((char_u *)title, NULL);
|
wbuf = (WCHAR *)enc_to_utf16((char_u *)title, NULL);
|
||||||
if (wbuf != NULL)
|
if (wbuf != NULL)
|
||||||
{
|
{
|
||||||
n = SetWindowTextW(hwnd, wbuf);
|
n = SetWindowTextW(hwnd, wbuf);
|
||||||
@@ -3222,7 +3222,7 @@ gui_mch_browseW(
|
|||||||
char_u *initdir,
|
char_u *initdir,
|
||||||
char_u *filter)
|
char_u *filter)
|
||||||
{
|
{
|
||||||
/* We always use the wide function. This means enc_to_ucs2() must work,
|
/* We always use the wide function. This means enc_to_utf16() must work,
|
||||||
* otherwise it fails miserably! */
|
* otherwise it fails miserably! */
|
||||||
OPENFILENAMEW fileStruct;
|
OPENFILENAMEW fileStruct;
|
||||||
WCHAR fileBuf[MAXPATHL];
|
WCHAR fileBuf[MAXPATHL];
|
||||||
@@ -3238,7 +3238,7 @@ gui_mch_browseW(
|
|||||||
fileBuf[0] = NUL;
|
fileBuf[0] = NUL;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
wp = enc_to_ucs2(dflt, NULL);
|
wp = enc_to_utf16(dflt, NULL);
|
||||||
if (wp == NULL)
|
if (wp == NULL)
|
||||||
fileBuf[0] = NUL;
|
fileBuf[0] = NUL;
|
||||||
else
|
else
|
||||||
@@ -3263,11 +3263,11 @@ gui_mch_browseW(
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (title != NULL)
|
if (title != NULL)
|
||||||
titlep = enc_to_ucs2(title, NULL);
|
titlep = enc_to_utf16(title, NULL);
|
||||||
fileStruct.lpstrTitle = titlep;
|
fileStruct.lpstrTitle = titlep;
|
||||||
|
|
||||||
if (ext != NULL)
|
if (ext != NULL)
|
||||||
extp = enc_to_ucs2(ext, NULL);
|
extp = enc_to_utf16(ext, NULL);
|
||||||
fileStruct.lpstrDefExt = extp;
|
fileStruct.lpstrDefExt = extp;
|
||||||
|
|
||||||
fileStruct.lpstrFile = fileBuf;
|
fileStruct.lpstrFile = fileBuf;
|
||||||
@@ -3278,7 +3278,7 @@ gui_mch_browseW(
|
|||||||
if (initdir != NULL && *initdir != NUL)
|
if (initdir != NULL && *initdir != NUL)
|
||||||
{
|
{
|
||||||
/* Must have backslashes here, no matter what 'shellslash' says */
|
/* Must have backslashes here, no matter what 'shellslash' says */
|
||||||
initdirp = enc_to_ucs2(initdir, NULL);
|
initdirp = enc_to_utf16(initdir, NULL);
|
||||||
if (initdirp != NULL)
|
if (initdirp != NULL)
|
||||||
{
|
{
|
||||||
for (wp = initdirp; *wp != NUL; ++wp)
|
for (wp = initdirp; *wp != NUL; ++wp)
|
||||||
@@ -3318,7 +3318,7 @@ gui_mch_browseW(
|
|||||||
vim_free(extp);
|
vim_free(extp);
|
||||||
|
|
||||||
/* Convert from UCS2 to 'encoding'. */
|
/* Convert from UCS2 to 'encoding'. */
|
||||||
p = ucs2_to_enc(fileBuf, NULL);
|
p = utf16_to_enc(fileBuf, NULL);
|
||||||
if (p != NULL)
|
if (p != NULL)
|
||||||
/* when out of memory we get garbage for non-ASCII chars */
|
/* when out of memory we get garbage for non-ASCII chars */
|
||||||
STRCPY(fileBuf, p);
|
STRCPY(fileBuf, p);
|
||||||
@@ -3518,7 +3518,7 @@ _OnDropFiles(
|
|||||||
{
|
{
|
||||||
#ifdef FEAT_MBYTE
|
#ifdef FEAT_MBYTE
|
||||||
if (DragQueryFileW(hDrop, i, wszFile, BUFPATHLEN) > 0)
|
if (DragQueryFileW(hDrop, i, wszFile, BUFPATHLEN) > 0)
|
||||||
fnames[i] = ucs2_to_enc(wszFile, NULL);
|
fnames[i] = utf16_to_enc(wszFile, NULL);
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
@@ -6101,7 +6101,7 @@ string_convert_ext(vcp, ptr, lenp, unconvlenp)
|
|||||||
|
|
||||||
/* 1. codepage/UTF-8 -> ucs-2. */
|
/* 1. codepage/UTF-8 -> ucs-2. */
|
||||||
if (vcp->vc_cpfrom == 0)
|
if (vcp->vc_cpfrom == 0)
|
||||||
tmp_len = utf8_to_ucs2(ptr, len, NULL, NULL);
|
tmp_len = utf8_to_utf16(ptr, len, NULL, NULL);
|
||||||
else
|
else
|
||||||
tmp_len = MultiByteToWideChar(vcp->vc_cpfrom, 0,
|
tmp_len = MultiByteToWideChar(vcp->vc_cpfrom, 0,
|
||||||
ptr, len, 0, 0);
|
ptr, len, 0, 0);
|
||||||
@@ -6109,13 +6109,13 @@ string_convert_ext(vcp, ptr, lenp, unconvlenp)
|
|||||||
if (tmp == NULL)
|
if (tmp == NULL)
|
||||||
break;
|
break;
|
||||||
if (vcp->vc_cpfrom == 0)
|
if (vcp->vc_cpfrom == 0)
|
||||||
utf8_to_ucs2(ptr, len, tmp, unconvlenp);
|
utf8_to_utf16(ptr, len, tmp, unconvlenp);
|
||||||
else
|
else
|
||||||
MultiByteToWideChar(vcp->vc_cpfrom, 0, ptr, len, tmp, tmp_len);
|
MultiByteToWideChar(vcp->vc_cpfrom, 0, ptr, len, tmp, tmp_len);
|
||||||
|
|
||||||
/* 2. ucs-2 -> codepage/UTF-8. */
|
/* 2. ucs-2 -> codepage/UTF-8. */
|
||||||
if (vcp->vc_cpto == 0)
|
if (vcp->vc_cpto == 0)
|
||||||
retlen = ucs2_to_utf8(tmp, tmp_len, NULL);
|
retlen = utf16_to_utf8(tmp, tmp_len, NULL);
|
||||||
else
|
else
|
||||||
retlen = WideCharToMultiByte(vcp->vc_cpto, 0,
|
retlen = WideCharToMultiByte(vcp->vc_cpto, 0,
|
||||||
tmp, tmp_len, 0, 0, 0, 0);
|
tmp, tmp_len, 0, 0, 0, 0);
|
||||||
@@ -6123,7 +6123,7 @@ string_convert_ext(vcp, ptr, lenp, unconvlenp)
|
|||||||
if (retval != NULL)
|
if (retval != NULL)
|
||||||
{
|
{
|
||||||
if (vcp->vc_cpto == 0)
|
if (vcp->vc_cpto == 0)
|
||||||
ucs2_to_utf8(tmp, tmp_len, retval);
|
utf16_to_utf8(tmp, tmp_len, retval);
|
||||||
else
|
else
|
||||||
WideCharToMultiByte(vcp->vc_cpto, 0,
|
WideCharToMultiByte(vcp->vc_cpto, 0,
|
||||||
tmp, tmp_len, retval, retlen, 0, 0);
|
tmp, tmp_len, retval, retlen, 0, 0);
|
||||||
|
@@ -8728,7 +8728,7 @@ dos_expandpath(
|
|||||||
/* The active codepage differs from 'encoding'. Attempt using the
|
/* The active codepage differs from 'encoding'. Attempt using the
|
||||||
* wide function. If it fails because it is not implemented fall back
|
* wide function. If it fails because it is not implemented fall back
|
||||||
* to the non-wide version (for Windows 98) */
|
* to the non-wide version (for Windows 98) */
|
||||||
wn = enc_to_ucs2(buf, NULL);
|
wn = enc_to_utf16(buf, NULL);
|
||||||
if (wn != NULL)
|
if (wn != NULL)
|
||||||
{
|
{
|
||||||
hFind = FindFirstFileW(wn, &wfb);
|
hFind = FindFirstFileW(wn, &wfb);
|
||||||
@@ -8756,7 +8756,7 @@ dos_expandpath(
|
|||||||
#ifdef WIN3264
|
#ifdef WIN3264
|
||||||
# ifdef FEAT_MBYTE
|
# ifdef FEAT_MBYTE
|
||||||
if (wn != NULL)
|
if (wn != NULL)
|
||||||
p = ucs2_to_enc(wfb.cFileName, NULL); /* p is allocated here */
|
p = utf16_to_enc(wfb.cFileName, NULL); /* p is allocated here */
|
||||||
else
|
else
|
||||||
# endif
|
# endif
|
||||||
p = (char_u *)fb.cFileName;
|
p = (char_u *)fb.cFileName;
|
||||||
@@ -8830,7 +8830,7 @@ dos_expandpath(
|
|||||||
if (wn != NULL)
|
if (wn != NULL)
|
||||||
{
|
{
|
||||||
vim_free(wn);
|
vim_free(wn);
|
||||||
wn = enc_to_ucs2(buf, NULL);
|
wn = enc_to_utf16(buf, NULL);
|
||||||
if (wn != NULL)
|
if (wn != NULL)
|
||||||
hFind = FindFirstFileW(wn, &wfb);
|
hFind = FindFirstFileW(wn, &wfb);
|
||||||
}
|
}
|
||||||
|
@@ -309,7 +309,7 @@ mch_settitle(
|
|||||||
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
|
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
|
||||||
{
|
{
|
||||||
/* Convert the title from 'encoding' to the active codepage. */
|
/* Convert the title from 'encoding' to the active codepage. */
|
||||||
WCHAR *wp = enc_to_ucs2(title, NULL);
|
WCHAR *wp = enc_to_utf16(title, NULL);
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
if (wp != NULL)
|
if (wp != NULL)
|
||||||
@@ -406,10 +406,10 @@ mch_FullName(
|
|||||||
* - invoke _wfullpath()
|
* - invoke _wfullpath()
|
||||||
* - convert the result from UCS2 to 'encoding'.
|
* - convert the result from UCS2 to 'encoding'.
|
||||||
*/
|
*/
|
||||||
wname = enc_to_ucs2(fname, NULL);
|
wname = enc_to_utf16(fname, NULL);
|
||||||
if (wname != NULL && _wfullpath(wbuf, wname, MAX_PATH - 1) != NULL)
|
if (wname != NULL && _wfullpath(wbuf, wname, MAX_PATH - 1) != NULL)
|
||||||
{
|
{
|
||||||
cname = ucs2_to_enc((short_u *)wbuf, NULL);
|
cname = utf16_to_enc((short_u *)wbuf, NULL);
|
||||||
if (cname != NULL)
|
if (cname != NULL)
|
||||||
{
|
{
|
||||||
vim_strncpy(buf, cname, len - 1);
|
vim_strncpy(buf, cname, len - 1);
|
||||||
@@ -507,7 +507,7 @@ vim_stat(const char *name, struct stat *stp)
|
|||||||
# endif
|
# endif
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
WCHAR *wp = enc_to_ucs2(buf, NULL);
|
WCHAR *wp = enc_to_utf16(buf, NULL);
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
if (wp != NULL)
|
if (wp != NULL)
|
||||||
@@ -668,7 +668,7 @@ mch_chdir(char *path)
|
|||||||
#ifdef FEAT_MBYTE
|
#ifdef FEAT_MBYTE
|
||||||
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
|
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
|
||||||
{
|
{
|
||||||
WCHAR *p = enc_to_ucs2(path, NULL);
|
WCHAR *p = enc_to_utf16(path, NULL);
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
if (p != NULL)
|
if (p != NULL)
|
||||||
@@ -891,19 +891,20 @@ mch_libcall(
|
|||||||
|
|
||||||
#if defined(FEAT_MBYTE) || defined(PROTO)
|
#if defined(FEAT_MBYTE) || defined(PROTO)
|
||||||
/*
|
/*
|
||||||
* Convert an UTF-8 string to UCS-2.
|
* Convert an UTF-8 string to UTF-16.
|
||||||
* "instr[inlen]" is the input. "inlen" is in bytes.
|
* "instr[inlen]" is the input. "inlen" is in bytes.
|
||||||
* When "outstr" is NULL only return the number of UCS-2 words produced.
|
* When "outstr" is NULL only return the number of UTF-16 words produced.
|
||||||
* Otherwise "outstr" must be a buffer of sufficient size.
|
* Otherwise "outstr" must be a buffer of sufficient size.
|
||||||
* Returns the number of UCS-2 words produced.
|
* Returns the number of UTF-16 words produced.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
utf8_to_ucs2(char_u *instr, int inlen, short_u *outstr, int *unconvlenp)
|
utf8_to_utf16(char_u *instr, int inlen, short_u *outstr, int *unconvlenp)
|
||||||
{
|
{
|
||||||
int outlen = 0;
|
int outlen = 0;
|
||||||
char_u *p = instr;
|
char_u *p = instr;
|
||||||
int todo = inlen;
|
int todo = inlen;
|
||||||
int l;
|
int l;
|
||||||
|
int ch;
|
||||||
|
|
||||||
while (todo > 0)
|
while (todo > 0)
|
||||||
{
|
{
|
||||||
@@ -917,8 +918,19 @@ utf8_to_ucs2(char_u *instr, int inlen, short_u *outstr, int *unconvlenp)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (outstr != NULL)
|
ch = utf_ptr2char(p);
|
||||||
*outstr++ = utf_ptr2char(p);
|
if (ch >= 0x10000)
|
||||||
|
{
|
||||||
|
/* non-BMP character, encoding with surrogate pairs */
|
||||||
|
++outlen;
|
||||||
|
if (outstr != NULL)
|
||||||
|
{
|
||||||
|
*outstr++ = (0xD800 - (0x10000 >> 10)) + (ch >> 10);
|
||||||
|
*outstr++ = 0xDC00 | (ch & 0x3FF);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (outstr != NULL)
|
||||||
|
*outstr++ = ch;
|
||||||
++outlen;
|
++outlen;
|
||||||
p += l;
|
p += l;
|
||||||
todo -= l;
|
todo -= l;
|
||||||
@@ -928,29 +940,42 @@ utf8_to_ucs2(char_u *instr, int inlen, short_u *outstr, int *unconvlenp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Convert an UCS-2 string to UTF-8.
|
* Convert an UTF-16 string to UTF-8.
|
||||||
* The input is "instr[inlen]" with "inlen" in number of ucs-2 words.
|
* The input is "instr[inlen]" with "inlen" in number of UTF-16 words.
|
||||||
* When "outstr" is NULL only return the required number of bytes.
|
* When "outstr" is NULL only return the required number of bytes.
|
||||||
* Otherwise "outstr" must be a buffer of sufficient size.
|
* Otherwise "outstr" must be a buffer of sufficient size.
|
||||||
* Return the number of bytes produced.
|
* Return the number of bytes produced.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
ucs2_to_utf8(short_u *instr, int inlen, char_u *outstr)
|
utf16_to_utf8(short_u *instr, int inlen, char_u *outstr)
|
||||||
{
|
{
|
||||||
int outlen = 0;
|
int outlen = 0;
|
||||||
int todo = inlen;
|
int todo = inlen;
|
||||||
short_u *p = instr;
|
short_u *p = instr;
|
||||||
int l;
|
int l;
|
||||||
|
int ch, ch2;
|
||||||
|
|
||||||
while (todo > 0)
|
while (todo > 0)
|
||||||
{
|
{
|
||||||
|
ch = *p;
|
||||||
|
if (ch >= 0xD800 && ch <= 0xDBFF && todo > 1)
|
||||||
|
{
|
||||||
|
/* surrogate pairs handling */
|
||||||
|
ch2 = p[1];
|
||||||
|
if (ch2 >= 0xDC00 && ch2 <= 0xDFFF)
|
||||||
|
{
|
||||||
|
ch = ((ch - 0xD800) << 10) + (ch2 & 0x3FF) + 0x10000;
|
||||||
|
++p;
|
||||||
|
--todo;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (outstr != NULL)
|
if (outstr != NULL)
|
||||||
{
|
{
|
||||||
l = utf_char2bytes(*p, outstr);
|
l = utf_char2bytes(ch, outstr);
|
||||||
outstr += l;
|
outstr += l;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
l = utf_char2len(*p);
|
l = utf_char2len(ch);
|
||||||
++p;
|
++p;
|
||||||
outlen += l;
|
outlen += l;
|
||||||
--todo;
|
--todo;
|
||||||
@@ -1079,14 +1104,14 @@ crnl_to_nl(const char_u *str, int *size)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Convert "str" from 'encoding' to UCS-2.
|
* Convert "str" from 'encoding' to UTF-16.
|
||||||
* Input in "str" with length "*lenp". When "lenp" is NULL, use strlen().
|
* Input in "str" with length "*lenp". When "lenp" is NULL, use strlen().
|
||||||
* Output is returned as an allocated string. "*lenp" is set to the length of
|
* Output is returned as an allocated string. "*lenp" is set to the length of
|
||||||
* the result. A trailing NUL is always added.
|
* the result. A trailing NUL is always added.
|
||||||
* Returns NULL when out of memory.
|
* Returns NULL when out of memory.
|
||||||
*/
|
*/
|
||||||
short_u *
|
short_u *
|
||||||
enc_to_ucs2(char_u *str, int *lenp)
|
enc_to_utf16(char_u *str, int *lenp)
|
||||||
{
|
{
|
||||||
vimconv_T conv;
|
vimconv_T conv;
|
||||||
WCHAR *ret;
|
WCHAR *ret;
|
||||||
@@ -1102,7 +1127,7 @@ enc_to_ucs2(char_u *str, int *lenp)
|
|||||||
|
|
||||||
if (enc_codepage > 0)
|
if (enc_codepage > 0)
|
||||||
{
|
{
|
||||||
/* We can do any CP### -> UCS-2 in one pass, and we can do it
|
/* We can do any CP### -> UTF-16 in one pass, and we can do it
|
||||||
* without iconv() (convert_* may need iconv). */
|
* without iconv() (convert_* may need iconv). */
|
||||||
MultiByteToWideChar_alloc(enc_codepage, 0, str, *lenp, &ret, &length);
|
MultiByteToWideChar_alloc(enc_codepage, 0, str, *lenp, &ret, &length);
|
||||||
}
|
}
|
||||||
@@ -1123,11 +1148,11 @@ enc_to_ucs2(char_u *str, int *lenp)
|
|||||||
}
|
}
|
||||||
convert_setup(&conv, NULL, NULL);
|
convert_setup(&conv, NULL, NULL);
|
||||||
|
|
||||||
length = utf8_to_ucs2(str, *lenp, NULL, NULL);
|
length = utf8_to_utf16(str, *lenp, NULL, NULL);
|
||||||
ret = (WCHAR *)alloc((unsigned)((length + 1) * sizeof(WCHAR)));
|
ret = (WCHAR *)alloc((unsigned)((length + 1) * sizeof(WCHAR)));
|
||||||
if (ret != NULL)
|
if (ret != NULL)
|
||||||
{
|
{
|
||||||
utf8_to_ucs2(str, *lenp, (short_u *)ret, NULL);
|
utf8_to_utf16(str, *lenp, (short_u *)ret, NULL);
|
||||||
ret[length] = 0;
|
ret[length] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1139,7 +1164,7 @@ enc_to_ucs2(char_u *str, int *lenp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Convert an UCS-2 string to 'encoding'.
|
* Convert an UTF-16 string to 'encoding'.
|
||||||
* Input in "str" with length (counted in wide characters) "*lenp". When
|
* Input in "str" with length (counted in wide characters) "*lenp". When
|
||||||
* "lenp" is NULL, use wcslen().
|
* "lenp" is NULL, use wcslen().
|
||||||
* Output is returned as an allocated string. If "*lenp" is not NULL it is
|
* Output is returned as an allocated string. If "*lenp" is not NULL it is
|
||||||
@@ -1147,7 +1172,7 @@ enc_to_ucs2(char_u *str, int *lenp)
|
|||||||
* Returns NULL when out of memory.
|
* Returns NULL when out of memory.
|
||||||
*/
|
*/
|
||||||
char_u *
|
char_u *
|
||||||
ucs2_to_enc(short_u *str, int *lenp)
|
utf16_to_enc(short_u *str, int *lenp)
|
||||||
{
|
{
|
||||||
vimconv_T conv;
|
vimconv_T conv;
|
||||||
char_u *utf8_str = NULL, *enc_str = NULL;
|
char_u *utf8_str = NULL, *enc_str = NULL;
|
||||||
@@ -1161,7 +1186,7 @@ ucs2_to_enc(short_u *str, int *lenp)
|
|||||||
|
|
||||||
if (enc_codepage > 0)
|
if (enc_codepage > 0)
|
||||||
{
|
{
|
||||||
/* We can do any UCS-2 -> CP### in one pass. */
|
/* We can do any UTF-16 -> CP### in one pass. */
|
||||||
int length;
|
int length;
|
||||||
|
|
||||||
WideCharToMultiByte_alloc(enc_codepage, 0, str, *lenp,
|
WideCharToMultiByte_alloc(enc_codepage, 0, str, *lenp,
|
||||||
@@ -1171,10 +1196,10 @@ ucs2_to_enc(short_u *str, int *lenp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Avoid allocating zero bytes, it generates an error message. */
|
/* Avoid allocating zero bytes, it generates an error message. */
|
||||||
utf8_str = alloc(ucs2_to_utf8(str, *lenp == 0 ? 1 : *lenp, NULL));
|
utf8_str = alloc(utf16_to_utf8(str, *lenp == 0 ? 1 : *lenp, NULL));
|
||||||
if (utf8_str != NULL)
|
if (utf8_str != NULL)
|
||||||
{
|
{
|
||||||
*lenp = ucs2_to_utf8(str, *lenp, utf8_str);
|
*lenp = utf16_to_utf8(str, *lenp, utf8_str);
|
||||||
|
|
||||||
/* We might be called before we have p_enc set up. */
|
/* We might be called before we have p_enc set up. */
|
||||||
conv.vc_type = CONV_NONE;
|
conv.vc_type = CONV_NONE;
|
||||||
@@ -1308,7 +1333,7 @@ clip_mch_request_selection(VimClipboard *cbd)
|
|||||||
if (hMemWstr[str_size] == NUL)
|
if (hMemWstr[str_size] == NUL)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
to_free = str = ucs2_to_enc((short_u *)hMemWstr, &str_size);
|
to_free = str = utf16_to_enc((short_u *)hMemWstr, &str_size);
|
||||||
GlobalUnlock(hMemW);
|
GlobalUnlock(hMemW);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1340,7 +1365,7 @@ clip_mch_request_selection(VimClipboard *cbd)
|
|||||||
|
|
||||||
# if defined(FEAT_MBYTE) && defined(WIN3264)
|
# if defined(FEAT_MBYTE) && defined(WIN3264)
|
||||||
/* The text is in the active codepage. Convert to 'encoding',
|
/* The text is in the active codepage. Convert to 'encoding',
|
||||||
* going through UCS-2. */
|
* going through UTF-16. */
|
||||||
acp_to_enc(str, str_size, &to_free, &maxlen);
|
acp_to_enc(str, str_size, &to_free, &maxlen);
|
||||||
if (to_free != NULL)
|
if (to_free != NULL)
|
||||||
{
|
{
|
||||||
@@ -1404,7 +1429,7 @@ acp_to_enc(str, str_size, out, outlen)
|
|||||||
if (widestr != NULL)
|
if (widestr != NULL)
|
||||||
{
|
{
|
||||||
++*outlen; /* Include the 0 after the string */
|
++*outlen; /* Include the 0 after the string */
|
||||||
*out = ucs2_to_enc((short_u *)widestr, outlen);
|
*out = utf16_to_enc((short_u *)widestr, outlen);
|
||||||
vim_free(widestr);
|
vim_free(widestr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1466,9 +1491,9 @@ clip_mch_set_selection(VimClipboard *cbd)
|
|||||||
WCHAR *out;
|
WCHAR *out;
|
||||||
int len = metadata.txtlen;
|
int len = metadata.txtlen;
|
||||||
|
|
||||||
/* Convert the text to UCS-2. This is put on the clipboard as
|
/* Convert the text to UTF-16. This is put on the clipboard as
|
||||||
* CF_UNICODETEXT. */
|
* CF_UNICODETEXT. */
|
||||||
out = (WCHAR *)enc_to_ucs2(str, &len);
|
out = (WCHAR *)enc_to_utf16(str, &len);
|
||||||
if (out != NULL)
|
if (out != NULL)
|
||||||
{
|
{
|
||||||
WCHAR *lpszMemW;
|
WCHAR *lpszMemW;
|
||||||
@@ -1488,7 +1513,7 @@ clip_mch_set_selection(VimClipboard *cbd)
|
|||||||
WideCharToMultiByte(GetACP(), 0, out, len,
|
WideCharToMultiByte(GetACP(), 0, out, len,
|
||||||
str, metadata.txtlen, 0, 0);
|
str, metadata.txtlen, 0, 0);
|
||||||
|
|
||||||
/* Allocate memory for the UCS-2 text, add one NUL word to
|
/* Allocate memory for the UTF-16 text, add one NUL word to
|
||||||
* terminate the string. */
|
* terminate the string. */
|
||||||
hMemW = (LPSTR)GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE,
|
hMemW = (LPSTR)GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE,
|
||||||
(len + 1) * sizeof(WCHAR));
|
(len + 1) * sizeof(WCHAR));
|
||||||
|
@@ -1587,7 +1587,7 @@ executable_exists(char *name)
|
|||||||
#ifdef FEAT_MBYTE
|
#ifdef FEAT_MBYTE
|
||||||
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
|
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
|
||||||
{
|
{
|
||||||
WCHAR *p = enc_to_ucs2(name, NULL);
|
WCHAR *p = enc_to_utf16(name, NULL);
|
||||||
WCHAR fnamew[_MAX_PATH];
|
WCHAR fnamew[_MAX_PATH];
|
||||||
WCHAR *dumw;
|
WCHAR *dumw;
|
||||||
long n;
|
long n;
|
||||||
@@ -2440,7 +2440,7 @@ mch_dirname(
|
|||||||
|
|
||||||
if (GetCurrentDirectoryW(_MAX_PATH, wbuf) != 0)
|
if (GetCurrentDirectoryW(_MAX_PATH, wbuf) != 0)
|
||||||
{
|
{
|
||||||
char_u *p = ucs2_to_enc(wbuf, NULL);
|
char_u *p = utf16_to_enc(wbuf, NULL);
|
||||||
|
|
||||||
if (p != NULL)
|
if (p != NULL)
|
||||||
{
|
{
|
||||||
@@ -2466,7 +2466,7 @@ mch_getperm(char_u *name)
|
|||||||
#ifdef FEAT_MBYTE
|
#ifdef FEAT_MBYTE
|
||||||
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
|
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
|
||||||
{
|
{
|
||||||
WCHAR *p = enc_to_ucs2(name, NULL);
|
WCHAR *p = enc_to_utf16(name, NULL);
|
||||||
long n;
|
long n;
|
||||||
|
|
||||||
if (p != NULL)
|
if (p != NULL)
|
||||||
@@ -2495,7 +2495,7 @@ mch_setperm(
|
|||||||
#ifdef FEAT_MBYTE
|
#ifdef FEAT_MBYTE
|
||||||
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
|
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
|
||||||
{
|
{
|
||||||
WCHAR *p = enc_to_ucs2(name, NULL);
|
WCHAR *p = enc_to_utf16(name, NULL);
|
||||||
long n;
|
long n;
|
||||||
|
|
||||||
if (p != NULL)
|
if (p != NULL)
|
||||||
@@ -2522,7 +2522,7 @@ mch_hide(char_u *name)
|
|||||||
WCHAR *p = NULL;
|
WCHAR *p = NULL;
|
||||||
|
|
||||||
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
|
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
|
||||||
p = enc_to_ucs2(name, NULL);
|
p = enc_to_utf16(name, NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef FEAT_MBYTE
|
#ifdef FEAT_MBYTE
|
||||||
@@ -2590,7 +2590,7 @@ mch_is_linked(char_u *fname)
|
|||||||
WCHAR *wn = NULL;
|
WCHAR *wn = NULL;
|
||||||
|
|
||||||
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
|
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
|
||||||
wn = enc_to_ucs2(fname, NULL);
|
wn = enc_to_utf16(fname, NULL);
|
||||||
if (wn != NULL)
|
if (wn != NULL)
|
||||||
{
|
{
|
||||||
hFile = CreateFileW(wn, /* file name */
|
hFile = CreateFileW(wn, /* file name */
|
||||||
@@ -4239,7 +4239,7 @@ mch_remove(char_u *name)
|
|||||||
|
|
||||||
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
|
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
|
||||||
{
|
{
|
||||||
wn = enc_to_ucs2(name, NULL);
|
wn = enc_to_utf16(name, NULL);
|
||||||
if (wn != NULL)
|
if (wn != NULL)
|
||||||
{
|
{
|
||||||
SetFileAttributesW(wn, FILE_ATTRIBUTE_NORMAL);
|
SetFileAttributesW(wn, FILE_ATTRIBUTE_NORMAL);
|
||||||
@@ -4382,8 +4382,8 @@ mch_rename(
|
|||||||
|
|
||||||
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
|
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
|
||||||
{
|
{
|
||||||
wold = enc_to_ucs2((char_u *)pszOldFile, NULL);
|
wold = enc_to_utf16((char_u *)pszOldFile, NULL);
|
||||||
wnew = enc_to_ucs2((char_u *)pszNewFile, NULL);
|
wnew = enc_to_utf16((char_u *)pszNewFile, NULL);
|
||||||
if (wold != NULL && wnew != NULL)
|
if (wold != NULL && wnew != NULL)
|
||||||
retval = mch_wrename(wold, wnew);
|
retval = mch_wrename(wold, wnew);
|
||||||
vim_free(wold);
|
vim_free(wold);
|
||||||
@@ -4492,7 +4492,7 @@ mch_access(char *n, int p)
|
|||||||
WCHAR *wn = NULL;
|
WCHAR *wn = NULL;
|
||||||
|
|
||||||
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
|
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
|
||||||
wn = enc_to_ucs2(n, NULL);
|
wn = enc_to_utf16(n, NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (mch_isdir(n))
|
if (mch_isdir(n))
|
||||||
@@ -4618,7 +4618,7 @@ getout:
|
|||||||
|
|
||||||
#if defined(FEAT_MBYTE) || defined(PROTO)
|
#if defined(FEAT_MBYTE) || defined(PROTO)
|
||||||
/*
|
/*
|
||||||
* Version of open() that may use ucs2 file name.
|
* Version of open() that may use UTF-16 file name.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
mch_open(char *name, int flags, int mode)
|
mch_open(char *name, int flags, int mode)
|
||||||
@@ -4630,7 +4630,7 @@ mch_open(char *name, int flags, int mode)
|
|||||||
|
|
||||||
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
|
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
|
||||||
{
|
{
|
||||||
wn = enc_to_ucs2(name, NULL);
|
wn = enc_to_utf16(name, NULL);
|
||||||
if (wn != NULL)
|
if (wn != NULL)
|
||||||
{
|
{
|
||||||
f = _wopen(wn, flags, mode);
|
f = _wopen(wn, flags, mode);
|
||||||
@@ -4648,7 +4648,7 @@ mch_open(char *name, int flags, int mode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Version of fopen() that may use ucs2 file name.
|
* Version of fopen() that may use UTF-16 file name.
|
||||||
*/
|
*/
|
||||||
FILE *
|
FILE *
|
||||||
mch_fopen(char *name, char *mode)
|
mch_fopen(char *name, char *mode)
|
||||||
@@ -4675,8 +4675,8 @@ mch_fopen(char *name, char *mode)
|
|||||||
else if (newMode == 'b')
|
else if (newMode == 'b')
|
||||||
_set_fmode(_O_BINARY);
|
_set_fmode(_O_BINARY);
|
||||||
# endif
|
# endif
|
||||||
wn = enc_to_ucs2(name, NULL);
|
wn = enc_to_utf16(name, NULL);
|
||||||
wm = enc_to_ucs2(mode, NULL);
|
wm = enc_to_utf16(mode, NULL);
|
||||||
if (wn != NULL && wm != NULL)
|
if (wn != NULL && wm != NULL)
|
||||||
f = _wfopen(wn, wm);
|
f = _wfopen(wn, wm);
|
||||||
vim_free(wn);
|
vim_free(wn);
|
||||||
@@ -4776,8 +4776,8 @@ copy_infostreams(char_u *from, char_u *to)
|
|||||||
int len;
|
int len;
|
||||||
|
|
||||||
/* Convert the file names to wide characters. */
|
/* Convert the file names to wide characters. */
|
||||||
fromw = enc_to_ucs2(from, NULL);
|
fromw = enc_to_utf16(from, NULL);
|
||||||
tow = enc_to_ucs2(to, NULL);
|
tow = enc_to_utf16(to, NULL);
|
||||||
if (fromw != NULL && tow != NULL)
|
if (fromw != NULL && tow != NULL)
|
||||||
{
|
{
|
||||||
/* Open the file for reading. */
|
/* Open the file for reading. */
|
||||||
@@ -5122,7 +5122,7 @@ fix_arg_enc(void)
|
|||||||
for (i = 0; i < used_file_count; ++i)
|
for (i = 0; i < used_file_count; ++i)
|
||||||
{
|
{
|
||||||
idx = used_file_indexes[i];
|
idx = used_file_indexes[i];
|
||||||
str = ucs2_to_enc(ArglistW[idx], NULL);
|
str = utf16_to_enc(ArglistW[idx], NULL);
|
||||||
if (str != NULL)
|
if (str != NULL)
|
||||||
{
|
{
|
||||||
#ifdef FEAT_DIFF
|
#ifdef FEAT_DIFF
|
||||||
|
@@ -22,14 +22,14 @@ int mch_chdir __ARGS((char *path));
|
|||||||
int can_end_termcap_mode __ARGS((int give_msg));
|
int can_end_termcap_mode __ARGS((int give_msg));
|
||||||
int mch_screenmode __ARGS((char_u *arg));
|
int mch_screenmode __ARGS((char_u *arg));
|
||||||
int mch_libcall __ARGS((char_u *libname, char_u *funcname, char_u *argstring, int argint, char_u **string_result, int *number_result));
|
int mch_libcall __ARGS((char_u *libname, char_u *funcname, char_u *argstring, int argint, char_u **string_result, int *number_result));
|
||||||
int utf8_to_ucs2 __ARGS((char_u *instr, int inlen, short_u *outstr, int *unconvlenp));
|
int utf8_to_utf16 __ARGS((char_u *instr, int inlen, short_u *outstr, int *unconvlenp));
|
||||||
int ucs2_to_utf8 __ARGS((short_u *instr, int inlen, char_u *outstr));
|
int utf16_to_utf8 __ARGS((short_u *instr, int inlen, char_u *outstr));
|
||||||
void MultiByteToWideChar_alloc __ARGS((UINT cp, DWORD flags, LPCSTR in, int inlen, LPWSTR *out, int *outlen));
|
void MultiByteToWideChar_alloc __ARGS((UINT cp, DWORD flags, LPCSTR in, int inlen, LPWSTR *out, int *outlen));
|
||||||
void WideCharToMultiByte_alloc __ARGS((UINT cp, DWORD flags, LPCWSTR in, int inlen, LPSTR *out, int *outlen, LPCSTR def, LPBOOL useddef));
|
void WideCharToMultiByte_alloc __ARGS((UINT cp, DWORD flags, LPCWSTR in, int inlen, LPSTR *out, int *outlen, LPCSTR def, LPBOOL useddef));
|
||||||
int clip_mch_own_selection __ARGS((VimClipboard *cbd));
|
int clip_mch_own_selection __ARGS((VimClipboard *cbd));
|
||||||
void clip_mch_lose_selection __ARGS((VimClipboard *cbd));
|
void clip_mch_lose_selection __ARGS((VimClipboard *cbd));
|
||||||
short_u *enc_to_ucs2 __ARGS((char_u *str, int *lenp));
|
short_u *enc_to_utf16 __ARGS((char_u *str, int *lenp));
|
||||||
char_u *ucs2_to_enc __ARGS((short_u *str, int *lenp));
|
char_u *utf16_to_enc __ARGS((short_u *str, int *lenp));
|
||||||
void clip_mch_request_selection __ARGS((VimClipboard *cbd));
|
void clip_mch_request_selection __ARGS((VimClipboard *cbd));
|
||||||
void acp_to_enc __ARGS((char_u *str, int str_size, char_u **out, int *outlen));
|
void acp_to_enc __ARGS((char_u *str, int str_size, char_u **out, int *outlen));
|
||||||
void clip_mch_set_selection __ARGS((VimClipboard *cbd));
|
void clip_mch_set_selection __ARGS((VimClipboard *cbd));
|
||||||
|
@@ -676,6 +676,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
49,
|
||||||
/**/
|
/**/
|
||||||
48,
|
48,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user