diff options
| author | Eli Zaretskii | 2013-11-23 19:44:55 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2013-11-23 19:44:55 +0200 |
| commit | ff0c63f29a2dde0022cd7aad32ead28d7b5ac43d (patch) | |
| tree | 9d04892ac5a9e087203199695a5d307faf988226 | |
| parent | eac30cd471086f007a9dfaa6044870189d0fb323 (diff) | |
| download | emacs-ff0c63f29a2dde0022cd7aad32ead28d7b5ac43d.tar.gz emacs-ff0c63f29a2dde0022cd7aad32ead28d7b5ac43d.zip | |
w32-shell-execute converted, but not tested yet.
| -rw-r--r-- | src/w32fns.c | 170 |
1 files changed, 151 insertions, 19 deletions
diff --git a/src/w32fns.c b/src/w32fns.c index c2d2b069ec7..1acf5cb6efd 100644 --- a/src/w32fns.c +++ b/src/w32fns.c | |||
| @@ -6467,6 +6467,8 @@ Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */) | |||
| 6467 | } | 6467 | } |
| 6468 | len = MultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS, | 6468 | len = MultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS, |
| 6469 | SSDATA (prompt), -1, NULL, 0); | 6469 | SSDATA (prompt), -1, NULL, 0); |
| 6470 | if (len > 32768) | ||
| 6471 | len = 32768; | ||
| 6470 | prompt_w = alloca (len * sizeof (wchar_t)); | 6472 | prompt_w = alloca (len * sizeof (wchar_t)); |
| 6471 | MultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS, | 6473 | MultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS, |
| 6472 | SSDATA (prompt), -1, prompt_w, len); | 6474 | SSDATA (prompt), -1, prompt_w, len); |
| @@ -6483,10 +6485,14 @@ Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */) | |||
| 6483 | } | 6485 | } |
| 6484 | len = MultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS, | 6486 | len = MultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS, |
| 6485 | SSDATA (prompt), -1, NULL, 0); | 6487 | SSDATA (prompt), -1, NULL, 0); |
| 6488 | if (len > 32768) | ||
| 6489 | len = 32768; | ||
| 6486 | prompt_w = alloca (len * sizeof (wchar_t)); | 6490 | prompt_w = alloca (len * sizeof (wchar_t)); |
| 6487 | MultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS, | 6491 | MultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS, |
| 6488 | SSDATA (prompt), -1, prompt_w, len); | 6492 | SSDATA (prompt), -1, prompt_w, len); |
| 6489 | len = WideCharToMultiByte (CP_ACP, 0, prompt_w, -1, NULL, 0, NULL, NULL); | 6493 | len = WideCharToMultiByte (CP_ACP, 0, prompt_w, -1, NULL, 0, NULL, NULL); |
| 6494 | if (len > 32768) | ||
| 6495 | len = 32768; | ||
| 6490 | prompt_a = alloca (len); | 6496 | prompt_a = alloca (len); |
| 6491 | WideCharToMultiByte (CP_ACP, 0, prompt_w, -1, prompt_a, len, NULL, NULL); | 6497 | WideCharToMultiByte (CP_ACP, 0, prompt_w, -1, prompt_a, len, NULL, NULL); |
| 6492 | } | 6498 | } |
| @@ -6755,38 +6761,164 @@ an integer representing a ShowWindow flag: | |||
| 6755 | 6 - start minimized */) | 6761 | 6 - start minimized */) |
| 6756 | (Lisp_Object operation, Lisp_Object document, Lisp_Object parameters, Lisp_Object show_flag) | 6762 | (Lisp_Object operation, Lisp_Object document, Lisp_Object parameters, Lisp_Object show_flag) |
| 6757 | { | 6763 | { |
| 6758 | Lisp_Object current_dir; | ||
| 6759 | char *errstr; | 6764 | char *errstr; |
| 6765 | Lisp_Object current_dir = BVAR (current_buffer, directory);; | ||
| 6766 | wchar_t *doc_w = NULL, *params_w = NULL, *ops_w = NULL; | ||
| 6767 | int result; | ||
| 6768 | #ifndef CYGWIN | ||
| 6769 | int use_unicode = w32_unicode_filenames; | ||
| 6770 | char *doc_a = NULL, *params_a = NULL, *ops_a = NULL; | ||
| 6771 | #endif | ||
| 6760 | 6772 | ||
| 6761 | CHECK_STRING (document); | 6773 | CHECK_STRING (document); |
| 6762 | 6774 | ||
| 6763 | /* Encode filename, current directory and parameters. */ | ||
| 6764 | current_dir = BVAR (current_buffer, directory); | ||
| 6765 | |||
| 6766 | #ifdef CYGWIN | 6775 | #ifdef CYGWIN |
| 6767 | current_dir = Fcygwin_convert_file_name_to_windows (current_dir, Qt); | 6776 | current_dir = Fcygwin_convert_file_name_to_windows (current_dir, Qt); |
| 6768 | if (STRINGP (document)) | 6777 | if (STRINGP (document)) |
| 6769 | document = Fcygwin_convert_file_name_to_windows (document, Qt); | 6778 | document = Fcygwin_convert_file_name_to_windows (document, Qt); |
| 6770 | #endif /* CYGWIN */ | ||
| 6771 | 6779 | ||
| 6780 | /* Encode filename, current directory and parameters. */ | ||
| 6772 | current_dir = GUI_ENCODE_FILE (current_dir); | 6781 | current_dir = GUI_ENCODE_FILE (current_dir); |
| 6773 | if (STRINGP (document)) | 6782 | if (STRINGP (document)) |
| 6774 | document = GUI_ENCODE_FILE (document); | 6783 | { |
| 6784 | document = GUI_ENCODE_FILE (document); | ||
| 6785 | doc_w = GUI_SDATA (document); | ||
| 6786 | } | ||
| 6775 | if (STRINGP (parameters)) | 6787 | if (STRINGP (parameters)) |
| 6776 | parameters = GUI_ENCODE_SYSTEM (parameters); | 6788 | { |
| 6777 | 6789 | parameters = GUI_ENCODE_SYSTEM (parameters); | |
| 6778 | if ((int) GUI_FN (ShellExecute) (NULL, | 6790 | params_w = GUI_SDATA (parameters); |
| 6779 | (STRINGP (operation) ? | 6791 | } |
| 6780 | GUI_SDATA (operation) : NULL), | 6792 | if (STRINGP (operation)) |
| 6781 | GUI_SDATA (document), | 6793 | { |
| 6782 | (STRINGP (parameters) ? | 6794 | operation = GUI_ENCODE_SYSTEM (operation); |
| 6783 | GUI_SDATA (parameters) : NULL), | 6795 | ops_w = GUI_SDATA (operation); |
| 6784 | GUI_SDATA (current_dir), | 6796 | } |
| 6785 | (INTEGERP (show_flag) ? | 6797 | result = (int) ShellExecuteW (NULL, ops_w, doc_w, params_w, |
| 6786 | XINT (show_flag) : SW_SHOWDEFAULT)) | 6798 | GUI_SDATA (current_dir), |
| 6787 | > 32) | 6799 | (INTEGERP (show_flag) |
| 6800 | ? XINT (show_flag) : SW_SHOWDEFAULT)); | ||
| 6801 | #else /* !CYGWIN */ | ||
| 6802 | if (use_unicode) | ||
| 6803 | { | ||
| 6804 | wchar_t document_w[MAX_PATH], current_dir_w[MAX_PATH]; | ||
| 6805 | |||
| 6806 | /* Encode filename, current directory and parameters, and | ||
| 6807 | convert operation to UTF-16. */ | ||
| 6808 | current_dir = ENCODE_FILE (current_dir); | ||
| 6809 | filename_to_utf16 (SSDATA (current_dir), current_dir_w); | ||
| 6810 | if (STRINGP (document)) | ||
| 6811 | { | ||
| 6812 | filename_to_utf16 (SSDATA (document), document_w); | ||
| 6813 | doc_w = document_w; | ||
| 6814 | } | ||
| 6815 | if (STRINGP (parameters)) | ||
| 6816 | { | ||
| 6817 | int len = MultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS, | ||
| 6818 | SSDATA (parameters), -1, NULL, 0); | ||
| 6819 | if (len > 32768) | ||
| 6820 | len = 32768; | ||
| 6821 | params_w = alloca (len * sizeof (wchar_t)); | ||
| 6822 | MultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS, | ||
| 6823 | SSDATA (parameters), -1, params_w, len); | ||
| 6824 | } | ||
| 6825 | if (STRINGP (operation)) | ||
| 6826 | { | ||
| 6827 | /* Assume OPERATION is pure ASCII. */ | ||
| 6828 | const char *s = SSDATA (operation); | ||
| 6829 | wchar_t *d; | ||
| 6830 | int len = SBYTES (operation); | ||
| 6831 | |||
| 6832 | if (len > 32768) | ||
| 6833 | len = 32768; | ||
| 6834 | d = ops_w = alloca (len * sizeof (wchar_t)); | ||
| 6835 | while (d < ops_w + len - 1) | ||
| 6836 | *d++ = *s++; | ||
| 6837 | *d = 0; | ||
| 6838 | } | ||
| 6839 | result = (int) ShellExecuteW (NULL, ops_w, doc_w, params_w, | ||
| 6840 | current_dir_w, | ||
| 6841 | (INTEGERP (show_flag) | ||
| 6842 | ? XINT (show_flag) : SW_SHOWDEFAULT)); | ||
| 6843 | } | ||
| 6844 | else | ||
| 6845 | { | ||
| 6846 | char document_a[MAX_PATH], current_dir_a[MAX_PATH]; | ||
| 6847 | |||
| 6848 | current_dir = ENCODE_FILE (current_dir); | ||
| 6849 | filename_to_ansi (SSDATA (current_dir), current_dir_a); | ||
| 6850 | if (STRINGP (document)) | ||
| 6851 | { | ||
| 6852 | filename_to_ansi (SSDATA (document), document_a); | ||
| 6853 | doc_a = document_a; | ||
| 6854 | } | ||
| 6855 | if (STRINGP (parameters)) | ||
| 6856 | { | ||
| 6857 | int len = MultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS, | ||
| 6858 | SSDATA (parameters), -1, NULL, 0); | ||
| 6859 | if (len > 32768) | ||
| 6860 | len = 32768; | ||
| 6861 | params_w = alloca (len * sizeof (wchar_t)); | ||
| 6862 | MultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS, | ||
| 6863 | SSDATA (parameters), -1, params_w, len); | ||
| 6864 | len = WideCharToMultiByte (CP_ACP, 0, params_w, -1, NULL, 0, | ||
| 6865 | NULL, NULL); | ||
| 6866 | if (len > 32768) | ||
| 6867 | len = 32768; | ||
| 6868 | params_a = alloca (len); | ||
| 6869 | WideCharToMultiByte (CP_ACP, 0, params_w, -1, params_a, len, | ||
| 6870 | NULL, NULL); | ||
| 6871 | } | ||
| 6872 | if (STRINGP (operation)) | ||
| 6873 | { | ||
| 6874 | /* Assume OPERATION is pure ASCII. */ | ||
| 6875 | ops_a = SSDATA (operation); | ||
| 6876 | } | ||
| 6877 | result = (int) ShellExecuteA (NULL, ops_a, doc_a, params_a, | ||
| 6878 | current_dir_a, | ||
| 6879 | (INTEGERP (show_flag) | ||
| 6880 | ? XINT (show_flag) : SW_SHOWDEFAULT)); | ||
| 6881 | } | ||
| 6882 | #endif /* !CYGWIN */ | ||
| 6883 | |||
| 6884 | if (result > 32) | ||
| 6788 | return Qt; | 6885 | return Qt; |
| 6789 | errstr = w32_strerror (0); | 6886 | |
| 6887 | switch (result) | ||
| 6888 | { | ||
| 6889 | case SE_ERR_ACCESSDENIED: | ||
| 6890 | errstr = w32_strerror (ERROR_ACCESS_DENIED); | ||
| 6891 | break; | ||
| 6892 | case SE_ERR_ASSOCINCOMPLETE: | ||
| 6893 | case SE_ERR_NOASSOC: | ||
| 6894 | errstr = w32_strerror (ERROR_NO_ASSOCIATION); | ||
| 6895 | break; | ||
| 6896 | case SE_ERR_DDEBUSY: | ||
| 6897 | case SE_ERR_DDEFAIL: | ||
| 6898 | errstr = w32_strerror (ERROR_DDE_FAIL); | ||
| 6899 | break; | ||
| 6900 | case SE_ERR_DDETIMEOUT: | ||
| 6901 | errstr = w32_strerror (ERROR_TIMEOUT); | ||
| 6902 | break; | ||
| 6903 | case SE_ERR_DLLNOTFOUND: | ||
| 6904 | errstr = w32_strerror (ERROR_DLL_NOT_FOUND); | ||
| 6905 | break; | ||
| 6906 | case SE_ERR_FNF: | ||
| 6907 | errstr = w32_strerror (ERROR_FILE_NOT_FOUND); | ||
| 6908 | break; | ||
| 6909 | case SE_ERR_OOM: | ||
| 6910 | errstr = w32_strerror (ERROR_NOT_ENOUGH_MEMORY); | ||
| 6911 | break; | ||
| 6912 | case SE_ERR_PNF: | ||
| 6913 | errstr = w32_strerror (ERROR_PATH_NOT_FOUND); | ||
| 6914 | break; | ||
| 6915 | case SE_ERR_SHARE: | ||
| 6916 | errstr = w32_strerror (ERROR_SHARING_VIOLATION); | ||
| 6917 | break; | ||
| 6918 | default: | ||
| 6919 | errstr = w32_strerror (0); | ||
| 6920 | break; | ||
| 6921 | } | ||
| 6790 | /* The error string might be encoded in the locale's encoding. */ | 6922 | /* The error string might be encoded in the locale's encoding. */ |
| 6791 | if (!NILP (Vlocale_coding_system)) | 6923 | if (!NILP (Vlocale_coding_system)) |
| 6792 | { | 6924 | { |