/* Process support for GNU Emacs on the Microsoft W32 API.
- Copyright (C) 1992, 1995 Free Software Foundation, Inc.
+ Copyright (C) 1992, 1995, 1999, 2000, 2001 Free Software Foundation, Inc.
This file is part of GNU Emacs.
#undef kill
#include <windows.h>
+#ifdef __GNUC__
+/* This definition is missing from mingw32 headers. */
+extern BOOL WINAPI IsValidLocale(LCID, DWORD);
+#endif
#include "lisp.h"
#include "w32.h"
#include "systime.h"
#include "syswait.h"
#include "process.h"
+#include "syssignal.h"
#include "w32term.h"
/* Control whether spawnve quotes arguments as necessary to ensure
Lisp_Object Qhigh, Qlow;
-#ifndef SYS_SIGLIST_DECLARED
-extern char *sys_siglist[];
-#endif
-
#ifdef EMACSDEBUG
void _DebPrint (const char *fmt, ...)
{
static char * process_dir;
static BOOL
-create_child (char *exe, char *cmdline, char *env,
+create_child (char *exe, char *cmdline, char *env, int is_gui_app,
int * pPid, child_process *cp)
{
STARTUPINFO start;
SECURITY_ATTRIBUTES sec_attrs;
+#if 0
SECURITY_DESCRIPTOR sec_desc;
+#endif
DWORD flags;
char dir[ MAXPATHLEN ];
start.cb = sizeof (start);
#ifdef HAVE_NTGUI
- if (NILP (Vw32_start_process_show_window))
+ if (NILP (Vw32_start_process_show_window) && !is_gui_app)
start.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
else
start.dwFlags = STARTF_USESTDHANDLES;
start.hStdError = GetStdHandle (STD_ERROR_HANDLE);
#endif /* HAVE_NTGUI */
+#if 0
/* Explicitly specify no security */
if (!InitializeSecurityDescriptor (&sec_desc, SECURITY_DESCRIPTOR_REVISION))
goto EH_Fail;
if (!SetSecurityDescriptorDacl (&sec_desc, TRUE, NULL, FALSE))
goto EH_Fail;
+#endif
sec_attrs.nLength = sizeof (sec_attrs);
- sec_attrs.lpSecurityDescriptor = &sec_desc;
+ sec_attrs.lpSecurityDescriptor = NULL /* &sec_desc */;
sec_attrs.bInheritHandle = FALSE;
strcpy (dir, process_dir);
else if (WIFSIGNALED (retval))
{
int code = WTERMSIG (retval);
- char *signame = 0;
-
- if (code < NSIG)
- {
- /* Suppress warning if the table has const char *. */
- signame = (char *) sys_siglist[code];
- }
+ char *signame;
+
+ synchronize_system_messages_locale ();
+ signame = strsignal (code);
+
if (signame == 0)
signame = "unknown";
}
void
-w32_executable_type (char * filename, int * is_dos_app, int * is_cygnus_app)
+w32_executable_type (char * filename, int * is_dos_app, int * is_cygnus_app, int * is_gui_app)
{
file_data executable;
char * p;
/* Default values in case we can't tell for sure. */
*is_dos_app = FALSE;
*is_cygnus_app = FALSE;
+ *is_gui_app = FALSE;
if (!open_input_file (&executable, filename))
return;
extension, which is defined in the registry. */
p = egetenv ("COMSPEC");
if (p)
- w32_executable_type (p, is_dos_app, is_cygnus_app);
+ w32_executable_type (p, is_dos_app, is_cygnus_app, is_gui_app);
}
else
{
break;
}
}
+
+ /* Check whether app is marked as a console or windowed (aka
+ GUI) app. Accept Posix and OS2 subsytem apps as console
+ apps. */
+ *is_gui_app = (nt_header->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI);
}
}
}
int
-compare_env (const char **strp1, const char **strp2)
+compare_env (const void *strp1, const void *strp2)
{
- const char *str1 = *strp1, *str2 = *strp2;
+ const char *str1 = *(const char **)strp1, *str2 = *(const char **)strp2;
while (*str1 && *str2 && *str1 != '=' && *str2 != '=')
{
- if (tolower (*str1) > tolower (*str2))
+ /* Sort order in command.com/cmd.exe is based on uppercasing
+ names, so do the same here. */
+ if (toupper (*str1) > toupper (*str2))
return 1;
- else if (tolower (*str1) < tolower (*str2))
+ else if (toupper (*str1) < toupper (*str2))
return -1;
str1++, str2++;
}
int arglen, numenv;
int pid;
child_process *cp;
- int is_dos_app, is_cygnus_app;
+ int is_dos_app, is_cygnus_app, is_gui_app;
int do_quoting = 0;
char escape_char;
/* We pass our process ID to our children by setting up an environment
variable in their environment. */
char ppid_env_var_buffer[64];
char *extra_env[] = {ppid_env_var_buffer, NULL};
+ char *sepchars = " \t";
/* We don't care about the other modes */
if (mode != _P_NOWAIT)
full = Qnil;
GCPRO1 (program);
- openp (Vexec_path, program, EXEC_SUFFIXES, &full, 1);
+ openp (Vexec_path, program, Vexec_suffixes, &full, 1);
UNGCPRO;
if (NILP (full))
{
executable that is implicitly linked to the Cygnus dll (implying it
was compiled with the Cygnus GNU toolchain and hence relies on
cygwin.dll to parse the command line - we use this to decide how to
- escape quote chars in command line args that must be quoted). */
- w32_executable_type (cmdname, &is_dos_app, &is_cygnus_app);
+ escape quote chars in command line args that must be quoted).
+
+ Also determine whether it is a GUI app, so that we don't hide its
+ initial window unless specifically requested. */
+ w32_executable_type (cmdname, &is_dos_app, &is_cygnus_app, &is_gui_app);
/* On Windows 95, if cmdname is a DOS app, we invoke a helper
application to start it by specifying the helper app as cmdname,
escape_char = is_cygnus_app ? '"' : '\\';
}
+ /* Cygwin apps needs quoting a bit more often */
+ if (escape_char == '"')
+ sepchars = "\r\n\t\f '";
+
/* do argv... */
arglen = 0;
targ = argv;
need_quotes = 1;
for ( ; *p; p++)
{
- if (*p == '"')
+ if (escape_char == '"' && *p == '\\')
+ /* If it's a Cygwin app, \ needs to be escaped. */
+ arglen++;
+ else if (*p == '"')
{
/* allow for embedded quotes to be escaped */
arglen++;
arglen += escape_char_run;
}
}
- else if (*p == ' ' || *p == '\t')
+ else if (strchr (sepchars, *p) != NULL)
{
need_quotes = 1;
}
if (do_quoting)
{
for ( ; *p; p++)
- if (*p == ' ' || *p == '\t' || *p == '"')
+ if ((strchr (sepchars, *p) != NULL) || *p == '"')
need_quotes = 1;
}
if (need_quotes)
/* escape all quote chars, even at beginning or end */
*parg++ = escape_char;
}
+ else if (escape_char == '"' && *p == '\\')
+ *parg++ = '\\';
*parg++ = *p;
if (*p == escape_char && escape_char != '"')
}
/* Now create the process. */
- if (!create_child (cmdname, cmdline, env, &pid, cp))
+ if (!create_child (cmdname, cmdline, env, is_gui_app, &pid, cp))
{
delete_child (cp);
errno = ENOEXEC;
/* Substitute for certain kill () operations */
static BOOL CALLBACK
-find_child_console (HWND hwnd, child_process * cp)
+find_child_console (HWND hwnd, LPARAM arg)
{
+ child_process * cp = (child_process *) arg;
DWORD thread_id;
DWORD process_id;
EnumWindows (find_child_console, (LPARAM) cp);
}
- if (sig == SIGINT)
+ if (sig == SIGINT || sig == SIGQUIT)
{
if (NILP (Vw32_start_process_share_console) && cp && cp->hwnd)
{
BYTE control_scan_code = (BYTE) MapVirtualKey (VK_CONTROL, 0);
- BYTE vk_break_code = VK_CANCEL;
+ /* Fake Ctrl-C for SIGINT, and Ctrl-Break for SIGQUIT. */
+ BYTE vk_break_code = (sig == SIGINT) ? 'C' : VK_CANCEL;
BYTE break_scan_code = (BYTE) MapVirtualKey (vk_break_code, 0);
HWND foreground_window;
if (break_scan_code == 0)
{
- /* Fake Ctrl-C if we can't manage Ctrl-Break. */
+ /* Fake Ctrl-C for SIGQUIT if we can't manage Ctrl-Break. */
vk_break_code = 'C';
break_scan_code = (BYTE) MapVirtualKey (vk_break_code, 0);
}
{
char shortname[MAX_PATH];
- CHECK_STRING (filename, 0);
+ CHECK_STRING (filename);
/* first expand it. */
filename = Fexpand_file_name (filename, Qnil);
{
char longname[ MAX_PATH ];
- CHECK_STRING (filename, 0);
+ CHECK_STRING (filename);
/* first expand it. */
filename = Fexpand_file_name (filename, Qnil);
DWORD priority_class = NORMAL_PRIORITY_CLASS;
Lisp_Object result = Qnil;
- CHECK_SYMBOL (priority, 0);
+ CHECK_SYMBOL (priority);
if (!NILP (process))
{
DWORD pid;
child_process *cp;
- CHECK_NUMBER (process, 0);
+ CHECK_NUMBER (process);
/* Allow pid to be an internally generated one, or one obtained
externally. This is necessary because real pids on Win95 are
char abbrev_name[32] = { 0 };
char full_name[256] = { 0 };
- CHECK_NUMBER (lcid, 0);
+ CHECK_NUMBER (lcid);
if (!IsValidLocale (XINT (lcid), LCID_SUPPORTED))
return Qnil;
(lcid)
Lisp_Object lcid;
{
- CHECK_NUMBER (lcid, 0);
+ CHECK_NUMBER (lcid);
if (!IsValidLocale (XINT (lcid), LCID_SUPPORTED))
return Qnil;
(cp)
Lisp_Object cp;
{
- CHECK_NUMBER (cp, 0);
+ CHECK_NUMBER (cp);
if (!IsValidCodePage (XINT (cp)))
return Qnil;
(cp)
Lisp_Object cp;
{
- CHECK_NUMBER (cp, 0);
+ CHECK_NUMBER (cp);
if (!IsValidCodePage (XINT (cp)))
return Qnil;
{
CHARSETINFO info;
- CHECK_NUMBER (cp, 0);
+ CHECK_NUMBER (cp);
if (!IsValidCodePage (XINT (cp)))
return Qnil;
{
DWORD kl;
- CHECK_CONS (layout, 0);
- CHECK_NUMBER (XCONS (layout)->car, 0);
- CHECK_NUMBER (XCONS (layout)->cdr, 0);
+ CHECK_CONS (layout);
+ CHECK_NUMBER_CAR (layout);
+ CHECK_NUMBER_CDR (layout);
- kl = (XINT (XCONS (layout)->car) & 0xffff)
- | (XINT (XCONS (layout)->cdr) << 16);
+ kl = (XINT (XCAR (layout)) & 0xffff)
+ | (XINT (XCDR (layout)) << 16);
/* Synchronize layout with input thread. */
if (dwWindowsThreadId)
DEFVAR_LISP ("w32-start-process-show-window",
&Vw32_start_process_show_window,
"When nil, new child processes hide their windows.\n\
-When non-nil, they show their window in the method of their choice.");
+When non-nil, they show their window in the method of their choice.\n\
+This variable doesn't affect GUI applications, which will never be hidden.");
Vw32_start_process_show_window = Qnil;
DEFVAR_LISP ("w32-start-process-share-console",
DEFVAR_LISP ("w32-downcase-file-names", &Vw32_downcase_file_names,
"Non-nil means convert all-upper case file names to lower case.\n\
-This applies when performing completions and file name expansion.");
+This applies when performing completions and file name expansion.\n\
+Note that the value of this setting also affects remote file names,\n\
+so you probably don't want to set to non-nil if you use case-sensitive\n\
+filesystems via ange-ftp.");
Vw32_downcase_file_names = Qnil;
#if 0