struct option longopts[] =
{
{ "no-wait", no_argument, NULL, 'n' },
struct option longopts[] =
{
{ "no-wait", no_argument, NULL, 'n' },
{ "eval", no_argument, NULL, 'e' },
{ "help", no_argument, NULL, 'H' },
{ "version", no_argument, NULL, 'V' },
{ "eval", no_argument, NULL, 'e' },
{ "help", no_argument, NULL, 'H' },
{ "version", no_argument, NULL, 'V' },
struct stat dotstat, pwdstat;
/* If PWD is accurate, use it instead of calling getwd. PWD is
sometimes a nicer name, and using it may avoid a fatal error if a
struct stat dotstat, pwdstat;
/* If PWD is accurate, use it instead of calling getwd. PWD is
sometimes a nicer name, and using it may avoid a fatal error if a
#define REG_ROOT "SOFTWARE\\GNU\\Emacs"
/* Retrieve an environment variable from the Emacs subkeys of the registry.
#define REG_ROOT "SOFTWARE\\GNU\\Emacs"
/* Retrieve an environment variable from the Emacs subkeys of the registry.
- This is needed to duplicate Emacs's behavior, which is to look for environment
- variables in the registry if they don't appear in the environment.
-*/
+ Value is allocated on the heap, and can be free'd.
+
+ This is needed to duplicate Emacs's behavior, which is to look for
+ environment variables in the registry if they don't appear in the
+ environment. */
- /* Found in the environment. */
- return value;
+ /* Found in the environment. strdup it, because values returned
+ by getenv cannot be free'd. */
+ return xstrdup (value);
if (! (value = w32_get_resource (HKEY_CURRENT_USER, envvar, &dwType)) &&
! (value = w32_get_resource (HKEY_LOCAL_MACHINE, envvar, &dwType)))
if (! (value = w32_get_resource (HKEY_CURRENT_USER, envvar, &dwType)) &&
! (value = w32_get_resource (HKEY_LOCAL_MACHINE, envvar, &dwType)))
/* Display a normal or error message.
On Windows, use a message box if compiled as a Windows app. */
/* Display a normal or error message.
On Windows, use a message box if compiled as a Windows app. */
- va_start (args, message);
- vsprintf (msg, message, args);
+ va_start (args, format);
+ vsprintf (msg, format, args);
/* Decode the options from argv and argc.
The global variable `optind' will say how many arguments we used up. */
/* Decode the options from argv and argc.
The global variable `optind' will say how many arguments we used up. */
decode_options (int argc, char **argv)
{
alternate_editor = egetenv ("ALTERNATE_EDITOR");
decode_options (int argc, char **argv)
{
alternate_editor = egetenv ("ALTERNATE_EDITOR");
{
int opt = getopt_long_only (argc, argv,
#ifndef NO_SOCKETS_IN_FILE_SYSTEM
{
int opt = getopt_long_only (argc, argv,
#ifndef NO_SOCKETS_IN_FILE_SYSTEM
use the current Emacs frame\n\
-e, --eval Evaluate the FILE arguments as ELisp expressions\n\
-n, --no-wait Don't wait for the server to return\n\
use the current Emacs frame\n\
-e, --eval Evaluate the FILE arguments as ELisp expressions\n\
-n, --no-wait Don't wait for the server to return\n\
-d DISPLAY, --display=DISPLAY\n\
Visit the file in the given display\n\
--parent-id=ID Open in parent window ID, via XEmbed\n"
-d DISPLAY, --display=DISPLAY\n\
Visit the file in the given display\n\
--parent-id=ID Open in parent window ID, via XEmbed\n"
defined-- exit with an errorcode.
Uses argv, but gets it from the global variable main_argv.
*/
defined-- exit with an errorcode.
Uses argv, but gets it from the global variable main_argv.
*/
/* On Windows, the socket library was historically separate from the standard
C library, so errors are handled differently. */
/* On Windows, the socket library was historically separate from the standard
C library, so errors are handled differently. */
- the data ends in "\n", or
- the buffer is full (but this shouldn't happen)
Otherwise, we just accumulate it. */
- the data ends in "\n", or
- the buffer is full (but this shouldn't happen)
Otherwise, we just accumulate it. */
quote_argument (HSOCKET s, const char *str)
{
char *copy = (char *) xmalloc (strlen (str) * 2 + 1);
quote_argument (HSOCKET s, const char *str)
{
char *copy = (char *) xmalloc (strlen (str) * 2 + 1);
/* The inverse of quote_argument. Removes quoting in string STR by
modifying the string in place. Returns STR. */
/* The inverse of quote_argument. Removes quoting in string STR by
modifying the string in place. Returns STR. */
file_name_absolute_p (const char *filename)
{
/* Sanity check, it shouldn't happen. */
file_name_absolute_p (const char *filename)
{
/* Sanity check, it shouldn't happen. */
* Read the information needed to set up a TCP comm channel with
* the Emacs server: host, port, and authentication string.
*/
* Read the information needed to set up a TCP comm channel with
* the Emacs server: host, port, and authentication string.
*/
message (FALSE, "%s: connected to remote socket at %s\n",
progname, inet_ntoa (server.sin_addr));
message (FALSE, "%s: connected to remote socket at %s\n",
progname, inet_ntoa (server.sin_addr));
and the name in TTY_NAME, and return 1. Otherwise, fail if NOABORT
is zero, or return 0 if NOABORT is non-zero. */
and the name in TTY_NAME, and return 1. Otherwise, fail if NOABORT
is zero, or return 0 if NOABORT is non-zero. */
reality, we may get a SIGTSTP on C-z. Handling this signal and
notifying Emacs about it should get things under control again. */
reality, we may get a SIGTSTP on C-z. Handling this signal and
notifying Emacs about it should get things under control again. */
if (socket_name && !strchr (socket_name, '/')
&& !strchr (socket_name, '\\'))
if (socket_name && !strchr (socket_name, '/')
&& !strchr (socket_name, '\\'))
associated with the name. This is reminiscent of the logic
that init_editfns uses to set the global Vuser_full_name. */
associated with the name. This is reminiscent of the logic
that init_editfns uses to set the global Vuser_full_name. */
- char daemon[] = "--daemon";
- char *d_argv[] = {emacs, daemon, 0 };
+ char daemon_option[] = "--daemon";
+ char *d_argv[] = {emacs, daemon_option, 0 };
- int null_socket_name, null_server_file, start_daemon_if_needed;
+ int null_socket_name IF_LINT ( = 0);
+ int null_server_file IF_LINT ( = 0);
+ int start_daemon_if_needed;
- if ((emacs_socket = set_socket (alternate_editor
- || start_daemon_if_needed)) == INVALID_SOCKET)
- if (start_daemon_if_needed)
- {
- /* Reset socket_name and server_file if they were NULL
- before the set_socket call. */
- if (null_socket_name)
- socket_name = NULL;
- if (null_server_file)
- server_file = NULL;
-
- start_daemon_and_retry_set_socket ();
- }
- else
- fail ();
+ emacs_socket = set_socket (alternate_editor || start_daemon_if_needed);
+ if (emacs_socket == INVALID_SOCKET)
+ {
+ if (! start_daemon_if_needed)
+ fail ();
+
+ /* Reset socket_name and server_file if they were NULL
+ before the set_socket call. */
+ if (null_socket_name)
+ socket_name = NULL;
+ if (null_server_file)
+ server_file = NULL;
+
+ start_daemon_and_retry_set_socket ();
+ }
send_to_emacs (emacs_socket, "\n");
/* Wait for an answer. */
send_to_emacs (emacs_socket, "\n");
/* Wait for an answer. */
- while (exit_status == EXIT_SUCCESS
- && (rl = recv (emacs_socket, string, BUFSIZ, 0)) > 0)
+ while (exit_status == EXIT_SUCCESS)
+ do
+ {
+ errno = 0;
+ rl = recv (emacs_socket, string, BUFSIZ, 0);
+ }
+ /* If we receive a signal (e.g. SIGWINCH, which we pass
+ through to Emacs), on some OSes we get EINTR and must retry. */
+ while (rl < 0 && errno == EINTR);
+
+ if (rl <= 0)
+ break;
+