summaryrefslogtreecommitdiff
path: root/lib-src
diff options
context:
space:
mode:
authorAndreas Schwab <schwab@linux-m68k.org>2012-03-11 12:49:59 +0100
committerAndreas Schwab <schwab@linux-m68k.org>2012-03-11 12:49:59 +0100
commit2b84f674cce046d8155dd8098286800b471f0f4c (patch)
treece6d5c4e4d6db2c40361b81971548a16cc2414d2 /lib-src
parent6b0c89847a6291b41f73658a4a9c5d54761b2ab9 (diff)
downloademacs-2b84f674cce046d8155dd8098286800b471f0f4c.tar.gz
* emacsclient.c (main): Handle multiple messages in a single
datagram.
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/ChangeLog3
-rw-r--r--lib-src/emacsclient.c109
2 files changed, 59 insertions, 53 deletions
diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog
index b349533f87f..1478b3715f1 100644
--- a/lib-src/ChangeLog
+++ b/lib-src/ChangeLog
@@ -1,5 +1,8 @@
2012-03-11 Andreas Schwab <schwab@linux-m68k.org>
+ * emacsclient.c (main): Handle multiple messages in a single
+ datagram.
+
* emacsclient.c (socket_name): Add const.
(get_server_config): Add parameter config_file, use it instead of
global server_file.
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index 8779309f9b3..97ae029751d 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -1768,7 +1768,7 @@ main (int argc, char **argv)
/* Now, wait for an answer and print any messages. */
while (exit_status == EXIT_SUCCESS)
{
- char *p;
+ char *p, *end_p;
do
{
errno = 0;
@@ -1783,61 +1783,64 @@ main (int argc, char **argv)
string[rl] = '\0';
- p = string + strlen (string) - 1;
- while (p > string && *p == '\n')
- *p-- = 0;
+ /* Loop over all NL-terminated messages. */
+ for (end_p = p = string; end_p != NULL && *end_p != '\0'; p = end_p)
+ {
+ end_p = strchr (p, '\n');
+ if (end_p != NULL)
+ *end_p++ = '\0';
- if (strprefix ("-emacs-pid ", string))
- {
- /* -emacs-pid PID: The process id of the Emacs process. */
- emacs_pid = strtol (string + strlen ("-emacs-pid"), NULL, 10);
- }
- else if (strprefix ("-window-system-unsupported ", string))
- {
- /* -window-system-unsupported: Emacs was compiled without X
- support. Try again on the terminal. */
- nowait = 0;
- tty = 1;
- goto retry;
- }
- else if (strprefix ("-print ", string))
- {
- /* -print STRING: Print STRING on the terminal. */
- str = unquote_argument (string + strlen ("-print "));
- if (needlf)
- printf ("\n");
- printf ("%s", str);
- needlf = str[0] == '\0' ? needlf : str[strlen (str) - 1] != '\n';
- }
- else if (strprefix ("-error ", string))
- {
- /* -error DESCRIPTION: Signal an error on the terminal. */
- str = unquote_argument (string + strlen ("-error "));
- if (needlf)
- printf ("\n");
- fprintf (stderr, "*ERROR*: %s", str);
- needlf = str[0] == '\0' ? needlf : str[strlen (str) - 1] != '\n';
- exit_status = EXIT_FAILURE;
- }
+ if (strprefix ("-emacs-pid ", p))
+ {
+ /* -emacs-pid PID: The process id of the Emacs process. */
+ emacs_pid = strtol (p + strlen ("-emacs-pid"), NULL, 10);
+ }
+ else if (strprefix ("-window-system-unsupported ", p))
+ {
+ /* -window-system-unsupported: Emacs was compiled without X
+ support. Try again on the terminal. */
+ nowait = 0;
+ tty = 1;
+ goto retry;
+ }
+ else if (strprefix ("-print ", p))
+ {
+ /* -print STRING: Print STRING on the terminal. */
+ str = unquote_argument (p + strlen ("-print "));
+ if (needlf)
+ printf ("\n");
+ printf ("%s", str);
+ needlf = str[0] == '\0' ? needlf : str[strlen (str) - 1] != '\n';
+ }
+ else if (strprefix ("-error ", p))
+ {
+ /* -error DESCRIPTION: Signal an error on the terminal. */
+ str = unquote_argument (p + strlen ("-error "));
+ if (needlf)
+ printf ("\n");
+ fprintf (stderr, "*ERROR*: %s", str);
+ needlf = str[0] == '\0' ? needlf : str[strlen (str) - 1] != '\n';
+ exit_status = EXIT_FAILURE;
+ }
#ifdef SIGSTOP
- else if (strprefix ("-suspend ", string))
- {
- /* -suspend: Suspend this terminal, i.e., stop the process. */
- if (needlf)
- printf ("\n");
- needlf = 0;
- kill (0, SIGSTOP);
- }
+ else if (strprefix ("-suspend ", p))
+ {
+ /* -suspend: Suspend this terminal, i.e., stop the process. */
+ if (needlf)
+ printf ("\n");
+ needlf = 0;
+ kill (0, SIGSTOP);
+ }
#endif
- else
- {
- /* Unknown command. */
- if (needlf)
- printf ("\n");
- printf ("*ERROR*: Unknown message: %s", string);
- needlf = string[0]
- == '\0' ? needlf : string[strlen (string) - 1] != '\n';
- }
+ else
+ {
+ /* Unknown command. */
+ if (needlf)
+ printf ("\n");
+ needlf = 0;
+ printf ("*ERROR*: Unknown message: %s\n", p);
+ }
+ }
}
if (needlf)