annotate lib-src/emacsclient.c @ 83353:532e0a9335a9

Merged in changes from CVS trunk. Plus added lisp/term tweaks. Patches applied: * lorentey@elte.hu--2004/emacs--cvs-trunk--0--base-0 tag of miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-474 * lorentey@elte.hu--2004/emacs--cvs-trunk--0--patch-1 Add CVS metadata files. * lorentey@elte.hu--2004/emacs--cvs-trunk--0--patch-2 Update from CVS. git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-393
author Karoly Lorentey <lorentey@elte.hu>
date Sun, 04 Sep 2005 03:48:17 +0000
parents afade4ccd30c 6358e3c6075c
children 2b5fb28780be
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
493
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 478
diff changeset
1 /* Client process that communicates with GNU Emacs acting as server.
64769
6358e3c6075c Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64083
diff changeset
2 Copyright (C) 1986, 1987, 1994, 1999, 2000, 2001, 2002, 2003, 2004,
6358e3c6075c Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64083
diff changeset
3 2005 Free Software Foundation, Inc.
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 This file is part of GNU Emacs.
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 GNU Emacs is free software; you can redistribute it and/or modify
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 it under the terms of the GNU General Public License as published by
5522
64a936b21f74 Don't declare sys_errlist; declare strerror instead.
Roland McGrath <roland@gnu.org>
parents: 4696
diff changeset
9 the Free Software Foundation; either version 2, or (at your option)
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 any later version.
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 GNU Emacs is distributed in the hope that it will be useful,
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 GNU General Public License for more details.
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 along with GNU Emacs; see the file COPYING. If not, write to
64083
23a17af379b1 Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 60718
diff changeset
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23a17af379b1 Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 60718
diff changeset
20 Boston, MA 02110-1301, USA. */
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 #define NO_SHORTNAMES
42176
1f5dbeefa536 Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 39723
diff changeset
24
1f5dbeefa536 Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 39723
diff changeset
25 #ifdef HAVE_CONFIG_H
42412
83c1951257f1 Include <config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 42176
diff changeset
26 #include <config.h>
42176
1f5dbeefa536 Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 39723
diff changeset
27 #endif
1f5dbeefa536 Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 39723
diff changeset
28
3595
e10f7473d2e3 * emacsserver.c (main): When we're passing a `struct sockaddr_un'
Jim Blandy <jimb@redhat.com>
parents: 1031
diff changeset
29 #undef signal
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30
42176
1f5dbeefa536 Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 39723
diff changeset
31 #include <ctype.h>
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
32 #include <stdio.h>
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
33 #include <getopt.h>
21431
a080769e8f7d Move inclusion of unistd.h to top, else fails on
Dave Love <fx@gnu.org>
parents: 21387
diff changeset
34 #ifdef HAVE_UNISTD_H
a080769e8f7d Move inclusion of unistd.h to top, else fails on
Dave Love <fx@gnu.org>
parents: 21387
diff changeset
35 #include <unistd.h>
a080769e8f7d Move inclusion of unistd.h to top, else fails on
Dave Love <fx@gnu.org>
parents: 21387
diff changeset
36 #endif
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
38 #ifdef VMS
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
39 # include "vms-pwd.h"
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
40 #else
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
41 # include <pwd.h>
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
42 #endif /* not VMS */
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
43
82995
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
44 #include <signal.h>
53229
33c3c7c16e13 lib-src/emacsclient.c: Implemented --here option (open a new Emacs tty). Needs more work.
Karoly Lorentey <lorentey@elte.hu>
parents: 52848
diff changeset
45 #include <errno.h>
33c3c7c16e13 lib-src/emacsclient.c: Implemented --here option (open a new Emacs tty). Needs more work.
Karoly Lorentey <lorentey@elte.hu>
parents: 52848
diff changeset
46
33c3c7c16e13 lib-src/emacsclient.c: Implemented --here option (open a new Emacs tty). Needs more work.
Karoly Lorentey <lorentey@elte.hu>
parents: 52848
diff changeset
47
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
48 char *getenv (), *getwd ();
60718
96023ae0af92 * emacsclient.c: Avoid expansion of getcwd when defined as a macro.
Jan Djärv <jan.h.d@swipnet.se>
parents: 56446
diff changeset
49 char *(getcwd) ();
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
50
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
51 #ifndef VERSION
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
52 #define VERSION "unspecified"
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
53 #endif
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
54
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
55 /* Name used to invoke this program. */
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
56 char *progname;
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
57
53341
d4e6a050c9b1 Bugfix festival.
Karoly Lorentey <lorentey@elte.hu>
parents: 53233
diff changeset
58 /* The first argument to main. */
d4e6a050c9b1 Bugfix festival.
Karoly Lorentey <lorentey@elte.hu>
parents: 53233
diff changeset
59 int main_argc;
d4e6a050c9b1 Bugfix festival.
Karoly Lorentey <lorentey@elte.hu>
parents: 53233
diff changeset
60
d4e6a050c9b1 Bugfix festival.
Karoly Lorentey <lorentey@elte.hu>
parents: 53233
diff changeset
61 /* The second argument to main. */
d4e6a050c9b1 Bugfix festival.
Karoly Lorentey <lorentey@elte.hu>
parents: 53233
diff changeset
62 char **main_argv;
d4e6a050c9b1 Bugfix festival.
Karoly Lorentey <lorentey@elte.hu>
parents: 53233
diff changeset
63
16146
a649abfefbb1 (longopts): Change nowait to no-wait.
Richard M. Stallman <rms@gnu.org>
parents: 16074
diff changeset
64 /* Nonzero means don't wait for a response from Emacs. --no-wait. */
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
65 int nowait = 0;
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
66
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
67 /* Nonzero means args are expressions to be evaluated. --eval. */
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
68 int eval = 0;
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
69
83043
78a785f205ea Added -w option to emacsclient for opening a new X frame.
Karoly Lorentey <lorentey@elte.hu>
parents: 83037
diff changeset
70 /* Nonzero means open a new graphical frame. */
78a785f205ea Added -w option to emacsclient for opening a new X frame.
Karoly Lorentey <lorentey@elte.hu>
parents: 83037
diff changeset
71 int window_system = 0;
78a785f205ea Added -w option to emacsclient for opening a new X frame.
Karoly Lorentey <lorentey@elte.hu>
parents: 83037
diff changeset
72
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
73 /* The display on which Emacs should work. --display. */
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
74 char *display = NULL;
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
75
53229
33c3c7c16e13 lib-src/emacsclient.c: Implemented --here option (open a new Emacs tty). Needs more work.
Karoly Lorentey <lorentey@elte.hu>
parents: 52848
diff changeset
76 /* Nonzero means open a new Emacs frame on the current terminal. */
83043
78a785f205ea Added -w option to emacsclient for opening a new X frame.
Karoly Lorentey <lorentey@elte.hu>
parents: 83037
diff changeset
77 int tty = 0;
53229
33c3c7c16e13 lib-src/emacsclient.c: Implemented --here option (open a new Emacs tty). Needs more work.
Karoly Lorentey <lorentey@elte.hu>
parents: 52848
diff changeset
78
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
79 /* If non-NULL, the name of an editor to fallback to if the server
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
80 is not running. --alternate-editor. */
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
81 const char * alternate_editor = NULL;
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
82
52532
cd53bfef4ab1 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 52479
diff changeset
83 /* If non-NULL, the filename of the UNIX socket. */
52479
bc2610a13fbf (socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
84 char *socket_name = NULL;
bc2610a13fbf (socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
85
21387
4812cf228971 Include <stdlib.h> and <unistd.h> if available.
Andreas Schwab <schwab@suse.de>
parents: 19582
diff changeset
86 void print_help_and_exit ();
4812cf228971 Include <stdlib.h> and <unistd.h> if available.
Andreas Schwab <schwab@suse.de>
parents: 19582
diff changeset
87
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
88 struct option longopts[] =
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
89 {
16146
a649abfefbb1 (longopts): Change nowait to no-wait.
Richard M. Stallman <rms@gnu.org>
parents: 16074
diff changeset
90 { "no-wait", no_argument, NULL, 'n' },
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
91 { "eval", no_argument, NULL, 'e' },
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
92 { "help", no_argument, NULL, 'H' },
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
93 { "version", no_argument, NULL, 'V' },
82994
44ffe551079c Fix longopts option name for --tty.
Karoly Lorentey <lorentey@elte.hu>
parents: 82991
diff changeset
94 { "tty", no_argument, NULL, 't' },
83045
8ca11496d25c Changed emacsclient to open new frames by default.
Karoly Lorentey <lorentey@elte.hu>
parents: 83044
diff changeset
95 { "current-frame", no_argument, NULL, 'c' },
47515
6ee937dcfe16 (quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42412
diff changeset
96 { "alternate-editor", required_argument, NULL, 'a' },
52479
bc2610a13fbf (socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
97 { "socket-name", required_argument, NULL, 's' },
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
98 { "display", required_argument, NULL, 'd' },
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
99 { 0, 0, 0, 0 }
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
100 };
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
101
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
102 /* Decode the options from argv and argc.
16061
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
103 The global variable `optind' will say how many arguments we used up. */
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
104
16061
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
105 void
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
106 decode_options (argc, argv)
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
107 int argc;
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
108 char **argv;
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
109 {
53813
ddc4b99f4f8c (decode_options): Fix handling of alternate editor.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53734
diff changeset
110 alternate_editor = getenv ("ALTERNATE_EDITOR");
83043
78a785f205ea Added -w option to emacsclient for opening a new X frame.
Karoly Lorentey <lorentey@elte.hu>
parents: 83037
diff changeset
111 display = getenv ("DISPLAY");
83052
011894b9950a Fix a crash in emacsclient when DISPLAY is unset.
Karoly Lorentey <lorentey@elte.hu>
parents: 83045
diff changeset
112 if (display && strlen (display) == 0)
83045
8ca11496d25c Changed emacsclient to open new frames by default.
Karoly Lorentey <lorentey@elte.hu>
parents: 83044
diff changeset
113 display = NULL;
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
114
83045
8ca11496d25c Changed emacsclient to open new frames by default.
Karoly Lorentey <lorentey@elte.hu>
parents: 83044
diff changeset
115 if (display)
8ca11496d25c Changed emacsclient to open new frames by default.
Karoly Lorentey <lorentey@elte.hu>
parents: 83044
diff changeset
116 window_system = 1;
8ca11496d25c Changed emacsclient to open new frames by default.
Karoly Lorentey <lorentey@elte.hu>
parents: 83044
diff changeset
117 else
8ca11496d25c Changed emacsclient to open new frames by default.
Karoly Lorentey <lorentey@elte.hu>
parents: 83044
diff changeset
118 tty = 1;
53813
ddc4b99f4f8c (decode_options): Fix handling of alternate editor.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53734
diff changeset
119
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
120 while (1)
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
121 {
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
122 int opt = getopt_long (argc, argv,
83045
8ca11496d25c Changed emacsclient to open new frames by default.
Karoly Lorentey <lorentey@elte.hu>
parents: 83044
diff changeset
123 "VHnea:s:d:tc", longopts, 0);
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
124
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
125 if (opt == EOF)
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
126 break;
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
127
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
128 switch (opt)
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
129 {
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
130 case 0:
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
131 /* If getopt returns 0, then it has already processed a
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
132 long-named option. We should do nothing. */
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
133 break;
42176
1f5dbeefa536 Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 39723
diff changeset
134
27305
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
135 case 'a':
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
136 alternate_editor = optarg;
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
137 break;
42176
1f5dbeefa536 Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 39723
diff changeset
138
52479
bc2610a13fbf (socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
139 case 's':
bc2610a13fbf (socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
140 socket_name = optarg;
bc2610a13fbf (socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
141 break;
bc2610a13fbf (socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
142
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
143 case 'd':
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
144 display = optarg;
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
145 break;
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
146
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
147 case 'n':
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
148 nowait = 1;
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
149 break;
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
150
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
151 case 'e':
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
152 eval = 1;
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
153 break;
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
154
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
155 case 'V':
50101
e5f56d47b52c (print_help_and_exit): Print to stdout. Exit successfully. Added some blank
Juanma Barranquero <lekktu@gmail.com>
parents: 48627
diff changeset
156 printf ("emacsclient %s\n", VERSION);
55442
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53813
diff changeset
157 exit (EXIT_SUCCESS);
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
158 break;
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
159
82988
f82e3a6f5ccb A few more bugfixes and new features.
Karoly Lorentey <lorentey@elte.hu>
parents: 82987
diff changeset
160 case 't':
83043
78a785f205ea Added -w option to emacsclient for opening a new X frame.
Karoly Lorentey <lorentey@elte.hu>
parents: 83037
diff changeset
161 tty = 1;
78a785f205ea Added -w option to emacsclient for opening a new X frame.
Karoly Lorentey <lorentey@elte.hu>
parents: 83037
diff changeset
162 window_system = 0;
78a785f205ea Added -w option to emacsclient for opening a new X frame.
Karoly Lorentey <lorentey@elte.hu>
parents: 83037
diff changeset
163 break;
78a785f205ea Added -w option to emacsclient for opening a new X frame.
Karoly Lorentey <lorentey@elte.hu>
parents: 83037
diff changeset
164
83045
8ca11496d25c Changed emacsclient to open new frames by default.
Karoly Lorentey <lorentey@elte.hu>
parents: 83044
diff changeset
165 case 'c':
8ca11496d25c Changed emacsclient to open new frames by default.
Karoly Lorentey <lorentey@elte.hu>
parents: 83044
diff changeset
166 window_system = 0;
83043
78a785f205ea Added -w option to emacsclient for opening a new X frame.
Karoly Lorentey <lorentey@elte.hu>
parents: 83037
diff changeset
167 tty = 0;
53229
33c3c7c16e13 lib-src/emacsclient.c: Implemented --here option (open a new Emacs tty). Needs more work.
Karoly Lorentey <lorentey@elte.hu>
parents: 52848
diff changeset
168 break;
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
169
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
170 case 'H':
50101
e5f56d47b52c (print_help_and_exit): Print to stdout. Exit successfully. Added some blank
Juanma Barranquero <lekktu@gmail.com>
parents: 48627
diff changeset
171 print_help_and_exit ();
e5f56d47b52c (print_help_and_exit): Print to stdout. Exit successfully. Added some blank
Juanma Barranquero <lekktu@gmail.com>
parents: 48627
diff changeset
172 break;
e5f56d47b52c (print_help_and_exit): Print to stdout. Exit successfully. Added some blank
Juanma Barranquero <lekktu@gmail.com>
parents: 48627
diff changeset
173
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
174 default:
50101
e5f56d47b52c (print_help_and_exit): Print to stdout. Exit successfully. Added some blank
Juanma Barranquero <lekktu@gmail.com>
parents: 48627
diff changeset
175 fprintf (stderr, "Try `%s --help' for more information\n", progname);
55442
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53813
diff changeset
176 exit (EXIT_FAILURE);
50101
e5f56d47b52c (print_help_and_exit): Print to stdout. Exit successfully. Added some blank
Juanma Barranquero <lekktu@gmail.com>
parents: 48627
diff changeset
177 break;
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
178 }
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
179 }
53229
33c3c7c16e13 lib-src/emacsclient.c: Implemented --here option (open a new Emacs tty). Needs more work.
Karoly Lorentey <lorentey@elte.hu>
parents: 52848
diff changeset
180
83043
78a785f205ea Added -w option to emacsclient for opening a new X frame.
Karoly Lorentey <lorentey@elte.hu>
parents: 83037
diff changeset
181 if (tty) {
53229
33c3c7c16e13 lib-src/emacsclient.c: Implemented --here option (open a new Emacs tty). Needs more work.
Karoly Lorentey <lorentey@elte.hu>
parents: 52848
diff changeset
182 nowait = 0;
33c3c7c16e13 lib-src/emacsclient.c: Implemented --here option (open a new Emacs tty). Needs more work.
Karoly Lorentey <lorentey@elte.hu>
parents: 52848
diff changeset
183 display = 0;
33c3c7c16e13 lib-src/emacsclient.c: Implemented --here option (open a new Emacs tty). Needs more work.
Karoly Lorentey <lorentey@elte.hu>
parents: 52848
diff changeset
184 }
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
185 }
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
186
21387
4812cf228971 Include <stdlib.h> and <unistd.h> if available.
Andreas Schwab <schwab@suse.de>
parents: 19582
diff changeset
187 void
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
188 print_help_and_exit ()
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
189 {
50101
e5f56d47b52c (print_help_and_exit): Print to stdout. Exit successfully. Added some blank
Juanma Barranquero <lekktu@gmail.com>
parents: 48627
diff changeset
190 printf (
e5f56d47b52c (print_help_and_exit): Print to stdout. Exit successfully. Added some blank
Juanma Barranquero <lekktu@gmail.com>
parents: 48627
diff changeset
191 "Usage: %s [OPTIONS] FILE...\n\
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
192 Tell the Emacs server to visit the specified files.\n\
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
193 Every FILE can be either just a FILENAME or [+LINE[:COLUMN]] FILENAME.\n\
50101
e5f56d47b52c (print_help_and_exit): Print to stdout. Exit successfully. Added some blank
Juanma Barranquero <lekktu@gmail.com>
parents: 48627
diff changeset
194 \n\
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
195 The following OPTIONS are accepted:\n\
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
196 -V, --version Just print a version info and return\n\
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
197 -H, --help Print this usage information message\n\
82988
f82e3a6f5ccb A few more bugfixes and new features.
Karoly Lorentey <lorentey@elte.hu>
parents: 82987
diff changeset
198 -t, --tty Open a new Emacs frame on the current terminal\n\
83045
8ca11496d25c Changed emacsclient to open new frames by default.
Karoly Lorentey <lorentey@elte.hu>
parents: 83044
diff changeset
199 -c, --current-frame Do not create a new frame; use the current Emacs frame\n\
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
200 -n, --no-wait Don't wait for the server to return\n\
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
201 -e, --eval Evaluate the FILE arguments as ELisp expressions\n\
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
202 -d, --display=DISPLAY Visit the file in the given display\n\
52479
bc2610a13fbf (socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
203 -s, --socket-name=FILENAME\n\
bc2610a13fbf (socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
204 Set the filename of the UNIX socket for communication\n\
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
205 -a, --alternate-editor=EDITOR\n\
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
206 Editor to fallback to if the server is not running\n\
50101
e5f56d47b52c (print_help_and_exit): Print to stdout. Exit successfully. Added some blank
Juanma Barranquero <lekktu@gmail.com>
parents: 48627
diff changeset
207 \n\
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
208 Report bugs to bug-gnu-emacs@gnu.org.\n", progname);
55442
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53813
diff changeset
209 exit (EXIT_SUCCESS);
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
210 }
16061
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
211
83103
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
212 /* Like malloc but get fatal error if memory is exhausted. */
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
213
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
214 long *
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
215 xmalloc (size)
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
216 unsigned int size;
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
217 {
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
218 long *result = (long *) malloc (size);
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
219 if (result == NULL)
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
220 {
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
221 perror ("malloc");
83121
84cafe5c268f Merged in changes from CVS trunk.
Karoly Lorentey <lorentey@elte.hu>
parents: 83107 55442
diff changeset
222 exit (EXIT_FAILURE);
83103
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
223 }
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
224 return result;
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
225 }
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
226
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
227 /* Like strdup but get a fatal error if memory is exhausted. */
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
228
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
229 char *
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
230 xstrdup (const char *s)
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
231 {
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
232 char *result = strdup (s);
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
233 if (result == NULL)
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
234 {
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
235 perror ("strdup");
83121
84cafe5c268f Merged in changes from CVS trunk.
Karoly Lorentey <lorentey@elte.hu>
parents: 83107 55442
diff changeset
236 exit (EXIT_FAILURE);
83103
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
237 }
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
238 return result;
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
239 }
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
240
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
241 /* In STR, insert a & before each &, each space, each newline, and
52848
5c74e66d6c36 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 52635
diff changeset
242 any initial -. Change spaces to underscores, too, so that the
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
243 return value never contains a space.
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
244
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
245 Does not change the string. Outputs the result to STREAM. */
16061
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
246
52635
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
247 void
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
248 quote_argument (str, stream)
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
249 char *str;
52635
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
250 FILE *stream;
16061
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
251 {
83103
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
252 char *copy = (char *) xmalloc (strlen (str) * 2 + 1);
16061
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
253 char *p, *q;
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
254
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
255 p = str;
16061
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
256 q = copy;
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
257 while (*p)
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
258 {
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
259 if (*p == ' ')
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
260 {
16074
25cfff7ffced (quote_file_name): Quote with &, not \.
Richard M. Stallman <rms@gnu.org>
parents: 16061
diff changeset
261 *q++ = '&';
16061
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
262 *q++ = '_';
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
263 p++;
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
264 }
47515
6ee937dcfe16 (quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42412
diff changeset
265 else if (*p == '\n')
6ee937dcfe16 (quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42412
diff changeset
266 {
6ee937dcfe16 (quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42412
diff changeset
267 *q++ = '&';
6ee937dcfe16 (quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42412
diff changeset
268 *q++ = 'n';
6ee937dcfe16 (quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42412
diff changeset
269 p++;
6ee937dcfe16 (quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42412
diff changeset
270 }
16061
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
271 else
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
272 {
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
273 if (*p == '&' || (*p == '-' && p == str))
16074
25cfff7ffced (quote_file_name): Quote with &, not \.
Richard M. Stallman <rms@gnu.org>
parents: 16061
diff changeset
274 *q++ = '&';
16061
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
275 *q++ = *p++;
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
276 }
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
277 }
16074
25cfff7ffced (quote_file_name): Quote with &, not \.
Richard M. Stallman <rms@gnu.org>
parents: 16061
diff changeset
278 *q++ = 0;
16061
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
279
56446
dd7afcb02186 (quote_file_name): Pass COPY thru %s to output it.
Richard M. Stallman <rms@gnu.org>
parents: 55442
diff changeset
280 fprintf (stream, "%s", copy);
52635
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
281
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
282 free (copy);
16061
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
283 }
18701
9c7e0c926ed5 [C_ALLOCA] (xmalloc): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16218
diff changeset
284
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
285
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
286 /* The inverse of quote_argument. Removes quoting in string STR by
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
287 modifying the string in place. Returns STR. */
18701
9c7e0c926ed5 [C_ALLOCA] (xmalloc): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16218
diff changeset
288
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
289 char *
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
290 unquote_argument (str)
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
291 char *str;
18701
9c7e0c926ed5 [C_ALLOCA] (xmalloc): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16218
diff changeset
292 {
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
293 char *p, *q;
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
294
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
295 if (! str)
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
296 return str;
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
297
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
298 p = str;
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
299 q = str;
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
300 while (*p)
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
301 {
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
302 if (*p == '&')
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
303 {
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
304 p++;
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
305 if (*p == '&')
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
306 *p = '&';
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
307 else if (*p == '_')
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
308 *p = ' ';
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
309 else if (*p == 'n')
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
310 *p = '\n';
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
311 else if (*p == '-')
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
312 *p = '-';
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
313 }
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
314 *q++ = *p++;
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
315 }
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
316 *q = 0;
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
317 return str;
18701
9c7e0c926ed5 [C_ALLOCA] (xmalloc): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16218
diff changeset
318 }
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
319
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
320
27305
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
321 /*
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
322 Try to run a different command, or --if no alternate editor is
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
323 defined-- exit with an errorcode.
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
324 */
37165
32679fe3e196 (fail, main): Don't use implicit int return type.
Gerd Moellmann <gerd@gnu.org>
parents: 34953
diff changeset
325 void
82988
f82e3a6f5ccb A few more bugfixes and new features.
Karoly Lorentey <lorentey@elte.hu>
parents: 82987
diff changeset
326 fail (void)
27305
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
327 {
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
328 if (alternate_editor)
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
329 {
47515
6ee937dcfe16 (quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42412
diff changeset
330 int i = optind - 1;
53341
d4e6a050c9b1 Bugfix festival.
Karoly Lorentey <lorentey@elte.hu>
parents: 53233
diff changeset
331 execvp (alternate_editor, main_argv + i);
37225
ab2a21b7b7ed (fail): Don't return a value.
Dave Love <fx@gnu.org>
parents: 37165
diff changeset
332 return;
27305
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
333 }
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
334 else
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
335 {
55442
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53813
diff changeset
336 exit (EXIT_FAILURE);
27305
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
337 }
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
338 }
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
339
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
340 /* The process id of Emacs. */
53232
22aaf1e5fbe6 Full support for multiple terminal I/O (with some rough edges).
Karoly Lorentey <lorentey@elte.hu>
parents: 53229
diff changeset
341 int emacs_pid;
53229
33c3c7c16e13 lib-src/emacsclient.c: Implemented --here option (open a new Emacs tty). Needs more work.
Karoly Lorentey <lorentey@elte.hu>
parents: 52848
diff changeset
342
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
343 /* File handles for communicating with Emacs. */
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
344 FILE *out, *in;
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
345
83025
c66ebcc29777 Removed %T in mode-line-format. Trivial documentation changes.
Karoly Lorentey <lorentey@elte.hu>
parents: 83019
diff changeset
346 /* A signal handler that passes the signal to the Emacs process.
c66ebcc29777 Removed %T in mode-line-format. Trivial documentation changes.
Karoly Lorentey <lorentey@elte.hu>
parents: 83019
diff changeset
347 Useful for SIGWINCH. */
c66ebcc29777 Removed %T in mode-line-format. Trivial documentation changes.
Karoly Lorentey <lorentey@elte.hu>
parents: 83019
diff changeset
348
53229
33c3c7c16e13 lib-src/emacsclient.c: Implemented --here option (open a new Emacs tty). Needs more work.
Karoly Lorentey <lorentey@elte.hu>
parents: 52848
diff changeset
349 SIGTYPE
83004
7900111db01c Converted display hooks to be display-local. Plus many bugfixes.
Karoly Lorentey <lorentey@elte.hu>
parents: 82995
diff changeset
350 pass_signal_to_emacs (int signalnum)
53229
33c3c7c16e13 lib-src/emacsclient.c: Implemented --here option (open a new Emacs tty). Needs more work.
Karoly Lorentey <lorentey@elte.hu>
parents: 52848
diff changeset
351 {
33c3c7c16e13 lib-src/emacsclient.c: Implemented --here option (open a new Emacs tty). Needs more work.
Karoly Lorentey <lorentey@elte.hu>
parents: 52848
diff changeset
352 int old_errno = errno;
33c3c7c16e13 lib-src/emacsclient.c: Implemented --here option (open a new Emacs tty). Needs more work.
Karoly Lorentey <lorentey@elte.hu>
parents: 52848
diff changeset
353
82995
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
354 if (emacs_pid)
83004
7900111db01c Converted display hooks to be display-local. Plus many bugfixes.
Karoly Lorentey <lorentey@elte.hu>
parents: 82995
diff changeset
355 kill (emacs_pid, signalnum);
53229
33c3c7c16e13 lib-src/emacsclient.c: Implemented --here option (open a new Emacs tty). Needs more work.
Karoly Lorentey <lorentey@elte.hu>
parents: 52848
diff changeset
356
83004
7900111db01c Converted display hooks to be display-local. Plus many bugfixes.
Karoly Lorentey <lorentey@elte.hu>
parents: 82995
diff changeset
357 signal (signalnum, pass_signal_to_emacs);
53229
33c3c7c16e13 lib-src/emacsclient.c: Implemented --here option (open a new Emacs tty). Needs more work.
Karoly Lorentey <lorentey@elte.hu>
parents: 52848
diff changeset
358 errno = old_errno;
33c3c7c16e13 lib-src/emacsclient.c: Implemented --here option (open a new Emacs tty). Needs more work.
Karoly Lorentey <lorentey@elte.hu>
parents: 52848
diff changeset
359 }
33c3c7c16e13 lib-src/emacsclient.c: Implemented --here option (open a new Emacs tty). Needs more work.
Karoly Lorentey <lorentey@elte.hu>
parents: 52848
diff changeset
360
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
361 /* Signal handler for SIGCONT; notify the Emacs process that it can
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
362 now resume our tty frame. */
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
363
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
364 SIGTYPE
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
365 handle_sigcont (int signalnum)
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
366 {
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
367 int old_errno = errno;
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
368
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
369 if (tcgetpgrp (1) == getpgrp ())
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
370 {
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
371 /* We are in the foreground. */
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
372 fprintf (out, "-resume \n");
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
373 fflush (out);
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
374 fsync (fileno (out));
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
375 }
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
376 else
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
377 {
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
378 /* We are in the background; cancel the continue. */
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
379 kill (getpid (), SIGSTOP);
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
380 }
83348
afade4ccd30c Fix broken emacsclient resume on Solaris (by Dan Nicolaescu).
Karoly Lorentey <lorentey@elte.hu>
parents: 83332
diff changeset
381
afade4ccd30c Fix broken emacsclient resume on Solaris (by Dan Nicolaescu).
Karoly Lorentey <lorentey@elte.hu>
parents: 83332
diff changeset
382 signal (signalnum, handle_sigcont);
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
383 errno = old_errno;
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
384 }
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
385
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
386 /* Signal handler for SIGTSTP; notify the Emacs process that we are
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
387 going to sleep. Normally the suspend is initiated by Emacs via
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
388 server-handle-suspend-tty, but if the server gets out of sync with
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
389 reality, we may get a SIGTSTP on C-z. Handling this signal and
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
390 notifying Emacs about it should get things under control again. */
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
391
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
392 SIGTYPE
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
393 handle_sigtstp (int signalnum)
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
394 {
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
395 int old_errno = errno;
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
396 sigset_t set;
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
397
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
398 if (out)
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
399 {
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
400 fprintf (out, "-suspend \n");
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
401 fflush (out);
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
402 fsync (fileno (out));
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
403 }
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
404
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
405 /* Unblock this signal and call the default handler by temprarily
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
406 changing the handler and resignalling. */
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
407 sigprocmask (SIG_BLOCK, NULL, &set);
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
408 sigdelset (&set, signalnum);
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
409 signal (signalnum, SIG_DFL);
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
410 kill (getpid (), signalnum);
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
411 sigprocmask (SIG_SETMASK, &set, NULL); /* Let's the above signal through. */
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
412 signal (signalnum, handle_sigtstp);
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
413
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
414 errno = old_errno;
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
415 }
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
416
83025
c66ebcc29777 Removed %T in mode-line-format. Trivial documentation changes.
Karoly Lorentey <lorentey@elte.hu>
parents: 83019
diff changeset
417 /* Set up signal handlers before opening a frame on the current tty. */
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
418
82995
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
419 void
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
420 init_signals (void)
53229
33c3c7c16e13 lib-src/emacsclient.c: Implemented --here option (open a new Emacs tty). Needs more work.
Karoly Lorentey <lorentey@elte.hu>
parents: 52848
diff changeset
421 {
33c3c7c16e13 lib-src/emacsclient.c: Implemented --here option (open a new Emacs tty). Needs more work.
Karoly Lorentey <lorentey@elte.hu>
parents: 52848
diff changeset
422 /* Set up signal handlers. */
83004
7900111db01c Converted display hooks to be display-local. Plus many bugfixes.
Karoly Lorentey <lorentey@elte.hu>
parents: 82995
diff changeset
423 signal (SIGWINCH, pass_signal_to_emacs);
83012
4aa172a45af1 Fix C-g handling with multiple ttys.
Karoly Lorentey <lorentey@elte.hu>
parents: 83010
diff changeset
424
4aa172a45af1 Fix C-g handling with multiple ttys.
Karoly Lorentey <lorentey@elte.hu>
parents: 83010
diff changeset
425 /* Don't pass SIGINT and SIGQUIT to Emacs, because it has no way of
4aa172a45af1 Fix C-g handling with multiple ttys.
Karoly Lorentey <lorentey@elte.hu>
parents: 83010
diff changeset
426 deciding which terminal the signal came from. C-g is now a
4aa172a45af1 Fix C-g handling with multiple ttys.
Karoly Lorentey <lorentey@elte.hu>
parents: 83010
diff changeset
427 normal input event on secondary terminals. */
4aa172a45af1 Fix C-g handling with multiple ttys.
Karoly Lorentey <lorentey@elte.hu>
parents: 83010
diff changeset
428 #if 0
83004
7900111db01c Converted display hooks to be display-local. Plus many bugfixes.
Karoly Lorentey <lorentey@elte.hu>
parents: 82995
diff changeset
429 signal (SIGINT, pass_signal_to_emacs);
7900111db01c Converted display hooks to be display-local. Plus many bugfixes.
Karoly Lorentey <lorentey@elte.hu>
parents: 82995
diff changeset
430 signal (SIGQUIT, pass_signal_to_emacs);
83012
4aa172a45af1 Fix C-g handling with multiple ttys.
Karoly Lorentey <lorentey@elte.hu>
parents: 83010
diff changeset
431 #endif
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
432
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
433 signal (SIGCONT, handle_sigcont);
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
434 signal (SIGTSTP, handle_sigtstp);
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
435 signal (SIGTTOU, handle_sigtstp);
53229
33c3c7c16e13 lib-src/emacsclient.c: Implemented --here option (open a new Emacs tty). Needs more work.
Karoly Lorentey <lorentey@elte.hu>
parents: 52848
diff changeset
436 }
27305
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
437
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
438
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
439 #if !defined (HAVE_SOCKETS) || defined (NO_SOCKETS_IN_FILE_SYSTEM)
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
440
37165
32679fe3e196 (fail, main): Don't use implicit int return type.
Gerd Moellmann <gerd@gnu.org>
parents: 34953
diff changeset
441 int
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
442 main (argc, argv)
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
443 int argc;
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444 char **argv;
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445 {
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446 fprintf (stderr, "%s: Sorry, the Emacs server is supported only\n",
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447 argv[0]);
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
448 fprintf (stderr, "on systems with Berkeley sockets.\n");
27305
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
449
82988
f82e3a6f5ccb A few more bugfixes and new features.
Karoly Lorentey <lorentey@elte.hu>
parents: 82987
diff changeset
450 fail ();
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451 }
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
453 #else /* HAVE_SOCKETS */
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455 #include <sys/types.h>
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
456 #include <sys/socket.h>
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457 #include <sys/un.h>
493
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 478
diff changeset
458 #include <sys/stat.h>
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
459 #include <errno.h>
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
460
5522
64a936b21f74 Don't declare sys_errlist; declare strerror instead.
Roland McGrath <roland@gnu.org>
parents: 4696
diff changeset
461 extern char *strerror ();
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
462 extern int errno;
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
463
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
464 /* Three possibilities:
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
465 2 - can't be `stat'ed (sets errno)
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
466 1 - isn't owned by us
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
467 0 - success: none of the above */
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
468
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
469 static int
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
470 socket_status (socket_name)
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
471 char *socket_name;
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
472 {
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
473 struct stat statbfr;
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
475 if (stat (socket_name, &statbfr) == -1)
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
476 return 2;
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
477
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
478 if (statbfr.st_uid != geteuid ())
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
479 return 1;
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
480
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
481 return 0;
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
482 }
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
483
82995
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
484 /* Returns 1 if PREFIX is a prefix of STRING. */
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
485 static int
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
486 strprefix (char *prefix, char *string)
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
487 {
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
488 int i;
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
489 if (! prefix)
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
490 return 1;
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
491
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
492 if (!string)
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
493 return 0;
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
494
82995
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
495 for (i = 0; prefix[i]; i++)
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
496 if (!string[i] || string[i] != prefix[i])
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
497 return 0;
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
498 return 1;
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
499 }
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
500
9491
dd3b83e4ceb0 Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents: 8360
diff changeset
501 int
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
502 main (argc, argv)
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
503 int argc;
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
504 char **argv;
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
505 {
47515
6ee937dcfe16 (quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42412
diff changeset
506 int s, i, needlf = 0;
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
507 struct sockaddr_un server;
34953
71ff4d0af84f (main): Remove unused local variable statbfr.
Eli Zaretskii <eliz@gnu.org>
parents: 27474
diff changeset
508 char *cwd, *str;
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
509 char string[BUFSIZ];
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
510
53341
d4e6a050c9b1 Bugfix festival.
Karoly Lorentey <lorentey@elte.hu>
parents: 53233
diff changeset
511 main_argc = argc;
d4e6a050c9b1 Bugfix festival.
Karoly Lorentey <lorentey@elte.hu>
parents: 53233
diff changeset
512 main_argv = argv;
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
513 progname = argv[0];
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
514
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
515 /* Process options. */
16061
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
516 decode_options (argc, argv);
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
517
83043
78a785f205ea Added -w option to emacsclient for opening a new X frame.
Karoly Lorentey <lorentey@elte.hu>
parents: 83037
diff changeset
518 if ((argc - optind < 1) && !eval && !tty && !window_system)
50101
e5f56d47b52c (print_help_and_exit): Print to stdout. Exit successfully. Added some blank
Juanma Barranquero <lekktu@gmail.com>
parents: 48627
diff changeset
519 {
e5f56d47b52c (print_help_and_exit): Print to stdout. Exit successfully. Added some blank
Juanma Barranquero <lekktu@gmail.com>
parents: 48627
diff changeset
520 fprintf (stderr, "%s: file name or argument required\n", progname);
e5f56d47b52c (print_help_and_exit): Print to stdout. Exit successfully. Added some blank
Juanma Barranquero <lekktu@gmail.com>
parents: 48627
diff changeset
521 fprintf (stderr, "Try `%s --help' for more information\n", progname);
55442
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53813
diff changeset
522 exit (EXIT_FAILURE);
50101
e5f56d47b52c (print_help_and_exit): Print to stdout. Exit successfully. Added some blank
Juanma Barranquero <lekktu@gmail.com>
parents: 48627
diff changeset
523 }
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
524
42176
1f5dbeefa536 Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 39723
diff changeset
525 /*
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
526 * Open up an AF_UNIX socket in this person's home directory
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
527 */
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
528
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
529 if ((s = socket (AF_UNIX, SOCK_STREAM, 0)) < 0)
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
530 {
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
531 fprintf (stderr, "%s: ", argv[0]);
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
532 perror ("socket");
82988
f82e3a6f5ccb A few more bugfixes and new features.
Karoly Lorentey <lorentey@elte.hu>
parents: 82987
diff changeset
533 fail ();
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
534 }
42176
1f5dbeefa536 Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 39723
diff changeset
535
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
536 server.sun_family = AF_UNIX;
25261
89be69860eeb (main): Move the dynamic allocation of
Karl Heuer <kwzh@gnu.org>
parents: 24652
diff changeset
537
493
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 478
diff changeset
538 {
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
539 int sock_status = 0;
53646
8c55b1b400d5 (main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53543
diff changeset
540 int default_sock = !socket_name;
83010
82554ed1aed8 Merged in changes from CVS HEAD
Karoly Lorentey <lorentey@elte.hu>
parents: 83005 53543
diff changeset
541 int saved_errno = 0;
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
542
83031
1d2f73785d9d Merged in changes from CVS HEAD
Karoly Lorentey <lorentey@elte.hu>
parents: 83030 53734
diff changeset
543 char *server_name = "server";
53734
132739917566 (main): Don't use the hostname in the socket name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53693
diff changeset
544
83031
1d2f73785d9d Merged in changes from CVS HEAD
Karoly Lorentey <lorentey@elte.hu>
parents: 83030 53734
diff changeset
545 if (socket_name && !index (socket_name, '/') && !index (socket_name, '\\'))
1d2f73785d9d Merged in changes from CVS HEAD
Karoly Lorentey <lorentey@elte.hu>
parents: 83030 53734
diff changeset
546 { /* socket_name is a file name component. */
1d2f73785d9d Merged in changes from CVS HEAD
Karoly Lorentey <lorentey@elte.hu>
parents: 83030 53734
diff changeset
547 server_name = socket_name;
1d2f73785d9d Merged in changes from CVS HEAD
Karoly Lorentey <lorentey@elte.hu>
parents: 83030 53734
diff changeset
548 socket_name = NULL;
1d2f73785d9d Merged in changes from CVS HEAD
Karoly Lorentey <lorentey@elte.hu>
parents: 83030 53734
diff changeset
549 default_sock = 1; /* Try both UIDs. */
1d2f73785d9d Merged in changes from CVS HEAD
Karoly Lorentey <lorentey@elte.hu>
parents: 83030 53734
diff changeset
550 }
24084
c0b0893dd5a6 (main): Eliminate arbitrary limit on length of system_name.
Richard M. Stallman <rms@gnu.org>
parents: 23412
diff changeset
551
83031
1d2f73785d9d Merged in changes from CVS HEAD
Karoly Lorentey <lorentey@elte.hu>
parents: 83030 53734
diff changeset
552 if (default_sock)
52479
bc2610a13fbf (socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
553 {
83031
1d2f73785d9d Merged in changes from CVS HEAD
Karoly Lorentey <lorentey@elte.hu>
parents: 83030 53734
diff changeset
554 socket_name = alloca (100 + strlen (server_name));
1d2f73785d9d Merged in changes from CVS HEAD
Karoly Lorentey <lorentey@elte.hu>
parents: 83030 53734
diff changeset
555 sprintf (socket_name, "/tmp/emacs%d/%s",
1d2f73785d9d Merged in changes from CVS HEAD
Karoly Lorentey <lorentey@elte.hu>
parents: 83030 53734
diff changeset
556 (int) geteuid (), server_name);
52479
bc2610a13fbf (socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
557 }
bc2610a13fbf (socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
558
bc2610a13fbf (socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
559 if (strlen (socket_name) < sizeof (server.sun_path))
bc2610a13fbf (socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
560 strcpy (server.sun_path, socket_name);
bc2610a13fbf (socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
561 else
53646
8c55b1b400d5 (main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53543
diff changeset
562 {
82988
f82e3a6f5ccb A few more bugfixes and new features.
Karoly Lorentey <lorentey@elte.hu>
parents: 82987
diff changeset
563 fprintf (stderr, "%s: socket-name %s too long",
f82e3a6f5ccb A few more bugfixes and new features.
Karoly Lorentey <lorentey@elte.hu>
parents: 82987
diff changeset
564 argv[0], socket_name);
f82e3a6f5ccb A few more bugfixes and new features.
Karoly Lorentey <lorentey@elte.hu>
parents: 82987
diff changeset
565 fail ();
53646
8c55b1b400d5 (main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53543
diff changeset
566 }
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
567
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
568 /* See if the socket exists, and if it's owned by us. */
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
569 sock_status = socket_status (server.sun_path);
53543
fec82b542db2 (main): Save errno from socket_status.
Andreas Schwab <schwab@suse.de>
parents: 53497
diff changeset
570 saved_errno = errno;
53646
8c55b1b400d5 (main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53543
diff changeset
571 if (sock_status && default_sock)
493
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 478
diff changeset
572 {
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
573 /* Failing that, see if LOGNAME or USER exist and differ from
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
574 our euid. If so, look for a socket based on the UID
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
575 associated with the name. This is reminiscent of the logic
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
576 that init_editfns uses to set the global Vuser_full_name. */
42176
1f5dbeefa536 Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 39723
diff changeset
577
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
578 char *user_name = (char *) getenv ("LOGNAME");
53693
04e9ebd16fcd (main): Restore errno from saved_errno,
Richard M. Stallman <rms@gnu.org>
parents: 53646
diff changeset
579
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
580 if (!user_name)
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
581 user_name = (char *) getenv ("USER");
42176
1f5dbeefa536 Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 39723
diff changeset
582
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
583 if (user_name)
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
584 {
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
585 struct passwd *pw = getpwnam (user_name);
53693
04e9ebd16fcd (main): Restore errno from saved_errno,
Richard M. Stallman <rms@gnu.org>
parents: 53646
diff changeset
586
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
587 if (pw && (pw->pw_uid != geteuid ()))
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
588 {
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
589 /* We're running under su, apparently. */
53734
132739917566 (main): Don't use the hostname in the socket name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53693
diff changeset
590 socket_name = alloca (100 + strlen (server_name));
132739917566 (main): Don't use the hostname in the socket name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53693
diff changeset
591 sprintf (socket_name, "/tmp/emacs%d/%s",
132739917566 (main): Don't use the hostname in the socket name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53693
diff changeset
592 (int) pw->pw_uid, server_name);
53646
8c55b1b400d5 (main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53543
diff changeset
593
8c55b1b400d5 (main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53543
diff changeset
594 if (strlen (socket_name) < sizeof (server.sun_path))
8c55b1b400d5 (main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53543
diff changeset
595 strcpy (server.sun_path, socket_name);
8c55b1b400d5 (main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53543
diff changeset
596 else
8c55b1b400d5 (main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53543
diff changeset
597 {
8c55b1b400d5 (main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53543
diff changeset
598 fprintf (stderr, "%s: socket-name %s too long",
8c55b1b400d5 (main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53543
diff changeset
599 argv[0], socket_name);
55442
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53813
diff changeset
600 exit (EXIT_FAILURE);
53646
8c55b1b400d5 (main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53543
diff changeset
601 }
8c55b1b400d5 (main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53543
diff changeset
602
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
603 sock_status = socket_status (server.sun_path);
83010
82554ed1aed8 Merged in changes from CVS HEAD
Karoly Lorentey <lorentey@elte.hu>
parents: 83005 53543
diff changeset
604 saved_errno = errno;
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
605 }
53693
04e9ebd16fcd (main): Restore errno from saved_errno,
Richard M. Stallman <rms@gnu.org>
parents: 53646
diff changeset
606 else
04e9ebd16fcd (main): Restore errno from saved_errno,
Richard M. Stallman <rms@gnu.org>
parents: 53646
diff changeset
607 errno = saved_errno;
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
608 }
493
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 478
diff changeset
609 }
42176
1f5dbeefa536 Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 39723
diff changeset
610
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
611 switch (sock_status)
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
612 {
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
613 case 1:
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
614 /* There's a socket, but it isn't owned by us. This is OK if
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
615 we are root. */
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
616 if (0 != geteuid ())
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
617 {
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
618 fprintf (stderr, "%s: Invalid socket owner\n", argv[0]);
82988
f82e3a6f5ccb A few more bugfixes and new features.
Karoly Lorentey <lorentey@elte.hu>
parents: 82987
diff changeset
619 fail ();
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
620 }
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
621 break;
42176
1f5dbeefa536 Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 39723
diff changeset
622
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
623 case 2:
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
624 /* `stat' failed */
53543
fec82b542db2 (main): Save errno from socket_status.
Andreas Schwab <schwab@suse.de>
parents: 53497
diff changeset
625 if (saved_errno == ENOENT)
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
626 fprintf (stderr,
48627
c91408365d35 (main): Tell user how to start server within Emacs if socket could not
Stephen Eglen <stephen@gnu.org>
parents: 48617
diff changeset
627 "%s: can't find socket; have you started the server?\n\
c91408365d35 (main): Tell user how to start server within Emacs if socket could not
Stephen Eglen <stephen@gnu.org>
parents: 48617
diff changeset
628 To start the server in Emacs, type \"M-x server-start\".\n",
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
629 argv[0]);
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
630 else
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
631 fprintf (stderr, "%s: can't stat %s: %s\n",
53543
fec82b542db2 (main): Save errno from socket_status.
Andreas Schwab <schwab@suse.de>
parents: 53497
diff changeset
632 argv[0], server.sun_path, strerror (saved_errno));
82988
f82e3a6f5ccb A few more bugfixes and new features.
Karoly Lorentey <lorentey@elte.hu>
parents: 82987
diff changeset
633 fail ();
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
634 break;
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
635 }
493
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 478
diff changeset
636 }
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
637
3595
e10f7473d2e3 * emacsserver.c (main): When we're passing a `struct sockaddr_un'
Jim Blandy <jimb@redhat.com>
parents: 1031
diff changeset
638 if (connect (s, (struct sockaddr *) &server, strlen (server.sun_path) + 2)
e10f7473d2e3 * emacsserver.c (main): When we're passing a `struct sockaddr_un'
Jim Blandy <jimb@redhat.com>
parents: 1031
diff changeset
639 < 0)
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
640 {
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
641 fprintf (stderr, "%s: ", argv[0]);
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
642 perror ("connect");
82988
f82e3a6f5ccb A few more bugfixes and new features.
Karoly Lorentey <lorentey@elte.hu>
parents: 82987
diff changeset
643 fail ();
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
644 }
15758
7e712d42d371 (main) [HAVE_SOCKETS]: Use two separate stdio
Richard M. Stallman <rms@gnu.org>
parents: 14610
diff changeset
645
83103
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
646 /* We use the stream OUT to send our commands to the server. */
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
647 if ((out = fdopen (s, "r+")) == NULL)
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
648 {
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
649 fprintf (stderr, "%s: ", argv[0]);
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
650 perror ("fdopen");
82988
f82e3a6f5ccb A few more bugfixes and new features.
Karoly Lorentey <lorentey@elte.hu>
parents: 82987
diff changeset
651 fail ();
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
652 }
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
653
83103
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
654 /* We use the stream IN to read the responses.
15758
7e712d42d371 (main) [HAVE_SOCKETS]: Use two separate stdio
Richard M. Stallman <rms@gnu.org>
parents: 14610
diff changeset
655 We used to use just one stream for both output and input
7e712d42d371 (main) [HAVE_SOCKETS]: Use two separate stdio
Richard M. Stallman <rms@gnu.org>
parents: 14610
diff changeset
656 on the socket, but reversing direction works nonportably:
7e712d42d371 (main) [HAVE_SOCKETS]: Use two separate stdio
Richard M. Stallman <rms@gnu.org>
parents: 14610
diff changeset
657 on some systems, the output appears as the first input;
7e712d42d371 (main) [HAVE_SOCKETS]: Use two separate stdio
Richard M. Stallman <rms@gnu.org>
parents: 14610
diff changeset
658 on other systems it does not. */
7e712d42d371 (main) [HAVE_SOCKETS]: Use two separate stdio
Richard M. Stallman <rms@gnu.org>
parents: 14610
diff changeset
659 if ((in = fdopen (s, "r+")) == NULL)
7e712d42d371 (main) [HAVE_SOCKETS]: Use two separate stdio
Richard M. Stallman <rms@gnu.org>
parents: 14610
diff changeset
660 {
7e712d42d371 (main) [HAVE_SOCKETS]: Use two separate stdio
Richard M. Stallman <rms@gnu.org>
parents: 14610
diff changeset
661 fprintf (stderr, "%s: ", argv[0]);
7e712d42d371 (main) [HAVE_SOCKETS]: Use two separate stdio
Richard M. Stallman <rms@gnu.org>
parents: 14610
diff changeset
662 perror ("fdopen");
82988
f82e3a6f5ccb A few more bugfixes and new features.
Karoly Lorentey <lorentey@elte.hu>
parents: 82987
diff changeset
663 fail ();
15758
7e712d42d371 (main) [HAVE_SOCKETS]: Use two separate stdio
Richard M. Stallman <rms@gnu.org>
parents: 14610
diff changeset
664 }
7e712d42d371 (main) [HAVE_SOCKETS]: Use two separate stdio
Richard M. Stallman <rms@gnu.org>
parents: 14610
diff changeset
665
48617
802b2a15e451 (main): Test HAVE_GETCWD rather than BSD_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents: 47717
diff changeset
666 #ifdef HAVE_GETCWD
802b2a15e451 (main): Test HAVE_GETCWD rather than BSD_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents: 47717
diff changeset
667 cwd = getcwd (string, sizeof string);
802b2a15e451 (main): Test HAVE_GETCWD rather than BSD_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents: 47717
diff changeset
668 #else
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
669 cwd = getwd (string);
11030
3345f6426f49 Use BSD sockets whenever available, even if HAVE_SYSVIPC.
Richard M. Stallman <rms@gnu.org>
parents: 10124
diff changeset
670 #endif
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
671 if (cwd == 0)
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
672 {
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
673 /* getwd puts message in STRING if it fails. */
52069
76d453ac3c4f (main): Fix having macros in a printf statement.
Juanma Barranquero <lekktu@gmail.com>
parents: 50566
diff changeset
674
48617
802b2a15e451 (main): Test HAVE_GETCWD rather than BSD_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents: 47717
diff changeset
675 #ifdef HAVE_GETCWD
52069
76d453ac3c4f (main): Fix having macros in a printf statement.
Juanma Barranquero <lekktu@gmail.com>
parents: 50566
diff changeset
676 fprintf (stderr, "%s: %s (%s)\n", argv[0],
83103
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
677 "cannot get current working directory", strerror (errno));
48617
802b2a15e451 (main): Test HAVE_GETCWD rather than BSD_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents: 47717
diff changeset
678 #else
52069
76d453ac3c4f (main): Fix having macros in a printf statement.
Juanma Barranquero <lekktu@gmail.com>
parents: 50566
diff changeset
679 fprintf (stderr, "%s: %s (%s)\n", argv[0], string, strerror (errno));
19582
1289a4779e68 [HAVE_SYSVIPC]: Include errno.h, as in the other case.
Richard M. Stallman <rms@gnu.org>
parents: 18701
diff changeset
680 #endif
82988
f82e3a6f5ccb A few more bugfixes and new features.
Karoly Lorentey <lorentey@elte.hu>
parents: 82987
diff changeset
681 fail ();
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
682 }
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
683
83044
52039abab942 Verify the version of Emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83043
diff changeset
684 /* First of all, send our version number for verification. */
52039abab942 Verify the version of Emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83043
diff changeset
685 fprintf (out, "-version %s ", VERSION);
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
686
83103
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
687 /* Send over our environment. */
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
688 {
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
689 extern char **environ;
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
690 int i;
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
691 for (i = 0; environ[i]; i++)
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
692 {
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
693 char *name = xstrdup (environ[i]);
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
694 char *value = strchr (name, '=');
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
695 if (value && strlen (value) > 1)
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
696 {
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
697 *value++ = 0;
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
698 fprintf (out, "-env ");
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
699 quote_argument (name, out);
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
700 fprintf (out, " ");
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
701 quote_argument (value, out);
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
702 fprintf (out, " ");
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
703 fflush (out);
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
704 }
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
705 free (name);
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
706 }
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
707 }
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
708
83246
5bc762f84335 Prevent emacsclient errors when Emacs is compiled without X support.
Karoly Lorentey <lorentey@elte.hu>
parents: 83165
diff changeset
709 retry:
16061
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
710 if (nowait)
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
711 fprintf (out, "-nowait ");
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
712
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
713 if (display)
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
714 {
52635
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
715 fprintf (out, "-display ");
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
716 quote_argument (display, out);
52635
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
717 fprintf (out, " ");
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
718 }
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
719
83043
78a785f205ea Added -w option to emacsclient for opening a new X frame.
Karoly Lorentey <lorentey@elte.hu>
parents: 83037
diff changeset
720 if (tty)
53229
33c3c7c16e13 lib-src/emacsclient.c: Implemented --here option (open a new Emacs tty). Needs more work.
Karoly Lorentey <lorentey@elte.hu>
parents: 52848
diff changeset
721 {
82995
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
722 char *tty_name = ttyname (fileno (stdin));
83064
e7e9448cb3a0 Make emacsclient refuse to create a frame inside an Emacs term buffer.
Karoly Lorentey <lorentey@elte.hu>
parents: 83052
diff changeset
723 char *type = getenv ("TERM");
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
724
82995
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
725 if (! tty_name)
83064
e7e9448cb3a0 Make emacsclient refuse to create a frame inside an Emacs term buffer.
Karoly Lorentey <lorentey@elte.hu>
parents: 83052
diff changeset
726 {
e7e9448cb3a0 Make emacsclient refuse to create a frame inside an Emacs term buffer.
Karoly Lorentey <lorentey@elte.hu>
parents: 83052
diff changeset
727 fprintf (stderr, "%s: could not get terminal name\n", progname);
e7e9448cb3a0 Make emacsclient refuse to create a frame inside an Emacs term buffer.
Karoly Lorentey <lorentey@elte.hu>
parents: 83052
diff changeset
728 fail ();
e7e9448cb3a0 Make emacsclient refuse to create a frame inside an Emacs term buffer.
Karoly Lorentey <lorentey@elte.hu>
parents: 83052
diff changeset
729 }
e7e9448cb3a0 Make emacsclient refuse to create a frame inside an Emacs term buffer.
Karoly Lorentey <lorentey@elte.hu>
parents: 83052
diff changeset
730
e7e9448cb3a0 Make emacsclient refuse to create a frame inside an Emacs term buffer.
Karoly Lorentey <lorentey@elte.hu>
parents: 83052
diff changeset
731 if (! type)
e7e9448cb3a0 Make emacsclient refuse to create a frame inside an Emacs term buffer.
Karoly Lorentey <lorentey@elte.hu>
parents: 83052
diff changeset
732 {
e7e9448cb3a0 Make emacsclient refuse to create a frame inside an Emacs term buffer.
Karoly Lorentey <lorentey@elte.hu>
parents: 83052
diff changeset
733 fprintf (stderr, "%s: please set the TERM variable to your terminal type\n",
e7e9448cb3a0 Make emacsclient refuse to create a frame inside an Emacs term buffer.
Karoly Lorentey <lorentey@elte.hu>
parents: 83052
diff changeset
734 progname);
e7e9448cb3a0 Make emacsclient refuse to create a frame inside an Emacs term buffer.
Karoly Lorentey <lorentey@elte.hu>
parents: 83052
diff changeset
735 fail ();
e7e9448cb3a0 Make emacsclient refuse to create a frame inside an Emacs term buffer.
Karoly Lorentey <lorentey@elte.hu>
parents: 83052
diff changeset
736 }
e7e9448cb3a0 Make emacsclient refuse to create a frame inside an Emacs term buffer.
Karoly Lorentey <lorentey@elte.hu>
parents: 83052
diff changeset
737
e7e9448cb3a0 Make emacsclient refuse to create a frame inside an Emacs term buffer.
Karoly Lorentey <lorentey@elte.hu>
parents: 83052
diff changeset
738 if (! strcmp (type, "eterm"))
e7e9448cb3a0 Make emacsclient refuse to create a frame inside an Emacs term buffer.
Karoly Lorentey <lorentey@elte.hu>
parents: 83052
diff changeset
739 {
e7e9448cb3a0 Make emacsclient refuse to create a frame inside an Emacs term buffer.
Karoly Lorentey <lorentey@elte.hu>
parents: 83052
diff changeset
740 /* This causes nasty, MULTI_KBOARD-related input lockouts. */
e7e9448cb3a0 Make emacsclient refuse to create a frame inside an Emacs term buffer.
Karoly Lorentey <lorentey@elte.hu>
parents: 83052
diff changeset
741 fprintf (stderr, "%s: opening a frame in an Emacs term buffer"
e7e9448cb3a0 Make emacsclient refuse to create a frame inside an Emacs term buffer.
Karoly Lorentey <lorentey@elte.hu>
parents: 83052
diff changeset
742 " is not supported\n", progname);
e7e9448cb3a0 Make emacsclient refuse to create a frame inside an Emacs term buffer.
Karoly Lorentey <lorentey@elte.hu>
parents: 83052
diff changeset
743 fail ();
e7e9448cb3a0 Make emacsclient refuse to create a frame inside an Emacs term buffer.
Karoly Lorentey <lorentey@elte.hu>
parents: 83052
diff changeset
744 }
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
745
82995
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
746 init_signals ();
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
747
82988
f82e3a6f5ccb A few more bugfixes and new features.
Karoly Lorentey <lorentey@elte.hu>
parents: 82987
diff changeset
748 fprintf (out, "-tty ");
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
749 quote_argument (tty_name, out);
53229
33c3c7c16e13 lib-src/emacsclient.c: Implemented --here option (open a new Emacs tty). Needs more work.
Karoly Lorentey <lorentey@elte.hu>
parents: 52848
diff changeset
750 fprintf (out, " ");
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
751 quote_argument (type, out);
53229
33c3c7c16e13 lib-src/emacsclient.c: Implemented --here option (open a new Emacs tty). Needs more work.
Karoly Lorentey <lorentey@elte.hu>
parents: 52848
diff changeset
752 fprintf (out, " ");
33c3c7c16e13 lib-src/emacsclient.c: Implemented --here option (open a new Emacs tty). Needs more work.
Karoly Lorentey <lorentey@elte.hu>
parents: 52848
diff changeset
753 }
83043
78a785f205ea Added -w option to emacsclient for opening a new X frame.
Karoly Lorentey <lorentey@elte.hu>
parents: 83037
diff changeset
754
78a785f205ea Added -w option to emacsclient for opening a new X frame.
Karoly Lorentey <lorentey@elte.hu>
parents: 83037
diff changeset
755 if (window_system)
78a785f205ea Added -w option to emacsclient for opening a new X frame.
Karoly Lorentey <lorentey@elte.hu>
parents: 83037
diff changeset
756 fprintf (out, "-window-system ");
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
757
52635
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
758 if ((argc - optind > 0))
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
759 {
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
760 for (i = optind; i < argc; i++)
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
761 {
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
762 int relative = 0;
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
763
52635
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
764 if (eval)
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
765 {
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
766 /* Don't prepend any cwd or anything like that. */
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
767 fprintf (out, "-eval ");
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
768 quote_argument (argv[i], out);
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
769 fprintf (out, " ");
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
770 continue;
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
771 }
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
772
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
773 if (*argv[i] == '+')
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
774 {
52635
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
775 char *p = argv[i] + 1;
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
776 while (isdigit ((unsigned char) *p) || *p == ':') p++;
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
777 if (*p == 0)
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
778 {
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
779 fprintf (out, "-position ");
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
780 quote_argument (argv[i], out);
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
781 fprintf (out, " ");
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
782 continue;
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
783 }
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
784 else
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
785 relative = 1;
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
786 }
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
787 else if (*argv[i] != '/')
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
788 relative = 1;
52635
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
789
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
790 fprintf (out, "-file ");
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
791 if (relative)
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
792 {
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
793 quote_argument (cwd, out);
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
794 fprintf (out, "/");
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
795 }
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
796 quote_argument (argv[i], out);
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
797 fprintf (out, " ");
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
798 }
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
799 }
52635
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
800 else
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
801 {
83043
78a785f205ea Added -w option to emacsclient for opening a new X frame.
Karoly Lorentey <lorentey@elte.hu>
parents: 83037
diff changeset
802 if (!tty && !window_system)
53229
33c3c7c16e13 lib-src/emacsclient.c: Implemented --here option (open a new Emacs tty). Needs more work.
Karoly Lorentey <lorentey@elte.hu>
parents: 52848
diff changeset
803 {
33c3c7c16e13 lib-src/emacsclient.c: Implemented --here option (open a new Emacs tty). Needs more work.
Karoly Lorentey <lorentey@elte.hu>
parents: 52848
diff changeset
804 while ((str = fgets (string, BUFSIZ, stdin)))
33c3c7c16e13 lib-src/emacsclient.c: Implemented --here option (open a new Emacs tty). Needs more work.
Karoly Lorentey <lorentey@elte.hu>
parents: 52848
diff changeset
805 {
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
806 if (eval)
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
807 fprintf (out, "-eval ");
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
808 else
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
809 fprintf (out, "-file ");
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
810 quote_argument (str, out);
53229
33c3c7c16e13 lib-src/emacsclient.c: Implemented --here option (open a new Emacs tty). Needs more work.
Karoly Lorentey <lorentey@elte.hu>
parents: 52848
diff changeset
811 }
33c3c7c16e13 lib-src/emacsclient.c: Implemented --here option (open a new Emacs tty). Needs more work.
Karoly Lorentey <lorentey@elte.hu>
parents: 52848
diff changeset
812 fprintf (out, " ");
33c3c7c16e13 lib-src/emacsclient.c: Implemented --here option (open a new Emacs tty). Needs more work.
Karoly Lorentey <lorentey@elte.hu>
parents: 52848
diff changeset
813 }
52635
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
814 }
55442
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53813
diff changeset
815
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
816 fprintf (out, "\n");
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
817 fflush (out);
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
818 fsync (fileno (out));
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
819
83165
ed82e09208c9 Fix --no-wait in emacsclient (reported by Dan Nicolaescu).
Karoly Lorentey <lorentey@elte.hu>
parents: 83121
diff changeset
820 /* Wait for an answer. */
ed82e09208c9 Fix --no-wait in emacsclient (reported by Dan Nicolaescu).
Karoly Lorentey <lorentey@elte.hu>
parents: 83121
diff changeset
821 if (!eval && !tty && !nowait)
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
822 {
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
823 printf ("Waiting for Emacs...");
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
824 needlf = 2;
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
825 }
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
826 fflush (stdout);
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
827 fsync (1);
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
828
47515
6ee937dcfe16 (quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42412
diff changeset
829 /* Now, wait for an answer and print any messages. */
6ee937dcfe16 (quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42412
diff changeset
830 while ((str = fgets (string, BUFSIZ, in)))
6ee937dcfe16 (quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42412
diff changeset
831 {
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
832 char *p = str + strlen (str) - 1;
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
833 while (p > str && *p == '\n')
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
834 *p-- = 0;
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
835
83044
52039abab942 Verify the version of Emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83043
diff changeset
836 if (strprefix ("-good-version ", str))
52039abab942 Verify the version of Emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83043
diff changeset
837 {
83246
5bc762f84335 Prevent emacsclient errors when Emacs is compiled without X support.
Karoly Lorentey <lorentey@elte.hu>
parents: 83165
diff changeset
838 /* -good-version: The versions match. */
83044
52039abab942 Verify the version of Emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83043
diff changeset
839 }
52039abab942 Verify the version of Emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83043
diff changeset
840 else if (strprefix ("-emacs-pid ", str))
83043
78a785f205ea Added -w option to emacsclient for opening a new X frame.
Karoly Lorentey <lorentey@elte.hu>
parents: 83037
diff changeset
841 {
83246
5bc762f84335 Prevent emacsclient errors when Emacs is compiled without X support.
Karoly Lorentey <lorentey@elte.hu>
parents: 83165
diff changeset
842 /* -emacs-pid PID: The process id of the Emacs process. */
83043
78a785f205ea Added -w option to emacsclient for opening a new X frame.
Karoly Lorentey <lorentey@elte.hu>
parents: 83037
diff changeset
843 emacs_pid = strtol (string + strlen ("-emacs-pid"), NULL, 10);
78a785f205ea Added -w option to emacsclient for opening a new X frame.
Karoly Lorentey <lorentey@elte.hu>
parents: 83037
diff changeset
844 }
83246
5bc762f84335 Prevent emacsclient errors when Emacs is compiled without X support.
Karoly Lorentey <lorentey@elte.hu>
parents: 83165
diff changeset
845 else if (strprefix ("-window-system-unsupported ", str))
5bc762f84335 Prevent emacsclient errors when Emacs is compiled without X support.
Karoly Lorentey <lorentey@elte.hu>
parents: 83165
diff changeset
846 {
5bc762f84335 Prevent emacsclient errors when Emacs is compiled without X support.
Karoly Lorentey <lorentey@elte.hu>
parents: 83165
diff changeset
847 /* -window-system-unsupported: Emacs was compiled without X
5bc762f84335 Prevent emacsclient errors when Emacs is compiled without X support.
Karoly Lorentey <lorentey@elte.hu>
parents: 83165
diff changeset
848 support. Try again on the terminal. */
5bc762f84335 Prevent emacsclient errors when Emacs is compiled without X support.
Karoly Lorentey <lorentey@elte.hu>
parents: 83165
diff changeset
849 window_system = 0;
5bc762f84335 Prevent emacsclient errors when Emacs is compiled without X support.
Karoly Lorentey <lorentey@elte.hu>
parents: 83165
diff changeset
850 nowait = 0;
5bc762f84335 Prevent emacsclient errors when Emacs is compiled without X support.
Karoly Lorentey <lorentey@elte.hu>
parents: 83165
diff changeset
851 tty = 1;
5bc762f84335 Prevent emacsclient errors when Emacs is compiled without X support.
Karoly Lorentey <lorentey@elte.hu>
parents: 83165
diff changeset
852 goto retry;
5bc762f84335 Prevent emacsclient errors when Emacs is compiled without X support.
Karoly Lorentey <lorentey@elte.hu>
parents: 83165
diff changeset
853 }
83043
78a785f205ea Added -w option to emacsclient for opening a new X frame.
Karoly Lorentey <lorentey@elte.hu>
parents: 83037
diff changeset
854 else if (strprefix ("-print ", str))
82995
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
855 {
83246
5bc762f84335 Prevent emacsclient errors when Emacs is compiled without X support.
Karoly Lorentey <lorentey@elte.hu>
parents: 83165
diff changeset
856 /* -print STRING: Print STRING on the terminal. */
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
857 str = unquote_argument (str + strlen ("-print "));
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
858 if (needlf)
83043
78a785f205ea Added -w option to emacsclient for opening a new X frame.
Karoly Lorentey <lorentey@elte.hu>
parents: 83037
diff changeset
859 printf ("\n");
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
860 printf ("%s", str);
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
861 needlf = str[0] == '\0' ? needlf : str[strlen (str) - 1] != '\n';
83043
78a785f205ea Added -w option to emacsclient for opening a new X frame.
Karoly Lorentey <lorentey@elte.hu>
parents: 83037
diff changeset
862 }
78a785f205ea Added -w option to emacsclient for opening a new X frame.
Karoly Lorentey <lorentey@elte.hu>
parents: 83037
diff changeset
863 else if (strprefix ("-error ", str))
78a785f205ea Added -w option to emacsclient for opening a new X frame.
Karoly Lorentey <lorentey@elte.hu>
parents: 83037
diff changeset
864 {
83246
5bc762f84335 Prevent emacsclient errors when Emacs is compiled without X support.
Karoly Lorentey <lorentey@elte.hu>
parents: 83165
diff changeset
865 /* -error DESCRIPTION: Signal an error on the terminal. */
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
866 str = unquote_argument (str + strlen ("-error "));
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
867 if (needlf)
83043
78a785f205ea Added -w option to emacsclient for opening a new X frame.
Karoly Lorentey <lorentey@elte.hu>
parents: 83037
diff changeset
868 printf ("\n");
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
869 printf ("*ERROR*: %s", str);
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
870 needlf = str[0] == '\0' ? needlf : str[strlen (str) - 1] != '\n';
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
871 }
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
872 else if (strprefix ("-suspend ", str))
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
873 {
83246
5bc762f84335 Prevent emacsclient errors when Emacs is compiled without X support.
Karoly Lorentey <lorentey@elte.hu>
parents: 83165
diff changeset
874 /* -suspend: Suspend this terminal, i.e., stop the process. */
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
875 if (needlf)
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
876 printf ("\n");
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
877 needlf = 0;
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
878 kill (0, SIGSTOP);
82995
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
879 }
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
880 else
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
881 {
83246
5bc762f84335 Prevent emacsclient errors when Emacs is compiled without X support.
Karoly Lorentey <lorentey@elte.hu>
parents: 83165
diff changeset
882 /* Unknown command. */
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
883 if (needlf)
82995
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
884 printf ("\n");
83043
78a785f205ea Added -w option to emacsclient for opening a new X frame.
Karoly Lorentey <lorentey@elte.hu>
parents: 83037
diff changeset
885 printf ("*ERROR*: Unknown message: %s", str);
82995
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
886 needlf = str[0] == '\0' ? needlf : str[strlen (str) - 1] != '\n';
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
887 }
47515
6ee937dcfe16 (quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42412
diff changeset
888 }
42176
1f5dbeefa536 Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 39723
diff changeset
889
47515
6ee937dcfe16 (quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42412
diff changeset
890 if (needlf)
6ee937dcfe16 (quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42412
diff changeset
891 printf ("\n");
6ee937dcfe16 (quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42412
diff changeset
892 fflush (stdout);
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
893 fsync (1);
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
894
55442
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53813
diff changeset
895 return EXIT_SUCCESS;
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
896 }
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
897
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
898 #endif /* HAVE_SOCKETS */
5527
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
899
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
900 #ifndef HAVE_STRERROR
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
901 char *
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
902 strerror (errnum)
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
903 int errnum;
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
904 {
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
905 extern char *sys_errlist[];
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
906 extern int sys_nerr;
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
907
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
908 if (errnum >= 0 && errnum < sys_nerr)
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
909 return sys_errlist[errnum];
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
910 return (char *) "Unknown error";
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
911 }
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
912
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
913 #endif /* ! HAVE_STRERROR */
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 52069
diff changeset
914
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 52069
diff changeset
915 /* arch-tag: f39bb9c4-73eb-477e-896d-50832e2ca9a7
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 52069
diff changeset
916 (do not change this comment) */
55442
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53813
diff changeset
917
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53813
diff changeset
918 /* emacsclient.c ends here */