Mercurial > vim
comparison src/misc1.c @ 16196:973070a30381 v8.1.1103
patch 8.1.1103: MS-Windows: old API calls are no longer needed
commit https://github.com/vim/vim/commit/0eb035c974c47e65d32439b48e5a056b370ad429
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Apr 2 22:15:55 2019 +0200
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Problem: MS-Windows: old API calls are no longer needed.
Solution: Always use the wide functions. (Ken Takata, closes https://github.com/vim/vim/issues/4199)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 02 Apr 2019 22:30:04 +0200 |
parents | 6b0836727cf3 |
children | 0761a4c111a7 |
comparison
equal
deleted
inserted
replaced
16195:4d55a37f8b1b | 16196:973070a30381 |
---|---|
5668 regmatch_T regmatch; | 5668 regmatch_T regmatch; |
5669 int starts_with_dot; | 5669 int starts_with_dot; |
5670 int matches; | 5670 int matches; |
5671 int len; | 5671 int len; |
5672 int starstar = FALSE; | 5672 int starstar = FALSE; |
5673 static int stardepth = 0; /* depth for "**" expansion */ | 5673 static int stardepth = 0; // depth for "**" expansion |
5674 WIN32_FIND_DATA fb; | 5674 HANDLE hFind = INVALID_HANDLE_VALUE; |
5675 HANDLE hFind = (HANDLE)0; | |
5676 WIN32_FIND_DATAW wfb; | 5675 WIN32_FIND_DATAW wfb; |
5677 WCHAR *wn = NULL; /* UCS-2 name, NULL when not used. */ | 5676 WCHAR *wn = NULL; // UCS-2 name, NULL when not used. |
5678 char_u *matchname; | 5677 char_u *matchname; |
5679 int ok; | 5678 int ok; |
5680 | 5679 |
5681 /* Expanding "**" may take a long time, check for CTRL-C. */ | 5680 /* Expanding "**" may take a long time, check for CTRL-C. */ |
5682 if (stardepth > 0) | 5681 if (stardepth > 0) |
5781 --stardepth; | 5780 --stardepth; |
5782 } | 5781 } |
5783 | 5782 |
5784 /* Scan all files in the directory with "dir/ *.*" */ | 5783 /* Scan all files in the directory with "dir/ *.*" */ |
5785 STRCPY(s, "*.*"); | 5784 STRCPY(s, "*.*"); |
5786 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | 5785 wn = enc_to_utf16(buf, NULL); |
5787 { | 5786 if (wn != NULL) |
5788 /* The active codepage differs from 'encoding'. Attempt using the | 5787 hFind = FindFirstFileW(wn, &wfb); |
5789 * wide function. If it fails because it is not implemented fall back | |
5790 * to the non-wide version (for Windows 98) */ | |
5791 wn = enc_to_utf16(buf, NULL); | |
5792 if (wn != NULL) | |
5793 { | |
5794 hFind = FindFirstFileW(wn, &wfb); | |
5795 if (hFind == INVALID_HANDLE_VALUE | |
5796 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) | |
5797 VIM_CLEAR(wn); | |
5798 } | |
5799 } | |
5800 | |
5801 if (wn == NULL) | |
5802 hFind = FindFirstFile((LPCSTR)buf, &fb); | |
5803 ok = (hFind != INVALID_HANDLE_VALUE); | 5788 ok = (hFind != INVALID_HANDLE_VALUE); |
5804 | 5789 |
5805 while (ok) | 5790 while (ok) |
5806 { | 5791 { |
5807 if (wn != NULL) | 5792 p = utf16_to_enc(wfb.cFileName, NULL); // p is allocated here |
5808 p = utf16_to_enc(wfb.cFileName, NULL); /* p is allocated here */ | 5793 // Ignore entries starting with a dot, unless when asked for. Accept |
5809 else | 5794 // all entries found with "matchname". |
5810 p = (char_u *)fb.cFileName; | |
5811 /* Ignore entries starting with a dot, unless when asked for. Accept | |
5812 * all entries found with "matchname". */ | |
5813 if ((p[0] != '.' || starts_with_dot | 5795 if ((p[0] != '.' || starts_with_dot |
5814 || ((flags & EW_DODOT) | 5796 || ((flags & EW_DODOT) |
5815 && p[1] != NUL && (p[1] != '.' || p[2] != NUL))) | 5797 && p[1] != NUL && (p[1] != '.' || p[2] != NUL))) |
5816 && (matchname == NULL | 5798 && (matchname == NULL |
5817 || (regmatch.regprog != NULL | 5799 || (regmatch.regprog != NULL |
5849 if (mch_getperm(buf) >= 0) /* add existing file */ | 5831 if (mch_getperm(buf) >= 0) /* add existing file */ |
5850 addfile(gap, buf, flags); | 5832 addfile(gap, buf, flags); |
5851 } | 5833 } |
5852 } | 5834 } |
5853 | 5835 |
5854 if (wn != NULL) | 5836 vim_free(p); |
5855 { | 5837 ok = FindNextFileW(hFind, &wfb); |
5856 vim_free(p); | |
5857 ok = FindNextFileW(hFind, &wfb); | |
5858 } | |
5859 else | |
5860 ok = FindNextFile(hFind, &fb); | |
5861 | 5838 |
5862 /* If no more matches and no match was used, try expanding the name | 5839 /* If no more matches and no match was used, try expanding the name |
5863 * itself. Finds the long name of a short filename. */ | 5840 * itself. Finds the long name of a short filename. */ |
5864 if (!ok && matchname != NULL && gap->ga_len == start_len) | 5841 if (!ok && matchname != NULL && gap->ga_len == start_len) |
5865 { | 5842 { |
5866 STRCPY(s, matchname); | 5843 STRCPY(s, matchname); |
5867 FindClose(hFind); | 5844 FindClose(hFind); |
5845 vim_free(wn); | |
5846 wn = enc_to_utf16(buf, NULL); | |
5868 if (wn != NULL) | 5847 if (wn != NULL) |
5869 { | 5848 hFind = FindFirstFileW(wn, &wfb); |
5870 vim_free(wn); | 5849 else |
5871 wn = enc_to_utf16(buf, NULL); | 5850 hFind = INVALID_HANDLE_VALUE; |
5872 if (wn != NULL) | |
5873 hFind = FindFirstFileW(wn, &wfb); | |
5874 } | |
5875 if (wn == NULL) | |
5876 hFind = FindFirstFile((LPCSTR)buf, &fb); | |
5877 ok = (hFind != INVALID_HANDLE_VALUE); | 5851 ok = (hFind != INVALID_HANDLE_VALUE); |
5878 VIM_CLEAR(matchname); | 5852 VIM_CLEAR(matchname); |
5879 } | 5853 } |
5880 } | 5854 } |
5881 | 5855 |