annotate lib-src/emacsclient.c @ 83590:dab011361c2a

(s): Remove. (main): Define here instead. (main) [WINDOWSNT]: Don't call ttyname. Don't recognize -suspend option. (main) [NO_SOCKETS_IN_FILE_SYSTEM]: Don't call init_signals. (strprefix): Define unconditionally.
author Jason Rumney <jasonr@gnu.org>
date Tue, 15 May 2007 23:30:30 +0000
parents 07774e5c3ff5
children 9aa8a3a78f9e
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,
75348
3d45362f1d38 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 74729
diff changeset
3 2005, 2006, 2007 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
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
29 #ifdef WINDOWSNT
73585
7d264c036b25 [WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73583
diff changeset
30
73973
a36e68eb4ae8 [WINDOWSNT]: Undef _WINSOCKAPI_ and _WINSOCK_H.
Juanma Barranquero <lekktu@gmail.com>
parents: 73896
diff changeset
31 /* config.h defines these, which disables sockets altogether! */
a36e68eb4ae8 [WINDOWSNT]: Undef _WINSOCKAPI_ and _WINSOCK_H.
Juanma Barranquero <lekktu@gmail.com>
parents: 73896
diff changeset
32 # undef _WINSOCKAPI_
a36e68eb4ae8 [WINDOWSNT]: Undef _WINSOCKAPI_ and _WINSOCK_H.
Juanma Barranquero <lekktu@gmail.com>
parents: 73896
diff changeset
33 # undef _WINSOCK_H
a36e68eb4ae8 [WINDOWSNT]: Undef _WINSOCKAPI_ and _WINSOCK_H.
Juanma Barranquero <lekktu@gmail.com>
parents: 73896
diff changeset
34
73585
7d264c036b25 [WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73583
diff changeset
35 # include <malloc.h>
7d264c036b25 [WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73583
diff changeset
36 # include <stdlib.h>
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
37 # include <windows.h>
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
38
73585
7d264c036b25 [WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73583
diff changeset
39 # define NO_SOCKETS_IN_FILE_SYSTEM
7d264c036b25 [WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73583
diff changeset
40
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
41 # define HSOCKET SOCKET
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
42 # define CLOSE_SOCKET closesocket
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
43 # define INITIALIZE() (initialize_sockets ())
73585
7d264c036b25 [WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73583
diff changeset
44
7d264c036b25 [WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73583
diff changeset
45 #else /* !WINDOWSNT */
7d264c036b25 [WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73583
diff changeset
46
73896
09dabd95380c [!WINDOWSNT]: Include <sys/types.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73816
diff changeset
47 # include <sys/types.h>
09dabd95380c [!WINDOWSNT]: Include <sys/types.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73816
diff changeset
48
73617
7af864af10b6 [WINDOWSNT]: Define HAVE_INET_SOCKETS.
Juanma Barranquero <lekktu@gmail.com>
parents: 73601
diff changeset
49 # ifdef HAVE_INET_SOCKETS
7af864af10b6 [WINDOWSNT]: Define HAVE_INET_SOCKETS.
Juanma Barranquero <lekktu@gmail.com>
parents: 73601
diff changeset
50 # include <netinet/in.h>
7af864af10b6 [WINDOWSNT]: Define HAVE_INET_SOCKETS.
Juanma Barranquero <lekktu@gmail.com>
parents: 73601
diff changeset
51 # endif
73585
7d264c036b25 [WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73583
diff changeset
52
73578
e193b6a3f379 Fixes to emacsclient.c for GNU/Linux.
Juanma Barranquero <lekktu@gmail.com>
parents: 73562
diff changeset
53 # define INVALID_SOCKET -1
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
54 # define HSOCKET int
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
55 # define CLOSE_SOCKET close
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
56 # define INITIALIZE()
73585
7d264c036b25 [WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73583
diff changeset
57
7d264c036b25 [WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73583
diff changeset
58 #endif /* !WINDOWSNT */
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
59
3595
e10f7473d2e3 * emacsserver.c (main): When we're passing a `struct sockaddr_un'
Jim Blandy <jimb@redhat.com>
parents: 1031
diff changeset
60 #undef signal
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
62 #include <stdarg.h>
42176
1f5dbeefa536 Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 39723
diff changeset
63 #include <ctype.h>
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
64 #include <stdio.h>
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
65 #include "getopt.h"
21431
a080769e8f7d Move inclusion of unistd.h to top, else fails on
Dave Love <fx@gnu.org>
parents: 21387
diff changeset
66 #ifdef HAVE_UNISTD_H
a080769e8f7d Move inclusion of unistd.h to top, else fails on
Dave Love <fx@gnu.org>
parents: 21387
diff changeset
67 #include <unistd.h>
a080769e8f7d Move inclusion of unistd.h to top, else fails on
Dave Love <fx@gnu.org>
parents: 21387
diff changeset
68 #endif
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
70 #ifdef VMS
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
71 # include "vms-pwd.h"
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
72 #else /* not VMS */
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
73 #ifdef WINDOWSNT
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
74 # include <io.h>
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
75 #else /* not WINDOWSNT */
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
76 # include <pwd.h>
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
77 #endif /* not WINDOWSNT */
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
78 #endif /* not VMS */
83500
0a651d0085ee Fix compilation error on OpenBSD. (Reported by Han Boetes.)
Karoly Lorentey <lorentey@elte.hu>
parents: 83499
diff changeset
79 #include <sys/stat.h>
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
80
82995
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
81 #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
82 #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
83
83501
9490895469d4 Fix OpenBSD compilation some more. (Fix by Han Boetes.)
Karoly Lorentey <lorentey@elte.hu>
parents: 83500
diff changeset
84 /* From lisp.h */
9490895469d4 Fix OpenBSD compilation some more. (Fix by Han Boetes.)
Karoly Lorentey <lorentey@elte.hu>
parents: 83500
diff changeset
85 #ifndef DIRECTORY_SEP
9490895469d4 Fix OpenBSD compilation some more. (Fix by Han Boetes.)
Karoly Lorentey <lorentey@elte.hu>
parents: 83500
diff changeset
86 #define DIRECTORY_SEP '/'
9490895469d4 Fix OpenBSD compilation some more. (Fix by Han Boetes.)
Karoly Lorentey <lorentey@elte.hu>
parents: 83500
diff changeset
87 #endif
9490895469d4 Fix OpenBSD compilation some more. (Fix by Han Boetes.)
Karoly Lorentey <lorentey@elte.hu>
parents: 83500
diff changeset
88 #ifndef IS_DIRECTORY_SEP
9490895469d4 Fix OpenBSD compilation some more. (Fix by Han Boetes.)
Karoly Lorentey <lorentey@elte.hu>
parents: 83500
diff changeset
89 #define IS_DIRECTORY_SEP(_c_) ((_c_) == DIRECTORY_SEP)
9490895469d4 Fix OpenBSD compilation some more. (Fix by Han Boetes.)
Karoly Lorentey <lorentey@elte.hu>
parents: 83500
diff changeset
90 #endif
9490895469d4 Fix OpenBSD compilation some more. (Fix by Han Boetes.)
Karoly Lorentey <lorentey@elte.hu>
parents: 83500
diff changeset
91 #ifndef IS_DEVICE_SEP
9490895469d4 Fix OpenBSD compilation some more. (Fix by Han Boetes.)
Karoly Lorentey <lorentey@elte.hu>
parents: 83500
diff changeset
92 #ifndef DEVICE_SEP
9490895469d4 Fix OpenBSD compilation some more. (Fix by Han Boetes.)
Karoly Lorentey <lorentey@elte.hu>
parents: 83500
diff changeset
93 #define IS_DEVICE_SEP(_c_) 0
9490895469d4 Fix OpenBSD compilation some more. (Fix by Han Boetes.)
Karoly Lorentey <lorentey@elte.hu>
parents: 83500
diff changeset
94 #else
9490895469d4 Fix OpenBSD compilation some more. (Fix by Han Boetes.)
Karoly Lorentey <lorentey@elte.hu>
parents: 83500
diff changeset
95 #define IS_DEVICE_SEP(_c_) ((_c_) == DEVICE_SEP)
9490895469d4 Fix OpenBSD compilation some more. (Fix by Han Boetes.)
Karoly Lorentey <lorentey@elte.hu>
parents: 83500
diff changeset
96 #endif
9490895469d4 Fix OpenBSD compilation some more. (Fix by Han Boetes.)
Karoly Lorentey <lorentey@elte.hu>
parents: 83500
diff changeset
97 #endif
9490895469d4 Fix OpenBSD compilation some more. (Fix by Han Boetes.)
Karoly Lorentey <lorentey@elte.hu>
parents: 83500
diff changeset
98 #ifndef IS_ANY_SEP
9490895469d4 Fix OpenBSD compilation some more. (Fix by Han Boetes.)
Karoly Lorentey <lorentey@elte.hu>
parents: 83500
diff changeset
99 #define IS_ANY_SEP(_c_) (IS_DIRECTORY_SEP (_c_))
9490895469d4 Fix OpenBSD compilation some more. (Fix by Han Boetes.)
Karoly Lorentey <lorentey@elte.hu>
parents: 83500
diff changeset
100 #endif
9490895469d4 Fix OpenBSD compilation some more. (Fix by Han Boetes.)
Karoly Lorentey <lorentey@elte.hu>
parents: 83500
diff changeset
101
9490895469d4 Fix OpenBSD compilation some more. (Fix by Han Boetes.)
Karoly Lorentey <lorentey@elte.hu>
parents: 83500
diff changeset
102
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
103
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
104 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
105 char *(getcwd) ();
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
106
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
107 #ifndef VERSION
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
108 #define VERSION "unspecified"
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
109 #endif
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
110
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
111 #define SEND_STRING(data) (send_to_emacs (s, (data)))
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
112 #define SEND_QUOTED(data) (quote_argument (s, (data)))
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
113
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
114 #ifndef EXIT_SUCCESS
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
115 #define EXIT_SUCCESS 0
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
116 #endif
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
117
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
118 #ifndef EXIT_FAILURE
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
119 #define EXIT_FAILURE 1
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
120 #endif
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
121
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
122 #ifndef FALSE
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
123 #define FALSE 0
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
124 #endif
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
125
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
126 #ifndef TRUE
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
127 #define TRUE 1
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
128 #endif
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
129
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
130 #ifndef NO_RETURN
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
131 #define NO_RETURN
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
132 #endif
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
133
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
134 /* Name used to invoke this program. */
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
135 char *progname;
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
136
53341
d4e6a050c9b1 Bugfix festival.
Karoly Lorentey <lorentey@elte.hu>
parents: 53233
diff changeset
137 /* The first argument to main. */
d4e6a050c9b1 Bugfix festival.
Karoly Lorentey <lorentey@elte.hu>
parents: 53233
diff changeset
138 int main_argc;
d4e6a050c9b1 Bugfix festival.
Karoly Lorentey <lorentey@elte.hu>
parents: 53233
diff changeset
139
d4e6a050c9b1 Bugfix festival.
Karoly Lorentey <lorentey@elte.hu>
parents: 53233
diff changeset
140 /* The second argument to main. */
d4e6a050c9b1 Bugfix festival.
Karoly Lorentey <lorentey@elte.hu>
parents: 53233
diff changeset
141 char **main_argv;
d4e6a050c9b1 Bugfix festival.
Karoly Lorentey <lorentey@elte.hu>
parents: 53233
diff changeset
142
16146
a649abfefbb1 (longopts): Change nowait to no-wait.
Richard M. Stallman <rms@gnu.org>
parents: 16074
diff changeset
143 /* 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
144 int nowait = 0;
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
145
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
146 /* Nonzero means args are expressions to be evaluated. --eval. */
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
147 int eval = 0;
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
148
83367
2b5fb28780be Fix `emacsclient -ne '(+ 2 2)'' (reported by Han Boetes), and clean up some corner cases in Emacs server.
Karoly Lorentey <lorentey@elte.hu>
parents: 83353
diff changeset
149 /* Nonzero means don't open a new frame. --current-frame. */
2b5fb28780be Fix `emacsclient -ne '(+ 2 2)'' (reported by Han Boetes), and clean up some corner cases in Emacs server.
Karoly Lorentey <lorentey@elte.hu>
parents: 83353
diff changeset
150 int current_frame = 0;
2b5fb28780be Fix `emacsclient -ne '(+ 2 2)'' (reported by Han Boetes), and clean up some corner cases in Emacs server.
Karoly Lorentey <lorentey@elte.hu>
parents: 83353
diff changeset
151
83043
78a785f205ea Added -w option to emacsclient for opening a new X frame.
Karoly Lorentey <lorentey@elte.hu>
parents: 83037
diff changeset
152 /* 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
153 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
154
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
155 /* The display on which Emacs should work. --display. */
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
156 char *display = NULL;
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
157
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
158 /* 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
159 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
160
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
161 /* 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
162 is not running. --alternate-editor. */
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
163 const char *alternate_editor = NULL;
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
164
52532
cd53bfef4ab1 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 52479
diff changeset
165 /* 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
166 char *socket_name = NULL;
bc2610a13fbf (socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
167
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
168 /* If non-NULL, the filename of the authentication file. */
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
169 char *server_file = NULL;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
170
74342
c6cb776ffbb7 (emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents: 74341
diff changeset
171 /* PID of the Emacs server process. */
c6cb776ffbb7 (emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents: 74341
diff changeset
172 int emacs_pid = 0;
c6cb776ffbb7 (emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents: 74341
diff changeset
173
83551
d9dc7e67ad3f Fix various suspend-related bugs in emacsclient. (Report & patch by Dan Nicolaescu.)
Karoly Lorentey <lorentey@elte.hu>
parents: 83550
diff changeset
174 /* Socket used to communicate with the Emacs server process. */
83590
dab011361c2a (s): Remove.
Jason Rumney <jasonr@gnu.org>
parents: 83556
diff changeset
175 /*HSOCKET s;*/
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
176
72005
da0099bc0ba4 * ebrowse.c (usage, version): Mark as NO_RETURN.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 68647
diff changeset
177 void print_help_and_exit () NO_RETURN;
21387
4812cf228971 Include <stdlib.h> and <unistd.h> if available.
Andreas Schwab <schwab@suse.de>
parents: 19582
diff changeset
178
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
179 struct option longopts[] =
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
180 {
16146
a649abfefbb1 (longopts): Change nowait to no-wait.
Richard M. Stallman <rms@gnu.org>
parents: 16074
diff changeset
181 { "no-wait", no_argument, NULL, 'n' },
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
182 { "eval", no_argument, NULL, 'e' },
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
183 { "help", no_argument, NULL, 'H' },
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
184 { "version", no_argument, NULL, 'V' },
82994
44ffe551079c Fix longopts option name for --tty.
Karoly Lorentey <lorentey@elte.hu>
parents: 82991
diff changeset
185 { "tty", no_argument, NULL, 't' },
83045
8ca11496d25c Changed emacsclient to open new frames by default.
Karoly Lorentey <lorentey@elte.hu>
parents: 83044
diff changeset
186 { "current-frame", no_argument, NULL, 'c' },
47515
6ee937dcfe16 (quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42412
diff changeset
187 { "alternate-editor", required_argument, NULL, 'a' },
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
188 #ifndef NO_SOCKETS_IN_FILE_SYSTEM
52479
bc2610a13fbf (socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
189 { "socket-name", required_argument, NULL, 's' },
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
190 #endif
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
191 { "server-file", required_argument, NULL, 'f' },
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
192 { "display", required_argument, NULL, 'd' },
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
193 { 0, 0, 0, 0 }
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
194 };
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
195
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
196
83103
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
197 /* Like malloc but get fatal error if memory is exhausted. */
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
198
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
199 long *
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
200 xmalloc (size)
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
201 unsigned int size;
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
202 {
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
203 long *result = (long *) malloc (size);
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
204 if (result == NULL)
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
205 {
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
206 perror ("malloc");
83121
84cafe5c268f Merged in changes from CVS trunk.
Karoly Lorentey <lorentey@elte.hu>
parents: 83107 55442
diff changeset
207 exit (EXIT_FAILURE);
83103
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
208 }
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
209 return result;
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
210 }
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
211
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
212 /* 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
213
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
214 char *
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
215 xstrdup (const char *s)
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
216 {
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
217 char *result = strdup (s);
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
218 if (result == NULL)
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
219 {
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
220 perror ("strdup");
83121
84cafe5c268f Merged in changes from CVS trunk.
Karoly Lorentey <lorentey@elte.hu>
parents: 83107 55442
diff changeset
221 exit (EXIT_FAILURE);
83103
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
222 }
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
223 return result;
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
224 }
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
225
83499
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
226 /* From sysdep.c */
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
227 #if !defined (HAVE_GET_CURRENT_DIR_NAME) || defined (BROKEN_GET_CURRENT_DIR_NAME)
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
228
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
229 /* Return the current working directory. Returns NULL on errors.
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
230 Any other returned value must be freed with free. This is used
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
231 only when get_current_dir_name is not defined on the system. */
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
232 char*
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
233 get_current_dir_name ()
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
234 {
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
235 char *buf;
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
236 char *pwd;
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
237 struct stat dotstat, pwdstat;
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
238 /* If PWD is accurate, use it instead of calling getwd. PWD is
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
239 sometimes a nicer name, and using it may avoid a fatal error if a
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
240 parent directory is searchable but not readable. */
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
241 if ((pwd = getenv ("PWD")) != 0
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
242 && (IS_DIRECTORY_SEP (*pwd) || (*pwd && IS_DEVICE_SEP (pwd[1])))
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
243 && stat (pwd, &pwdstat) == 0
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
244 && stat (".", &dotstat) == 0
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
245 && dotstat.st_ino == pwdstat.st_ino
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
246 && dotstat.st_dev == pwdstat.st_dev
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
247 #ifdef MAXPATHLEN
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
248 && strlen (pwd) < MAXPATHLEN
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
249 #endif
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
250 )
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
251 {
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
252 buf = (char *) xmalloc (strlen (pwd) + 1);
83499
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
253 if (!buf)
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
254 return NULL;
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
255 strcpy (buf, pwd);
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
256 }
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
257 #ifdef HAVE_GETCWD
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
258 else
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
259 {
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
260 size_t buf_size = 1024;
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
261 buf = (char *) xmalloc (buf_size);
83499
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
262 if (!buf)
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
263 return NULL;
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
264 for (;;)
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
265 {
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
266 if (getcwd (buf, buf_size) == buf)
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
267 break;
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
268 if (errno != ERANGE)
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
269 {
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
270 int tmp_errno = errno;
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
271 free (buf);
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
272 errno = tmp_errno;
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
273 return NULL;
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
274 }
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
275 buf_size *= 2;
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
276 buf = (char *) realloc (buf, buf_size);
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
277 if (!buf)
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
278 return NULL;
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
279 }
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
280 }
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
281 #else
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
282 else
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
283 {
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
284 /* We need MAXPATHLEN here. */
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
285 buf = (char *) xmalloc (MAXPATHLEN + 1);
83499
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
286 if (!buf)
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
287 return NULL;
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
288 if (getwd (buf) == NULL)
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
289 {
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
290 int tmp_errno = errno;
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
291 free (buf);
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
292 errno = tmp_errno;
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
293 return NULL;
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
294 }
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
295 }
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
296 #endif
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
297 return buf;
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
298 }
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
299 #endif
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
300
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
301 /* Message functions. */
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
302
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
303 #ifdef WINDOWSNT
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
304 int
74645
aa3039743d63 Comment and whitespace changes.
Richard M. Stallman <rms@gnu.org>
parents: 74644
diff changeset
305 w32_window_app ()
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
306 {
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
307 static int window_app = -1;
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
308 char szTitle[MAX_PATH];
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
309
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
310 if (window_app < 0)
74644
4142abafc7b4 Rework a few comments.
Juanma Barranquero <lekktu@gmail.com>
parents: 74637
diff changeset
311 /* Checking for STDOUT does not work; it's a valid handle also in
4142abafc7b4 Rework a few comments.
Juanma Barranquero <lekktu@gmail.com>
parents: 74637
diff changeset
312 nonconsole apps. Testing for the console title seems to work. */
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
313 window_app = (GetConsoleTitleA (szTitle, MAX_PATH) == 0);
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
314
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
315 return window_app;
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
316 }
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
317 #endif
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
318
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
319 void
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
320 message (int is_error, char *message, ...)
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
321 {
74342
c6cb776ffbb7 (emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents: 74341
diff changeset
322 char msg [2048];
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
323 va_list args;
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
324
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
325 va_start (args, message);
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
326 vsprintf (msg, message, args);
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
327 va_end (args);
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
328
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
329 #ifdef WINDOWSNT
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
330 if (w32_window_app ())
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
331 {
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
332 if (is_error)
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
333 MessageBox (NULL, msg, "Emacsclient ERROR", MB_ICONERROR);
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
334 else
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
335 MessageBox (NULL, msg, "Emacsclient", MB_ICONINFORMATION);
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
336 }
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
337 else
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
338 #endif
74341
32079f79e240 (message): Make sure the message is properly written even if it contains printf
Juanma Barranquero <lekktu@gmail.com>
parents: 74176
diff changeset
339 {
32079f79e240 (message): Make sure the message is properly written even if it contains printf
Juanma Barranquero <lekktu@gmail.com>
parents: 74176
diff changeset
340 FILE *f = is_error ? stderr : stdout;
32079f79e240 (message): Make sure the message is properly written even if it contains printf
Juanma Barranquero <lekktu@gmail.com>
parents: 74176
diff changeset
341
32079f79e240 (message): Make sure the message is properly written even if it contains printf
Juanma Barranquero <lekktu@gmail.com>
parents: 74176
diff changeset
342 fputs (msg, f);
32079f79e240 (message): Make sure the message is properly written even if it contains printf
Juanma Barranquero <lekktu@gmail.com>
parents: 74176
diff changeset
343 fflush (f);
32079f79e240 (message): Make sure the message is properly written even if it contains printf
Juanma Barranquero <lekktu@gmail.com>
parents: 74176
diff changeset
344 }
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
345 }
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
346
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
347 /* Decode the options from argv and argc.
16061
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
348 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
349
16061
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
350 void
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
351 decode_options (argc, argv)
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
352 int argc;
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
353 char **argv;
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
354 {
53813
ddc4b99f4f8c (decode_options): Fix handling of alternate editor.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53734
diff changeset
355 alternate_editor = getenv ("ALTERNATE_EDITOR");
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
356 display = getenv ("DISPLAY");
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
357 if (display && strlen (display) == 0)
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
358 display = NULL;
53813
ddc4b99f4f8c (decode_options): Fix handling of alternate editor.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53734
diff changeset
359
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
360 while (1)
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
361 {
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
362 int opt = getopt_long (argc, argv,
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
363 #ifndef NO_SOCKETS_IN_FILE_SYSTEM
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
364 "VHnea:s:f:d:tc",
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
365 #else
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
366 "VHnea:f:d:tc",
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
367 #endif
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
368 longopts, 0);
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
369
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
370 if (opt == EOF)
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
371 break;
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
372
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
373 switch (opt)
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
374 {
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
375 case 0:
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
376 /* 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
377 long-named option. We should do nothing. */
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
378 break;
42176
1f5dbeefa536 Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 39723
diff changeset
379
27305
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
380 case 'a':
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
381 alternate_editor = optarg;
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
382 break;
42176
1f5dbeefa536 Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 39723
diff changeset
383
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
384 #ifndef NO_SOCKETS_IN_FILE_SYSTEM
52479
bc2610a13fbf (socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
385 case 's':
bc2610a13fbf (socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
386 socket_name = optarg;
bc2610a13fbf (socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
387 break;
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
388 #endif
52479
bc2610a13fbf (socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
389
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
390 case 'f':
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
391 server_file = optarg;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
392 break;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
393
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
394 case 'd':
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
395 display = optarg;
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
396 break;
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
397
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
398 case 'n':
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
399 nowait = 1;
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
400 break;
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
401
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
402 case 'e':
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
403 eval = 1;
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
404 break;
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
405
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
406 case 'V':
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
407 message (FALSE, "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
408 exit (EXIT_SUCCESS);
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
409 break;
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
410
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
411 case 't':
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
412 tty = 1;
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
413 break;
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
414
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
415 case 'c':
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
416 current_frame = 1;
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
417 break;
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
418
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
419 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
420 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
421 break;
e5f56d47b52c (print_help_and_exit): Print to stdout. Exit successfully. Added some blank
Juanma Barranquero <lekktu@gmail.com>
parents: 48627
diff changeset
422
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
423 default:
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
424 message (TRUE, "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
425 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
426 break;
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
427 }
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
428 }
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
429
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
430 if (!tty && display)
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
431 window_system = 1;
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
432 else
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
433 tty = 1;
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
434
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
435 /* --no-wait implies --current-frame on ttys when there are file
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
436 arguments or expressions given. */
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
437 if (nowait && tty && argc - optind > 0)
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
438 current_frame = 1;
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
439
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
440 if (current_frame)
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
441 {
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
442 tty = 0;
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
443 window_system = 0;
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
444 }
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
445
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
446 if (tty)
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
447 window_system = 0;
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
448 }
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
449
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
450
21387
4812cf228971 Include <stdlib.h> and <unistd.h> if available.
Andreas Schwab <schwab@suse.de>
parents: 19582
diff changeset
451 void
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
452 print_help_and_exit ()
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
453 {
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
454 message (FALSE,
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
455 "Usage: %s [OPTIONS] FILE...\n\
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
456 Tell the Emacs server to visit the specified files.\n\
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
457 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
458 \n\
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
459 The following OPTIONS are accepted:\n\
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
460 -V, --version Just print version info and return\n\
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
461 -H, --help Print this usage information message\n\
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
462 -t, --tty Open a new Emacs frame on the current terminal\n\
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
463 -c, --current-frame Do not create a new frame; use the current Emacs frame\n\
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
464 -e, --eval Evaluate the FILE arguments as ELisp expressions\n\
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
465 -n, --no-wait Don't wait for the server to return\n\
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
466 -d, --display=DISPLAY Visit the file in the given display\n"
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
467 #ifndef NO_SOCKETS_IN_FILE_SYSTEM
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
468 "-s, --socket-name=FILENAME\n\
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
469 Set filename of the UNIX socket for communication\n"
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
470 #endif
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
471 "-f, --server-file=FILENAME\n\
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
472 Set filename of the TCP authentication file\n\
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
473 -a, --alternate-editor=EDITOR\n\
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
474 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
475 \n\
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
476 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
477 exit (EXIT_SUCCESS);
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
478 }
16061
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
479
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
480 /*
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
481 Try to run a different command, or --if no alternate editor is
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
482 defined-- exit with an errorcode.
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
483 */
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
484 void
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
485 fail (void)
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
486 {
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
487 if (alternate_editor)
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
488 {
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
489 int i = optind - 1;
74637
fe8bd1af34c4 (w32_execvp): New function; wrapper for `execvp'.
Juanma Barranquero <lekktu@gmail.com>
parents: 74342
diff changeset
490
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
491 execvp (alternate_editor, main_argv + i);
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
492 message (TRUE, "%s: error executing alternate editor \"%s\"\n",
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
493 progname, alternate_editor);
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
494 }
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
495 exit (EXIT_FAILURE);
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
496 }
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
497
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
498
73617
7af864af10b6 [WINDOWSNT]: Define HAVE_INET_SOCKETS.
Juanma Barranquero <lekktu@gmail.com>
parents: 73601
diff changeset
499 #if !defined (HAVE_SOCKETS) || !defined (HAVE_INET_SOCKETS)
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
500
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
501 int
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
502 main (argc, argv)
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
503 int argc;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
504 char **argv;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
505 {
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
506 main_argc = argc;
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
507 main_argv = argv;
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
508 progname = argv[0];
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
509 message (TRUE, "%s: Sorry, the Emacs server is supported only\n"
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
510 "on systems with Berkeley sockets.\n",
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
511 argv[0]);
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
512 fail ();
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
513 }
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
514
73617
7af864af10b6 [WINDOWSNT]: Define HAVE_INET_SOCKETS.
Juanma Barranquero <lekktu@gmail.com>
parents: 73601
diff changeset
515 #else /* HAVE_SOCKETS && HAVE_INET_SOCKETS */
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
516
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
517 #ifdef WINDOWSNT
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
518 # include <winsock2.h>
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
519 #else
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
520 # include <sys/types.h>
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
521 # include <sys/socket.h>
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
522 # include <sys/un.h>
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
523 # include <sys/stat.h>
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
524 # include <errno.h>
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
525 #endif
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
526
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
527 #define AUTH_KEY_LENGTH 64
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
528 #define SEND_BUFFER_SIZE 4096
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
529
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
530 extern char *strerror ();
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
531 extern int errno;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
532
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
533 /* Buffer to accumulate data to send in TCP connections. */
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
534 char send_buffer[SEND_BUFFER_SIZE + 1];
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
535 int sblen = 0; /* Fill pointer for the send buffer. */
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
536
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
537 /* Let's send the data to Emacs when either
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
538 - the data ends in "\n", or
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
539 - the buffer is full (but this shouldn't happen)
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
540 Otherwise, we just accumulate it. */
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
541 void
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
542 send_to_emacs (s, data)
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
543 HSOCKET s;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
544 char *data;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
545 {
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
546 while (data)
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
547 {
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
548 int dlen = strlen (data);
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
549 if (dlen + sblen >= SEND_BUFFER_SIZE)
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
550 {
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
551 int part = SEND_BUFFER_SIZE - sblen;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
552 strncpy (&send_buffer[sblen], data, part);
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
553 data += part;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
554 sblen = SEND_BUFFER_SIZE;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
555 }
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
556 else if (dlen)
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
557 {
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
558 strcpy (&send_buffer[sblen], data);
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
559 data = NULL;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
560 sblen += dlen;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
561 }
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
562 else
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
563 break;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
564
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
565 if (sblen == SEND_BUFFER_SIZE
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
566 || (sblen > 0 && send_buffer[sblen-1] == '\n'))
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
567 {
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
568 int sent = send (s, send_buffer, sblen, 0);
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
569 if (sent != sblen)
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
570 strcpy (send_buffer, &send_buffer[sent]);
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
571 sblen -= sent;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
572 }
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
573 }
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
574 }
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
575
83499
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
576
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
577 /* 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
578 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
579 return value never contains a space.
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
580
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
581 Does not change the string. Outputs the result to STREAM. */
52635
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
582 void
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
583 quote_argument (s, str)
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
584 HSOCKET s;
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
585 char *str;
16061
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
586 {
83103
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
587 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
588 char *p, *q;
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
589
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
590 p = str;
16061
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
591 q = copy;
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
592 while (*p)
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
593 {
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
594 if (*p == ' ')
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
595 {
16074
25cfff7ffced (quote_file_name): Quote with &, not \.
Richard M. Stallman <rms@gnu.org>
parents: 16061
diff changeset
596 *q++ = '&';
16061
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
597 *q++ = '_';
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
598 p++;
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
599 }
47515
6ee937dcfe16 (quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42412
diff changeset
600 else if (*p == '\n')
6ee937dcfe16 (quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42412
diff changeset
601 {
6ee937dcfe16 (quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42412
diff changeset
602 *q++ = '&';
6ee937dcfe16 (quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42412
diff changeset
603 *q++ = 'n';
6ee937dcfe16 (quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42412
diff changeset
604 p++;
6ee937dcfe16 (quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42412
diff changeset
605 }
16061
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
606 else
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
607 {
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
608 if (*p == '&' || (*p == '-' && p == str))
16074
25cfff7ffced (quote_file_name): Quote with &, not \.
Richard M. Stallman <rms@gnu.org>
parents: 16061
diff changeset
609 *q++ = '&';
16061
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
610 *q++ = *p++;
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
611 }
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
612 }
16074
25cfff7ffced (quote_file_name): Quote with &, not \.
Richard M. Stallman <rms@gnu.org>
parents: 16061
diff changeset
613 *q++ = 0;
16061
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
614
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
615 SEND_STRING (copy);
52635
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
616
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
617 free (copy);
16061
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
618 }
18701
9c7e0c926ed5 [C_ALLOCA] (xmalloc): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16218
diff changeset
619
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
620
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
621 /* 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
622 modifying the string in place. Returns STR. */
18701
9c7e0c926ed5 [C_ALLOCA] (xmalloc): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16218
diff changeset
623
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
624 char *
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
625 unquote_argument (str)
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
626 char *str;
18701
9c7e0c926ed5 [C_ALLOCA] (xmalloc): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16218
diff changeset
627 {
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
628 char *p, *q;
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
629
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
630 if (! str)
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
631 return str;
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
632
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
633 p = str;
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
634 q = str;
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
635 while (*p)
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
636 {
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
637 if (*p == '&')
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
638 {
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
639 p++;
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
640 if (*p == '&')
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
641 *p = '&';
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
642 else if (*p == '_')
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
643 *p = ' ';
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
644 else if (*p == 'n')
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
645 *p = '\n';
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
646 else if (*p == '-')
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
647 *p = '-';
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
648 }
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
649 *q++ = *p++;
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
650 }
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
651 *q = 0;
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
652 return str;
18701
9c7e0c926ed5 [C_ALLOCA] (xmalloc): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16218
diff changeset
653 }
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
654
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
655
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
656 int
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
657 file_name_absolute_p (filename)
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
658 const unsigned char *filename;
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
659 {
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
660 /* Sanity check, it shouldn't happen. */
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
661 if (! filename) return FALSE;
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
662
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
663 /* /xxx is always an absolute path. */
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
664 if (filename[0] == '/') return TRUE;
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
665
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
666 /* Empty filenames (which shouldn't happen) are relative. */
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
667 if (filename[0] == '\0') return FALSE;
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
668
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
669 #ifdef WINDOWSNT
75956
6ef0c279b18c Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents: 75348
diff changeset
670 /* X:\xxx is always absolute. */
74176
6eee550d3bda (file_name_absolute_p) [WINDOWSNT]: Use isalpha().
Jason Rumney <jasonr@gnu.org>
parents: 74172
diff changeset
671 if (isalpha (filename[0])
74172
cbda0982f77c (file_name_absolute_p) [WINDOWSNT]: Support absolute file names with forward
Eli Zaretskii <eliz@gnu.org>
parents: 74145
diff changeset
672 && filename[1] == ':' && (filename[2] == '\\' || filename[2] == '/'))
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
673 return TRUE;
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
674
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
675 /* Both \xxx and \\xxx\yyy are absolute. */
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
676 if (filename[0] == '\\') return TRUE;
75956
6ef0c279b18c Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents: 75348
diff changeset
677
6ef0c279b18c Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents: 75348
diff changeset
678 /*
6ef0c279b18c Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents: 75348
diff changeset
679 FIXME: There's a corner case not dealt with, "x:y", where:
6ef0c279b18c Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents: 75348
diff changeset
680
6ef0c279b18c Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents: 75348
diff changeset
681 1) x is a valid drive designation (usually a letter in the A-Z range)
6ef0c279b18c Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents: 75348
diff changeset
682 and y is a path, relative to the current directory on drive x. This
6ef0c279b18c Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents: 75348
diff changeset
683 is absolute, *after* fixing the y part to include the current
6ef0c279b18c Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents: 75348
diff changeset
684 directory in x.
6ef0c279b18c Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents: 75348
diff changeset
685
6ef0c279b18c Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents: 75348
diff changeset
686 2) x is a relative file name, and y is an NTFS stream name. This is a
6ef0c279b18c Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents: 75348
diff changeset
687 correct relative path, but it is very unusual.
6ef0c279b18c Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents: 75348
diff changeset
688
6ef0c279b18c Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents: 75348
diff changeset
689 The trouble is that first case items are also valid examples of the
6ef0c279b18c Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents: 75348
diff changeset
690 second case, i.e., "c:test" can be understood as drive:path or as
6ef0c279b18c Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents: 75348
diff changeset
691 file:stream.
6ef0c279b18c Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents: 75348
diff changeset
692
6ef0c279b18c Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents: 75348
diff changeset
693 The "right" fix would involve checking whether
6ef0c279b18c Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents: 75348
diff changeset
694 - the current drive/partition is NTFS,
6ef0c279b18c Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents: 75348
diff changeset
695 - x is a valid (and accesible) drive designator,
6ef0c279b18c Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents: 75348
diff changeset
696 - x:y already exists as a file:stream in the current directory,
6ef0c279b18c Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents: 75348
diff changeset
697 - y already exists on the current directory of drive x,
6ef0c279b18c Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents: 75348
diff changeset
698 - the auspices are favorable,
6ef0c279b18c Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents: 75348
diff changeset
699 and then taking an "informed decision" based on the above.
6ef0c279b18c Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents: 75348
diff changeset
700
6ef0c279b18c Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents: 75348
diff changeset
701 Whatever the result, Emacs currently does a very bad job of dealing
6ef0c279b18c Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents: 75348
diff changeset
702 with NTFS file:streams: it cannot visit them, and the only way to
6ef0c279b18c Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents: 75348
diff changeset
703 create one is by setting `buffer-file-name' to point to it (either
6ef0c279b18c Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents: 75348
diff changeset
704 manually or with emacsclient). So perhaps resorting to 1) and ignoring
6ef0c279b18c Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents: 75348
diff changeset
705 2) for now is the right thing to do.
6ef0c279b18c Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents: 75348
diff changeset
706
6ef0c279b18c Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents: 75348
diff changeset
707 Anyway, something to decide After the Release.
6ef0c279b18c Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents: 75348
diff changeset
708 */
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
709 #endif
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
710
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
711 return FALSE;
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
712 }
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
713
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
714 #ifdef WINDOWSNT
74645
aa3039743d63 Comment and whitespace changes.
Richard M. Stallman <rms@gnu.org>
parents: 74644
diff changeset
715 /* Wrapper to make WSACleanup a cdecl, as required by atexit. */
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
716 void
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
717 __cdecl close_winsock ()
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
718 {
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
719 WSACleanup ();
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
720 }
18701
9c7e0c926ed5 [C_ALLOCA] (xmalloc): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16218
diff changeset
721
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
722 /* Initialize the WinSock2 library. */
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
723 void
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
724 initialize_sockets ()
18701
9c7e0c926ed5 [C_ALLOCA] (xmalloc): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16218
diff changeset
725 {
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
726 WSADATA wsaData;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
727
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
728 if (WSAStartup (MAKEWORD (2, 0), &wsaData))
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
729 {
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
730 message (TRUE, "%s: error initializing WinSock2", progname);
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
731 exit (EXIT_FAILURE);
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
732 }
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
733
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
734 atexit (close_winsock);
73578
e193b6a3f379 Fixes to emacsclient.c for GNU/Linux.
Juanma Barranquero <lekktu@gmail.com>
parents: 73562
diff changeset
735 }
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
736 #endif /* WINDOWSNT */
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
737
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
738
83550
17e0dd217877 Merged from emacs@sv.gnu.org.
Karoly Lorentey <lorentey@elte.hu>
parents: 83548 74729
diff changeset
739 #ifdef WINDOWSNT
17e0dd217877 Merged from emacs@sv.gnu.org.
Karoly Lorentey <lorentey@elte.hu>
parents: 83548 74729
diff changeset
740
17e0dd217877 Merged from emacs@sv.gnu.org.
Karoly Lorentey <lorentey@elte.hu>
parents: 83548 74729
diff changeset
741 /*
17e0dd217877 Merged from emacs@sv.gnu.org.
Karoly Lorentey <lorentey@elte.hu>
parents: 83548 74729
diff changeset
742 execvp wrapper for Windows. Quotes arguments with embedded spaces.
17e0dd217877 Merged from emacs@sv.gnu.org.
Karoly Lorentey <lorentey@elte.hu>
parents: 83548 74729
diff changeset
743
17e0dd217877 Merged from emacs@sv.gnu.org.
Karoly Lorentey <lorentey@elte.hu>
parents: 83548 74729
diff changeset
744 This is necessary due to the broken implementation of exec* routines in
17e0dd217877 Merged from emacs@sv.gnu.org.
Karoly Lorentey <lorentey@elte.hu>
parents: 83548 74729
diff changeset
745 the Microsoft libraries: they concatenate the arguments together without
17e0dd217877 Merged from emacs@sv.gnu.org.
Karoly Lorentey <lorentey@elte.hu>
parents: 83548 74729
diff changeset
746 quoting special characters, and pass the result to CreateProcess, with
17e0dd217877 Merged from emacs@sv.gnu.org.
Karoly Lorentey <lorentey@elte.hu>
parents: 83548 74729
diff changeset
747 predictably bad results. By contrast, Posix execvp passes the arguments
17e0dd217877 Merged from emacs@sv.gnu.org.
Karoly Lorentey <lorentey@elte.hu>
parents: 83548 74729
diff changeset
748 directly into the argv array of the child process.
17e0dd217877 Merged from emacs@sv.gnu.org.
Karoly Lorentey <lorentey@elte.hu>
parents: 83548 74729
diff changeset
749 */
17e0dd217877 Merged from emacs@sv.gnu.org.
Karoly Lorentey <lorentey@elte.hu>
parents: 83548 74729
diff changeset
750 int
17e0dd217877 Merged from emacs@sv.gnu.org.
Karoly Lorentey <lorentey@elte.hu>
parents: 83548 74729
diff changeset
751 w32_execvp (path, argv)
17e0dd217877 Merged from emacs@sv.gnu.org.
Karoly Lorentey <lorentey@elte.hu>
parents: 83548 74729
diff changeset
752 char *path;
17e0dd217877 Merged from emacs@sv.gnu.org.
Karoly Lorentey <lorentey@elte.hu>
parents: 83548 74729
diff changeset
753 char **argv;
17e0dd217877 Merged from emacs@sv.gnu.org.
Karoly Lorentey <lorentey@elte.hu>
parents: 83548 74729
diff changeset
754 {
17e0dd217877 Merged from emacs@sv.gnu.org.
Karoly Lorentey <lorentey@elte.hu>
parents: 83548 74729
diff changeset
755 int i;
17e0dd217877 Merged from emacs@sv.gnu.org.
Karoly Lorentey <lorentey@elte.hu>
parents: 83548 74729
diff changeset
756
17e0dd217877 Merged from emacs@sv.gnu.org.
Karoly Lorentey <lorentey@elte.hu>
parents: 83548 74729
diff changeset
757 /* Required to allow a .BAT script as alternate editor. */
17e0dd217877 Merged from emacs@sv.gnu.org.
Karoly Lorentey <lorentey@elte.hu>
parents: 83548 74729
diff changeset
758 argv[0] = (char *) alternate_editor;
17e0dd217877 Merged from emacs@sv.gnu.org.
Karoly Lorentey <lorentey@elte.hu>
parents: 83548 74729
diff changeset
759
17e0dd217877 Merged from emacs@sv.gnu.org.
Karoly Lorentey <lorentey@elte.hu>
parents: 83548 74729
diff changeset
760 for (i = 0; argv[i]; i++)
17e0dd217877 Merged from emacs@sv.gnu.org.
Karoly Lorentey <lorentey@elte.hu>
parents: 83548 74729
diff changeset
761 if (strchr (argv[i], ' '))
17e0dd217877 Merged from emacs@sv.gnu.org.
Karoly Lorentey <lorentey@elte.hu>
parents: 83548 74729
diff changeset
762 {
17e0dd217877 Merged from emacs@sv.gnu.org.
Karoly Lorentey <lorentey@elte.hu>
parents: 83548 74729
diff changeset
763 char *quoted = alloca (strlen (argv[i]) + 3);
17e0dd217877 Merged from emacs@sv.gnu.org.
Karoly Lorentey <lorentey@elte.hu>
parents: 83548 74729
diff changeset
764 sprintf (quoted, "\"%s\"", argv[i]);
17e0dd217877 Merged from emacs@sv.gnu.org.
Karoly Lorentey <lorentey@elte.hu>
parents: 83548 74729
diff changeset
765 argv[i] = quoted;
17e0dd217877 Merged from emacs@sv.gnu.org.
Karoly Lorentey <lorentey@elte.hu>
parents: 83548 74729
diff changeset
766 }
17e0dd217877 Merged from emacs@sv.gnu.org.
Karoly Lorentey <lorentey@elte.hu>
parents: 83548 74729
diff changeset
767
17e0dd217877 Merged from emacs@sv.gnu.org.
Karoly Lorentey <lorentey@elte.hu>
parents: 83548 74729
diff changeset
768 return execvp (path, argv);
17e0dd217877 Merged from emacs@sv.gnu.org.
Karoly Lorentey <lorentey@elte.hu>
parents: 83548 74729
diff changeset
769 }
17e0dd217877 Merged from emacs@sv.gnu.org.
Karoly Lorentey <lorentey@elte.hu>
parents: 83548 74729
diff changeset
770
17e0dd217877 Merged from emacs@sv.gnu.org.
Karoly Lorentey <lorentey@elte.hu>
parents: 83548 74729
diff changeset
771 #undef execvp
17e0dd217877 Merged from emacs@sv.gnu.org.
Karoly Lorentey <lorentey@elte.hu>
parents: 83548 74729
diff changeset
772 #define execvp w32_execvp
17e0dd217877 Merged from emacs@sv.gnu.org.
Karoly Lorentey <lorentey@elte.hu>
parents: 83548 74729
diff changeset
773
17e0dd217877 Merged from emacs@sv.gnu.org.
Karoly Lorentey <lorentey@elte.hu>
parents: 83548 74729
diff changeset
774 #endif /* WINDOWSNT */
17e0dd217877 Merged from emacs@sv.gnu.org.
Karoly Lorentey <lorentey@elte.hu>
parents: 83548 74729
diff changeset
775
27305
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
776 /*
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
777 * Read the information needed to set up a TCP comm channel with
73806
fbfa7d8c0a64 (get_server_config): Extract also the Emacs pid from the server file.
Juanma Barranquero <lekktu@gmail.com>
parents: 73765
diff changeset
778 * the Emacs server: host, port, pid and authentication string.
74729
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
779 */
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
780 int
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
781 get_server_config (server, authentication)
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
782 struct sockaddr_in *server;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
783 char *authentication;
27305
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
784 {
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
785 char dotted[32];
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
786 char *port;
73806
fbfa7d8c0a64 (get_server_config): Extract also the Emacs pid from the server file.
Juanma Barranquero <lekktu@gmail.com>
parents: 73765
diff changeset
787 char *pid;
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
788 FILE *config = NULL;
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
789
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
790 if (file_name_absolute_p (server_file))
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
791 config = fopen (server_file, "rb");
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
792 else
27305
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
793 {
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
794 char *home = getenv ("HOME");
73809
cbc1f46b6590 (get_server_config) [WINDOWSNT]: Search the server file on APPDATA
Juanma Barranquero <lekktu@gmail.com>
parents: 73806
diff changeset
795
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
796 if (home)
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
797 {
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
798 char *path = alloca (32 + strlen (home) + strlen (server_file));
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
799 sprintf (path, "%s/.emacs.d/server/%s", home, server_file);
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
800 config = fopen (path, "rb");
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
801 }
73809
cbc1f46b6590 (get_server_config) [WINDOWSNT]: Search the server file on APPDATA
Juanma Barranquero <lekktu@gmail.com>
parents: 73806
diff changeset
802 #ifdef WINDOWSNT
cbc1f46b6590 (get_server_config) [WINDOWSNT]: Search the server file on APPDATA
Juanma Barranquero <lekktu@gmail.com>
parents: 73806
diff changeset
803 if (!config && (home = getenv ("APPDATA")))
cbc1f46b6590 (get_server_config) [WINDOWSNT]: Search the server file on APPDATA
Juanma Barranquero <lekktu@gmail.com>
parents: 73806
diff changeset
804 {
cbc1f46b6590 (get_server_config) [WINDOWSNT]: Search the server file on APPDATA
Juanma Barranquero <lekktu@gmail.com>
parents: 73806
diff changeset
805 char *path = alloca (32 + strlen (home) + strlen (server_file));
cbc1f46b6590 (get_server_config) [WINDOWSNT]: Search the server file on APPDATA
Juanma Barranquero <lekktu@gmail.com>
parents: 73806
diff changeset
806 sprintf (path, "%s/.emacs.d/server/%s", home, server_file);
cbc1f46b6590 (get_server_config) [WINDOWSNT]: Search the server file on APPDATA
Juanma Barranquero <lekktu@gmail.com>
parents: 73806
diff changeset
807 config = fopen (path, "rb");
cbc1f46b6590 (get_server_config) [WINDOWSNT]: Search the server file on APPDATA
Juanma Barranquero <lekktu@gmail.com>
parents: 73806
diff changeset
808 }
cbc1f46b6590 (get_server_config) [WINDOWSNT]: Search the server file on APPDATA
Juanma Barranquero <lekktu@gmail.com>
parents: 73806
diff changeset
809 #endif
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
810 }
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
811
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
812 if (! config)
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
813 return FALSE;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
814
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
815 if (fgets (dotted, sizeof dotted, config)
73806
fbfa7d8c0a64 (get_server_config): Extract also the Emacs pid from the server file.
Juanma Barranquero <lekktu@gmail.com>
parents: 73765
diff changeset
816 && (port = strchr (dotted, ':'))
fbfa7d8c0a64 (get_server_config): Extract also the Emacs pid from the server file.
Juanma Barranquero <lekktu@gmail.com>
parents: 73765
diff changeset
817 && (pid = strchr (port, ' ')))
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
818 {
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
819 *port++ = '\0';
73806
fbfa7d8c0a64 (get_server_config): Extract also the Emacs pid from the server file.
Juanma Barranquero <lekktu@gmail.com>
parents: 73765
diff changeset
820 *pid++ = '\0';
27305
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
821 }
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
822 else
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
823 {
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
824 message (TRUE, "%s: invalid configuration info", progname);
55442
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53813
diff changeset
825 exit (EXIT_FAILURE);
27305
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
826 }
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
827
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
828 server->sin_family = AF_INET;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
829 server->sin_addr.s_addr = inet_addr (dotted);
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
830 server->sin_port = htons (atoi (port));
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
831
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
832 if (! fread (authentication, AUTH_KEY_LENGTH, 1, config))
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
833 {
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
834 message (TRUE, "%s: cannot read authentication info", progname);
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
835 exit (EXIT_FAILURE);
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
836 }
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
837
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
838 fclose (config);
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
839
74342
c6cb776ffbb7 (emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents: 74341
diff changeset
840 emacs_pid = atoi (pid);
73806
fbfa7d8c0a64 (get_server_config): Extract also the Emacs pid from the server file.
Juanma Barranquero <lekktu@gmail.com>
parents: 73765
diff changeset
841
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
842 return TRUE;
27305
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
843 }
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
844
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
845 HSOCKET
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
846 set_tcp_socket ()
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
847 {
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
848 HSOCKET s;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
849 struct sockaddr_in server;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
850 struct linger l_arg = {1, 1};
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
851 char auth_string[AUTH_KEY_LENGTH + 1];
27305
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
852
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
853 if (! get_server_config (&server, auth_string))
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
854 return INVALID_SOCKET;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
855
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
856 if (server.sin_addr.s_addr != inet_addr ("127.0.0.1"))
74341
32079f79e240 (message): Make sure the message is properly written even if it contains printf
Juanma Barranquero <lekktu@gmail.com>
parents: 74176
diff changeset
857 message (FALSE, "%s: connected to remote socket at %s\n",
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
858 progname, inet_ntoa (server.sin_addr));
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
859
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
860 /*
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
861 * Open up an AF_INET socket
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
862 */
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
863 if ((s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
864 {
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
865 message (TRUE, "%s: socket: %s\n", progname, strerror (errno));
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
866 return INVALID_SOCKET;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
867 }
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
868
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
869 /*
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
870 * Set up the socket
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
871 */
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
872 if (connect (s, (struct sockaddr *) &server, sizeof server) < 0)
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
873 {
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
874 message (TRUE, "%s: connect: %s\n", progname, strerror (errno));
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
875 return INVALID_SOCKET;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
876 }
27305
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
877
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
878 setsockopt (s, SOL_SOCKET, SO_LINGER, (char *) &l_arg, sizeof l_arg);
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
879
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
880 /*
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
881 * Send the authentication
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
882 */
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
883 auth_string[AUTH_KEY_LENGTH] = '\0';
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
884
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
885 SEND_STRING ("-auth ");
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
886 SEND_STRING (auth_string);
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
887 SEND_STRING ("\n");
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
888
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
889 return s;
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
890 }
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
891
83590
dab011361c2a (s): Remove.
Jason Rumney <jasonr@gnu.org>
parents: 83556
diff changeset
892
dab011361c2a (s): Remove.
Jason Rumney <jasonr@gnu.org>
parents: 83556
diff changeset
893 /* Returns 1 if PREFIX is a prefix of STRING. */
dab011361c2a (s): Remove.
Jason Rumney <jasonr@gnu.org>
parents: 83556
diff changeset
894 static int
dab011361c2a (s): Remove.
Jason Rumney <jasonr@gnu.org>
parents: 83556
diff changeset
895 strprefix (char *prefix, char *string)
dab011361c2a (s): Remove.
Jason Rumney <jasonr@gnu.org>
parents: 83556
diff changeset
896 {
dab011361c2a (s): Remove.
Jason Rumney <jasonr@gnu.org>
parents: 83556
diff changeset
897 int i;
dab011361c2a (s): Remove.
Jason Rumney <jasonr@gnu.org>
parents: 83556
diff changeset
898 if (! prefix)
dab011361c2a (s): Remove.
Jason Rumney <jasonr@gnu.org>
parents: 83556
diff changeset
899 return 1;
dab011361c2a (s): Remove.
Jason Rumney <jasonr@gnu.org>
parents: 83556
diff changeset
900
dab011361c2a (s): Remove.
Jason Rumney <jasonr@gnu.org>
parents: 83556
diff changeset
901 if (!string)
dab011361c2a (s): Remove.
Jason Rumney <jasonr@gnu.org>
parents: 83556
diff changeset
902 return 0;
dab011361c2a (s): Remove.
Jason Rumney <jasonr@gnu.org>
parents: 83556
diff changeset
903
dab011361c2a (s): Remove.
Jason Rumney <jasonr@gnu.org>
parents: 83556
diff changeset
904 for (i = 0; prefix[i]; i++)
dab011361c2a (s): Remove.
Jason Rumney <jasonr@gnu.org>
parents: 83556
diff changeset
905 if (!string[i] || string[i] != prefix[i])
dab011361c2a (s): Remove.
Jason Rumney <jasonr@gnu.org>
parents: 83556
diff changeset
906 return 0;
dab011361c2a (s): Remove.
Jason Rumney <jasonr@gnu.org>
parents: 83556
diff changeset
907 return 1;
dab011361c2a (s): Remove.
Jason Rumney <jasonr@gnu.org>
parents: 83556
diff changeset
908 }
dab011361c2a (s): Remove.
Jason Rumney <jasonr@gnu.org>
parents: 83556
diff changeset
909
dab011361c2a (s): Remove.
Jason Rumney <jasonr@gnu.org>
parents: 83556
diff changeset
910
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
911 #if !defined (NO_SOCKETS_IN_FILE_SYSTEM)
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
912
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
913 /* Three possibilities:
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
914 2 - can't be `stat'ed (sets errno)
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
915 1 - isn't owned by us
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
916 0 - success: none of the above */
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
917
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
918 static int
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
919 socket_status (socket_name)
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
920 char *socket_name;
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
921 {
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
922 struct stat statbfr;
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
923
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
924 if (stat (socket_name, &statbfr) == -1)
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
925 return 2;
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
926
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
927 if (statbfr.st_uid != geteuid ())
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
928 return 1;
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
929
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
930 return 0;
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
931 }
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
932
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
933
83025
c66ebcc29777 Removed %T in mode-line-format. Trivial documentation changes.
Karoly Lorentey <lorentey@elte.hu>
parents: 83019
diff changeset
934 /* 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
935 Useful for SIGWINCH. */
c66ebcc29777 Removed %T in mode-line-format. Trivial documentation changes.
Karoly Lorentey <lorentey@elte.hu>
parents: 83019
diff changeset
936
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
937 SIGTYPE
83004
7900111db01c Converted display hooks to be display-local. Plus many bugfixes.
Karoly Lorentey <lorentey@elte.hu>
parents: 82995
diff changeset
938 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
939 {
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
940 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
941
82995
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
942 if (emacs_pid)
83004
7900111db01c Converted display hooks to be display-local. Plus many bugfixes.
Karoly Lorentey <lorentey@elte.hu>
parents: 82995
diff changeset
943 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
944
83004
7900111db01c Converted display hooks to be display-local. Plus many bugfixes.
Karoly Lorentey <lorentey@elte.hu>
parents: 82995
diff changeset
945 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
946 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
947 }
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
948
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
949 /* 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
950 now resume our tty frame. */
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
951
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
952 SIGTYPE
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
953 handle_sigcont (int signalnum)
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
954 {
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
955 int old_errno = errno;
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
956
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
957 if (tcgetpgrp (1) == getpgrp ())
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
958 {
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
959 /* We are in the foreground. */
83551
d9dc7e67ad3f Fix various suspend-related bugs in emacsclient. (Report & patch by Dan Nicolaescu.)
Karoly Lorentey <lorentey@elte.hu>
parents: 83550
diff changeset
960 SEND_STRING ("-resume \n");
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
961 }
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
962 else
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
963 {
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
964 /* We are in the background; cancel the continue. */
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
965 kill (getpid (), SIGSTOP);
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
966 }
83348
afade4ccd30c Fix broken emacsclient resume on Solaris (by Dan Nicolaescu).
Karoly Lorentey <lorentey@elte.hu>
parents: 83332
diff changeset
967
afade4ccd30c Fix broken emacsclient resume on Solaris (by Dan Nicolaescu).
Karoly Lorentey <lorentey@elte.hu>
parents: 83332
diff changeset
968 signal (signalnum, handle_sigcont);
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
969 errno = old_errno;
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
970 }
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
971
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
972 /* 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
973 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
974 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
975 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
976 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
977
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
978 SIGTYPE
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
979 handle_sigtstp (int signalnum)
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
980 {
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
981 int old_errno = errno;
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
982 sigset_t set;
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
983
83551
d9dc7e67ad3f Fix various suspend-related bugs in emacsclient. (Report & patch by Dan Nicolaescu.)
Karoly Lorentey <lorentey@elte.hu>
parents: 83550
diff changeset
984 if (s)
d9dc7e67ad3f Fix various suspend-related bugs in emacsclient. (Report & patch by Dan Nicolaescu.)
Karoly Lorentey <lorentey@elte.hu>
parents: 83550
diff changeset
985 SEND_STRING ("-suspend \n");
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
986
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
987 /* 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
988 changing the handler and resignalling. */
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
989 sigprocmask (SIG_BLOCK, NULL, &set);
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
990 sigdelset (&set, signalnum);
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
991 signal (signalnum, SIG_DFL);
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
992 kill (getpid (), signalnum);
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
993 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
994 signal (signalnum, handle_sigtstp);
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
995
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
996 errno = old_errno;
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
997 }
83025
c66ebcc29777 Removed %T in mode-line-format. Trivial documentation changes.
Karoly Lorentey <lorentey@elte.hu>
parents: 83019
diff changeset
998 /* 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
999
82995
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
1000 void
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
1001 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
1002 {
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
1003 /* 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
1004 signal (SIGWINCH, pass_signal_to_emacs);
83012
4aa172a45af1 Fix C-g handling with multiple ttys.
Karoly Lorentey <lorentey@elte.hu>
parents: 83010
diff changeset
1005
4aa172a45af1 Fix C-g handling with multiple ttys.
Karoly Lorentey <lorentey@elte.hu>
parents: 83010
diff changeset
1006 /* 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
1007 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
1008 normal input event on secondary terminals. */
4aa172a45af1 Fix C-g handling with multiple ttys.
Karoly Lorentey <lorentey@elte.hu>
parents: 83010
diff changeset
1009 #if 0
83004
7900111db01c Converted display hooks to be display-local. Plus many bugfixes.
Karoly Lorentey <lorentey@elte.hu>
parents: 82995
diff changeset
1010 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
1011 signal (SIGQUIT, pass_signal_to_emacs);
83012
4aa172a45af1 Fix C-g handling with multiple ttys.
Karoly Lorentey <lorentey@elte.hu>
parents: 83010
diff changeset
1012 #endif
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1013
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1014 signal (SIGCONT, handle_sigcont);
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1015 signal (SIGTSTP, handle_sigtstp);
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1016 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
1017 }
27305
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
1018
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1019
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1020 HSOCKET
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1021 set_local_socket ()
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1022 {
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1023 HSOCKET s;
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1024 struct sockaddr_un server;
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1025
42176
1f5dbeefa536 Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 39723
diff changeset
1026 /*
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1027 * Open up an AF_UNIX socket in this person's home directory
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1028 */
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1029
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1030 if ((s = socket (AF_UNIX, SOCK_STREAM, 0)) < 0)
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1031 {
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
1032 message (TRUE, "%s: socket: %s\n", progname, strerror (errno));
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1033 return INVALID_SOCKET;
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1034 }
42176
1f5dbeefa536 Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 39723
diff changeset
1035
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1036 server.sun_family = AF_UNIX;
25261
89be69860eeb (main): Move the dynamic allocation of
Karl Heuer <kwzh@gnu.org>
parents: 24652
diff changeset
1037
493
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 478
diff changeset
1038 {
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
1039 int sock_status = 0;
53646
8c55b1b400d5 (main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53543
diff changeset
1040 int default_sock = !socket_name;
83010
82554ed1aed8 Merged in changes from CVS HEAD
Karoly Lorentey <lorentey@elte.hu>
parents: 83005 53543
diff changeset
1041 int saved_errno = 0;
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1042
53734
132739917566 (main): Don't use the hostname in the socket name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53693
diff changeset
1043 char *server_name = "server";
132739917566 (main): Don't use the hostname in the socket name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53693
diff changeset
1044
132739917566 (main): Don't use the hostname in the socket name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53693
diff changeset
1045 if (socket_name && !index (socket_name, '/') && !index (socket_name, '\\'))
132739917566 (main): Don't use the hostname in the socket name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53693
diff changeset
1046 { /* socket_name is a file name component. */
83031
1d2f73785d9d Merged in changes from CVS HEAD
Karoly Lorentey <lorentey@elte.hu>
parents: 83030 53734
diff changeset
1047 server_name = socket_name;
1d2f73785d9d Merged in changes from CVS HEAD
Karoly Lorentey <lorentey@elte.hu>
parents: 83030 53734
diff changeset
1048 socket_name = NULL;
1d2f73785d9d Merged in changes from CVS HEAD
Karoly Lorentey <lorentey@elte.hu>
parents: 83030 53734
diff changeset
1049 default_sock = 1; /* Try both UIDs. */
53734
132739917566 (main): Don't use the hostname in the socket name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53693
diff changeset
1050 }
24084
c0b0893dd5a6 (main): Eliminate arbitrary limit on length of system_name.
Richard M. Stallman <rms@gnu.org>
parents: 23412
diff changeset
1051
53646
8c55b1b400d5 (main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53543
diff changeset
1052 if (default_sock)
52479
bc2610a13fbf (socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
1053 {
83031
1d2f73785d9d Merged in changes from CVS HEAD
Karoly Lorentey <lorentey@elte.hu>
parents: 83030 53734
diff changeset
1054 socket_name = alloca (100 + strlen (server_name));
1d2f73785d9d Merged in changes from CVS HEAD
Karoly Lorentey <lorentey@elte.hu>
parents: 83030 53734
diff changeset
1055 sprintf (socket_name, "/tmp/emacs%d/%s",
1d2f73785d9d Merged in changes from CVS HEAD
Karoly Lorentey <lorentey@elte.hu>
parents: 83030 53734
diff changeset
1056 (int) geteuid (), server_name);
52479
bc2610a13fbf (socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
1057 }
bc2610a13fbf (socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
1058
bc2610a13fbf (socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
1059 if (strlen (socket_name) < sizeof (server.sun_path))
bc2610a13fbf (socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
1060 strcpy (server.sun_path, socket_name);
bc2610a13fbf (socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
1061 else
53646
8c55b1b400d5 (main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53543
diff changeset
1062 {
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1063 message (TRUE, "%s: socket-name %s too long",
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1064 progname, socket_name);
82988
f82e3a6f5ccb A few more bugfixes and new features.
Karoly Lorentey <lorentey@elte.hu>
parents: 82987
diff changeset
1065 fail ();
53646
8c55b1b400d5 (main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53543
diff changeset
1066 }
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1067
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
1068 /* 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
1069 sock_status = socket_status (server.sun_path);
53543
fec82b542db2 (main): Save errno from socket_status.
Andreas Schwab <schwab@suse.de>
parents: 53497
diff changeset
1070 saved_errno = errno;
53646
8c55b1b400d5 (main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53543
diff changeset
1071 if (sock_status && default_sock)
493
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 478
diff changeset
1072 {
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
1073 /* 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
1074 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
1075 associated with the name. This is reminiscent of the logic
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
1076 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
1077
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
1078 char *user_name = (char *) getenv ("LOGNAME");
53693
04e9ebd16fcd (main): Restore errno from saved_errno,
Richard M. Stallman <rms@gnu.org>
parents: 53646
diff changeset
1079
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
1080 if (!user_name)
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
1081 user_name = (char *) getenv ("USER");
42176
1f5dbeefa536 Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 39723
diff changeset
1082
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
1083 if (user_name)
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
1084 {
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
1085 struct passwd *pw = getpwnam (user_name);
53693
04e9ebd16fcd (main): Restore errno from saved_errno,
Richard M. Stallman <rms@gnu.org>
parents: 53646
diff changeset
1086
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
1087 if (pw && (pw->pw_uid != geteuid ()))
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
1088 {
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
1089 /* 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
1090 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
1091 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
1092 (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
1093
8c55b1b400d5 (main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53543
diff changeset
1094 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
1095 strcpy (server.sun_path, socket_name);
8c55b1b400d5 (main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53543
diff changeset
1096 else
8c55b1b400d5 (main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53543
diff changeset
1097 {
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
1098 message (TRUE, "%s: socket-name %s too long",
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1099 progname, socket_name);
55442
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53813
diff changeset
1100 exit (EXIT_FAILURE);
53646
8c55b1b400d5 (main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53543
diff changeset
1101 }
8c55b1b400d5 (main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53543
diff changeset
1102
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
1103 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
1104 saved_errno = errno;
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
1105 }
53693
04e9ebd16fcd (main): Restore errno from saved_errno,
Richard M. Stallman <rms@gnu.org>
parents: 53646
diff changeset
1106 else
04e9ebd16fcd (main): Restore errno from saved_errno,
Richard M. Stallman <rms@gnu.org>
parents: 53646
diff changeset
1107 errno = saved_errno;
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
1108 }
493
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 478
diff changeset
1109 }
42176
1f5dbeefa536 Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 39723
diff changeset
1110
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1111 switch (sock_status)
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1112 {
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1113 case 1:
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1114 /* There's a socket, but it isn't owned by us. This is OK if
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1115 we are root. */
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1116 if (0 != geteuid ())
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1117 {
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1118 message (TRUE, "%s: Invalid socket owner\n", progname);
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1119 return INVALID_SOCKET;
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1120 }
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1121 break;
42176
1f5dbeefa536 Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 39723
diff changeset
1122
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1123 case 2:
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1124 /* `stat' failed */
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1125 if (saved_errno == ENOENT)
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1126 message (TRUE,
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1127 "%s: can't find socket; have you started the server?\n\
48627
c91408365d35 (main): Tell user how to start server within Emacs if socket could not
Stephen Eglen <stephen@gnu.org>
parents: 48617
diff changeset
1128 To start the server in Emacs, type \"M-x server-start\".\n",
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1129 progname);
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1130 else
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1131 message (TRUE, "%s: can't stat %s: %s\n",
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1132 progname, server.sun_path, strerror (saved_errno));
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1133 return INVALID_SOCKET;
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1134 }
493
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 478
diff changeset
1135 }
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1136
3595
e10f7473d2e3 * emacsserver.c (main): When we're passing a `struct sockaddr_un'
Jim Blandy <jimb@redhat.com>
parents: 1031
diff changeset
1137 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
1138 < 0)
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1139 {
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
1140 message (TRUE, "%s: connect: %s\n", progname, strerror (errno));
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1141 return INVALID_SOCKET;
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1142 }
15758
7e712d42d371 (main) [HAVE_SOCKETS]: Use two separate stdio
Richard M. Stallman <rms@gnu.org>
parents: 14610
diff changeset
1143
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1144 return s;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1145 }
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1146 #endif /* ! NO_SOCKETS_IN_FILE_SYSTEM */
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1147
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1148 HSOCKET
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1149 set_socket ()
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1150 {
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
1151 HSOCKET s;
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1152
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
1153 INITIALIZE ();
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1154
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1155 #ifndef NO_SOCKETS_IN_FILE_SYSTEM
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
1156 /* Explicit --socket-name argument. */
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
1157 if (socket_name)
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1158 {
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
1159 s = set_local_socket ();
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
1160 if ((s != INVALID_SOCKET) || alternate_editor)
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1161 return s;
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
1162 message (TRUE, "%s: error accessing socket \"%s\"",
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1163 progname, socket_name);
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
1164 exit (EXIT_FAILURE);
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1165 }
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1166 #endif
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
1167
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
1168 /* Explicit --server-file arg or EMACS_SERVER_FILE variable. */
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
1169 if (!server_file)
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
1170 server_file = getenv ("EMACS_SERVER_FILE");
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
1171
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
1172 if (server_file)
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
1173 {
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
1174 s = set_tcp_socket ();
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
1175 if ((s != INVALID_SOCKET) || alternate_editor)
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1176 return s;
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1177
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
1178 message (TRUE, "%s: error accessing server file \"%s\"",
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1179 progname, server_file);
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
1180 exit (EXIT_FAILURE);
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
1181 }
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1182
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
1183 #ifndef NO_SOCKETS_IN_FILE_SYSTEM
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
1184 /* Implicit local socket. */
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
1185 s = set_local_socket ();
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
1186 if (s != INVALID_SOCKET)
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
1187 return s;
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
1188 #endif
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
1189
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
1190 /* Implicit server file. */
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
1191 server_file = "server";
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
1192 s = set_tcp_socket ();
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
1193 if ((s != INVALID_SOCKET) || alternate_editor)
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
1194 return s;
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
1195
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
1196 /* No implicit or explicit socket, and no alternate editor. */
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
1197 message (TRUE, "%s: No socket or alternate editor. Please use:\n\n"
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
1198 #ifndef NO_SOCKETS_IN_FILE_SYSTEM
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
1199 "\t--socket-name\n"
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
1200 #endif
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
1201 "\t--server-file (or environment variable EMACS_SERVER_FILE)\n\
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
1202 \t--alternate-editor (or environment variable ALTERNATE_EDITOR)\n",
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
1203 progname);
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
1204 exit (EXIT_FAILURE);
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1205 }
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1206
74729
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1207 #ifdef WINDOWSNT
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1208 FARPROC set_fg; /* Pointer to AllowSetForegroundWindow. */
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1209 FARPROC get_wc; /* Pointer to RealGetWindowClassA. */
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1210
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1211 BOOL CALLBACK
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1212 w32_find_emacs_process (hWnd, lParam)
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1213 HWND hWnd;
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1214 LPARAM lParam;
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1215 {
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1216 DWORD pid;
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1217 char class[6];
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1218
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1219 /* Reject any window not of class "Emacs". */
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1220 if (! get_wc (hWnd, class, sizeof (class))
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1221 || strcmp (class, "Emacs"))
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1222 return TRUE;
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1223
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1224 /* We only need the process id, not the thread id. */
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1225 (void) GetWindowThreadProcessId (hWnd, &pid);
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1226
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1227 /* Not the one we're looking for. */
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1228 if (pid != (DWORD) emacs_pid) return TRUE;
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1229
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1230 /* OK, let's raise it. */
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1231 set_fg (emacs_pid);
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1232
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1233 /* Stop enumeration. */
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1234 return FALSE;
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1235 }
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1236
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1237 /*
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1238 * Search for a window of class "Emacs" and owned by a process with
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1239 * process id = emacs_pid. If found, allow it to grab the focus.
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1240 */
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1241 void
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1242 w32_give_focus ()
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1243 {
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1244 HMODULE hUser32;
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1245
75956
6ef0c279b18c Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents: 75348
diff changeset
1246 /* It shouldn't happen when dealing with TCP sockets. */
74729
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1247 if (!emacs_pid) return;
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1248
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1249 if (!(hUser32 = LoadLibrary ("user32.dll"))) return;
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1250
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1251 /* Modern Windows restrict which processes can set the foreground window.
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1252 emacsclient can allow Emacs to grab the focus by calling the function
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1253 AllowSetForegroundWindow. Unfortunately, older Windows (W95, W98 and
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1254 NT) lack this function, so we have to check its availability. */
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1255 if ((set_fg = GetProcAddress (hUser32, "AllowSetForegroundWindow"))
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1256 && (get_wc = GetProcAddress (hUser32, "RealGetWindowClassA")))
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1257 EnumWindows (w32_find_emacs_process, (LPARAM) 0);
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1258
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1259 FreeLibrary (hUser32);
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1260 }
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1261 #endif
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1262
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1263 int
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1264 main (argc, argv)
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1265 int argc;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1266 char **argv;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1267 {
83590
dab011361c2a (s): Remove.
Jason Rumney <jasonr@gnu.org>
parents: 83556
diff changeset
1268 HSOCKET s;
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1269 int i, rl, needlf = 0;
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1270 char *cwd, *str;
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1271 char string[BUFSIZ+1];
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1272
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1273 main_argc = argc;
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1274 main_argv = argv;
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1275 progname = argv[0];
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1276
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1277 /* Process options. */
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1278 decode_options (argc, argv);
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1279
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1280 if ((argc - optind < 1) && !eval && !tty && !window_system)
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1281 {
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1282 message (TRUE, "%s: file name or argument required\n"
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1283 "Try `%s --help' for more information\n",
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1284 progname, progname);
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1285 exit (EXIT_FAILURE);
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1286 }
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1287
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1288 if ((s = set_socket ()) == INVALID_SOCKET)
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1289 fail ();
15758
7e712d42d371 (main) [HAVE_SOCKETS]: Use two separate stdio
Richard M. Stallman <rms@gnu.org>
parents: 14610
diff changeset
1290
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1291
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1292 cwd = get_current_dir_name ();
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1293 if (cwd == 0)
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1294 {
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1295 /* getwd puts message in STRING if it fails. */
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1296 message (TRUE, "%s: %s\n", progname,
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1297 "Cannot get current working directory");
82988
f82e3a6f5ccb A few more bugfixes and new features.
Karoly Lorentey <lorentey@elte.hu>
parents: 82987
diff changeset
1298 fail ();
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1299 }
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1300
74342
c6cb776ffbb7 (emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents: 74341
diff changeset
1301 #ifdef WINDOWSNT
74729
303099bc66d9 [WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents: 74645
diff changeset
1302 w32_give_focus ();
74342
c6cb776ffbb7 (emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents: 74341
diff changeset
1303 #endif
c6cb776ffbb7 (emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents: 74341
diff changeset
1304
83044
52039abab942 Verify the version of Emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83043
diff changeset
1305 /* First of all, send our version number for verification. */
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1306 SEND_STRING ("-version ");
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1307 SEND_STRING (VERSION);
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1308 SEND_STRING (" ");
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1309
83103
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
1310 /* Send over our environment. */
83403
51eb0aa362f3 Store client's environment in terminal parameters, not server parameters.
Karoly Lorentey <lorentey@elte.hu>
parents: 83371
diff changeset
1311 if (!current_frame)
51eb0aa362f3 Store client's environment in terminal parameters, not server parameters.
Karoly Lorentey <lorentey@elte.hu>
parents: 83371
diff changeset
1312 {
51eb0aa362f3 Store client's environment in terminal parameters, not server parameters.
Karoly Lorentey <lorentey@elte.hu>
parents: 83371
diff changeset
1313 extern char **environ;
51eb0aa362f3 Store client's environment in terminal parameters, not server parameters.
Karoly Lorentey <lorentey@elte.hu>
parents: 83371
diff changeset
1314 int i;
51eb0aa362f3 Store client's environment in terminal parameters, not server parameters.
Karoly Lorentey <lorentey@elte.hu>
parents: 83371
diff changeset
1315 for (i = 0; environ[i]; i++)
51eb0aa362f3 Store client's environment in terminal parameters, not server parameters.
Karoly Lorentey <lorentey@elte.hu>
parents: 83371
diff changeset
1316 {
51eb0aa362f3 Store client's environment in terminal parameters, not server parameters.
Karoly Lorentey <lorentey@elte.hu>
parents: 83371
diff changeset
1317 char *name = xstrdup (environ[i]);
51eb0aa362f3 Store client's environment in terminal parameters, not server parameters.
Karoly Lorentey <lorentey@elte.hu>
parents: 83371
diff changeset
1318 char *value = strchr (name, '=');
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1319 SEND_STRING ("-env ");
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1320 SEND_QUOTED (environ[i]);
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1321 SEND_STRING (" ");
83403
51eb0aa362f3 Store client's environment in terminal parameters, not server parameters.
Karoly Lorentey <lorentey@elte.hu>
parents: 83371
diff changeset
1322 }
51eb0aa362f3 Store client's environment in terminal parameters, not server parameters.
Karoly Lorentey <lorentey@elte.hu>
parents: 83371
diff changeset
1323 }
83103
efc0b56b83d9 Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents: 83065
diff changeset
1324
83499
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
1325 /* Send over our current directory. */
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
1326 if (!current_frame)
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
1327 {
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1328 SEND_STRING ("-dir ");
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1329 SEND_QUOTED (cwd);
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1330 SEND_STRING ("/");
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1331 SEND_STRING (" ");
83499
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
1332 }
0fe580113f72 Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83468
diff changeset
1333
83246
5bc762f84335 Prevent emacsclient errors when Emacs is compiled without X support.
Karoly Lorentey <lorentey@elte.hu>
parents: 83165
diff changeset
1334 retry:
16061
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
1335 if (nowait)
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1336 SEND_STRING ("-nowait ");
16061
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
1337
83367
2b5fb28780be Fix `emacsclient -ne '(+ 2 2)'' (reported by Han Boetes), and clean up some corner cases in Emacs server.
Karoly Lorentey <lorentey@elte.hu>
parents: 83353
diff changeset
1338 if (current_frame)
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1339 SEND_STRING ("-current-frame ");
83367
2b5fb28780be Fix `emacsclient -ne '(+ 2 2)'' (reported by Han Boetes), and clean up some corner cases in Emacs server.
Karoly Lorentey <lorentey@elte.hu>
parents: 83353
diff changeset
1340
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
1341 if (display)
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1342 {
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1343 SEND_STRING ("-display ");
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1344 SEND_QUOTED (display);
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1345 SEND_STRING (" ");
52635
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
1346 }
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
1347
83043
78a785f205ea Added -w option to emacsclient for opening a new X frame.
Karoly Lorentey <lorentey@elte.hu>
parents: 83037
diff changeset
1348 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
1349 {
83590
dab011361c2a (s): Remove.
Jason Rumney <jasonr@gnu.org>
parents: 83556
diff changeset
1350 char *tty_name = NULL;
dab011361c2a (s): Remove.
Jason Rumney <jasonr@gnu.org>
parents: 83556
diff changeset
1351 #ifndef WINDOWSNT
dab011361c2a (s): Remove.
Jason Rumney <jasonr@gnu.org>
parents: 83556
diff changeset
1352 tty_name = ttyname (fileno (stdin));
dab011361c2a (s): Remove.
Jason Rumney <jasonr@gnu.org>
parents: 83556
diff changeset
1353 #endif
83064
e7e9448cb3a0 Make emacsclient refuse to create a frame inside an Emacs term buffer.
Karoly Lorentey <lorentey@elte.hu>
parents: 83052
diff changeset
1354 char *type = getenv ("TERM");
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1355
82995
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
1356 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
1357 {
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1358 message (TRUE, "%s: could not get terminal name\n", progname);
83064
e7e9448cb3a0 Make emacsclient refuse to create a frame inside an Emacs term buffer.
Karoly Lorentey <lorentey@elte.hu>
parents: 83052
diff changeset
1359 fail ();
e7e9448cb3a0 Make emacsclient refuse to create a frame inside an Emacs term buffer.
Karoly Lorentey <lorentey@elte.hu>
parents: 83052
diff changeset
1360 }
e7e9448cb3a0 Make emacsclient refuse to create a frame inside an Emacs term buffer.
Karoly Lorentey <lorentey@elte.hu>
parents: 83052
diff changeset
1361
e7e9448cb3a0 Make emacsclient refuse to create a frame inside an Emacs term buffer.
Karoly Lorentey <lorentey@elte.hu>
parents: 83052
diff changeset
1362 if (! type)
e7e9448cb3a0 Make emacsclient refuse to create a frame inside an Emacs term buffer.
Karoly Lorentey <lorentey@elte.hu>
parents: 83052
diff changeset
1363 {
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1364 message (TRUE, "%s: please set the TERM variable to your terminal type\n",
83064
e7e9448cb3a0 Make emacsclient refuse to create a frame inside an Emacs term buffer.
Karoly Lorentey <lorentey@elte.hu>
parents: 83052
diff changeset
1365 progname);
e7e9448cb3a0 Make emacsclient refuse to create a frame inside an Emacs term buffer.
Karoly Lorentey <lorentey@elte.hu>
parents: 83052
diff changeset
1366 fail ();
e7e9448cb3a0 Make emacsclient refuse to create a frame inside an Emacs term buffer.
Karoly Lorentey <lorentey@elte.hu>
parents: 83052
diff changeset
1367 }
e7e9448cb3a0 Make emacsclient refuse to create a frame inside an Emacs term buffer.
Karoly Lorentey <lorentey@elte.hu>
parents: 83052
diff changeset
1368
e7e9448cb3a0 Make emacsclient refuse to create a frame inside an Emacs term buffer.
Karoly Lorentey <lorentey@elte.hu>
parents: 83052
diff changeset
1369 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
1370 {
e7e9448cb3a0 Make emacsclient refuse to create a frame inside an Emacs term buffer.
Karoly Lorentey <lorentey@elte.hu>
parents: 83052
diff changeset
1371 /* This causes nasty, MULTI_KBOARD-related input lockouts. */
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1372 message (TRUE, "%s: opening a frame in an Emacs term buffer"
83064
e7e9448cb3a0 Make emacsclient refuse to create a frame inside an Emacs term buffer.
Karoly Lorentey <lorentey@elte.hu>
parents: 83052
diff changeset
1373 " 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
1374 fail ();
e7e9448cb3a0 Make emacsclient refuse to create a frame inside an Emacs term buffer.
Karoly Lorentey <lorentey@elte.hu>
parents: 83052
diff changeset
1375 }
83590
dab011361c2a (s): Remove.
Jason Rumney <jasonr@gnu.org>
parents: 83556
diff changeset
1376 #if !defined (NO_SOCKETS_IN_FILE_SYSTEM)
82995
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
1377 init_signals ();
83590
dab011361c2a (s): Remove.
Jason Rumney <jasonr@gnu.org>
parents: 83556
diff changeset
1378 #endif
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1379
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1380 SEND_STRING ("-tty ");
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1381 SEND_QUOTED (tty_name);
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1382 SEND_STRING (" ");
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1383 SEND_QUOTED (type);
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1384 SEND_STRING (" ");
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
1385 }
83043
78a785f205ea Added -w option to emacsclient for opening a new X frame.
Karoly Lorentey <lorentey@elte.hu>
parents: 83037
diff changeset
1386
78a785f205ea Added -w option to emacsclient for opening a new X frame.
Karoly Lorentey <lorentey@elte.hu>
parents: 83037
diff changeset
1387 if (window_system)
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1388 SEND_STRING ("-window-system ");
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1389
52635
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
1390 if ((argc - optind > 0))
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
1391 {
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
1392 for (i = optind; i < argc; i++)
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1393 {
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1394 int relative = 0;
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1395
52635
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
1396 if (eval)
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1397 {
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1398 /* Don't prepend cwd or anything like that. */
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1399 SEND_STRING ("-eval ");
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1400 SEND_QUOTED (argv[i]);
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1401 SEND_STRING (" ");
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1402 continue;
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1403 }
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1404
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1405 if (*argv[i] == '+')
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1406 {
52635
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
1407 char *p = argv[i] + 1;
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
1408 while (isdigit ((unsigned char) *p) || *p == ':') p++;
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1409 if (*p == 0)
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1410 {
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1411 SEND_STRING ("-position ");
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1412 SEND_QUOTED (argv[i]);
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1413 SEND_STRING (" ");
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1414 continue;
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1415 }
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1416 else
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1417 relative = 1;
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1418 }
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
1419 else if (! file_name_absolute_p (argv[i]))
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1420 relative = 1;
52635
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
1421
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1422 SEND_STRING ("-file ");
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1423 if (relative)
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1424 {
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1425 SEND_QUOTED (cwd);
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1426 SEND_STRING ("/");
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1427 }
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1428 SEND_QUOTED (argv[i]);
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1429 SEND_STRING (" ");
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1430 }
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1431 }
52635
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
1432 else
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
1433 {
83043
78a785f205ea Added -w option to emacsclient for opening a new X frame.
Karoly Lorentey <lorentey@elte.hu>
parents: 83037
diff changeset
1434 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
1435 {
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
1436 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
1437 {
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1438 if (eval)
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1439 SEND_STRING ("-eval ");
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1440 else
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1441 SEND_STRING ("-file ");
83551
d9dc7e67ad3f Fix various suspend-related bugs in emacsclient. (Report & patch by Dan Nicolaescu.)
Karoly Lorentey <lorentey@elte.hu>
parents: 83550
diff changeset
1442 SEND_QUOTED (str);
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
1443 }
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1444 SEND_STRING (" ");
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
1445 }
52635
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
1446 }
55442
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53813
diff changeset
1447
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1448 SEND_STRING ("\n");
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1449
83165
ed82e09208c9 Fix --no-wait in emacsclient (reported by Dan Nicolaescu).
Karoly Lorentey <lorentey@elte.hu>
parents: 83121
diff changeset
1450 /* Wait for an answer. */
ed82e09208c9 Fix --no-wait in emacsclient (reported by Dan Nicolaescu).
Karoly Lorentey <lorentey@elte.hu>
parents: 83121
diff changeset
1451 if (!eval && !tty && !nowait)
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
1452 {
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
1453 printf ("Waiting for Emacs...");
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
1454 needlf = 2;
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
1455 }
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1456 fflush (stdout);
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1457 fsync (1);
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1458
47515
6ee937dcfe16 (quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42412
diff changeset
1459 /* Now, wait for an answer and print any messages. */
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1460 while ((rl = recv (s, string, BUFSIZ, 0)) > 0)
47515
6ee937dcfe16 (quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42412
diff changeset
1461 {
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1462 char *p;
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1463 string[rl] = '\0';
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1464
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1465 p = string + strlen (string) - 1;
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1466 while (p > string && *p == '\n')
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1467 *p-- = 0;
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1468
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1469 if (strprefix ("-good-version ", string))
83044
52039abab942 Verify the version of Emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83043
diff changeset
1470 {
83246
5bc762f84335 Prevent emacsclient errors when Emacs is compiled without X support.
Karoly Lorentey <lorentey@elte.hu>
parents: 83165
diff changeset
1471 /* -good-version: The versions match. */
83044
52039abab942 Verify the version of Emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents: 83043
diff changeset
1472 }
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1473 else if (strprefix ("-emacs-pid ", string))
83043
78a785f205ea Added -w option to emacsclient for opening a new X frame.
Karoly Lorentey <lorentey@elte.hu>
parents: 83037
diff changeset
1474 {
83246
5bc762f84335 Prevent emacsclient errors when Emacs is compiled without X support.
Karoly Lorentey <lorentey@elte.hu>
parents: 83165
diff changeset
1475 /* -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
1476 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
1477 }
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1478 else if (strprefix ("-window-system-unsupported ", string))
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1479 {
83246
5bc762f84335 Prevent emacsclient errors when Emacs is compiled without X support.
Karoly Lorentey <lorentey@elte.hu>
parents: 83165
diff changeset
1480 /* -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
1481 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
1482 window_system = 0;
5bc762f84335 Prevent emacsclient errors when Emacs is compiled without X support.
Karoly Lorentey <lorentey@elte.hu>
parents: 83165
diff changeset
1483 nowait = 0;
5bc762f84335 Prevent emacsclient errors when Emacs is compiled without X support.
Karoly Lorentey <lorentey@elte.hu>
parents: 83165
diff changeset
1484 tty = 1;
5bc762f84335 Prevent emacsclient errors when Emacs is compiled without X support.
Karoly Lorentey <lorentey@elte.hu>
parents: 83165
diff changeset
1485 goto retry;
5bc762f84335 Prevent emacsclient errors when Emacs is compiled without X support.
Karoly Lorentey <lorentey@elte.hu>
parents: 83165
diff changeset
1486 }
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1487 else if (strprefix ("-print ", string))
82995
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
1488 {
83246
5bc762f84335 Prevent emacsclient errors when Emacs is compiled without X support.
Karoly Lorentey <lorentey@elte.hu>
parents: 83165
diff changeset
1489 /* -print STRING: Print STRING on the terminal. */
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1490 str = unquote_argument (string + strlen ("-print "));
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1491 if (needlf)
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1492 printf ("\n");
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1493 printf ("%s", str);
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1494 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
1495 }
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1496 else if (strprefix ("-error ", string))
83043
78a785f205ea Added -w option to emacsclient for opening a new X frame.
Karoly Lorentey <lorentey@elte.hu>
parents: 83037
diff changeset
1497 {
83246
5bc762f84335 Prevent emacsclient errors when Emacs is compiled without X support.
Karoly Lorentey <lorentey@elte.hu>
parents: 83165
diff changeset
1498 /* -error DESCRIPTION: Signal an error on the terminal. */
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1499 str = unquote_argument (string + strlen ("-error "));
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1500 if (needlf)
83043
78a785f205ea Added -w option to emacsclient for opening a new X frame.
Karoly Lorentey <lorentey@elte.hu>
parents: 83037
diff changeset
1501 printf ("\n");
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1502 fprintf (stderr, "*ERROR*: %s", str);
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1503 needlf = str[0] == '\0' ? needlf : str[strlen (str) - 1] != '\n';
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1504 }
83590
dab011361c2a (s): Remove.
Jason Rumney <jasonr@gnu.org>
parents: 83556
diff changeset
1505 #ifndef WINDOWSNT
83551
d9dc7e67ad3f Fix various suspend-related bugs in emacsclient. (Report & patch by Dan Nicolaescu.)
Karoly Lorentey <lorentey@elte.hu>
parents: 83550
diff changeset
1506 else if (strprefix ("-suspend ", string))
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1507 {
83246
5bc762f84335 Prevent emacsclient errors when Emacs is compiled without X support.
Karoly Lorentey <lorentey@elte.hu>
parents: 83165
diff changeset
1508 /* -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
1509 if (needlf)
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1510 printf ("\n");
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1511 needlf = 0;
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1512 kill (0, SIGSTOP);
82995
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
1513 }
83590
dab011361c2a (s): Remove.
Jason Rumney <jasonr@gnu.org>
parents: 83556
diff changeset
1514 #endif
82995
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
1515 else
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
1516 {
83246
5bc762f84335 Prevent emacsclient errors when Emacs is compiled without X support.
Karoly Lorentey <lorentey@elte.hu>
parents: 83165
diff changeset
1517 /* Unknown command. */
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1518 if (needlf)
82995
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
1519 printf ("\n");
83548
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1520 printf ("*ERROR*: Unknown message: %s", string);
c71725faff1a Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
parents: 83533 74342
diff changeset
1521 needlf = string[0] == '\0' ? needlf : string[strlen (string) - 1] != '\n';
82995
039bd6989d29 Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents: 82994
diff changeset
1522 }
47515
6ee937dcfe16 (quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42412
diff changeset
1523 }
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1524
47515
6ee937dcfe16 (quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42412
diff changeset
1525 if (needlf)
6ee937dcfe16 (quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42412
diff changeset
1526 printf ("\n");
6ee937dcfe16 (quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42412
diff changeset
1527 fflush (stdout);
83065
a871be7b26a5 Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents: 83064
diff changeset
1528 fsync (1);
42176
1f5dbeefa536 Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 39723
diff changeset
1529
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1530 CLOSE_SOCKET (s);
55442
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53813
diff changeset
1531 return EXIT_SUCCESS;
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1532 }
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1533
73617
7af864af10b6 [WINDOWSNT]: Define HAVE_INET_SOCKETS.
Juanma Barranquero <lekktu@gmail.com>
parents: 73601
diff changeset
1534 #endif /* HAVE_SOCKETS && HAVE_INET_SOCKETS */
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
1535
5527
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
1536
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
1537 #ifndef HAVE_STRERROR
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
1538 char *
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
1539 strerror (errnum)
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
1540 int errnum;
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
1541 {
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
1542 extern char *sys_errlist[];
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
1543 extern int sys_nerr;
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
1544
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
1545 if (errnum >= 0 && errnum < sys_nerr)
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
1546 return sys_errlist[errnum];
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
1547 return (char *) "Unknown error";
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
1548 }
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
1549
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
1550 #endif /* ! HAVE_STRERROR */
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 52069
diff changeset
1551
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 52069
diff changeset
1552 /* arch-tag: f39bb9c4-73eb-477e-896d-50832e2ca9a7
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 52069
diff changeset
1553 (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
1554
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53813
diff changeset
1555 /* emacsclient.c ends here */