mirror of
https://github.com/neovim/neovim.git
synced 2025-09-15 07:48:18 +00:00
@@ -4030,8 +4030,8 @@ void fname_expand(buf_T *buf, char_u **ffname, char_u **sfname)
|
|||||||
if (!buf->b_p_bin) {
|
if (!buf->b_p_bin) {
|
||||||
char_u *rfname;
|
char_u *rfname;
|
||||||
|
|
||||||
/* If the file name is a shortcut file, use the file it links to. */
|
// If the file name is a shortcut file, use the file it links to.
|
||||||
rfname = mch_resolve_shortcut(*ffname);
|
rfname = os_resolve_shortcut(*ffname);
|
||||||
if (rfname != NULL) {
|
if (rfname != NULL) {
|
||||||
xfree(*ffname);
|
xfree(*ffname);
|
||||||
*ffname = rfname;
|
*ffname = rfname;
|
||||||
|
@@ -13637,12 +13637,13 @@ static void f_resolve(typval_T *argvars, typval_T *rettv)
|
|||||||
{
|
{
|
||||||
char_u *v = NULL;
|
char_u *v = NULL;
|
||||||
|
|
||||||
v = mch_resolve_shortcut(p);
|
v = os_resolve_shortcut(p);
|
||||||
if (v != NULL)
|
if (v != NULL) {
|
||||||
rettv->vval.v_string = v;
|
rettv->vval.v_string = v;
|
||||||
else
|
} else {
|
||||||
rettv->vval.v_string = vim_strsave(p);
|
rettv->vval.v_string = vim_strsave(p);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
# ifdef HAVE_READLINK
|
# ifdef HAVE_READLINK
|
||||||
{
|
{
|
||||||
|
@@ -1885,6 +1885,86 @@ static int utf_strnicmp(char_u *s1, char_u *s2, size_t n1, size_t n2)
|
|||||||
return n1 == 0 ? -1 : 1;
|
return n1 == 0 ? -1 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#ifndef CP_UTF8
|
||||||
|
# define CP_UTF8 65001 /* magic number from winnls.h */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int utf8_to_utf16(const char *str, WCHAR **strw)
|
||||||
|
FUNC_ATTR_NONNULL_ALL
|
||||||
|
{
|
||||||
|
ssize_t wchar_len = 0;
|
||||||
|
|
||||||
|
// Compute the length needed to store the converted widechar string.
|
||||||
|
wchar_len = MultiByteToWideChar(CP_UTF8,
|
||||||
|
0, // dwFlags: must be 0 for utf8
|
||||||
|
str, // lpMultiByteStr: string to convert
|
||||||
|
-1, // -1 => process up to NUL
|
||||||
|
NULL, // lpWideCharStr: converted string
|
||||||
|
0); // 0 => return length, don't convert
|
||||||
|
if (wchar_len == 0) {
|
||||||
|
return GetLastError();
|
||||||
|
}
|
||||||
|
|
||||||
|
ssize_t buf_sz = wchar_len * sizeof(WCHAR);
|
||||||
|
|
||||||
|
if (buf_sz == 0) {
|
||||||
|
*strw = NULL;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *buf = xmalloc(buf_sz);
|
||||||
|
char *pos = buf;
|
||||||
|
|
||||||
|
int r = MultiByteToWideChar(CP_UTF8,
|
||||||
|
0,
|
||||||
|
str,
|
||||||
|
-1,
|
||||||
|
(WCHAR *)pos,
|
||||||
|
wchar_len);
|
||||||
|
assert(r == wchar_len);
|
||||||
|
*strw = (WCHAR *)pos;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int utf16_to_utf8(const WCHAR *strw, char **str)
|
||||||
|
FUNC_ATTR_NONNULL_ALL
|
||||||
|
{
|
||||||
|
// Compute the space required to store the string as UTF-8.
|
||||||
|
ssize_t utf8_len = WideCharToMultiByte(CP_UTF8,
|
||||||
|
0,
|
||||||
|
strw,
|
||||||
|
-1,
|
||||||
|
NULL,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL);
|
||||||
|
if (utf8_len == 0) {
|
||||||
|
return GetLastError();
|
||||||
|
}
|
||||||
|
|
||||||
|
ssize_t buf_sz = utf8_len * sizeof(char);
|
||||||
|
char *buf = xmalloc(buf_sz);
|
||||||
|
char *pos = buf;
|
||||||
|
|
||||||
|
// Convert string to UTF-8.
|
||||||
|
int r = WideCharToMultiByte(CP_UTF8,
|
||||||
|
0,
|
||||||
|
strw,
|
||||||
|
-1,
|
||||||
|
(LPSTR *)pos,
|
||||||
|
utf8_len,
|
||||||
|
NULL,
|
||||||
|
NULL);
|
||||||
|
assert(r == utf8_len);
|
||||||
|
*str = pos;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Version of strnicmp() that handles multi-byte characters.
|
* Version of strnicmp() that handles multi-byte characters.
|
||||||
* Needed for Big5, Shift-JIS and UTF-8 encoding. Other DBCS encodings can
|
* Needed for Big5, Shift-JIS and UTF-8 encoding. Other DBCS encodings can
|
||||||
|
@@ -25,6 +25,10 @@
|
|||||||
#include "nvim/path.h"
|
#include "nvim/path.h"
|
||||||
#include "nvim/strings.h"
|
#include "nvim/strings.h"
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#include "nvim/mbyte.h" // for utf8_to_utf16, utf16_to_utf8
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||||
# include "os/fs.c.generated.h"
|
# include "os/fs.c.generated.h"
|
||||||
#endif
|
#endif
|
||||||
@@ -929,3 +933,93 @@ bool os_fileid_equal_fileinfo(const FileID *file_id,
|
|||||||
&& file_id->device_id == file_info->stat.st_dev;
|
&& file_id->device_id == file_info->stat.st_dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
# include <shlobj.h>
|
||||||
|
|
||||||
|
/// When "fname" is the name of a shortcut (*.lnk) resolve the file it points
|
||||||
|
/// to and return that name in allocated memory.
|
||||||
|
/// Otherwise NULL is returned.
|
||||||
|
char_u * os_resolve_shortcut(char_u *fname)
|
||||||
|
{
|
||||||
|
HRESULT hr;
|
||||||
|
IPersistFile *ppf = NULL;
|
||||||
|
OLECHAR wsz[MAX_PATH];
|
||||||
|
char_u *rfname = NULL;
|
||||||
|
int len;
|
||||||
|
int conversion_result;
|
||||||
|
IShellLinkW *pslw = NULL;
|
||||||
|
WIN32_FIND_DATAW ffdw;
|
||||||
|
|
||||||
|
// Check if the file name ends in ".lnk". Avoid calling CoCreateInstance(),
|
||||||
|
// it's quite slow.
|
||||||
|
if (fname == NULL) {
|
||||||
|
return rfname;
|
||||||
|
}
|
||||||
|
len = (int)STRLEN(fname);
|
||||||
|
if (len <= 4 || STRNICMP(fname + len - 4, ".lnk", 4) != 0) {
|
||||||
|
return rfname;
|
||||||
|
}
|
||||||
|
|
||||||
|
CoInitialize(NULL);
|
||||||
|
|
||||||
|
// create a link manager object and request its interface
|
||||||
|
hr = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
|
||||||
|
&IID_IShellLinkW, (void **)&pslw);
|
||||||
|
if (hr == S_OK) {
|
||||||
|
WCHAR *p;
|
||||||
|
int conversion_result = utf8_to_utf16((char *)fname, &p);
|
||||||
|
if (conversion_result != 0) {
|
||||||
|
EMSG2("utf8_to_utf16 failed: %s", uv_strerror(conversion_result));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p != NULL) {
|
||||||
|
// Get a pointer to the IPersistFile interface.
|
||||||
|
hr = pslw->lpVtbl->QueryInterface(
|
||||||
|
pslw, &IID_IPersistFile, (void **)&ppf);
|
||||||
|
if (hr != S_OK) {
|
||||||
|
goto shortcut_errorw;
|
||||||
|
}
|
||||||
|
|
||||||
|
// "load" the name and resolve the link
|
||||||
|
hr = ppf->lpVtbl->Load(ppf, p, STGM_READ);
|
||||||
|
if (hr != S_OK) {
|
||||||
|
goto shortcut_errorw;
|
||||||
|
}
|
||||||
|
|
||||||
|
# if 0 // This makes Vim wait a long time if the target does not exist.
|
||||||
|
hr = pslw->lpVtbl->Resolve(pslw, NULL, SLR_NO_UI);
|
||||||
|
if (hr != S_OK) {
|
||||||
|
goto shortcut_errorw;
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
|
||||||
|
// Get the path to the link target.
|
||||||
|
ZeroMemory(wsz, MAX_PATH * sizeof(WCHAR));
|
||||||
|
hr = pslw->lpVtbl->GetPath(pslw, wsz, MAX_PATH, &ffdw, 0);
|
||||||
|
if (hr == S_OK && wsz[0] != NUL) {
|
||||||
|
int conversion_result = utf16_to_utf8(wsz, &rfname);
|
||||||
|
if (conversion_result != 0) {
|
||||||
|
EMSG2("utf16_to_utf8 failed: %s", uv_strerror(conversion_result));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
shortcut_errorw:
|
||||||
|
xfree(p);
|
||||||
|
goto shortcut_end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
shortcut_end:
|
||||||
|
// Release all interface pointers (both belong to the same object)
|
||||||
|
if (ppf != NULL) {
|
||||||
|
ppf->lpVtbl->Release(ppf);
|
||||||
|
}
|
||||||
|
if (pslw != NULL) {
|
||||||
|
pslw->lpVtbl->Release(pslw);
|
||||||
|
}
|
||||||
|
|
||||||
|
CoUninitialize();
|
||||||
|
return rfname;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
Reference in New Issue
Block a user