diff options
| author | Eli Zaretskii | 2015-06-27 13:48:26 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2015-06-27 13:48:26 +0300 |
| commit | 31807189b55d9519a46e4b35fadbe20218e4ebea (patch) | |
| tree | c2d926b9871ebb9788923c2fe2241670e903f423 /src | |
| parent | 5a7fb4f0cc5a21808ab6fa062050059ceac027e4 (diff) | |
| download | emacs-31807189b55d9519a46e4b35fadbe20218e4ebea.tar.gz emacs-31807189b55d9519a46e4b35fadbe20218e4ebea.zip | |
Add a new function w32-application-type
* src/w32proc.c (Fw32_application_type): New function.
; * etc/NEWS: Mention w32-application-type.
Diffstat (limited to 'src')
| -rw-r--r-- | src/w32proc.c | 104 |
1 files changed, 89 insertions, 15 deletions
diff --git a/src/w32proc.c b/src/w32proc.c index 1f633d834c2..b301fcf18ab 100644 --- a/src/w32proc.c +++ b/src/w32proc.c | |||
| @@ -1527,22 +1527,25 @@ waitpid (pid_t pid, int *status, int options) | |||
| 1527 | 1527 | ||
| 1528 | /* Implementation note: This function works with file names encoded in | 1528 | /* Implementation note: This function works with file names encoded in |
| 1529 | the current ANSI codepage. */ | 1529 | the current ANSI codepage. */ |
| 1530 | static void | 1530 | static int |
| 1531 | w32_executable_type (char * filename, | 1531 | w32_executable_type (char * filename, |
| 1532 | int * is_dos_app, | 1532 | int * is_dos_app, |
| 1533 | int * is_cygnus_app, | 1533 | int * is_cygnus_app, |
| 1534 | int * is_msys_app, | ||
| 1534 | int * is_gui_app) | 1535 | int * is_gui_app) |
| 1535 | { | 1536 | { |
| 1536 | file_data executable; | 1537 | file_data executable; |
| 1537 | char * p; | 1538 | char * p; |
| 1539 | int retval = 0; | ||
| 1538 | 1540 | ||
| 1539 | /* Default values in case we can't tell for sure. */ | 1541 | /* Default values in case we can't tell for sure. */ |
| 1540 | *is_dos_app = FALSE; | 1542 | *is_dos_app = FALSE; |
| 1541 | *is_cygnus_app = FALSE; | 1543 | *is_cygnus_app = FALSE; |
| 1544 | *is_msys_app = FALSE; | ||
| 1542 | *is_gui_app = FALSE; | 1545 | *is_gui_app = FALSE; |
| 1543 | 1546 | ||
| 1544 | if (!open_input_file (&executable, filename)) | 1547 | if (!open_input_file (&executable, filename)) |
| 1545 | return; | 1548 | return -1; |
| 1546 | 1549 | ||
| 1547 | p = strrchr (filename, '.'); | 1550 | p = strrchr (filename, '.'); |
| 1548 | 1551 | ||
| @@ -1560,7 +1563,8 @@ w32_executable_type (char * filename, | |||
| 1560 | extension, which is defined in the registry. */ | 1563 | extension, which is defined in the registry. */ |
| 1561 | p = egetenv ("COMSPEC"); | 1564 | p = egetenv ("COMSPEC"); |
| 1562 | if (p) | 1565 | if (p) |
| 1563 | w32_executable_type (p, is_dos_app, is_cygnus_app, is_gui_app); | 1566 | retval = w32_executable_type (p, is_dos_app, is_cygnus_app, is_msys_app, |
| 1567 | is_gui_app); | ||
| 1564 | } | 1568 | } |
| 1565 | else | 1569 | else |
| 1566 | { | 1570 | { |
| @@ -1637,6 +1641,16 @@ w32_executable_type (char * filename, | |||
| 1637 | *is_cygnus_app = TRUE; | 1641 | *is_cygnus_app = TRUE; |
| 1638 | break; | 1642 | break; |
| 1639 | } | 1643 | } |
| 1644 | else if (strncmp (dllname, "msys-", 5) == 0) | ||
| 1645 | { | ||
| 1646 | /* This catches both MSYS 1.x and MSYS2 | ||
| 1647 | executables (the DLL name is msys-1.0.dll and | ||
| 1648 | msys-2.0.dll, respectively). There's doesn't | ||
| 1649 | seem to be a reason to distinguish between | ||
| 1650 | the two, for now. */ | ||
| 1651 | *is_msys_app = TRUE; | ||
| 1652 | break; | ||
| 1653 | } | ||
| 1640 | } | 1654 | } |
| 1641 | } | 1655 | } |
| 1642 | } | 1656 | } |
| @@ -1644,6 +1658,7 @@ w32_executable_type (char * filename, | |||
| 1644 | 1658 | ||
| 1645 | unwind: | 1659 | unwind: |
| 1646 | close_file_data (&executable); | 1660 | close_file_data (&executable); |
| 1661 | return retval; | ||
| 1647 | } | 1662 | } |
| 1648 | 1663 | ||
| 1649 | static int | 1664 | static int |
| @@ -1702,7 +1717,7 @@ sys_spawnve (int mode, char *cmdname, char **argv, char **envp) | |||
| 1702 | int arglen, numenv; | 1717 | int arglen, numenv; |
| 1703 | pid_t pid; | 1718 | pid_t pid; |
| 1704 | child_process *cp; | 1719 | child_process *cp; |
| 1705 | int is_dos_app, is_cygnus_app, is_gui_app; | 1720 | int is_dos_app, is_cygnus_app, is_msys_app, is_gui_app; |
| 1706 | int do_quoting = 0; | 1721 | int do_quoting = 0; |
| 1707 | /* We pass our process ID to our children by setting up an environment | 1722 | /* We pass our process ID to our children by setting up an environment |
| 1708 | variable in their environment. */ | 1723 | variable in their environment. */ |
| @@ -1713,10 +1728,10 @@ sys_spawnve (int mode, char *cmdname, char **argv, char **envp) | |||
| 1713 | argument being split into two or more. Arguments with wildcards | 1728 | argument being split into two or more. Arguments with wildcards |
| 1714 | are also quoted, for consistency with posix platforms, where wildcards | 1729 | are also quoted, for consistency with posix platforms, where wildcards |
| 1715 | are not expanded if we run the program directly without a shell. | 1730 | are not expanded if we run the program directly without a shell. |
| 1716 | Some extra whitespace characters need quoting in Cygwin programs, | 1731 | Some extra whitespace characters need quoting in Cygwin/MSYS programs, |
| 1717 | so this list is conditionally modified below. */ | 1732 | so this list is conditionally modified below. */ |
| 1718 | char *sepchars = " \t*?"; | 1733 | char *sepchars = " \t*?"; |
| 1719 | /* This is for native w32 apps; modified below for Cygwin apps. */ | 1734 | /* This is for native w32 apps; modified below for Cygwin/MSUS apps. */ |
| 1720 | char escape_char = '\\'; | 1735 | char escape_char = '\\'; |
| 1721 | char cmdname_a[MAX_PATH]; | 1736 | char cmdname_a[MAX_PATH]; |
| 1722 | 1737 | ||
| @@ -1777,15 +1792,17 @@ sys_spawnve (int mode, char *cmdname, char **argv, char **envp) | |||
| 1777 | cmdname = cmdname_a; | 1792 | cmdname = cmdname_a; |
| 1778 | argv[0] = cmdname; | 1793 | argv[0] = cmdname; |
| 1779 | 1794 | ||
| 1780 | /* Determine whether program is a 16-bit DOS executable, or a 32-bit Windows | 1795 | /* Determine whether program is a 16-bit DOS executable, or a 32-bit |
| 1781 | executable that is implicitly linked to the Cygnus dll (implying it | 1796 | Windows executable that is implicitly linked to the Cygnus or |
| 1782 | was compiled with the Cygnus GNU toolchain and hence relies on | 1797 | MSYS dll (implying it was compiled with the Cygnus/MSYS GNU |
| 1783 | cygwin.dll to parse the command line - we use this to decide how to | 1798 | toolchain and hence relies on cygwin.dll or MSYS DLL to parse the |
| 1784 | escape quote chars in command line args that must be quoted). | 1799 | command line - we use this to decide how to escape quote chars in |
| 1800 | command line args that must be quoted). | ||
| 1785 | 1801 | ||
| 1786 | Also determine whether it is a GUI app, so that we don't hide its | 1802 | Also determine whether it is a GUI app, so that we don't hide its |
| 1787 | initial window unless specifically requested. */ | 1803 | initial window unless specifically requested. */ |
| 1788 | w32_executable_type (cmdname, &is_dos_app, &is_cygnus_app, &is_gui_app); | 1804 | w32_executable_type (cmdname, &is_dos_app, &is_cygnus_app, &is_msys_app, |
| 1805 | &is_gui_app); | ||
| 1789 | 1806 | ||
| 1790 | /* On Windows 95, if cmdname is a DOS app, we invoke a helper | 1807 | /* On Windows 95, if cmdname is a DOS app, we invoke a helper |
| 1791 | application to start it by specifying the helper app as cmdname, | 1808 | application to start it by specifying the helper app as cmdname, |
| @@ -1845,10 +1862,10 @@ sys_spawnve (int mode, char *cmdname, char **argv, char **envp) | |||
| 1845 | if (INTEGERP (Vw32_quote_process_args)) | 1862 | if (INTEGERP (Vw32_quote_process_args)) |
| 1846 | escape_char = XINT (Vw32_quote_process_args); | 1863 | escape_char = XINT (Vw32_quote_process_args); |
| 1847 | else | 1864 | else |
| 1848 | escape_char = is_cygnus_app ? '"' : '\\'; | 1865 | escape_char = (is_cygnus_app || is_msys_app) ? '"' : '\\'; |
| 1849 | } | 1866 | } |
| 1850 | 1867 | ||
| 1851 | /* Cygwin apps needs quoting a bit more often. */ | 1868 | /* Cygwin/MSYS apps need quoting a bit more often. */ |
| 1852 | if (escape_char == '"') | 1869 | if (escape_char == '"') |
| 1853 | sepchars = "\r\n\t\f '"; | 1870 | sepchars = "\r\n\t\f '"; |
| 1854 | 1871 | ||
| @@ -1866,7 +1883,7 @@ sys_spawnve (int mode, char *cmdname, char **argv, char **envp) | |||
| 1866 | for ( ; *p; p++) | 1883 | for ( ; *p; p++) |
| 1867 | { | 1884 | { |
| 1868 | if (escape_char == '"' && *p == '\\') | 1885 | if (escape_char == '"' && *p == '\\') |
| 1869 | /* If it's a Cygwin app, \ needs to be escaped. */ | 1886 | /* If it's a Cygwin/MSYS app, \ needs to be escaped. */ |
| 1870 | arglen++; | 1887 | arglen++; |
| 1871 | else if (*p == '"') | 1888 | else if (*p == '"') |
| 1872 | { | 1889 | { |
| @@ -2947,6 +2964,59 @@ If successful, the return value is t, otherwise nil. */) | |||
| 2947 | return result; | 2964 | return result; |
| 2948 | } | 2965 | } |
| 2949 | 2966 | ||
| 2967 | DEFUN ("w32-application-type", Fw32_application_type, | ||
| 2968 | Sw32_application_type, 1, 1, 0, | ||
| 2969 | doc: /* Return the type of an MS-Windows PROGRAM. | ||
| 2970 | |||
| 2971 | Knowing the type of an executable could be useful for formatting | ||
| 2972 | file names passed to it or for quoting its command-line arguments. | ||
| 2973 | |||
| 2974 | PROGRAM should specify an executable file, including the extension. | ||
| 2975 | |||
| 2976 | The value is one of the following: | ||
| 2977 | |||
| 2978 | `dos' -- a DOS .com program or some other non-PE executable | ||
| 2979 | `cygwin' -- a Cygwin program that depends on Cygwin DLL | ||
| 2980 | `msys' -- an MSYS 1.x or MSYS2 program | ||
| 2981 | `w32-native' -- a native Windows application | ||
| 2982 | `unknown' -- a file that doesn't exist, or cannot be open, or whose | ||
| 2983 | name is not encodable in the current ANSI codepage. | ||
| 2984 | |||
| 2985 | Note that for .bat and .cmd batch files the function returns the type | ||
| 2986 | of their command interpreter, as specified by the \"COMSPEC\" | ||
| 2987 | environment variable. | ||
| 2988 | |||
| 2989 | This function returns `unknown' for programs whose file names | ||
| 2990 | include characters not supported by the current ANSI codepage, as | ||
| 2991 | such programs cannot be invoked by Emacs anyway. */) | ||
| 2992 | (Lisp_Object program) | ||
| 2993 | { | ||
| 2994 | int is_dos_app, is_cygwin_app, is_msys_app, dummy; | ||
| 2995 | Lisp_Object encoded_progname; | ||
| 2996 | char *progname, progname_a[MAX_PATH]; | ||
| 2997 | |||
| 2998 | program = Fexpand_file_name (program, Qnil); | ||
| 2999 | encoded_progname = ENCODE_FILE (program); | ||
| 3000 | progname = SDATA (encoded_progname); | ||
| 3001 | unixtodos_filename (progname); | ||
| 3002 | filename_to_ansi (progname, progname_a); | ||
| 3003 | /* Reject file names that cannot be encoded in the current ANSI | ||
| 3004 | codepage. */ | ||
| 3005 | if (_mbspbrk (progname_a, "?")) | ||
| 3006 | return Qunknown; | ||
| 3007 | |||
| 3008 | if (w32_executable_type (progname_a, &is_dos_app, &is_cygwin_app, | ||
| 3009 | &is_msys_app, &dummy) != 0) | ||
| 3010 | return Qunknown; | ||
| 3011 | if (is_dos_app) | ||
| 3012 | return Qdos; | ||
| 3013 | if (is_cygwin_app) | ||
| 3014 | return Qcygwin; | ||
| 3015 | if (is_msys_app) | ||
| 3016 | return Qmsys; | ||
| 3017 | return Qw32_native; | ||
| 3018 | } | ||
| 3019 | |||
| 2950 | #ifdef HAVE_LANGINFO_CODESET | 3020 | #ifdef HAVE_LANGINFO_CODESET |
| 2951 | /* Emulation of nl_langinfo. Used in fns.c:Flocale_info. */ | 3021 | /* Emulation of nl_langinfo. Used in fns.c:Flocale_info. */ |
| 2952 | char * | 3022 | char * |
| @@ -3541,6 +3611,9 @@ syms_of_ntproc (void) | |||
| 3541 | { | 3611 | { |
| 3542 | DEFSYM (Qhigh, "high"); | 3612 | DEFSYM (Qhigh, "high"); |
| 3543 | DEFSYM (Qlow, "low"); | 3613 | DEFSYM (Qlow, "low"); |
| 3614 | DEFSYM (Qcygwin, "cygwin"); | ||
| 3615 | DEFSYM (Qmsys, "msys"); | ||
| 3616 | DEFSYM (Qw32_native, "w32-native"); | ||
| 3544 | 3617 | ||
| 3545 | defsubr (&Sw32_has_winsock); | 3618 | defsubr (&Sw32_has_winsock); |
| 3546 | defsubr (&Sw32_unload_winsock); | 3619 | defsubr (&Sw32_unload_winsock); |
| @@ -3548,6 +3621,7 @@ syms_of_ntproc (void) | |||
| 3548 | defsubr (&Sw32_short_file_name); | 3621 | defsubr (&Sw32_short_file_name); |
| 3549 | defsubr (&Sw32_long_file_name); | 3622 | defsubr (&Sw32_long_file_name); |
| 3550 | defsubr (&Sw32_set_process_priority); | 3623 | defsubr (&Sw32_set_process_priority); |
| 3624 | defsubr (&Sw32_application_type); | ||
| 3551 | defsubr (&Sw32_get_locale_info); | 3625 | defsubr (&Sw32_get_locale_info); |
| 3552 | defsubr (&Sw32_get_current_locale_id); | 3626 | defsubr (&Sw32_get_current_locale_id); |
| 3553 | defsubr (&Sw32_get_default_locale_id); | 3627 | defsubr (&Sw32_get_default_locale_id); |