char *getenv (), *getwd ();
char *getcwd ();
-/* This is defined with -D from the compilation command,
- which extracts it from ../lisp/version.el. */
-
#ifndef VERSION
#define VERSION "unspecified"
#endif
case 'V':
printf ("emacsclient %s\n", VERSION);
- exit (0);
+ exit (EXIT_SUCCESS);
break;
case 't':
default:
fprintf (stderr, "Try `%s --help' for more information\n", progname);
- exit (1);
+ exit (EXIT_FAILURE);
break;
}
}
Editor to fallback to if the server is not running\n\
\n\
Report bugs to bug-gnu-emacs@gnu.org.\n", progname);
- exit (0);
+ exit (EXIT_SUCCESS);
+}
+
+/* Like malloc but get fatal error if memory is exhausted. */
+
+long *
+xmalloc (size)
+ unsigned int size;
+{
+ long *result = (long *) malloc (size);
+ if (result == NULL)
+ {
+ perror ("malloc");
+ exit (EXIT_FAILURE);
+ }
+ return result;
+}
+
+/* Like strdup but get a fatal error if memory is exhausted. */
+
+char *
+xstrdup (const char *s)
+{
+ char *result = strdup (s);
+ if (result == NULL)
+ {
+ perror ("strdup");
+ exit (EXIT_FAILURE);
+ }
+ return result;
}
/* In STR, insert a & before each &, each space, each newline, and
char *str;
FILE *stream;
{
- char *copy = (char *) malloc (strlen (str) * 2 + 1);
+ char *copy = (char *) xmalloc (strlen (str) * 2 + 1);
char *p, *q;
p = str;
}
*q++ = 0;
- fprintf (stream, copy);
+ fprintf (stream, "%s", copy);
free (copy);
}
return str;
}
-/* Like malloc but get fatal error if memory is exhausted. */
-
-long *
-xmalloc (size)
- unsigned int size;
-{
- long *result = (long *) malloc (size);
- if (result == NULL)
- {
- perror ("malloc");
- exit (1);
- }
- return result;
-}
\f
/*
Try to run a different command, or --if no alternate editor is
}
else
{
- exit (1);
+ exit (EXIT_FAILURE);
}
}
{
fprintf (stderr, "%s: file name or argument required\n", progname);
fprintf (stderr, "Try `%s --help' for more information\n", progname);
- exit (1);
+ exit (EXIT_FAILURE);
}
/*
{
fprintf (stderr, "%s: socket-name %s too long",
argv[0], socket_name);
- exit (1);
+ exit (EXIT_FAILURE);
}
sock_status = socket_status (server.sun_path);
/* `stat' failed */
if (saved_errno == ENOENT)
fprintf (stderr,
- "%s: Can't find socket; have you started the server?\n\
+ "%s: can't find socket; have you started the server?\n\
To start the server in Emacs, type \"M-x server-start\".\n",
argv[0]);
else
- fprintf (stderr, "%s: Can't stat %s: %s\n",
+ fprintf (stderr, "%s: can't stat %s: %s\n",
argv[0], server.sun_path, strerror (saved_errno));
fail ();
break;
fail ();
}
- /* We use the stream OUT to send our command to the server. */
+ /* We use the stream OUT to send our commands to the server. */
if ((out = fdopen (s, "r+")) == NULL)
{
fprintf (stderr, "%s: ", argv[0]);
fail ();
}
- /* We use the stream IN to read the response.
+ /* We use the stream IN to read the responses.
We used to use just one stream for both output and input
on the socket, but reversing direction works nonportably:
on some systems, the output appears as the first input;
#ifdef HAVE_GETCWD
fprintf (stderr, "%s: %s (%s)\n", argv[0],
- "Cannot get current working directory", strerror (errno));
+ "cannot get current working directory", strerror (errno));
#else
fprintf (stderr, "%s: %s (%s)\n", argv[0], string, strerror (errno));
#endif
/* First of all, send our version number for verification. */
fprintf (out, "-version %s ", VERSION);
+ /* Send over our environment. */
+ {
+ extern char **environ;
+ int i;
+ for (i = 0; environ[i]; i++)
+ {
+ char *name = xstrdup (environ[i]);
+ char *value = strchr (name, '=');
+ if (value && strlen (value) > 1)
+ {
+ *value++ = 0;
+ fprintf (out, "-env ");
+ quote_argument (name, out);
+ fprintf (out, " ");
+ quote_argument (value, out);
+ fprintf (out, " ");
+ fflush (out);
+ }
+ free (name);
+ }
+ }
+
if (nowait)
fprintf (out, "-nowait ");
fflush (out);
fsync (fileno (out));
- /* Maybe wait for an answer. */
- if (nowait)
- {
- return 0;
- }
-
- if (!eval && !tty)
+ /* Wait for an answer. */
+ if (!eval && !tty && !nowait)
{
printf ("Waiting for Emacs...");
needlf = 2;
fflush (stdout);
fsync (1);
- return 0;
+ return EXIT_SUCCESS;
}
#endif /* HAVE_SOCKETS */
/* arch-tag: f39bb9c4-73eb-477e-896d-50832e2ca9a7
(do not change this comment) */
+
+/* emacsclient.c ends here */