aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
authorKaroly Lorentey2004-04-18 01:34:11 +0000
committerKaroly Lorentey2004-04-18 01:34:11 +0000
commit9002956fd888928dcca6ba30bbb90c739741377a (patch)
tree2f03e3b645c290e3ac909d999fbfec3cb0fd56ad /lib-src
parent6839f1e289a61989536a4f45922cc60083a3ca19 (diff)
downloademacs-9002956fd888928dcca6ba30bbb90c739741377a.tar.gz
emacs-9002956fd888928dcca6ba30bbb90c739741377a.zip
Another server.el overhaul.
lib-src/emacsclient.c (xstrdup): New function. (quote_argument): Use xmalloc, not malloc. (main): Send environment variable values. lisp/server.el (server-clients): Documentation update. (server-ttys, server-frames): Removed. (server-client, server-client-get, server-client-set) (server-clients-with, server-add-client) (server-delete-client): New functions. (server-sentinel, server-handle-suspend-tty) (server-handle-delete-tty, server-handle-delete-frame) (server-start, server-process-filter, server-visit-files) (server-buffer-done, server-kill-buffer-query-function) (server-kill-emacs-query-function, server-switch-buffer): Use them. (server-log): Handle both kinds of client references. (server-start): Set up all hooks here. (server-process-filter): Cleanup. Store version in client. Handle -env commands for passing environment variable values. (server-buffer-done): Don't close clients that were created bufferless. (server-switch-buffer): Only look at frameless clients. Don't switch away from current buffer if there is no next-buffer. (server-unload-hook): Remove frame/tty hooks, too. lisp/server.el (server-quote-arg, server-unquote-arg) (server-process-filter, server-kill-buffer-query-function) (server-kill-emacs-query-function): Doc update. (server-buffer-done, server-switch-buffer): Use buffer-live-p, not buffer-name. git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-143
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/emacsclient.c77
1 files changed, 57 insertions, 20 deletions
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index 79642cbe47e..b86277844c9 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -212,6 +212,35 @@ Report bugs to bug-gnu-emacs@gnu.org.\n", progname);
212 exit (0); 212 exit (0);
213} 213}
214 214
215/* Like malloc but get fatal error if memory is exhausted. */
216
217long *
218xmalloc (size)
219 unsigned int size;
220{
221 long *result = (long *) malloc (size);
222 if (result == NULL)
223 {
224 perror ("malloc");
225 exit (1);
226 }
227 return result;
228}
229
230/* Like strdup but get a fatal error if memory is exhausted. */
231
232char *
233xstrdup (const char *s)
234{
235 char *result = strdup (s);
236 if (result == NULL)
237 {
238 perror ("strdup");
239 exit (1);
240 }
241 return result;
242}
243
215/* In STR, insert a & before each &, each space, each newline, and 244/* In STR, insert a & before each &, each space, each newline, and
216 any initial -. Change spaces to underscores, too, so that the 245 any initial -. Change spaces to underscores, too, so that the
217 return value never contains a space. 246 return value never contains a space.
@@ -223,7 +252,7 @@ quote_argument (str, stream)
223 char *str; 252 char *str;
224 FILE *stream; 253 FILE *stream;
225{ 254{
226 char *copy = (char *) malloc (strlen (str) * 2 + 1); 255 char *copy = (char *) xmalloc (strlen (str) * 2 + 1);
227 char *p, *q; 256 char *p, *q;
228 257
229 p = str; 258 p = str;
@@ -291,20 +320,6 @@ unquote_argument (str)
291 return str; 320 return str;
292} 321}
293 322
294/* Like malloc but get fatal error if memory is exhausted. */
295
296long *
297xmalloc (size)
298 unsigned int size;
299{
300 long *result = (long *) malloc (size);
301 if (result == NULL)
302 {
303 perror ("malloc");
304 exit (1);
305 }
306 return result;
307}
308 323
309/* 324/*
310 Try to run a different command, or --if no alternate editor is 325 Try to run a different command, or --if no alternate editor is
@@ -610,11 +625,11 @@ main (argc, argv)
610 /* `stat' failed */ 625 /* `stat' failed */
611 if (saved_errno == ENOENT) 626 if (saved_errno == ENOENT)
612 fprintf (stderr, 627 fprintf (stderr,
613 "%s: Can't find socket; have you started the server?\n\ 628 "%s: can't find socket; have you started the server?\n\
614To start the server in Emacs, type \"M-x server-start\".\n", 629To start the server in Emacs, type \"M-x server-start\".\n",
615 argv[0]); 630 argv[0]);
616 else 631 else
617 fprintf (stderr, "%s: Can't stat %s: %s\n", 632 fprintf (stderr, "%s: can't stat %s: %s\n",
618 argv[0], server.sun_path, strerror (saved_errno)); 633 argv[0], server.sun_path, strerror (saved_errno));
619 fail (); 634 fail ();
620 break; 635 break;
@@ -629,7 +644,7 @@ To start the server in Emacs, type \"M-x server-start\".\n",
629 fail (); 644 fail ();
630 } 645 }
631 646
632 /* We use the stream OUT to send our command to the server. */ 647 /* We use the stream OUT to send our commands to the server. */
633 if ((out = fdopen (s, "r+")) == NULL) 648 if ((out = fdopen (s, "r+")) == NULL)
634 { 649 {
635 fprintf (stderr, "%s: ", argv[0]); 650 fprintf (stderr, "%s: ", argv[0]);
@@ -637,7 +652,7 @@ To start the server in Emacs, type \"M-x server-start\".\n",
637 fail (); 652 fail ();
638 } 653 }
639 654
640 /* We use the stream IN to read the response. 655 /* We use the stream IN to read the responses.
641 We used to use just one stream for both output and input 656 We used to use just one stream for both output and input
642 on the socket, but reversing direction works nonportably: 657 on the socket, but reversing direction works nonportably:
643 on some systems, the output appears as the first input; 658 on some systems, the output appears as the first input;
@@ -660,7 +675,7 @@ To start the server in Emacs, type \"M-x server-start\".\n",
660 675
661#ifdef HAVE_GETCWD 676#ifdef HAVE_GETCWD
662 fprintf (stderr, "%s: %s (%s)\n", argv[0], 677 fprintf (stderr, "%s: %s (%s)\n", argv[0],
663 "Cannot get current working directory", strerror (errno)); 678 "cannot get current working directory", strerror (errno));
664#else 679#else
665 fprintf (stderr, "%s: %s (%s)\n", argv[0], string, strerror (errno)); 680 fprintf (stderr, "%s: %s (%s)\n", argv[0], string, strerror (errno));
666#endif 681#endif
@@ -670,6 +685,28 @@ To start the server in Emacs, type \"M-x server-start\".\n",
670 /* First of all, send our version number for verification. */ 685 /* First of all, send our version number for verification. */
671 fprintf (out, "-version %s ", VERSION); 686 fprintf (out, "-version %s ", VERSION);
672 687
688 /* Send over our environment. */
689 {
690 extern char **environ;
691 int i;
692 for (i = 0; environ[i]; i++)
693 {
694 char *name = xstrdup (environ[i]);
695 char *value = strchr (name, '=');
696 if (value && strlen (value) > 1)
697 {
698 *value++ = 0;
699 fprintf (out, "-env ");
700 quote_argument (name, out);
701 fprintf (out, " ");
702 quote_argument (value, out);
703 fprintf (out, " ");
704 fflush (out);
705 }
706 free (name);
707 }
708 }
709
673 if (nowait) 710 if (nowait)
674 fprintf (out, "-nowait "); 711 fprintf (out, "-nowait ");
675 712