comparison src/GvimExt/gvimext.cpp @ 2295:b9bc9c5df131 vim73

Support wide file names in gvimext. (Szabolcs Horvat)
author Bram Moolenaar <bram@vim.org>
date Sat, 10 Jul 2010 19:22:44 +0200
parents 378e33d47ab0
children bdc3335bd72e
comparison
equal deleted inserted replaced
2294:2209060c340d 2295:b9bc9c5df131
81 strcpy(name, "gvim"); // finds gvim.bat or gvim.exe 81 strcpy(name, "gvim"); // finds gvim.bat or gvim.exe
82 82
83 // avoid that Vim tries to expand wildcards in the file names 83 // avoid that Vim tries to expand wildcards in the file names
84 strcat(name, " --literal"); 84 strcat(name, " --literal");
85 } 85 }
86 }
87
88 static void
89 getGvimNameW(wchar_t *nameW)
90 {
91 char *name;
92
93 name = (char *)malloc(BUFSIZE);
94 getGvimName(name, 0);
95 mbstowcs(nameW, name, BUFSIZE);
96 free(name);
86 } 97 }
87 98
88 // 99 //
89 // Get the Vim runtime directory into buf[BUFSIZE]. 100 // Get the Vim runtime directory into buf[BUFSIZE].
90 // The result is empty when it failed. 101 // The result is empty when it failed.
846 LPCSTR /* pszWorkingDir */, 857 LPCSTR /* pszWorkingDir */,
847 LPCSTR /* pszCmd */, 858 LPCSTR /* pszCmd */,
848 LPCSTR /* pszParam */, 859 LPCSTR /* pszParam */,
849 int /* iShowCmd */) 860 int /* iShowCmd */)
850 { 861 {
851 char m_szFileUserClickedOn[BUFSIZE]; 862 wchar_t m_szFileUserClickedOn[BUFSIZE];
852 char cmdStr[BUFSIZE]; 863 wchar_t cmdStrW[BUFSIZE];
853 UINT i; 864 UINT i;
854 865
855 for (i = 0; i < cbFiles; i++) 866 for (i = 0; i < cbFiles; i++)
856 { 867 {
857 DragQueryFile((HDROP)medium.hGlobal, 868 DragQueryFileW((HDROP)medium.hGlobal,
858 i, 869 i,
859 m_szFileUserClickedOn, 870 m_szFileUserClickedOn,
860 sizeof(m_szFileUserClickedOn)); 871 sizeof(m_szFileUserClickedOn));
861 872
862 getGvimName(cmdStr, 0); 873 getGvimNameW(cmdStrW);
863 strcat(cmdStr, " \""); 874 wcscat(cmdStrW, L" \"");
864 875
865 if ((strlen(cmdStr) + strlen(m_szFileUserClickedOn) + 2) < BUFSIZE) 876 if ((wcslen(cmdStrW) + wcslen(m_szFileUserClickedOn) + 2) < BUFSIZE)
866 { 877 {
867 strcat(cmdStr, m_szFileUserClickedOn); 878 wcscat(cmdStrW, m_szFileUserClickedOn);
868 strcat(cmdStr, "\""); 879 wcscat(cmdStrW, L"\"");
869 880
870 STARTUPINFO si; 881 STARTUPINFOW si;
871 PROCESS_INFORMATION pi; 882 PROCESS_INFORMATION pi;
872 883
873 ZeroMemory(&si, sizeof(si)); 884 ZeroMemory(&si, sizeof(si));
874 si.cb = sizeof(si); 885 si.cb = sizeof(si);
875 886
876 // Start the child process. 887 // Start the child process.
877 if (!CreateProcess(NULL, // No module name (use command line). 888 if (!CreateProcessW(NULL, // No module name (use command line).
878 cmdStr, // Command line. 889 cmdStrW, // Command line.
879 NULL, // Process handle not inheritable. 890 NULL, // Process handle not inheritable.
880 NULL, // Thread handle not inheritable. 891 NULL, // Thread handle not inheritable.
881 FALSE, // Set handle inheritance to FALSE. 892 FALSE, // Set handle inheritance to FALSE.
882 0, // No creation flags. 893 0, // No creation flags.
883 NULL, // Use parent's environment block. 894 NULL, // Use parent's environment block.
917 LPCSTR /* pszCmd */, 928 LPCSTR /* pszCmd */,
918 LPCSTR /* pszParam */, 929 LPCSTR /* pszParam */,
919 int /* iShowCmd */, 930 int /* iShowCmd */,
920 int useDiff) 931 int useDiff)
921 { 932 {
922 char m_szFileUserClickedOn[BUFSIZE]; 933 wchar_t m_szFileUserClickedOn[BUFSIZE];
923 char *cmdStr; 934 wchar_t *cmdStrW;
924 size_t cmdlen; 935 size_t cmdlen;
925 size_t len; 936 size_t len;
926 UINT i; 937 UINT i;
927 938
928 cmdlen = BUFSIZE; 939 cmdlen = BUFSIZE;
929 cmdStr = (char *)malloc(cmdlen); 940 cmdStrW = (wchar_t *) malloc(cmdlen * sizeof(wchar_t));
930 getGvimName(cmdStr, 0); 941 getGvimNameW(cmdStrW);
942
931 if (useDiff) 943 if (useDiff)
932 strcat(cmdStr, " -d"); 944 wcscat(cmdStrW, L" -d");
933 for (i = 0; i < cbFiles; i++) 945 for (i = 0; i < cbFiles; i++)
934 { 946 {
935 DragQueryFile((HDROP)medium.hGlobal, 947 DragQueryFileW((HDROP)medium.hGlobal,
936 i, 948 i,
937 m_szFileUserClickedOn, 949 m_szFileUserClickedOn,
938 sizeof(m_szFileUserClickedOn)); 950 sizeof(m_szFileUserClickedOn));
939 951
940 len = strlen(cmdStr) + strlen(m_szFileUserClickedOn) + 4; 952 len = wcslen(cmdStrW) + wcslen(m_szFileUserClickedOn) + 4;
941 if (len > cmdlen) 953 if (len > cmdlen)
942 { 954 {
943 cmdlen = len + BUFSIZE; 955 cmdlen = len + BUFSIZE;
944 cmdStr = (char *)realloc(cmdStr, cmdlen); 956 cmdStrW = (wchar_t *)realloc(cmdStrW, cmdlen * sizeof(wchar_t));
945 } 957 }
946 strcat(cmdStr, " \""); 958 wcscat(cmdStrW, L" \"");
947 strcat(cmdStr, m_szFileUserClickedOn); 959 wcscat(cmdStrW, m_szFileUserClickedOn);
948 strcat(cmdStr, "\""); 960 wcscat(cmdStrW, L"\"");
949 } 961 }
950 962
951 STARTUPINFO si; 963 STARTUPINFOW si;
952 PROCESS_INFORMATION pi; 964 PROCESS_INFORMATION pi;
953 965
954 ZeroMemory(&si, sizeof(si)); 966 ZeroMemory(&si, sizeof(si));
955 si.cb = sizeof(si); 967 si.cb = sizeof(si);
956 968
957 // Start the child process. 969 // Start the child process.
958 if (!CreateProcess(NULL, // No module name (use command line). 970 if (!CreateProcessW(NULL, // No module name (use command line).
959 cmdStr, // Command line. 971 cmdStrW, // Command line.
960 NULL, // Process handle not inheritable. 972 NULL, // Process handle not inheritable.
961 NULL, // Thread handle not inheritable. 973 NULL, // Thread handle not inheritable.
962 FALSE, // Set handle inheritance to FALSE. 974 FALSE, // Set handle inheritance to FALSE.
963 0, // No creation flags. 975 0, // No creation flags.
964 NULL, // Use parent's environment block. 976 NULL, // Use parent's environment block.
977 { 989 {
978 CloseHandle(pi.hProcess); 990 CloseHandle(pi.hProcess);
979 CloseHandle(pi.hThread); 991 CloseHandle(pi.hThread);
980 } 992 }
981 993
982 free(cmdStr); 994 free(cmdStrW);
983 995
984 return NOERROR; 996 return NOERROR;
985 } 997 }