diff options
author | Akira Kakuto <kakuto@fuk.kindai.ac.jp> | 2021-02-01 06:11:18 +0000 |
---|---|---|
committer | Akira Kakuto <kakuto@fuk.kindai.ac.jp> | 2021-02-01 06:11:18 +0000 |
commit | 4f9de1dfebdc66d367d730252d6f224d37e96ee6 (patch) | |
tree | 3750421fabf3aa8a8e1f4f6d5558d489e9d4fe02 /Build/source/libs/xpdf/xpdf-src/goo/gfile.cc | |
parent | 9d694205709f79666458dc2ee685767b28bcd9ac (diff) |
xpdf 4.03
git-svn-id: svn://tug.org/texlive/trunk@57588 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/libs/xpdf/xpdf-src/goo/gfile.cc')
-rw-r--r-- | Build/source/libs/xpdf/xpdf-src/goo/gfile.cc | 141 |
1 files changed, 90 insertions, 51 deletions
diff --git a/Build/source/libs/xpdf/xpdf-src/goo/gfile.cc b/Build/source/libs/xpdf/xpdf-src/goo/gfile.cc index e7112b2039d..570f4e7ab13 100644 --- a/Build/source/libs/xpdf/xpdf-src/goo/gfile.cc +++ b/Build/source/libs/xpdf/xpdf-src/goo/gfile.cc @@ -18,6 +18,8 @@ # include <windows.h> # include <time.h> # include <direct.h> +# include <shobjidl.h> +# include <shlguid.h> #else # if !defined(ACORN) # include <sys/types.h> @@ -579,68 +581,49 @@ GString *fileNameToUTF8(wchar_t *path) { } return s; } + +wchar_t *fileNameToUCS2(const char *path, wchar_t *out, size_t outSize) { + const char *p; + size_t i; + + for (p = path, i = 0; *p && i < outSize - 1; ++i) { + if ((p[0] & 0xe0) == 0xc0 && + p[1] && (p[1] & 0xc0) == 0x80) { + out[i] = (wchar_t)(((p[0] & 0x1f) << 6) | + (p[1] & 0x3f)); + p += 2; + } else if ((p[0] & 0xf0) == 0xe0 && + (p[1] & 0xc0) == 0x80 && + (p[2] & 0xc0) == 0x80) { + out[i] = (wchar_t)(((p[0] & 0x0f) << 12) | + ((p[1] & 0x3f) << 6) | + (p[2] & 0x3f)); + p += 3; + } else { + out[i] = (wchar_t)(p[0] & 0xff); + p += 1; + } + } + out[i] = (wchar_t)0; + return out; +} #endif FILE *openFile(const char *path, const char *mode) { #if defined(_WIN32) return fopen(path, mode); #if 0 - OSVERSIONINFO version; wchar_t wPath[_MAX_PATH + 1]; - char nPath[_MAX_PATH + 1]; wchar_t wMode[8]; - const char *p; int i; - // NB: _wfopen is only available in NT - version.dwOSVersionInfoSize = sizeof(version); - GetVersionEx(&version); - if (version.dwPlatformId == VER_PLATFORM_WIN32_NT) { - for (p = path, i = 0; *p && i < _MAX_PATH; ++i) { - if ((p[0] & 0xe0) == 0xc0 && - p[1] && (p[1] & 0xc0) == 0x80) { - wPath[i] = (wchar_t)(((p[0] & 0x1f) << 6) | - (p[1] & 0x3f)); - p += 2; - } else if ((p[0] & 0xf0) == 0xe0 && - p[1] && (p[1] & 0xc0) == 0x80 && - p[2] && (p[2] & 0xc0) == 0x80) { - wPath[i] = (wchar_t)(((p[0] & 0x0f) << 12) | - ((p[1] & 0x3f) << 6) | - (p[2] & 0x3f)); - p += 3; - } else { - wPath[i] = (wchar_t)(p[0] & 0xff); - p += 1; - } - } - wPath[i] = (wchar_t)0; - for (i = 0; mode[i] && i < sizeof(wMode)/sizeof(wchar_t) - 1; ++i) { - wMode[i] = (wchar_t)(mode[i] & 0xff); - } - wMode[i] = (wchar_t)0; - return _wfopen(wPath, wMode); - } else { - for (p = path, i = 0; *p && i < _MAX_PATH; ++i) { - if ((p[0] & 0xe0) == 0xc0 && - p[1] && (p[1] & 0xc0) == 0x80) { - nPath[i] = (char)(((p[0] & 0x1f) << 6) | - (p[1] & 0x3f)); - p += 2; - } else if ((p[0] & 0xf0) == 0xe0 && - p[1] && (p[1] & 0xc0) == 0x80 && - p[2] && (p[2] & 0xc0) == 0x80) { - nPath[i] = (char)(((p[1] & 0x3f) << 6) | - (p[2] & 0x3f)); - p += 3; - } else { - nPath[i] = p[0]; - p += 1; - } - } - nPath[i] = '\0'; - return fopen(nPath, mode); + fileNameToUCS2(path, wPath, sizeof(wPath) / sizeof(wchar_t)); + for (i = 0; mode[i] && i < sizeof(wMode)/sizeof(wchar_t) - 1; ++i) { + wMode[i] = (wchar_t)(mode[i] & 0xff); } + wMode[i] = (wchar_t)0; + readWindowsShortcut(wPath, _MAX_PATH + 1); + return _wfopen(wPath, wMode); #endif /* 0 */ #elif defined(VMS) return fopen(path, mode, "ctx=stm"); @@ -649,6 +632,62 @@ FILE *openFile(const char *path, const char *mode) { #endif } +#if 0 +#ifdef _WIN32 +void readWindowsShortcut(wchar_t *wPath, size_t wPathSize) { + size_t n = wcslen(wPath); + if (n < 4 || wcscmp(wPath + n - 4, L".lnk")) { + return; + } + IShellLinkW *shellLink; + HRESULT hres; + hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, + IID_IShellLinkW, (LPVOID *)&shellLink); + bool needCoUninit = false; + if (hres == CO_E_NOTINITIALIZED) { + CoInitialize(NULL); + needCoUninit = true; + hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, + IID_IShellLinkW, (LPVOID *)&shellLink); + } + if (FAILED(hres)) { + return; + } + IPersistFile *persistFile; + hres = shellLink->QueryInterface(IID_IPersistFile, (LPVOID *)&persistFile); + if (FAILED(hres)) { + return; + } + hres = persistFile->Load(wPath, STGM_READ); + if (FAILED(hres)) { + fprintf(stderr, "IPersistFile.Load failed: 0x%08x\n", hres); + exit(1); + } + wchar_t target[_MAX_PATH + 1]; + hres = shellLink->GetPath(target, _MAX_PATH + 1, NULL, 0); + if (FAILED(hres)) { + return; + } + shellLink->Release(); + if (needCoUninit) { + CoUninitialize(); + } + if (wcslen(target) > wPathSize - 1) { + return; + } + wcscpy(wPath, target); +} +#endif +#endif /* 0 */ + +int makeDir(const char *path, int mode) { +#ifdef _WIN32 + return _mkdir(path); +#else + return mkdir(path, (mode_t)mode); +#endif +} + char *getLine(char *buf, int size, FILE *f) { int c, i; |