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