Mercurial > emacs
annotate lib-src/emacsclient.c @ 112318:deae5bb3f0f6
Give a name FLOAT_TO_STRING_BUFSIZE to the constant 350.
* lisp.h (FLOAT_TO_STRING_BUFSIZE): New macro.
* data.c (Fnumber_to_string): Use it.
* print.c (float_to_string, print_object): Likewise.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Sun, 09 Jan 2011 00:21:21 -0800 |
parents | 7df2e30d72ec |
children | 17e0028efc29 |
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, |
106815 | 3 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
412 | 4 |
5 This file is part of GNU Emacs. | |
6 | |
94828
3a4bc081639c
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
92159
diff
changeset
|
7 GNU Emacs is free software: you can redistribute it and/or modify |
412 | 8 it under the terms of the GNU General Public License as published by |
94828
3a4bc081639c
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
92159
diff
changeset
|
9 the Free Software Foundation, either version 3 of the License, or |
3a4bc081639c
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
92159
diff
changeset
|
10 (at your option) any later version. |
412 | 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 | |
94828
3a4bc081639c
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
92159
diff
changeset
|
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
412 | 19 |
20 | |
42412 | 21 #include <config.h> |
42176
1f5dbeefa536
Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents:
39723
diff
changeset
|
22 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
23 #ifdef WINDOWSNT |
73585
7d264c036b25
[WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73583
diff
changeset
|
24 |
73973
a36e68eb4ae8
[WINDOWSNT]: Undef _WINSOCKAPI_ and _WINSOCK_H.
Juanma Barranquero <lekktu@gmail.com>
parents:
73896
diff
changeset
|
25 /* config.h defines these, which disables sockets altogether! */ |
a36e68eb4ae8
[WINDOWSNT]: Undef _WINSOCKAPI_ and _WINSOCK_H.
Juanma Barranquero <lekktu@gmail.com>
parents:
73896
diff
changeset
|
26 # undef _WINSOCKAPI_ |
a36e68eb4ae8
[WINDOWSNT]: Undef _WINSOCKAPI_ and _WINSOCK_H.
Juanma Barranquero <lekktu@gmail.com>
parents:
73896
diff
changeset
|
27 # undef _WINSOCK_H |
a36e68eb4ae8
[WINDOWSNT]: Undef _WINSOCKAPI_ and _WINSOCK_H.
Juanma Barranquero <lekktu@gmail.com>
parents:
73896
diff
changeset
|
28 |
73585
7d264c036b25
[WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73583
diff
changeset
|
29 # include <malloc.h> |
7d264c036b25
[WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73583
diff
changeset
|
30 # include <stdlib.h> |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
31 # include <windows.h> |
78904
5025525d6c9d
(w32_window_app): Init common controls when windowed.
Jason Rumney <jasonr@gnu.org>
parents:
78257
diff
changeset
|
32 # include <commctrl.h> |
109652
eb720d8ea1c6
emacsclient.c cleanups.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
109517
diff
changeset
|
33 # include <io.h> |
eb720d8ea1c6
emacsclient.c cleanups.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
109517
diff
changeset
|
34 # include <winsock2.h> |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
35 |
73585
7d264c036b25
[WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73583
diff
changeset
|
36 # define NO_SOCKETS_IN_FILE_SYSTEM |
7d264c036b25
[WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73583
diff
changeset
|
37 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
38 # define HSOCKET SOCKET |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
39 # define CLOSE_SOCKET closesocket |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
40 # define INITIALIZE() (initialize_sockets ()) |
73585
7d264c036b25
[WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73583
diff
changeset
|
41 |
110746
5c1a707ab452
Fix compilation warnings.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
110706
diff
changeset
|
42 char *w32_getenv (char *); |
5c1a707ab452
Fix compilation warnings.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
110706
diff
changeset
|
43 #define egetenv(VAR) w32_getenv(VAR) |
5c1a707ab452
Fix compilation warnings.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
110706
diff
changeset
|
44 |
73585
7d264c036b25
[WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73583
diff
changeset
|
45 #else /* !WINDOWSNT */ |
7d264c036b25
[WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73583
diff
changeset
|
46 |
100418
9ad0989a1e66
Include syswait.h instead of sys/types.h.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100364
diff
changeset
|
47 # include "syswait.h" |
73896
09dabd95380c
[!WINDOWSNT]: Include <sys/types.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73816
diff
changeset
|
48 |
73617
7af864af10b6
[WINDOWSNT]: Define HAVE_INET_SOCKETS.
Juanma Barranquero <lekktu@gmail.com>
parents:
73601
diff
changeset
|
49 # ifdef HAVE_INET_SOCKETS |
7af864af10b6
[WINDOWSNT]: Define HAVE_INET_SOCKETS.
Juanma Barranquero <lekktu@gmail.com>
parents:
73601
diff
changeset
|
50 # include <netinet/in.h> |
109652
eb720d8ea1c6
emacsclient.c cleanups.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
109517
diff
changeset
|
51 # ifdef HAVE_SOCKETS |
eb720d8ea1c6
emacsclient.c cleanups.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
109517
diff
changeset
|
52 # include <sys/types.h> |
eb720d8ea1c6
emacsclient.c cleanups.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
109517
diff
changeset
|
53 # include <sys/socket.h> |
eb720d8ea1c6
emacsclient.c cleanups.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
109517
diff
changeset
|
54 # include <sys/un.h> |
eb720d8ea1c6
emacsclient.c cleanups.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
109517
diff
changeset
|
55 # endif /* HAVE_SOCKETS */ |
73617
7af864af10b6
[WINDOWSNT]: Define HAVE_INET_SOCKETS.
Juanma Barranquero <lekktu@gmail.com>
parents:
73601
diff
changeset
|
56 # endif |
100154 | 57 # include <arpa/inet.h> |
100149
61db5ca5de78
Include <darpa/inet.h>.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
99334
diff
changeset
|
58 |
73578
e193b6a3f379
Fixes to emacsclient.c for GNU/Linux.
Juanma Barranquero <lekktu@gmail.com>
parents:
73562
diff
changeset
|
59 # define INVALID_SOCKET -1 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
60 # define HSOCKET int |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
61 # define CLOSE_SOCKET close |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
62 # define INITIALIZE() |
73585
7d264c036b25
[WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73583
diff
changeset
|
63 |
100364
1cbff49af513
(WCONTINUED): New compatibility define for older systems.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100344
diff
changeset
|
64 # ifndef WCONTINUED |
1cbff49af513
(WCONTINUED): New compatibility define for older systems.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100344
diff
changeset
|
65 # define WCONTINUED 8 |
1cbff49af513
(WCONTINUED): New compatibility define for older systems.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100344
diff
changeset
|
66 # endif |
1cbff49af513
(WCONTINUED): New compatibility define for older systems.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100344
diff
changeset
|
67 |
110746
5c1a707ab452
Fix compilation warnings.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
110706
diff
changeset
|
68 #define egetenv(VAR) getenv(VAR) |
5c1a707ab452
Fix compilation warnings.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
110706
diff
changeset
|
69 |
73585
7d264c036b25
[WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73583
diff
changeset
|
70 #endif /* !WINDOWSNT */ |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
71 |
3595
e10f7473d2e3
* emacsserver.c (main): When we're passing a `struct sockaddr_un'
Jim Blandy <jimb@redhat.com>
parents:
1031
diff
changeset
|
72 #undef signal |
412 | 73 |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
74 #include <stdarg.h> |
42176
1f5dbeefa536
Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents:
39723
diff
changeset
|
75 #include <ctype.h> |
16030
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
76 #include <stdio.h> |
112316
2887524f362a
Include <getopt.h> not "getopt.h".
Paul Eggert <eggert@cs.ucla.edu>
parents:
111626
diff
changeset
|
77 #include <getopt.h> |
112317
7df2e30d72ec
Include <unistd.h> unilaterally.
Paul Eggert <eggert@cs.ucla.edu>
parents:
112316
diff
changeset
|
78 #include <unistd.h> |
412 | 79 |
109652
eb720d8ea1c6
emacsclient.c cleanups.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
109517
diff
changeset
|
80 #include <pwd.h> |
83500
0a651d0085ee
Fix compilation error on OpenBSD. (Reported by Han Boetes.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83499
diff
changeset
|
81 #include <sys/stat.h> |
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 |
109652
eb720d8ea1c6
emacsclient.c cleanups.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
109517
diff
changeset
|
85 |
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
|
86 |
109111
52b76722152a
Convert function definitions to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
108828
diff
changeset
|
87 char *getenv (const char *), *getwd (char *); |
109517
d22063077a0c
* emacsclient.c (getcwd): Fix previous change.
Juanma Barranquero <lekktu@gmail.com>
parents:
109516
diff
changeset
|
88 #ifdef HAVE_GETCWD |
d22063077a0c
* emacsclient.c (getcwd): Fix previous change.
Juanma Barranquero <lekktu@gmail.com>
parents:
109516
diff
changeset
|
89 char *(getcwd) (char *, size_t); |
79232
7970215aa6e5
Add a wrapper for getenv so it also checks the registry on Windows.
Juanma Barranquero <lekktu@gmail.com>
parents:
79226
diff
changeset
|
90 #endif |
7970215aa6e5
Add a wrapper for getenv so it also checks the registry on Windows.
Juanma Barranquero <lekktu@gmail.com>
parents:
79226
diff
changeset
|
91 |
16030
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
92 #ifndef VERSION |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
93 #define VERSION "unspecified" |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
94 #endif |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
95 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
96 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
97 #ifndef EXIT_SUCCESS |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
98 #define EXIT_SUCCESS 0 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
99 #endif |
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_FAILURE |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
102 #define EXIT_FAILURE 1 |
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 FALSE |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
106 #define FALSE 0 |
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 TRUE |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
110 #define TRUE 1 |
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 |
99215
e0e326adf3bc
* emacsclient.c (EXTRA_SPACE): New macro.
Juanma Barranquero <lekktu@gmail.com>
parents:
99209
diff
changeset
|
113 /* Additional space when allocating buffers for filenames, etc. */ |
e0e326adf3bc
* emacsclient.c (EXTRA_SPACE): New macro.
Juanma Barranquero <lekktu@gmail.com>
parents:
99209
diff
changeset
|
114 #define EXTRA_SPACE 100 |
e0e326adf3bc
* emacsclient.c (EXTRA_SPACE): New macro.
Juanma Barranquero <lekktu@gmail.com>
parents:
99209
diff
changeset
|
115 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
116 |
16030
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
117 /* Name used to invoke this program. */ |
110746
5c1a707ab452
Fix compilation warnings.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
110706
diff
changeset
|
118 const char *progname; |
16030
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
119 |
53341 | 120 /* The second argument to main. */ |
121 char **main_argv; | |
122 | |
16146
a649abfefbb1
(longopts): Change nowait to no-wait.
Richard M. Stallman <rms@gnu.org>
parents:
16074
diff
changeset
|
123 /* 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
|
124 int nowait = 0; |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
125 |
47647
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
126 /* Nonzero means args are expressions to be evaluated. --eval. */ |
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
127 int eval = 0; |
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
128 |
84667
f2c11a35b0e3
(current_frame): Change the default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
83666
diff
changeset
|
129 /* 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
|
130 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
|
131 |
47647
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
132 /* The display on which Emacs should work. --display. */ |
109744
fdbd24f8d999
Fix warnings produced by compiling with -Wwrite_strings (i.e. use const char *).
Jan D <jan.h.d@swipnet.se>
parents:
109652
diff
changeset
|
133 const char *display = NULL; |
47647
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
134 |
108828
87dad1e1c860
Add --parent-id argument to emacsclient.
Chong Yidong <cyd@stupidchicken.com>
parents:
107737
diff
changeset
|
135 /* The parent window ID, if we are opening a frame via XEmbed. */ |
87dad1e1c860
Add --parent-id argument to emacsclient.
Chong Yidong <cyd@stupidchicken.com>
parents:
107737
diff
changeset
|
136 char *parent_id = NULL; |
47647
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
137 |
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
|
138 /* 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
|
139 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
|
140 |
47647
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
141 /* 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
|
142 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
|
143 const char *alternate_editor = NULL; |
47647
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
144 |
52532 | 145 /* 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
|
146 char *socket_name = NULL; |
bc2610a13fbf
(socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
147 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
148 /* If non-NULL, the filename of the authentication file. */ |
109744
fdbd24f8d999
Fix warnings produced by compiling with -Wwrite_strings (i.e. use const char *).
Jan D <jan.h.d@swipnet.se>
parents:
109652
diff
changeset
|
149 const char *server_file = NULL; |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
150 |
74342
c6cb776ffbb7
(emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
74341
diff
changeset
|
151 /* PID of the Emacs server process. */ |
c6cb776ffbb7
(emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
74341
diff
changeset
|
152 int emacs_pid = 0; |
c6cb776ffbb7
(emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
74341
diff
changeset
|
153 |
109111
52b76722152a
Convert function definitions to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
108828
diff
changeset
|
154 void print_help_and_exit (void) NO_RETURN; |
109511
09a43f890565
Add NO_RETURN specifiers to functions in lib-src.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
109480
diff
changeset
|
155 void fail (void) NO_RETURN; |
09a43f890565
Add NO_RETURN specifiers to functions in lib-src.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
109480
diff
changeset
|
156 |
21387
4812cf228971
Include <stdlib.h> and <unistd.h> if available.
Andreas Schwab <schwab@suse.de>
parents:
19582
diff
changeset
|
157 |
16030
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
158 struct option longopts[] = |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
159 { |
16146
a649abfefbb1
(longopts): Change nowait to no-wait.
Richard M. Stallman <rms@gnu.org>
parents:
16074
diff
changeset
|
160 { "no-wait", no_argument, NULL, 'n' }, |
47647
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
161 { "eval", no_argument, NULL, 'e' }, |
16030
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
162 { "help", no_argument, NULL, 'H' }, |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
163 { "version", no_argument, NULL, 'V' }, |
82994
44ffe551079c
Fix longopts option name for --tty.
Karoly Lorentey <lorentey@elte.hu>
parents:
82991
diff
changeset
|
164 { "tty", no_argument, NULL, 't' }, |
98676
d63a9c87e0ac
(longopts, print_help_and_exit): Add -nw.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
98245
diff
changeset
|
165 { "nw", no_argument, NULL, 't' }, |
84667
f2c11a35b0e3
(current_frame): Change the default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
83666
diff
changeset
|
166 { "create-frame", no_argument, NULL, 'c' }, |
47515
6ee937dcfe16
(quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42412
diff
changeset
|
167 { "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
|
168 #ifndef NO_SOCKETS_IN_FILE_SYSTEM |
52479
bc2610a13fbf
(socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
169 { "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
|
170 #endif |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
171 { "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
|
172 #ifndef WINDOWSNT |
47647
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
173 { "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
|
174 #endif |
108828
87dad1e1c860
Add --parent-id argument to emacsclient.
Chong Yidong <cyd@stupidchicken.com>
parents:
107737
diff
changeset
|
175 { "parent-id", required_argument, NULL, 'p' }, |
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 * |
109111
52b76722152a
Convert function definitions to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
108828
diff
changeset
|
183 xmalloc (unsigned int size) |
79232
7970215aa6e5
Add a wrapper for getenv so it also checks the registry on Windows.
Juanma Barranquero <lekktu@gmail.com>
parents:
79226
diff
changeset
|
184 { |
7970215aa6e5
Add a wrapper for getenv so it also checks the registry on Windows.
Juanma Barranquero <lekktu@gmail.com>
parents:
79226
diff
changeset
|
185 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
|
186 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
|
187 { |
7970215aa6e5
Add a wrapper for getenv so it also checks the registry on Windows.
Juanma Barranquero <lekktu@gmail.com>
parents:
79226
diff
changeset
|
188 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
|
189 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
|
190 } |
7970215aa6e5
Add a wrapper for getenv so it also checks the registry on Windows.
Juanma Barranquero <lekktu@gmail.com>
parents:
79226
diff
changeset
|
191 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
|
192 } |
7970215aa6e5
Add a wrapper for getenv so it also checks the registry on Windows.
Juanma Barranquero <lekktu@gmail.com>
parents:
79226
diff
changeset
|
193 |
83103
efc0b56b83d9
Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents:
83065
diff
changeset
|
194 /* 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
|
195 |
efc0b56b83d9
Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents:
83065
diff
changeset
|
196 char * |
efc0b56b83d9
Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents:
83065
diff
changeset
|
197 xstrdup (const char *s) |
efc0b56b83d9
Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents:
83065
diff
changeset
|
198 { |
efc0b56b83d9
Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents:
83065
diff
changeset
|
199 char *result = strdup (s); |
efc0b56b83d9
Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents:
83065
diff
changeset
|
200 if (result == NULL) |
efc0b56b83d9
Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents:
83065
diff
changeset
|
201 { |
efc0b56b83d9
Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents:
83065
diff
changeset
|
202 perror ("strdup"); |
83121 | 203 exit (EXIT_FAILURE); |
83103
efc0b56b83d9
Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents:
83065
diff
changeset
|
204 } |
efc0b56b83d9
Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents:
83065
diff
changeset
|
205 return result; |
efc0b56b83d9
Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents:
83065
diff
changeset
|
206 } |
efc0b56b83d9
Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents:
83065
diff
changeset
|
207 |
83499
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
208 /* From sysdep.c */ |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
209 #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
|
210 |
84681
f44a6d77db08
(DIRECTORY_SEP, IS_DIRECTORY_SEP, IS_DEVICE_SEP)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
84677
diff
changeset
|
211 /* From lisp.h */ |
f44a6d77db08
(DIRECTORY_SEP, IS_DIRECTORY_SEP, IS_DEVICE_SEP)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
84677
diff
changeset
|
212 #ifndef DIRECTORY_SEP |
f44a6d77db08
(DIRECTORY_SEP, IS_DIRECTORY_SEP, IS_DEVICE_SEP)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
84677
diff
changeset
|
213 #define DIRECTORY_SEP '/' |
f44a6d77db08
(DIRECTORY_SEP, IS_DIRECTORY_SEP, IS_DEVICE_SEP)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
84677
diff
changeset
|
214 #endif |
f44a6d77db08
(DIRECTORY_SEP, IS_DIRECTORY_SEP, IS_DEVICE_SEP)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
84677
diff
changeset
|
215 #ifndef IS_DIRECTORY_SEP |
f44a6d77db08
(DIRECTORY_SEP, IS_DIRECTORY_SEP, IS_DEVICE_SEP)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
84677
diff
changeset
|
216 #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
|
217 #endif |
f44a6d77db08
(DIRECTORY_SEP, IS_DIRECTORY_SEP, IS_DEVICE_SEP)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
84677
diff
changeset
|
218 #ifndef IS_DEVICE_SEP |
f44a6d77db08
(DIRECTORY_SEP, IS_DIRECTORY_SEP, IS_DEVICE_SEP)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
84677
diff
changeset
|
219 #ifndef DEVICE_SEP |
f44a6d77db08
(DIRECTORY_SEP, IS_DIRECTORY_SEP, IS_DEVICE_SEP)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
84677
diff
changeset
|
220 #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
|
221 #else |
f44a6d77db08
(DIRECTORY_SEP, IS_DIRECTORY_SEP, IS_DEVICE_SEP)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
84677
diff
changeset
|
222 #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
|
223 #endif |
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 #ifndef IS_ANY_SEP |
f44a6d77db08
(DIRECTORY_SEP, IS_DIRECTORY_SEP, IS_DEVICE_SEP)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
84677
diff
changeset
|
226 #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
|
227 #endif |
f44a6d77db08
(DIRECTORY_SEP, IS_DIRECTORY_SEP, IS_DEVICE_SEP)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
84677
diff
changeset
|
228 |
f44a6d77db08
(DIRECTORY_SEP, IS_DIRECTORY_SEP, IS_DEVICE_SEP)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
84677
diff
changeset
|
229 |
83499
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
230 /* 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
|
231 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
|
232 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
|
233 char* |
109480
d12162869c07
Convert some more functions to standard C.
Juanma Barranquero <lekktu@gmail.com>
parents:
109315
diff
changeset
|
234 get_current_dir_name (void) |
83499
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
235 { |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
236 char *buf; |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
237 char *pwd; |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
238 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
|
239 /* 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
|
240 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
|
241 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
|
242 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
|
243 && (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
|
244 && 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
|
245 && stat (".", &dotstat) == 0 |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
246 && 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
|
247 && 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
|
248 #ifdef MAXPATHLEN |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
249 && strlen (pwd) < MAXPATHLEN |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
250 #endif |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
251 ) |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
252 { |
83548
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
253 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
|
254 if (!buf) |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
255 return NULL; |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
256 strcpy (buf, pwd); |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
257 } |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
258 #ifdef HAVE_GETCWD |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
259 else |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
260 { |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
261 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
|
262 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
|
263 if (!buf) |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
264 return NULL; |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
265 for (;;) |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
266 { |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
267 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
|
268 break; |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
269 if (errno != ERANGE) |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
270 { |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
271 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
|
272 free (buf); |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
273 errno = tmp_errno; |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
274 return NULL; |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
275 } |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
276 buf_size *= 2; |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
277 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
|
278 if (!buf) |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
279 return NULL; |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
280 } |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
281 } |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
282 #else |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
283 else |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
284 { |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
285 /* 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
|
286 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
|
287 if (!buf) |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
288 return NULL; |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
289 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
|
290 { |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
291 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
|
292 free (buf); |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
293 errno = tmp_errno; |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
294 return NULL; |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
295 } |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
296 } |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
297 #endif |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
298 return buf; |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
299 } |
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
300 #endif |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
301 |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
302 #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
|
303 |
7970215aa6e5
Add a wrapper for getenv so it also checks the registry on Windows.
Juanma Barranquero <lekktu@gmail.com>
parents:
79226
diff
changeset
|
304 #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
|
305 |
7970215aa6e5
Add a wrapper for getenv so it also checks the registry on Windows.
Juanma Barranquero <lekktu@gmail.com>
parents:
79226
diff
changeset
|
306 /* 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
|
307 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
|
308 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
|
309 char * |
109480
d12162869c07
Convert some more functions to standard C.
Juanma Barranquero <lekktu@gmail.com>
parents:
109315
diff
changeset
|
310 w32_get_resource (HKEY predefined, char *key, LPDWORD type) |
79232
7970215aa6e5
Add a wrapper for getenv so it also checks the registry on Windows.
Juanma Barranquero <lekktu@gmail.com>
parents:
79226
diff
changeset
|
311 { |
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 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
|
313 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
|
314 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
|
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 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
|
317 { |
7970215aa6e5
Add a wrapper for getenv so it also checks the registry on Windows.
Juanma Barranquero <lekktu@gmail.com>
parents:
79226
diff
changeset
|
318 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
|
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 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
|
321 |
99215
e0e326adf3bc
* emacsclient.c (EXTRA_SPACE): New macro.
Juanma Barranquero <lekktu@gmail.com>
parents:
99209
diff
changeset
|
322 if ((RegQueryValueEx (hrootkey, key, NULL, type, result, &cbData) != ERROR_SUCCESS) |
e0e326adf3bc
* emacsclient.c (EXTRA_SPACE): New macro.
Juanma Barranquero <lekktu@gmail.com>
parents:
99209
diff
changeset
|
323 || (*result == 0)) |
79232
7970215aa6e5
Add a wrapper for getenv so it also checks the registry on Windows.
Juanma Barranquero <lekktu@gmail.com>
parents:
79226
diff
changeset
|
324 { |
7970215aa6e5
Add a wrapper for getenv so it also checks the registry on Windows.
Juanma Barranquero <lekktu@gmail.com>
parents:
79226
diff
changeset
|
325 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
|
326 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
|
327 } |
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 |
7970215aa6e5
Add a wrapper for getenv so it also checks the registry on Windows.
Juanma Barranquero <lekktu@gmail.com>
parents:
79226
diff
changeset
|
330 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
|
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 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
|
334 } |
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 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
|
338 |
106818
a3da62473e24
Fix typos in comments and ChangeLogs.
Juanma Barranquero <lekktu@gmail.com>
parents:
106815
diff
changeset
|
339 This is needed to duplicate Emacs's behavior, which is to look for environment |
79232
7970215aa6e5
Add a wrapper for getenv so it also checks the registry on Windows.
Juanma Barranquero <lekktu@gmail.com>
parents:
79226
diff
changeset
|
340 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
|
341 */ |
7970215aa6e5
Add a wrapper for getenv so it also checks the registry on Windows.
Juanma Barranquero <lekktu@gmail.com>
parents:
79226
diff
changeset
|
342 char * |
109480
d12162869c07
Convert some more functions to standard C.
Juanma Barranquero <lekktu@gmail.com>
parents:
109315
diff
changeset
|
343 w32_getenv (char *envvar) |
79232
7970215aa6e5
Add a wrapper for getenv so it also checks the registry on Windows.
Juanma Barranquero <lekktu@gmail.com>
parents:
79226
diff
changeset
|
344 { |
7970215aa6e5
Add a wrapper for getenv so it also checks the registry on Windows.
Juanma Barranquero <lekktu@gmail.com>
parents:
79226
diff
changeset
|
345 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
|
346 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
|
347 |
7970215aa6e5
Add a wrapper for getenv so it also checks the registry on Windows.
Juanma Barranquero <lekktu@gmail.com>
parents:
79226
diff
changeset
|
348 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
|
349 /* 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
|
350 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
|
351 |
7970215aa6e5
Add a wrapper for getenv so it also checks the registry on Windows.
Juanma Barranquero <lekktu@gmail.com>
parents:
79226
diff
changeset
|
352 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
|
353 ! (value = w32_get_resource (HKEY_LOCAL_MACHINE, envvar, &dwType))) |
99311
9e2c3c623db2
(main) [WINDOWSNT]: Don't ifdef away the call to `ttyname'.
Eli Zaretskii <eliz@gnu.org>
parents:
99297
diff
changeset
|
354 { |
9e2c3c623db2
(main) [WINDOWSNT]: Don't ifdef away the call to `ttyname'.
Eli Zaretskii <eliz@gnu.org>
parents:
99297
diff
changeset
|
355 /* "w32console" is what Emacs on Windows uses for tty-type under -nw. */ |
9e2c3c623db2
(main) [WINDOWSNT]: Don't ifdef away the call to `ttyname'.
Eli Zaretskii <eliz@gnu.org>
parents:
99297
diff
changeset
|
356 if (strcmp (envvar, "TERM") == 0) |
9e2c3c623db2
(main) [WINDOWSNT]: Don't ifdef away the call to `ttyname'.
Eli Zaretskii <eliz@gnu.org>
parents:
99297
diff
changeset
|
357 return xstrdup ("w32console"); |
9e2c3c623db2
(main) [WINDOWSNT]: Don't ifdef away the call to `ttyname'.
Eli Zaretskii <eliz@gnu.org>
parents:
99297
diff
changeset
|
358 /* Found neither in the environment nor in the registry. */ |
9e2c3c623db2
(main) [WINDOWSNT]: Don't ifdef away the call to `ttyname'.
Eli Zaretskii <eliz@gnu.org>
parents:
99297
diff
changeset
|
359 return NULL; |
9e2c3c623db2
(main) [WINDOWSNT]: Don't ifdef away the call to `ttyname'.
Eli Zaretskii <eliz@gnu.org>
parents:
99297
diff
changeset
|
360 } |
79232
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 |
103641
48d529d3a5a4
bug#1849 - Windows 7 Taskbar Support
Jason Rumney <jasonr@gnu.org>
parents:
103026
diff
changeset
|
390 void |
109480
d12162869c07
Convert some more functions to standard C.
Juanma Barranquero <lekktu@gmail.com>
parents:
109315
diff
changeset
|
391 w32_set_user_model_id (void) |
103641
48d529d3a5a4
bug#1849 - Windows 7 Taskbar Support
Jason Rumney <jasonr@gnu.org>
parents:
103026
diff
changeset
|
392 { |
48d529d3a5a4
bug#1849 - Windows 7 Taskbar Support
Jason Rumney <jasonr@gnu.org>
parents:
103026
diff
changeset
|
393 HMODULE shell; |
103716
7bad97f82eb6
* w32term.c (w32_initialize): Use standard types.
Jason Rumney <jasonr@gnu.org>
parents:
103641
diff
changeset
|
394 HRESULT (WINAPI * set_user_model) (wchar_t * id); |
103641
48d529d3a5a4
bug#1849 - Windows 7 Taskbar Support
Jason Rumney <jasonr@gnu.org>
parents:
103026
diff
changeset
|
395 |
48d529d3a5a4
bug#1849 - Windows 7 Taskbar Support
Jason Rumney <jasonr@gnu.org>
parents:
103026
diff
changeset
|
396 /* On Windows 7 and later, we need to set the user model ID |
48d529d3a5a4
bug#1849 - Windows 7 Taskbar Support
Jason Rumney <jasonr@gnu.org>
parents:
103026
diff
changeset
|
397 to associate emacsclient launched files with Emacs frames |
48d529d3a5a4
bug#1849 - Windows 7 Taskbar Support
Jason Rumney <jasonr@gnu.org>
parents:
103026
diff
changeset
|
398 in the UI. */ |
109516
68ca98ae70fb
Make building under stricter warning flags somewhat cleaner.
Juanma Barranquero <lekktu@gmail.com>
parents:
109511
diff
changeset
|
399 shell = LoadLibrary ("shell32.dll"); |
103641
48d529d3a5a4
bug#1849 - Windows 7 Taskbar Support
Jason Rumney <jasonr@gnu.org>
parents:
103026
diff
changeset
|
400 if (shell) |
48d529d3a5a4
bug#1849 - Windows 7 Taskbar Support
Jason Rumney <jasonr@gnu.org>
parents:
103026
diff
changeset
|
401 { |
48d529d3a5a4
bug#1849 - Windows 7 Taskbar Support
Jason Rumney <jasonr@gnu.org>
parents:
103026
diff
changeset
|
402 set_user_model |
48d529d3a5a4
bug#1849 - Windows 7 Taskbar Support
Jason Rumney <jasonr@gnu.org>
parents:
103026
diff
changeset
|
403 = (void *) GetProcAddress (shell, |
48d529d3a5a4
bug#1849 - Windows 7 Taskbar Support
Jason Rumney <jasonr@gnu.org>
parents:
103026
diff
changeset
|
404 "SetCurrentProcessExplicitAppUserModelID"); |
48d529d3a5a4
bug#1849 - Windows 7 Taskbar Support
Jason Rumney <jasonr@gnu.org>
parents:
103026
diff
changeset
|
405 /* If the function is defined, then we are running on Windows 7 |
48d529d3a5a4
bug#1849 - Windows 7 Taskbar Support
Jason Rumney <jasonr@gnu.org>
parents:
103026
diff
changeset
|
406 or newer, and the UI uses this to group related windows |
48d529d3a5a4
bug#1849 - Windows 7 Taskbar Support
Jason Rumney <jasonr@gnu.org>
parents:
103026
diff
changeset
|
407 together. Since emacs, runemacs, emacsclient are related, we |
48d529d3a5a4
bug#1849 - Windows 7 Taskbar Support
Jason Rumney <jasonr@gnu.org>
parents:
103026
diff
changeset
|
408 want them grouped even though the executables are different, |
48d529d3a5a4
bug#1849 - Windows 7 Taskbar Support
Jason Rumney <jasonr@gnu.org>
parents:
103026
diff
changeset
|
409 so we need to set a consistent ID between them. */ |
48d529d3a5a4
bug#1849 - Windows 7 Taskbar Support
Jason Rumney <jasonr@gnu.org>
parents:
103026
diff
changeset
|
410 if (set_user_model) |
48d529d3a5a4
bug#1849 - Windows 7 Taskbar Support
Jason Rumney <jasonr@gnu.org>
parents:
103026
diff
changeset
|
411 set_user_model (L"GNU.Emacs"); |
48d529d3a5a4
bug#1849 - Windows 7 Taskbar Support
Jason Rumney <jasonr@gnu.org>
parents:
103026
diff
changeset
|
412 |
48d529d3a5a4
bug#1849 - Windows 7 Taskbar Support
Jason Rumney <jasonr@gnu.org>
parents:
103026
diff
changeset
|
413 FreeLibrary (shell); |
48d529d3a5a4
bug#1849 - Windows 7 Taskbar Support
Jason Rumney <jasonr@gnu.org>
parents:
103026
diff
changeset
|
414 } |
48d529d3a5a4
bug#1849 - Windows 7 Taskbar Support
Jason Rumney <jasonr@gnu.org>
parents:
103026
diff
changeset
|
415 } |
48d529d3a5a4
bug#1849 - Windows 7 Taskbar Support
Jason Rumney <jasonr@gnu.org>
parents:
103026
diff
changeset
|
416 |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
417 int |
109480
d12162869c07
Convert some more functions to standard C.
Juanma Barranquero <lekktu@gmail.com>
parents:
109315
diff
changeset
|
418 w32_window_app (void) |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
419 { |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
420 static int window_app = -1; |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
421 char szTitle[MAX_PATH]; |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
422 |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
423 if (window_app < 0) |
78904
5025525d6c9d
(w32_window_app): Init common controls when windowed.
Jason Rumney <jasonr@gnu.org>
parents:
78257
diff
changeset
|
424 { |
5025525d6c9d
(w32_window_app): Init common controls when windowed.
Jason Rumney <jasonr@gnu.org>
parents:
78257
diff
changeset
|
425 /* 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
|
426 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
|
427 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
|
428 if (window_app) |
109516
68ca98ae70fb
Make building under stricter warning flags somewhat cleaner.
Juanma Barranquero <lekktu@gmail.com>
parents:
109511
diff
changeset
|
429 InitCommonControls (); |
78904
5025525d6c9d
(w32_window_app): Init common controls when windowed.
Jason Rumney <jasonr@gnu.org>
parents:
78257
diff
changeset
|
430 } |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
431 |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
432 return window_app; |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
433 } |
83600
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 /* |
84681
f44a6d77db08
(DIRECTORY_SEP, IS_DIRECTORY_SEP, IS_DEVICE_SEP)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
84677
diff
changeset
|
436 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
|
437 |
9aa8a3a78f9e
* emacsclient.c (s): Restore.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
83590
diff
changeset
|
438 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
|
439 the Microsoft libraries: they concatenate the arguments together without |
9aa8a3a78f9e
* emacsclient.c (s): Restore.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
83590
diff
changeset
|
440 quoting special characters, and pass the result to CreateProcess, with |
109480
d12162869c07
Convert some more functions to standard C.
Juanma Barranquero <lekktu@gmail.com>
parents:
109315
diff
changeset
|
441 predictably bad results. By contrast, POSIX execvp passes the arguments |
83600
9aa8a3a78f9e
* emacsclient.c (s): Restore.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
83590
diff
changeset
|
442 directly into the argv array of the child process. |
9aa8a3a78f9e
* emacsclient.c (s): Restore.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
83590
diff
changeset
|
443 */ |
9aa8a3a78f9e
* emacsclient.c (s): Restore.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
83590
diff
changeset
|
444 int |
109480
d12162869c07
Convert some more functions to standard C.
Juanma Barranquero <lekktu@gmail.com>
parents:
109315
diff
changeset
|
445 w32_execvp (const char *path, char **argv) |
83600
9aa8a3a78f9e
* emacsclient.c (s): Restore.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
83590
diff
changeset
|
446 { |
9aa8a3a78f9e
* emacsclient.c (s): Restore.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
83590
diff
changeset
|
447 int i; |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
448 |
83600
9aa8a3a78f9e
* emacsclient.c (s): Restore.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
83590
diff
changeset
|
449 /* Required to allow a .BAT script as alternate editor. */ |
9aa8a3a78f9e
* emacsclient.c (s): Restore.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
83590
diff
changeset
|
450 argv[0] = (char *) alternate_editor; |
9aa8a3a78f9e
* emacsclient.c (s): Restore.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
83590
diff
changeset
|
451 |
9aa8a3a78f9e
* emacsclient.c (s): Restore.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
83590
diff
changeset
|
452 for (i = 0; argv[i]; i++) |
9aa8a3a78f9e
* emacsclient.c (s): Restore.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
83590
diff
changeset
|
453 if (strchr (argv[i], ' ')) |
9aa8a3a78f9e
* emacsclient.c (s): Restore.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
83590
diff
changeset
|
454 { |
9aa8a3a78f9e
* emacsclient.c (s): Restore.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
83590
diff
changeset
|
455 char *quoted = alloca (strlen (argv[i]) + 3); |
9aa8a3a78f9e
* emacsclient.c (s): Restore.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
83590
diff
changeset
|
456 sprintf (quoted, "\"%s\"", argv[i]); |
9aa8a3a78f9e
* emacsclient.c (s): Restore.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
83590
diff
changeset
|
457 argv[i] = quoted; |
9aa8a3a78f9e
* emacsclient.c (s): Restore.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
83590
diff
changeset
|
458 } |
9aa8a3a78f9e
* emacsclient.c (s): Restore.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
83590
diff
changeset
|
459 |
9aa8a3a78f9e
* emacsclient.c (s): Restore.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
83590
diff
changeset
|
460 return execvp (path, argv); |
9aa8a3a78f9e
* emacsclient.c (s): Restore.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
83590
diff
changeset
|
461 } |
9aa8a3a78f9e
* emacsclient.c (s): Restore.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
83590
diff
changeset
|
462 |
9aa8a3a78f9e
* emacsclient.c (s): Restore.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
83590
diff
changeset
|
463 #undef execvp |
9aa8a3a78f9e
* emacsclient.c (s): Restore.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
83590
diff
changeset
|
464 #define execvp w32_execvp |
9aa8a3a78f9e
* emacsclient.c (s): Restore.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
83590
diff
changeset
|
465 |
99311
9e2c3c623db2
(main) [WINDOWSNT]: Don't ifdef away the call to `ttyname'.
Eli Zaretskii <eliz@gnu.org>
parents:
99297
diff
changeset
|
466 /* Emulation of ttyname for Windows. */ |
9e2c3c623db2
(main) [WINDOWSNT]: Don't ifdef away the call to `ttyname'.
Eli Zaretskii <eliz@gnu.org>
parents:
99297
diff
changeset
|
467 char * |
9e2c3c623db2
(main) [WINDOWSNT]: Don't ifdef away the call to `ttyname'.
Eli Zaretskii <eliz@gnu.org>
parents:
99297
diff
changeset
|
468 ttyname (int fd) |
9e2c3c623db2
(main) [WINDOWSNT]: Don't ifdef away the call to `ttyname'.
Eli Zaretskii <eliz@gnu.org>
parents:
99297
diff
changeset
|
469 { |
9e2c3c623db2
(main) [WINDOWSNT]: Don't ifdef away the call to `ttyname'.
Eli Zaretskii <eliz@gnu.org>
parents:
99297
diff
changeset
|
470 return "CONOUT$"; |
9e2c3c623db2
(main) [WINDOWSNT]: Don't ifdef away the call to `ttyname'.
Eli Zaretskii <eliz@gnu.org>
parents:
99297
diff
changeset
|
471 } |
9e2c3c623db2
(main) [WINDOWSNT]: Don't ifdef away the call to `ttyname'.
Eli Zaretskii <eliz@gnu.org>
parents:
99297
diff
changeset
|
472 |
83600
9aa8a3a78f9e
* emacsclient.c (s): Restore.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
83590
diff
changeset
|
473 #endif /* WINDOWSNT */ |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
474 |
85691 | 475 /* Display a normal or error message. |
476 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
|
477 void |
109744
fdbd24f8d999
Fix warnings produced by compiling with -Wwrite_strings (i.e. use const char *).
Jan D <jan.h.d@swipnet.se>
parents:
109652
diff
changeset
|
478 message (int is_error, const char *message, ...) |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
479 { |
109516
68ca98ae70fb
Make building under stricter warning flags somewhat cleaner.
Juanma Barranquero <lekktu@gmail.com>
parents:
109511
diff
changeset
|
480 char msg[2048]; |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
481 va_list args; |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
482 |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
483 va_start (args, message); |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
484 vsprintf (msg, message, args); |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
485 va_end (args); |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
486 |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
487 #ifdef WINDOWSNT |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
488 if (w32_window_app ()) |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
489 { |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
490 if (is_error) |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
491 MessageBox (NULL, msg, "Emacsclient ERROR", MB_ICONERROR); |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
492 else |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
493 MessageBox (NULL, msg, "Emacsclient", MB_ICONINFORMATION); |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
494 } |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
495 else |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
496 #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
|
497 { |
32079f79e240
(message): Make sure the message is properly written even if it contains printf
Juanma Barranquero <lekktu@gmail.com>
parents:
74176
diff
changeset
|
498 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
|
499 |
32079f79e240
(message): Make sure the message is properly written even if it contains printf
Juanma Barranquero <lekktu@gmail.com>
parents:
74176
diff
changeset
|
500 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
|
501 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
|
502 } |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
503 } |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
504 |
16030
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
505 /* Decode the options from argv and argc. |
16061
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
506 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
|
507 |
16061
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
508 void |
109111
52b76722152a
Convert function definitions to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
108828
diff
changeset
|
509 decode_options (int argc, char **argv) |
16030
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
510 { |
79232
7970215aa6e5
Add a wrapper for getenv so it also checks the registry on Windows.
Juanma Barranquero <lekktu@gmail.com>
parents:
79226
diff
changeset
|
511 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
|
512 |
16030
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
513 while (1) |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
514 { |
98676
d63a9c87e0ac
(longopts, print_help_and_exit): Add -nw.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
98245
diff
changeset
|
515 int opt = getopt_long_only (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
|
516 #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
|
517 "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
|
518 #else |
83548
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
519 "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
|
520 #endif |
83548
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
521 longopts, 0); |
16030
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
522 |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
523 if (opt == EOF) |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
524 break; |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
525 |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
526 switch (opt) |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
527 { |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
528 case 0: |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
529 /* 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
|
530 long-named option. We should do nothing. */ |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
531 break; |
42176
1f5dbeefa536
Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents:
39723
diff
changeset
|
532 |
27305
4161adef5fd3
Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
533 case 'a': |
4161adef5fd3
Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
534 alternate_editor = optarg; |
4161adef5fd3
Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
535 break; |
42176
1f5dbeefa536
Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents:
39723
diff
changeset
|
536 |
73765
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
537 #ifndef NO_SOCKETS_IN_FILE_SYSTEM |
52479
bc2610a13fbf
(socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
538 case 's': |
bc2610a13fbf
(socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
539 socket_name = optarg; |
bc2610a13fbf
(socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
540 break; |
73765
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
541 #endif |
52479
bc2610a13fbf
(socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
542 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
543 case 'f': |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
544 server_file = optarg; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
545 break; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
546 |
88014
e830695cdb7f
(decode_options): Default to a NULL display, as Emacs-22.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87965
diff
changeset
|
547 /* 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
|
548 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
|
549 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
|
550 support. */ |
47647
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
551 case 'd': |
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
552 display = optarg; |
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
553 break; |
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
554 |
16030
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
555 case 'n': |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
556 nowait = 1; |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
557 break; |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
558 |
47647
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
559 case 'e': |
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
560 eval = 1; |
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
561 break; |
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
562 |
16030
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
563 case 'V': |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
564 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
|
565 exit (EXIT_SUCCESS); |
16030
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
566 break; |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
567 |
83548
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
568 case 't': |
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
569 tty = 1; |
84715
e872fac85e8c
(decode_options): -t implies -c.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
84681
diff
changeset
|
570 current_frame = 0; |
83548
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
571 break; |
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
572 |
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
573 case 'c': |
84667
f2c11a35b0e3
(current_frame): Change the default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
83666
diff
changeset
|
574 current_frame = 0; |
83548
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
575 break; |
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
576 |
108828
87dad1e1c860
Add --parent-id argument to emacsclient.
Chong Yidong <cyd@stupidchicken.com>
parents:
107737
diff
changeset
|
577 case 'p': |
87dad1e1c860
Add --parent-id argument to emacsclient.
Chong Yidong <cyd@stupidchicken.com>
parents:
107737
diff
changeset
|
578 parent_id = optarg; |
87dad1e1c860
Add --parent-id argument to emacsclient.
Chong Yidong <cyd@stupidchicken.com>
parents:
107737
diff
changeset
|
579 current_frame = 0; |
87dad1e1c860
Add --parent-id argument to emacsclient.
Chong Yidong <cyd@stupidchicken.com>
parents:
107737
diff
changeset
|
580 break; |
87dad1e1c860
Add --parent-id argument to emacsclient.
Chong Yidong <cyd@stupidchicken.com>
parents:
107737
diff
changeset
|
581 |
16030
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
582 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
|
583 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
|
584 break; |
e5f56d47b52c
(print_help_and_exit): Print to stdout. Exit successfully. Added some blank
Juanma Barranquero <lekktu@gmail.com>
parents:
48627
diff
changeset
|
585 |
16030
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
586 default: |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
587 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
|
588 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
|
589 break; |
16030
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
590 } |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
591 } |
83548
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
592 |
99333
a999ab783eff
(window_system): Delete redundant variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
99311
diff
changeset
|
593 /* If the -c option is used (without -t) and no --display argument |
a999ab783eff
(window_system): Delete redundant variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
99311
diff
changeset
|
594 is provided, try $DISPLAY. |
a999ab783eff
(window_system): Delete redundant variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
99311
diff
changeset
|
595 Without the -c option, we used to set `display' to $DISPLAY by |
a999ab783eff
(window_system): Delete redundant variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
99311
diff
changeset
|
596 default, but this changed the default behavior and is sometimes |
a999ab783eff
(window_system): Delete redundant variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
99311
diff
changeset
|
597 inconvenient. So we force users to use "--display $DISPLAY" if |
a999ab783eff
(window_system): Delete redundant variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
99311
diff
changeset
|
598 they want Emacs to connect to their 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
|
599 if (!current_frame && !tty && !display) |
101397
b4aa70dece55
* emacsclient.c (decode_options): Use a dummy display name under NS/Cocoa.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
100958
diff
changeset
|
600 { |
b4aa70dece55
* emacsclient.c (decode_options): Use a dummy display name under NS/Cocoa.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
100958
diff
changeset
|
601 display = egetenv ("DISPLAY"); |
b4aa70dece55
* emacsclient.c (decode_options): Use a dummy display name under NS/Cocoa.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
100958
diff
changeset
|
602 #ifdef NS_IMPL_COCOA |
b4aa70dece55
* emacsclient.c (decode_options): Use a dummy display name under NS/Cocoa.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
100958
diff
changeset
|
603 /* Under Cocoa, we don't really use displays the same way as in X, |
b4aa70dece55
* emacsclient.c (decode_options): Use a dummy display name under NS/Cocoa.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
100958
diff
changeset
|
604 so provide a dummy. */ |
b4aa70dece55
* emacsclient.c (decode_options): Use a dummy display name under NS/Cocoa.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
100958
diff
changeset
|
605 if (!display || strlen (display) == 0) |
b4aa70dece55
* emacsclient.c (decode_options): Use a dummy display name under NS/Cocoa.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
100958
diff
changeset
|
606 display = "ns"; |
b4aa70dece55
* emacsclient.c (decode_options): Use a dummy display name under NS/Cocoa.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
100958
diff
changeset
|
607 #endif |
b4aa70dece55
* emacsclient.c (decode_options): Use a dummy display name under NS/Cocoa.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
100958
diff
changeset
|
608 } |
91663
2b045ea84cf9
(decode_options): Pass --display implicitly if -c
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
88014
diff
changeset
|
609 |
99333
a999ab783eff
(window_system): Delete redundant variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
99311
diff
changeset
|
610 /* A null-string display is invalid. */ |
88014
e830695cdb7f
(decode_options): Default to a NULL display, as Emacs-22.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87965
diff
changeset
|
611 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
|
612 display = NULL; |
e830695cdb7f
(decode_options): Default to a NULL display, as Emacs-22.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87965
diff
changeset
|
613 |
99333
a999ab783eff
(window_system): Delete redundant variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
99311
diff
changeset
|
614 /* If no display is available, new frames are tty frames. */ |
a999ab783eff
(window_system): Delete redundant variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
99311
diff
changeset
|
615 if (!current_frame && !display) |
83548
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
616 tty = 1; |
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
|
617 |
83548
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
618 /* --no-wait implies --current-frame on ttys when there are file |
99333
a999ab783eff
(window_system): Delete redundant variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
99311
diff
changeset
|
619 arguments or expressions given. */ |
83548
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
620 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
|
621 current_frame = 1; |
100318
00d91c609c41
(EMACS_DAEMON): Remove definition.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100314
diff
changeset
|
622 |
00d91c609c41
(EMACS_DAEMON): Remove definition.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100314
diff
changeset
|
623 #ifdef WINDOWSNT |
100321
ebafebeca927
(decode_options): Fix typo.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100318
diff
changeset
|
624 if (alternate_editor && alternate_editor[0] == '\0') |
100318
00d91c609c41
(EMACS_DAEMON): Remove definition.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100314
diff
changeset
|
625 { |
00d91c609c41
(EMACS_DAEMON): Remove definition.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100314
diff
changeset
|
626 message (TRUE, "--alternate-editor argument or ALTERNATE_EDITOR variable cannot be\n\ |
00d91c609c41
(EMACS_DAEMON): Remove definition.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100314
diff
changeset
|
627 an empty string"); |
00d91c609c41
(EMACS_DAEMON): Remove definition.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100314
diff
changeset
|
628 exit (EXIT_FAILURE); |
00d91c609c41
(EMACS_DAEMON): Remove definition.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100314
diff
changeset
|
629 } |
00d91c609c41
(EMACS_DAEMON): Remove definition.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100314
diff
changeset
|
630 #endif /* WINDOWSNT */ |
16030
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
631 } |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
632 |
83548
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
633 |
21387
4812cf228971
Include <stdlib.h> and <unistd.h> if available.
Andreas Schwab <schwab@suse.de>
parents:
19582
diff
changeset
|
634 void |
109111
52b76722152a
Convert function definitions to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
108828
diff
changeset
|
635 print_help_and_exit (void) |
16030
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
636 { |
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
|
637 /* 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
|
638 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
|
639 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
|
640 when using emacsclientw. */ |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
641 message (FALSE, |
83548
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
642 "Usage: %s [OPTIONS] FILE...\n\ |
47647
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
643 Tell the Emacs server to visit the specified files.\n\ |
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
644 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
|
645 \n\ |
47647
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
646 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
|
647 -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
|
648 -H, --help Print this usage information message\n\ |
98676
d63a9c87e0ac
(longopts, print_help_and_exit): Add -nw.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
98245
diff
changeset
|
649 -nw, -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
|
650 -c, --create-frame Create a new frame instead of trying to\n\ |
103026
9265a8db20b3
* emacsclient.c (print_help_and_exit): Fix typo and tabify (careful
Juanma Barranquero <lekktu@gmail.com>
parents:
103025
diff
changeset
|
651 use the current Emacs frame\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
|
652 -e, --eval Evaluate the FILE arguments as ELisp expressions\n\ |
91852
e05f6258e35f
(print_help_and_exit): Show -d option on Windows.
Juanma Barranquero <lekktu@gmail.com>
parents:
91664
diff
changeset
|
653 -n, --no-wait Don't wait for the server to return\n\ |
103025
fdccf299eae0
* emacsclient.c (print_help_and_exit): Clarify argument placement
Chong Yidong <cyd@stupidchicken.com>
parents:
102823
diff
changeset
|
654 -d DISPLAY, --display=DISPLAY\n\ |
108828
87dad1e1c860
Add --parent-id argument to emacsclient.
Chong Yidong <cyd@stupidchicken.com>
parents:
107737
diff
changeset
|
655 Visit the file in the given display\n\ |
87dad1e1c860
Add --parent-id argument to emacsclient.
Chong Yidong <cyd@stupidchicken.com>
parents:
107737
diff
changeset
|
656 --parent-id=ID Open in parent window ID, via XEmbed\n" |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
657 #ifndef NO_SOCKETS_IN_FILE_SYSTEM |
103025
fdccf299eae0
* emacsclient.c (print_help_and_exit): Clarify argument placement
Chong Yidong <cyd@stupidchicken.com>
parents:
102823
diff
changeset
|
658 "-s SOCKET, --socket-name=SOCKET\n\ |
103026
9265a8db20b3
* emacsclient.c (print_help_and_exit): Fix typo and tabify (careful
Juanma Barranquero <lekktu@gmail.com>
parents:
103025
diff
changeset
|
659 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
|
660 #endif |
103025
fdccf299eae0
* emacsclient.c (print_help_and_exit): Clarify argument placement
Chong Yidong <cyd@stupidchicken.com>
parents:
102823
diff
changeset
|
661 "-f SERVER, --server-file=SERVER\n\ |
103026
9265a8db20b3
* emacsclient.c (print_help_and_exit): Fix typo and tabify (careful
Juanma Barranquero <lekktu@gmail.com>
parents:
103025
diff
changeset
|
662 Set filename of the TCP authentication file\n\ |
103025
fdccf299eae0
* emacsclient.c (print_help_and_exit): Clarify argument placement
Chong Yidong <cyd@stupidchicken.com>
parents:
102823
diff
changeset
|
663 -a EDITOR, --alternate-editor=EDITOR\n\ |
103026
9265a8db20b3
* emacsclient.c (print_help_and_exit): Fix typo and tabify (careful
Juanma Barranquero <lekktu@gmail.com>
parents:
103025
diff
changeset
|
664 Editor to fallback to if the server is not running\n" |
102823
3b582fef386d
(print_help_and_exit): Fix typo.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
102474
diff
changeset
|
665 #ifndef WINDOWSNT |
100314
9c9346f62ad8
* emacsclient.c [!WINDOWSNT] (EMACS_DAEMON): New define.
Juanma Barranquero <lekktu@gmail.com>
parents:
100312
diff
changeset
|
666 " If EDITOR is the empty string, start Emacs in daemon\n\ |
9c9346f62ad8
* emacsclient.c [!WINDOWSNT] (EMACS_DAEMON): New define.
Juanma Barranquero <lekktu@gmail.com>
parents:
100312
diff
changeset
|
667 mode and try connecting again\n" |
102823
3b582fef386d
(print_help_and_exit): Fix typo.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
102474
diff
changeset
|
668 #endif /* not WINDOWSNT */ |
100314
9c9346f62ad8
* emacsclient.c [!WINDOWSNT] (EMACS_DAEMON): New define.
Juanma Barranquero <lekktu@gmail.com>
parents:
100312
diff
changeset
|
669 "\n\ |
105608
1af242c07461
(print_help_and_exit): Fix bug report instructions.
Glenn Morris <rgm@gnu.org>
parents:
103716
diff
changeset
|
670 Report bugs with M-x report-emacs-bug.\n", progname); |
55442
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
53813
diff
changeset
|
671 exit (EXIT_SUCCESS); |
16030
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
672 } |
16061
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
673 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
674 /* |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
675 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
|
676 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
|
677 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
|
678 */ |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
679 void |
83548
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
680 fail (void) |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
681 { |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
682 if (alternate_editor) |
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 int i = optind - 1; |
74637
fe8bd1af34c4
(w32_execvp): New function; wrapper for `execvp'.
Juanma Barranquero <lekktu@gmail.com>
parents:
74342
diff
changeset
|
685 |
83548
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
686 execvp (alternate_editor, main_argv + i); |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
687 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
|
688 progname, alternate_editor); |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
689 } |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
690 exit (EXIT_FAILURE); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
691 } |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
692 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
693 |
73617
7af864af10b6
[WINDOWSNT]: Define HAVE_INET_SOCKETS.
Juanma Barranquero <lekktu@gmail.com>
parents:
73601
diff
changeset
|
694 #if !defined (HAVE_SOCKETS) || !defined (HAVE_INET_SOCKETS) |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
695 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
696 int |
109652
eb720d8ea1c6
emacsclient.c cleanups.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
109517
diff
changeset
|
697 main (int argc, char **argv) |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
698 { |
83548
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
699 main_argv = argv; |
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
700 progname = argv[0]; |
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
701 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
|
702 "on systems with Berkeley sockets.\n", |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
703 argv[0]); |
83548
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
704 fail (); |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
705 } |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
706 |
73617
7af864af10b6
[WINDOWSNT]: Define HAVE_INET_SOCKETS.
Juanma Barranquero <lekktu@gmail.com>
parents:
73601
diff
changeset
|
707 #else /* HAVE_SOCKETS && HAVE_INET_SOCKETS */ |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
708 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
709 #define AUTH_KEY_LENGTH 64 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
710 #define SEND_BUFFER_SIZE 4096 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
711 |
109111
52b76722152a
Convert function definitions to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
108828
diff
changeset
|
712 extern char *strerror (int); |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
713 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
714 /* Buffer to accumulate data to send in TCP connections. */ |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
715 char send_buffer[SEND_BUFFER_SIZE + 1]; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
716 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
|
717 /* Socket used to communicate with the Emacs server process. */ |
8365dbf64d14
(emacs_socket): Rename from s.
Jason Rumney <jasonr@gnu.org>
parents:
83600
diff
changeset
|
718 HSOCKET emacs_socket = 0; |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
719 |
79226
8919d6b286e1
(sock_err_message): New function.
Jason Rumney <jasonr@gnu.org>
parents:
78904
diff
changeset
|
720 /* 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
|
721 C library, so errors are handled differently. */ |
8919d6b286e1
(sock_err_message): New function.
Jason Rumney <jasonr@gnu.org>
parents:
78904
diff
changeset
|
722 void |
109744
fdbd24f8d999
Fix warnings produced by compiling with -Wwrite_strings (i.e. use const char *).
Jan D <jan.h.d@swipnet.se>
parents:
109652
diff
changeset
|
723 sock_err_message (const char *function_name) |
79226
8919d6b286e1
(sock_err_message): New function.
Jason Rumney <jasonr@gnu.org>
parents:
78904
diff
changeset
|
724 { |
8919d6b286e1
(sock_err_message): New function.
Jason Rumney <jasonr@gnu.org>
parents:
78904
diff
changeset
|
725 #ifdef WINDOWSNT |
8919d6b286e1
(sock_err_message): New function.
Jason Rumney <jasonr@gnu.org>
parents:
78904
diff
changeset
|
726 char* msg = NULL; |
8919d6b286e1
(sock_err_message): New function.
Jason Rumney <jasonr@gnu.org>
parents:
78904
diff
changeset
|
727 |
8919d6b286e1
(sock_err_message): New function.
Jason Rumney <jasonr@gnu.org>
parents:
78904
diff
changeset
|
728 FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM |
8919d6b286e1
(sock_err_message): New function.
Jason Rumney <jasonr@gnu.org>
parents:
78904
diff
changeset
|
729 | FORMAT_MESSAGE_ALLOCATE_BUFFER |
8919d6b286e1
(sock_err_message): New function.
Jason Rumney <jasonr@gnu.org>
parents:
78904
diff
changeset
|
730 | FORMAT_MESSAGE_ARGUMENT_ARRAY, |
8919d6b286e1
(sock_err_message): New function.
Jason Rumney <jasonr@gnu.org>
parents:
78904
diff
changeset
|
731 NULL, WSAGetLastError (), 0, (LPTSTR)&msg, 0, NULL); |
8919d6b286e1
(sock_err_message): New function.
Jason Rumney <jasonr@gnu.org>
parents:
78904
diff
changeset
|
732 |
8919d6b286e1
(sock_err_message): New function.
Jason Rumney <jasonr@gnu.org>
parents:
78904
diff
changeset
|
733 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
|
734 |
8919d6b286e1
(sock_err_message): New function.
Jason Rumney <jasonr@gnu.org>
parents:
78904
diff
changeset
|
735 LocalFree (msg); |
8919d6b286e1
(sock_err_message): New function.
Jason Rumney <jasonr@gnu.org>
parents:
78904
diff
changeset
|
736 #else |
8919d6b286e1
(sock_err_message): New function.
Jason Rumney <jasonr@gnu.org>
parents:
78904
diff
changeset
|
737 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
|
738 #endif |
8919d6b286e1
(sock_err_message): New function.
Jason Rumney <jasonr@gnu.org>
parents:
78904
diff
changeset
|
739 } |
8919d6b286e1
(sock_err_message): New function.
Jason Rumney <jasonr@gnu.org>
parents:
78904
diff
changeset
|
740 |
8919d6b286e1
(sock_err_message): New function.
Jason Rumney <jasonr@gnu.org>
parents:
78904
diff
changeset
|
741 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
742 /* Let's send the data to Emacs when either |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
743 - the data ends in "\n", or |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
744 - the buffer is full (but this shouldn't happen) |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
745 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
|
746 void |
109744
fdbd24f8d999
Fix warnings produced by compiling with -Wwrite_strings (i.e. use const char *).
Jan D <jan.h.d@swipnet.se>
parents:
109652
diff
changeset
|
747 send_to_emacs (HSOCKET s, const char *data) |
73562
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 while (data) |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
750 { |
110746
5c1a707ab452
Fix compilation warnings.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
110706
diff
changeset
|
751 size_t dlen = strlen (data); |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
752 if (dlen + sblen >= SEND_BUFFER_SIZE) |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
753 { |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
754 int part = SEND_BUFFER_SIZE - sblen; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
755 strncpy (&send_buffer[sblen], data, part); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
756 data += part; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
757 sblen = SEND_BUFFER_SIZE; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
758 } |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
759 else if (dlen) |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
760 { |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
761 strcpy (&send_buffer[sblen], data); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
762 data = NULL; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
763 sblen += dlen; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
764 } |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
765 else |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
766 break; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
767 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
768 if (sblen == SEND_BUFFER_SIZE |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
769 || (sblen > 0 && send_buffer[sblen-1] == '\n')) |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
770 { |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
771 int sent = send (s, send_buffer, sblen, 0); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
772 if (sent != sblen) |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
773 strcpy (send_buffer, &send_buffer[sent]); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
774 sblen -= sent; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
775 } |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
776 } |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
777 } |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
778 |
83499
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
779 |
83065
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
780 /* In STR, insert a & before each &, each space, each newline, and |
52848 | 781 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
|
782 return value never contains a space. |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
783 |
109115 | 784 Does not change the string. Outputs the result to S. */ |
52635
9963e9da5850
(quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents:
52532
diff
changeset
|
785 void |
109744
fdbd24f8d999
Fix warnings produced by compiling with -Wwrite_strings (i.e. use const char *).
Jan D <jan.h.d@swipnet.se>
parents:
109652
diff
changeset
|
786 quote_argument (HSOCKET s, const char *str) |
16061
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
787 { |
83103
efc0b56b83d9
Another server.el overhaul.
Karoly Lorentey <lorentey@elte.hu>
parents:
83065
diff
changeset
|
788 char *copy = (char *) xmalloc (strlen (str) * 2 + 1); |
109744
fdbd24f8d999
Fix warnings produced by compiling with -Wwrite_strings (i.e. use const char *).
Jan D <jan.h.d@swipnet.se>
parents:
109652
diff
changeset
|
789 const char *p; |
fdbd24f8d999
Fix warnings produced by compiling with -Wwrite_strings (i.e. use const char *).
Jan D <jan.h.d@swipnet.se>
parents:
109652
diff
changeset
|
790 char *q; |
16061
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
791 |
83065
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
792 p = str; |
16061
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
793 q = copy; |
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
794 while (*p) |
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
795 { |
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
796 if (*p == ' ') |
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
797 { |
16074
25cfff7ffced
(quote_file_name): Quote with &, not \.
Richard M. Stallman <rms@gnu.org>
parents:
16061
diff
changeset
|
798 *q++ = '&'; |
16061
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
799 *q++ = '_'; |
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
800 p++; |
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
801 } |
47515
6ee937dcfe16
(quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42412
diff
changeset
|
802 else if (*p == '\n') |
6ee937dcfe16
(quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42412
diff
changeset
|
803 { |
6ee937dcfe16
(quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42412
diff
changeset
|
804 *q++ = '&'; |
6ee937dcfe16
(quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42412
diff
changeset
|
805 *q++ = 'n'; |
6ee937dcfe16
(quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42412
diff
changeset
|
806 p++; |
6ee937dcfe16
(quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42412
diff
changeset
|
807 } |
16061
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
808 else |
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
809 { |
83065
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
810 if (*p == '&' || (*p == '-' && p == str)) |
16074
25cfff7ffced
(quote_file_name): Quote with &, not \.
Richard M. Stallman <rms@gnu.org>
parents:
16061
diff
changeset
|
811 *q++ = '&'; |
16061
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
812 *q++ = *p++; |
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
813 } |
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
814 } |
16074
25cfff7ffced
(quote_file_name): Quote with &, not \.
Richard M. Stallman <rms@gnu.org>
parents:
16061
diff
changeset
|
815 *q++ = 0; |
16061
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
816 |
83603
54df157e987d
(emacs_socket): Rename from s.
Jason Rumney <jasonr@gnu.org>
parents:
83601
diff
changeset
|
817 send_to_emacs (s, copy); |
52635
9963e9da5850
(quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents:
52532
diff
changeset
|
818 |
9963e9da5850
(quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents:
52532
diff
changeset
|
819 free (copy); |
16061
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
820 } |
18701
9c7e0c926ed5
[C_ALLOCA] (xmalloc): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
821 |
83065
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
822 |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
823 /* 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
|
824 modifying the string in place. Returns STR. */ |
18701
9c7e0c926ed5
[C_ALLOCA] (xmalloc): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
825 |
83065
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
826 char * |
109111
52b76722152a
Convert function definitions to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
108828
diff
changeset
|
827 unquote_argument (char *str) |
18701
9c7e0c926ed5
[C_ALLOCA] (xmalloc): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
828 { |
83065
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
829 char *p, *q; |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
830 |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
831 if (! str) |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
832 return str; |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
833 |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
834 p = str; |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
835 q = str; |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
836 while (*p) |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
837 { |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
838 if (*p == '&') |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
839 { |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
840 p++; |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
841 if (*p == '&') |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
842 *p = '&'; |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
843 else if (*p == '_') |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
844 *p = ' '; |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
845 else if (*p == 'n') |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
846 *p = '\n'; |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
847 else if (*p == '-') |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
848 *p = '-'; |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
849 } |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
850 *q++ = *p++; |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
851 } |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
852 *q = 0; |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
853 return str; |
18701
9c7e0c926ed5
[C_ALLOCA] (xmalloc): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
854 } |
83065
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
855 |
16030
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
856 |
73765
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
857 int |
109111
52b76722152a
Convert function definitions to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
108828
diff
changeset
|
858 file_name_absolute_p (const unsigned char *filename) |
73765
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
859 { |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
860 /* 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
|
861 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
|
862 |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
863 /* /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
|
864 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
|
865 |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
866 /* 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
|
867 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
|
868 |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
869 #ifdef WINDOWSNT |
75956
6ef0c279b18c
Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents:
75348
diff
changeset
|
870 /* X:\xxx is always absolute. */ |
74176
6eee550d3bda
(file_name_absolute_p) [WINDOWSNT]: Use isalpha().
Jason Rumney <jasonr@gnu.org>
parents:
74172
diff
changeset
|
871 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
|
872 && 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
|
873 return TRUE; |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
874 |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
875 /* 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
|
876 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
|
877 #endif |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
878 |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
879 return FALSE; |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
880 } |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
881 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
882 #ifdef WINDOWSNT |
74645
aa3039743d63
Comment and whitespace changes.
Richard M. Stallman <rms@gnu.org>
parents:
74644
diff
changeset
|
883 /* Wrapper to make WSACleanup a cdecl, as required by atexit. */ |
109480
d12162869c07
Convert some more functions to standard C.
Juanma Barranquero <lekktu@gmail.com>
parents:
109315
diff
changeset
|
884 void __cdecl |
d12162869c07
Convert some more functions to standard C.
Juanma Barranquero <lekktu@gmail.com>
parents:
109315
diff
changeset
|
885 close_winsock (void) |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
886 { |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
887 WSACleanup (); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
888 } |
18701
9c7e0c926ed5
[C_ALLOCA] (xmalloc): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
889 |
73765
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
890 /* 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
|
891 void |
109480
d12162869c07
Convert some more functions to standard C.
Juanma Barranquero <lekktu@gmail.com>
parents:
109315
diff
changeset
|
892 initialize_sockets (void) |
18701
9c7e0c926ed5
[C_ALLOCA] (xmalloc): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
893 { |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
894 WSADATA wsaData; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
895 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
896 if (WSAStartup (MAKEWORD (2, 0), &wsaData)) |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
897 { |
87669
b8b050fde307
Add missing final newlines to message calls.
Glenn Morris <rgm@gnu.org>
parents:
87668
diff
changeset
|
898 message (TRUE, "%s: error initializing WinSock2\n", progname); |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
899 exit (EXIT_FAILURE); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
900 } |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
901 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
902 atexit (close_winsock); |
73578
e193b6a3f379
Fixes to emacsclient.c for GNU/Linux.
Juanma Barranquero <lekktu@gmail.com>
parents:
73562
diff
changeset
|
903 } |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
904 #endif /* WINDOWSNT */ |
83548
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
905 |
16030
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
906 |
27305
4161adef5fd3
Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
907 /* |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
908 * Read the information needed to set up a TCP comm channel with |
110660
4b5aaeebe785
lisp/server.el: Use just one way to pass the Emacs PID to emacsclient.
Juanma Barranquero <lekktu@gmail.com>
parents:
110643
diff
changeset
|
909 * the Emacs server: host, port, and authentication string. |
74729
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
910 */ |
73765
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
911 int |
109111
52b76722152a
Convert function definitions to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
108828
diff
changeset
|
912 get_server_config (struct sockaddr_in *server, char *authentication) |
27305
4161adef5fd3
Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
913 { |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
914 char dotted[32]; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
915 char *port; |
73765
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
916 FILE *config = NULL; |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
917 |
73765
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
918 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
|
919 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
|
920 else |
27305
4161adef5fd3
Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
921 { |
79232
7970215aa6e5
Add a wrapper for getenv so it also checks the registry on Windows.
Juanma Barranquero <lekktu@gmail.com>
parents:
79226
diff
changeset
|
922 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
|
923 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
924 if (home) |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
925 { |
99215
e0e326adf3bc
* emacsclient.c (EXTRA_SPACE): New macro.
Juanma Barranquero <lekktu@gmail.com>
parents:
99209
diff
changeset
|
926 char *path = alloca (strlen (home) + strlen (server_file) |
e0e326adf3bc
* emacsclient.c (EXTRA_SPACE): New macro.
Juanma Barranquero <lekktu@gmail.com>
parents:
99209
diff
changeset
|
927 + EXTRA_SPACE); |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
928 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
|
929 config = fopen (path, "rb"); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
930 } |
73809
cbc1f46b6590
(get_server_config) [WINDOWSNT]: Search the server file on APPDATA
Juanma Barranquero <lekktu@gmail.com>
parents:
73806
diff
changeset
|
931 #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
|
932 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
|
933 { |
99215
e0e326adf3bc
* emacsclient.c (EXTRA_SPACE): New macro.
Juanma Barranquero <lekktu@gmail.com>
parents:
99209
diff
changeset
|
934 char *path = alloca (strlen (home) + strlen (server_file) |
e0e326adf3bc
* emacsclient.c (EXTRA_SPACE): New macro.
Juanma Barranquero <lekktu@gmail.com>
parents:
99209
diff
changeset
|
935 + EXTRA_SPACE); |
73809
cbc1f46b6590
(get_server_config) [WINDOWSNT]: Search the server file on APPDATA
Juanma Barranquero <lekktu@gmail.com>
parents:
73806
diff
changeset
|
936 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
|
937 config = fopen (path, "rb"); |
cbc1f46b6590
(get_server_config) [WINDOWSNT]: Search the server file on APPDATA
Juanma Barranquero <lekktu@gmail.com>
parents:
73806
diff
changeset
|
938 } |
cbc1f46b6590
(get_server_config) [WINDOWSNT]: Search the server file on APPDATA
Juanma Barranquero <lekktu@gmail.com>
parents:
73806
diff
changeset
|
939 #endif |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
940 } |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
941 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
942 if (! config) |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
943 return FALSE; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
944 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
945 if (fgets (dotted, sizeof dotted, config) |
110660
4b5aaeebe785
lisp/server.el: Use just one way to pass the Emacs PID to emacsclient.
Juanma Barranquero <lekktu@gmail.com>
parents:
110643
diff
changeset
|
946 && (port = strchr (dotted, ':'))) |
4b5aaeebe785
lisp/server.el: Use just one way to pass the Emacs PID to emacsclient.
Juanma Barranquero <lekktu@gmail.com>
parents:
110643
diff
changeset
|
947 *port++ = '\0'; |
27305
4161adef5fd3
Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
948 else |
4161adef5fd3
Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
949 { |
87669
b8b050fde307
Add missing final newlines to message calls.
Glenn Morris <rgm@gnu.org>
parents:
87668
diff
changeset
|
950 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
|
951 exit (EXIT_FAILURE); |
27305
4161adef5fd3
Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
952 } |
73562
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 server->sin_family = AF_INET; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
955 server->sin_addr.s_addr = inet_addr (dotted); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
956 server->sin_port = htons (atoi (port)); |
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 if (! fread (authentication, AUTH_KEY_LENGTH, 1, config)) |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
959 { |
87669
b8b050fde307
Add missing final newlines to message calls.
Glenn Morris <rgm@gnu.org>
parents:
87668
diff
changeset
|
960 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
|
961 exit (EXIT_FAILURE); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
962 } |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
963 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
964 fclose (config); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
965 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
966 return TRUE; |
27305
4161adef5fd3
Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
967 } |
4161adef5fd3
Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
968 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
969 HSOCKET |
109111
52b76722152a
Convert function definitions to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
108828
diff
changeset
|
970 set_tcp_socket (void) |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
971 { |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
972 HSOCKET s; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
973 struct sockaddr_in server; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
974 struct linger l_arg = {1, 1}; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
975 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
|
976 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
977 if (! get_server_config (&server, auth_string)) |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
978 return INVALID_SOCKET; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
979 |
73765
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
980 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
|
981 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
|
982 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
|
983 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
984 /* |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
985 * Open up an AF_INET 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 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
|
988 { |
79226
8919d6b286e1
(sock_err_message): New function.
Jason Rumney <jasonr@gnu.org>
parents:
78904
diff
changeset
|
989 sock_err_message ("socket"); |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
990 return INVALID_SOCKET; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
991 } |
412 | 992 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
993 /* |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
994 * Set up the socket |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
995 */ |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
996 if (connect (s, (struct sockaddr *) &server, sizeof server) < 0) |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
997 { |
79226
8919d6b286e1
(sock_err_message): New function.
Jason Rumney <jasonr@gnu.org>
parents:
78904
diff
changeset
|
998 sock_err_message ("connect"); |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
999 return INVALID_SOCKET; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1000 } |
27305
4161adef5fd3
Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
1001 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1002 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
|
1003 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1004 /* |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1005 * Send the authentication |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1006 */ |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1007 auth_string[AUTH_KEY_LENGTH] = '\0'; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1008 |
83603
54df157e987d
(emacs_socket): Rename from s.
Jason Rumney <jasonr@gnu.org>
parents:
83601
diff
changeset
|
1009 send_to_emacs (s, "-auth "); |
54df157e987d
(emacs_socket): Rename from s.
Jason Rumney <jasonr@gnu.org>
parents:
83601
diff
changeset
|
1010 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
|
1011 send_to_emacs (s, " "); |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1012 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1013 return s; |
412 | 1014 } |
1015 | |
83590 | 1016 |
1017 /* Returns 1 if PREFIX is a prefix of STRING. */ | |
1018 static int | |
109744
fdbd24f8d999
Fix warnings produced by compiling with -Wwrite_strings (i.e. use const char *).
Jan D <jan.h.d@swipnet.se>
parents:
109652
diff
changeset
|
1019 strprefix (const char *prefix, const char *string) |
83590 | 1020 { |
84681
f44a6d77db08
(DIRECTORY_SEP, IS_DIRECTORY_SEP, IS_DEVICE_SEP)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
84677
diff
changeset
|
1021 return !strncmp (prefix, string, strlen (prefix)); |
83590 | 1022 } |
1023 | |
99334 | 1024 /* Get tty name and type. If successful, return the type in TTY_TYPE |
1025 and the name in TTY_NAME, and return 1. Otherwise, fail if NOABORT | |
1026 is zero, or return 0 if NOABORT is non-zero. */ | |
1027 | |
1028 int | |
1029 find_tty (char **tty_type, char **tty_name, int noabort) | |
1030 { | |
1031 char *type = egetenv ("TERM"); | |
1032 char *name = ttyname (fileno (stdout)); | |
1033 | |
1034 if (!name) | |
1035 { | |
1036 if (noabort) | |
1037 return 0; | |
1038 else | |
1039 { | |
1040 message (TRUE, "%s: could not get terminal name\n", progname); | |
1041 fail (); | |
1042 } | |
1043 } | |
1044 | |
1045 if (!type) | |
1046 { | |
1047 if (noabort) | |
1048 return 0; | |
1049 else | |
1050 { | |
1051 message (TRUE, "%s: please set the TERM variable to your terminal type\n", | |
1052 progname); | |
1053 fail (); | |
1054 } | |
1055 } | |
1056 | |
1057 if (strcmp (type, "eterm") == 0) | |
1058 { | |
1059 if (noabort) | |
1060 return 0; | |
1061 else | |
1062 { | |
1063 /* This causes nasty, MULTI_KBOARD-related input lockouts. */ | |
1064 message (TRUE, "%s: opening a frame in an Emacs term buffer" | |
1065 " is not supported\n", progname); | |
1066 fail (); | |
1067 } | |
1068 } | |
1069 | |
1070 *tty_name = name; | |
1071 *tty_type = type; | |
1072 return 1; | |
1073 } | |
1074 | |
83590 | 1075 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1076 #if !defined (NO_SOCKETS_IN_FILE_SYSTEM) |
412 | 1077 |
27474
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
1078 /* Three possibilities: |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
1079 2 - can't be `stat'ed (sets errno) |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
1080 1 - isn't owned by us |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
1081 0 - success: none of the above */ |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
1082 |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
1083 static int |
109111
52b76722152a
Convert function definitions to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
108828
diff
changeset
|
1084 socket_status (char *socket_name) |
27474
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
1085 { |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
1086 struct stat statbfr; |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
1087 |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
1088 if (stat (socket_name, &statbfr) == -1) |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
1089 return 2; |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
1090 |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
1091 if (statbfr.st_uid != geteuid ()) |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
1092 return 1; |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
1093 |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
1094 return 0; |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
1095 } |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
1096 |
83548
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
1097 |
83025
c66ebcc29777
Removed %T in mode-line-format. Trivial documentation changes.
Karoly Lorentey <lorentey@elte.hu>
parents:
83019
diff
changeset
|
1098 /* 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
|
1099 Useful for SIGWINCH. */ |
c66ebcc29777
Removed %T in mode-line-format. Trivial documentation changes.
Karoly Lorentey <lorentey@elte.hu>
parents:
83019
diff
changeset
|
1100 |
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
|
1101 SIGTYPE |
83004
7900111db01c
Converted display hooks to be display-local. Plus many bugfixes.
Karoly Lorentey <lorentey@elte.hu>
parents:
82995
diff
changeset
|
1102 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
|
1103 { |
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
|
1104 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
|
1105 |
82995
039bd6989d29
Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents:
82994
diff
changeset
|
1106 if (emacs_pid) |
83004
7900111db01c
Converted display hooks to be display-local. Plus many bugfixes.
Karoly Lorentey <lorentey@elte.hu>
parents:
82995
diff
changeset
|
1107 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
|
1108 |
83004
7900111db01c
Converted display hooks to be display-local. Plus many bugfixes.
Karoly Lorentey <lorentey@elte.hu>
parents:
82995
diff
changeset
|
1109 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
|
1110 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
|
1111 } |
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
|
1112 |
83065
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1113 /* 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
|
1114 now resume our tty frame. */ |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1115 |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1116 SIGTYPE |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1117 handle_sigcont (int signalnum) |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1118 { |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1119 int old_errno = errno; |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1120 |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1121 if (tcgetpgrp (1) == getpgrp ()) |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1122 { |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1123 /* We are in the foreground. */ |
83603
54df157e987d
(emacs_socket): Rename from s.
Jason Rumney <jasonr@gnu.org>
parents:
83601
diff
changeset
|
1124 send_to_emacs (emacs_socket, "-resume \n"); |
83065
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1125 } |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1126 else |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1127 { |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1128 /* We are in the background; cancel the continue. */ |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1129 kill (getpid (), SIGSTOP); |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1130 } |
83348
afade4ccd30c
Fix broken emacsclient resume on Solaris (by Dan Nicolaescu).
Karoly Lorentey <lorentey@elte.hu>
parents:
83332
diff
changeset
|
1131 |
afade4ccd30c
Fix broken emacsclient resume on Solaris (by Dan Nicolaescu).
Karoly Lorentey <lorentey@elte.hu>
parents:
83332
diff
changeset
|
1132 signal (signalnum, handle_sigcont); |
83065
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1133 errno = old_errno; |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1134 } |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1135 |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1136 /* 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
|
1137 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
|
1138 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
|
1139 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
|
1140 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
|
1141 |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1142 SIGTYPE |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1143 handle_sigtstp (int signalnum) |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1144 { |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1145 int old_errno = errno; |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1146 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
|
1147 |
83611
a5651b79b31b
* emacsclient.c (handle_sigtstp): Use the new name for the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
83607
diff
changeset
|
1148 if (emacs_socket) |
83603
54df157e987d
(emacs_socket): Rename from s.
Jason Rumney <jasonr@gnu.org>
parents:
83601
diff
changeset
|
1149 send_to_emacs (emacs_socket, "-suspend \n"); |
83065
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1150 |
87965
e66c061f4966
(set_tcp_socket): Don't send a "\n" after the authentication string;
Juanma Barranquero <lekktu@gmail.com>
parents:
87724
diff
changeset
|
1151 /* 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
|
1152 changing the handler and resignalling. */ |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1153 sigprocmask (SIG_BLOCK, NULL, &set); |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1154 sigdelset (&set, signalnum); |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1155 signal (signalnum, SIG_DFL); |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1156 kill (getpid (), signalnum); |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1157 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
|
1158 signal (signalnum, handle_sigtstp); |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1159 |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1160 errno = old_errno; |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1161 } |
99333
a999ab783eff
(window_system): Delete redundant variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
99311
diff
changeset
|
1162 |
a999ab783eff
(window_system): Delete redundant variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
99311
diff
changeset
|
1163 |
83025
c66ebcc29777
Removed %T in mode-line-format. Trivial documentation changes.
Karoly Lorentey <lorentey@elte.hu>
parents:
83019
diff
changeset
|
1164 /* 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
|
1165 |
82995
039bd6989d29
Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents:
82994
diff
changeset
|
1166 void |
039bd6989d29
Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents:
82994
diff
changeset
|
1167 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
|
1168 { |
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
|
1169 /* 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
|
1170 signal (SIGWINCH, pass_signal_to_emacs); |
83012
4aa172a45af1
Fix C-g handling with multiple ttys.
Karoly Lorentey <lorentey@elte.hu>
parents:
83010
diff
changeset
|
1171 |
4aa172a45af1
Fix C-g handling with multiple ttys.
Karoly Lorentey <lorentey@elte.hu>
parents:
83010
diff
changeset
|
1172 /* 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
|
1173 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
|
1174 normal input event on secondary terminals. */ |
4aa172a45af1
Fix C-g handling with multiple ttys.
Karoly Lorentey <lorentey@elte.hu>
parents:
83010
diff
changeset
|
1175 #if 0 |
83004
7900111db01c
Converted display hooks to be display-local. Plus many bugfixes.
Karoly Lorentey <lorentey@elte.hu>
parents:
82995
diff
changeset
|
1176 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
|
1177 signal (SIGQUIT, pass_signal_to_emacs); |
83012
4aa172a45af1
Fix C-g handling with multiple ttys.
Karoly Lorentey <lorentey@elte.hu>
parents:
83010
diff
changeset
|
1178 #endif |
83065
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1179 |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1180 signal (SIGCONT, handle_sigcont); |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1181 signal (SIGTSTP, handle_sigtstp); |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1182 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
|
1183 } |
27305
4161adef5fd3
Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
1184 |
412 | 1185 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1186 HSOCKET |
109111
52b76722152a
Convert function definitions to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
108828
diff
changeset
|
1187 set_local_socket (void) |
412 | 1188 { |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1189 HSOCKET s; |
412 | 1190 struct sockaddr_un server; |
1191 | |
42176
1f5dbeefa536
Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents:
39723
diff
changeset
|
1192 /* |
412 | 1193 * Open up an AF_UNIX socket in this person's home directory |
1194 */ | |
1195 | |
1196 if ((s = socket (AF_UNIX, SOCK_STREAM, 0)) < 0) | |
1197 { | |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
1198 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
|
1199 return INVALID_SOCKET; |
412 | 1200 } |
42176
1f5dbeefa536
Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents:
39723
diff
changeset
|
1201 |
412 | 1202 server.sun_family = AF_UNIX; |
25261
89be69860eeb
(main): Move the dynamic allocation of
Karl Heuer <kwzh@gnu.org>
parents:
24652
diff
changeset
|
1203 |
493 | 1204 { |
27474
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
1205 int sock_status = 0; |
53646
8c55b1b400d5
(main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
53543
diff
changeset
|
1206 int default_sock = !socket_name; |
83010 | 1207 int saved_errno = 0; |
109744
fdbd24f8d999
Fix warnings produced by compiling with -Wwrite_strings (i.e. use const char *).
Jan D <jan.h.d@swipnet.se>
parents:
109652
diff
changeset
|
1208 const char *server_name = "server"; |
fdbd24f8d999
Fix warnings produced by compiling with -Wwrite_strings (i.e. use const char *).
Jan D <jan.h.d@swipnet.se>
parents:
109652
diff
changeset
|
1209 const char *tmpdir; |
53734
132739917566
(main): Don't use the hostname in the socket name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
53693
diff
changeset
|
1210 |
109315
8f3464b85afb
Use strchr, strrchr instead of index, rindex
Andreas Schwab <schwab@linux-m68k.org>
parents:
109115
diff
changeset
|
1211 if (socket_name && !strchr (socket_name, '/') |
8f3464b85afb
Use strchr, strrchr instead of index, rindex
Andreas Schwab <schwab@linux-m68k.org>
parents:
109115
diff
changeset
|
1212 && !strchr (socket_name, '\\')) |
8f3464b85afb
Use strchr, strrchr instead of index, rindex
Andreas Schwab <schwab@linux-m68k.org>
parents:
109115
diff
changeset
|
1213 { |
8f3464b85afb
Use strchr, strrchr instead of index, rindex
Andreas Schwab <schwab@linux-m68k.org>
parents:
109115
diff
changeset
|
1214 /* socket_name is a file name component. */ |
83031 | 1215 server_name = socket_name; |
1216 socket_name = NULL; | |
1217 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
|
1218 } |
24084
c0b0893dd5a6
(main): Eliminate arbitrary limit on length of system_name.
Richard M. Stallman <rms@gnu.org>
parents:
23412
diff
changeset
|
1219 |
53646
8c55b1b400d5
(main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
53543
diff
changeset
|
1220 if (default_sock) |
52479
bc2610a13fbf
(socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
1221 { |
99209
01e8c1513572
* server.el, emacsclient.c: Use TMPDIR (default /tmp) instead of hardcoded /tmp.
Juanma Barranquero <lekktu@gmail.com>
parents:
98676
diff
changeset
|
1222 tmpdir = egetenv ("TMPDIR"); |
01e8c1513572
* server.el, emacsclient.c: Use TMPDIR (default /tmp) instead of hardcoded /tmp.
Juanma Barranquero <lekktu@gmail.com>
parents:
98676
diff
changeset
|
1223 if (!tmpdir) |
110833 | 1224 { |
1225 #ifdef DARWIN_OS | |
111598
66622c9fb890
Add fall-back definition of _CS_DARWIN_USER_TEMP_DIR (fix last failed check-in).
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
110833
diff
changeset
|
1226 #ifndef _CS_DARWIN_USER_TEMP_DIR |
66622c9fb890
Add fall-back definition of _CS_DARWIN_USER_TEMP_DIR (fix last failed check-in).
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
110833
diff
changeset
|
1227 #define _CS_DARWIN_USER_TEMP_DIR 65537 |
66622c9fb890
Add fall-back definition of _CS_DARWIN_USER_TEMP_DIR (fix last failed check-in).
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
110833
diff
changeset
|
1228 #endif |
110833 | 1229 size_t n = confstr (_CS_DARWIN_USER_TEMP_DIR, NULL, (size_t) 0); |
1230 if (n > 0) | |
1231 { | |
1232 tmpdir = alloca (n); | |
1233 confstr (_CS_DARWIN_USER_TEMP_DIR, tmpdir, n); | |
1234 } | |
1235 else | |
1236 #endif | |
1237 tmpdir = "/tmp"; | |
1238 } | |
99215
e0e326adf3bc
* emacsclient.c (EXTRA_SPACE): New macro.
Juanma Barranquero <lekktu@gmail.com>
parents:
99209
diff
changeset
|
1239 socket_name = alloca (strlen (tmpdir) + strlen (server_name) |
e0e326adf3bc
* emacsclient.c (EXTRA_SPACE): New macro.
Juanma Barranquero <lekktu@gmail.com>
parents:
99209
diff
changeset
|
1240 + EXTRA_SPACE); |
99209
01e8c1513572
* server.el, emacsclient.c: Use TMPDIR (default /tmp) instead of hardcoded /tmp.
Juanma Barranquero <lekktu@gmail.com>
parents:
98676
diff
changeset
|
1241 sprintf (socket_name, "%s/emacs%d/%s", |
01e8c1513572
* server.el, emacsclient.c: Use TMPDIR (default /tmp) instead of hardcoded /tmp.
Juanma Barranquero <lekktu@gmail.com>
parents:
98676
diff
changeset
|
1242 tmpdir, (int) geteuid (), server_name); |
52479
bc2610a13fbf
(socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
1243 } |
bc2610a13fbf
(socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
1244 |
bc2610a13fbf
(socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
1245 if (strlen (socket_name) < sizeof (server.sun_path)) |
bc2610a13fbf
(socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
1246 strcpy (server.sun_path, socket_name); |
bc2610a13fbf
(socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
1247 else |
53646
8c55b1b400d5
(main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
53543
diff
changeset
|
1248 { |
87669
b8b050fde307
Add missing final newlines to message calls.
Glenn Morris <rgm@gnu.org>
parents:
87668
diff
changeset
|
1249 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
|
1250 progname, socket_name); |
82988
f82e3a6f5ccb
A few more bugfixes and new features.
Karoly Lorentey <lorentey@elte.hu>
parents:
82987
diff
changeset
|
1251 fail (); |
53646
8c55b1b400d5
(main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
53543
diff
changeset
|
1252 } |
412 | 1253 |
27474
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
1254 /* 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
|
1255 sock_status = socket_status (server.sun_path); |
53543
fec82b542db2
(main): Save errno from socket_status.
Andreas Schwab <schwab@suse.de>
parents:
53497
diff
changeset
|
1256 saved_errno = errno; |
53646
8c55b1b400d5
(main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
53543
diff
changeset
|
1257 if (sock_status && default_sock) |
493 | 1258 { |
27474
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
1259 /* 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
|
1260 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
|
1261 associated with the name. This is reminiscent of the logic |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
1262 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
|
1263 |
79232
7970215aa6e5
Add a wrapper for getenv so it also checks the registry on Windows.
Juanma Barranquero <lekktu@gmail.com>
parents:
79226
diff
changeset
|
1264 char *user_name = (char *) egetenv ("LOGNAME"); |
53693
04e9ebd16fcd
(main): Restore errno from saved_errno,
Richard M. Stallman <rms@gnu.org>
parents:
53646
diff
changeset
|
1265 |
27474
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
1266 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
|
1267 user_name = (char *) egetenv ("USER"); |
42176
1f5dbeefa536
Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents:
39723
diff
changeset
|
1268 |
27474
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
1269 if (user_name) |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
1270 { |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
1271 struct passwd *pw = getpwnam (user_name); |
53693
04e9ebd16fcd
(main): Restore errno from saved_errno,
Richard M. Stallman <rms@gnu.org>
parents:
53646
diff
changeset
|
1272 |
27474
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
1273 if (pw && (pw->pw_uid != geteuid ())) |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
1274 { |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
1275 /* We're running under su, apparently. */ |
99215
e0e326adf3bc
* emacsclient.c (EXTRA_SPACE): New macro.
Juanma Barranquero <lekktu@gmail.com>
parents:
99209
diff
changeset
|
1276 socket_name = alloca (strlen (tmpdir) + strlen (server_name) |
e0e326adf3bc
* emacsclient.c (EXTRA_SPACE): New macro.
Juanma Barranquero <lekktu@gmail.com>
parents:
99209
diff
changeset
|
1277 + EXTRA_SPACE); |
99209
01e8c1513572
* server.el, emacsclient.c: Use TMPDIR (default /tmp) instead of hardcoded /tmp.
Juanma Barranquero <lekktu@gmail.com>
parents:
98676
diff
changeset
|
1278 sprintf (socket_name, "%s/emacs%d/%s", |
01e8c1513572
* server.el, emacsclient.c: Use TMPDIR (default /tmp) instead of hardcoded /tmp.
Juanma Barranquero <lekktu@gmail.com>
parents:
98676
diff
changeset
|
1279 tmpdir, (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
|
1280 |
8c55b1b400d5
(main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
53543
diff
changeset
|
1281 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
|
1282 strcpy (server.sun_path, socket_name); |
8c55b1b400d5
(main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
53543
diff
changeset
|
1283 else |
8c55b1b400d5
(main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
53543
diff
changeset
|
1284 { |
87669
b8b050fde307
Add missing final newlines to message calls.
Glenn Morris <rgm@gnu.org>
parents:
87668
diff
changeset
|
1285 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
|
1286 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
|
1287 exit (EXIT_FAILURE); |
53646
8c55b1b400d5
(main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
53543
diff
changeset
|
1288 } |
8c55b1b400d5
(main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
53543
diff
changeset
|
1289 |
27474
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
1290 sock_status = socket_status (server.sun_path); |
83010 | 1291 saved_errno = errno; |
27474
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
1292 } |
53693
04e9ebd16fcd
(main): Restore errno from saved_errno,
Richard M. Stallman <rms@gnu.org>
parents:
53646
diff
changeset
|
1293 else |
04e9ebd16fcd
(main): Restore errno from saved_errno,
Richard M. Stallman <rms@gnu.org>
parents:
53646
diff
changeset
|
1294 errno = saved_errno; |
27474
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
1295 } |
493 | 1296 } |
42176
1f5dbeefa536
Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents:
39723
diff
changeset
|
1297 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1298 switch (sock_status) |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1299 { |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1300 case 1: |
83548
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
1301 /* 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
|
1302 we are root. */ |
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
1303 if (0 != geteuid ()) |
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
1304 { |
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
1305 message (TRUE, "%s: Invalid socket owner\n", progname); |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1306 return INVALID_SOCKET; |
83548
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
1307 } |
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
1308 break; |
42176
1f5dbeefa536
Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents:
39723
diff
changeset
|
1309 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1310 case 2: |
83548
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
1311 /* `stat' failed */ |
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
1312 if (saved_errno == ENOENT) |
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
1313 message (TRUE, |
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
1314 "%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
|
1315 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
|
1316 progname); |
83548
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
1317 else |
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
1318 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
|
1319 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
|
1320 return INVALID_SOCKET; |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1321 } |
493 | 1322 } |
412 | 1323 |
3595
e10f7473d2e3
* emacsserver.c (main): When we're passing a `struct sockaddr_un'
Jim Blandy <jimb@redhat.com>
parents:
1031
diff
changeset
|
1324 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
|
1325 < 0) |
412 | 1326 { |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
1327 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
|
1328 return INVALID_SOCKET; |
412 | 1329 } |
15758
7e712d42d371
(main) [HAVE_SOCKETS]: Use two separate stdio
Richard M. Stallman <rms@gnu.org>
parents:
14610
diff
changeset
|
1330 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1331 return s; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1332 } |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1333 #endif /* ! NO_SOCKETS_IN_FILE_SYSTEM */ |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1334 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1335 HSOCKET |
100312
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1336 set_socket (int no_exit_if_error) |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1337 { |
73765
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
1338 HSOCKET s; |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
1339 |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
1340 INITIALIZE (); |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
1341 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1342 #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
|
1343 /* 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
|
1344 if (socket_name) |
412 | 1345 { |
73765
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
1346 s = set_local_socket (); |
100312
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1347 if ((s != INVALID_SOCKET) || no_exit_if_error) |
83548
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
1348 return s; |
87668
98943cbe28fb
Daniel Hackney <dan at haxney.org> (tiny change)
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
1349 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
|
1350 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
|
1351 exit (EXIT_FAILURE); |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1352 } |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1353 #endif |
73765
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
1354 |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
1355 /* 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
|
1356 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
|
1357 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
|
1358 |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
1359 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
|
1360 { |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
1361 s = set_tcp_socket (); |
100312
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1362 if ((s != INVALID_SOCKET) || no_exit_if_error) |
83548
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
1363 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
|
1364 |
87669
b8b050fde307
Add missing final newlines to message calls.
Glenn Morris <rgm@gnu.org>
parents:
87668
diff
changeset
|
1365 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
|
1366 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
|
1367 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
|
1368 } |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
1369 |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
1370 #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
|
1371 /* 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
|
1372 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
|
1373 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
|
1374 return s; |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
1375 #endif |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
1376 |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
1377 /* 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
|
1378 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
|
1379 s = set_tcp_socket (); |
100312
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1380 if ((s != INVALID_SOCKET) || no_exit_if_error) |
73765
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
1381 return s; |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
1382 |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
1383 /* No implicit or explicit socket, and no alternate editor. */ |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
1384 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
|
1385 #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
|
1386 "\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
|
1387 #endif |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
1388 "\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
|
1389 \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
|
1390 progname); |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
1391 exit (EXIT_FAILURE); |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1392 } |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1393 |
74729
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
1394 #ifdef WINDOWSNT |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
1395 FARPROC set_fg; /* Pointer to AllowSetForegroundWindow. */ |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
1396 FARPROC get_wc; /* Pointer to RealGetWindowClassA. */ |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
1397 |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
1398 BOOL CALLBACK |
109480
d12162869c07
Convert some more functions to standard C.
Juanma Barranquero <lekktu@gmail.com>
parents:
109315
diff
changeset
|
1399 w32_find_emacs_process (HWND hWnd, LPARAM lParam) |
74729
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
1400 { |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
1401 DWORD pid; |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
1402 char class[6]; |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
1403 |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
1404 /* Reject any window not of class "Emacs". */ |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
1405 if (! get_wc (hWnd, class, sizeof (class)) |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
1406 || strcmp (class, "Emacs")) |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
1407 return TRUE; |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
1408 |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
1409 /* 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
|
1410 (void) GetWindowThreadProcessId (hWnd, &pid); |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
1411 |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
1412 /* Not the one we're looking for. */ |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
1413 if (pid != (DWORD) emacs_pid) return TRUE; |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
1414 |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
1415 /* OK, let's raise it. */ |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
1416 set_fg (emacs_pid); |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
1417 |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
1418 /* Stop enumeration. */ |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
1419 return FALSE; |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
1420 } |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
1421 |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
1422 /* |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
1423 * 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
|
1424 * 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
|
1425 */ |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
1426 void |
109480
d12162869c07
Convert some more functions to standard C.
Juanma Barranquero <lekktu@gmail.com>
parents:
109315
diff
changeset
|
1427 w32_give_focus (void) |
74729
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
1428 { |
103641
48d529d3a5a4
bug#1849 - Windows 7 Taskbar Support
Jason Rumney <jasonr@gnu.org>
parents:
103026
diff
changeset
|
1429 HANDLE user32; |
74729
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
1430 |
75956
6ef0c279b18c
Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents:
75348
diff
changeset
|
1431 /* 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
|
1432 if (!emacs_pid) return; |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
1433 |
103641
48d529d3a5a4
bug#1849 - Windows 7 Taskbar Support
Jason Rumney <jasonr@gnu.org>
parents:
103026
diff
changeset
|
1434 user32 = GetModuleHandle ("user32.dll"); |
48d529d3a5a4
bug#1849 - Windows 7 Taskbar Support
Jason Rumney <jasonr@gnu.org>
parents:
103026
diff
changeset
|
1435 |
48d529d3a5a4
bug#1849 - Windows 7 Taskbar Support
Jason Rumney <jasonr@gnu.org>
parents:
103026
diff
changeset
|
1436 if (!user32) |
48d529d3a5a4
bug#1849 - Windows 7 Taskbar Support
Jason Rumney <jasonr@gnu.org>
parents:
103026
diff
changeset
|
1437 return; |
74729
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
1438 |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
1439 /* 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
|
1440 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
|
1441 AllowSetForegroundWindow. Unfortunately, older Windows (W95, W98 and |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
1442 NT) lack this function, so we have to check its availability. */ |
103641
48d529d3a5a4
bug#1849 - Windows 7 Taskbar Support
Jason Rumney <jasonr@gnu.org>
parents:
103026
diff
changeset
|
1443 if ((set_fg = GetProcAddress (user32, "AllowSetForegroundWindow")) |
48d529d3a5a4
bug#1849 - Windows 7 Taskbar Support
Jason Rumney <jasonr@gnu.org>
parents:
103026
diff
changeset
|
1444 && (get_wc = GetProcAddress (user32, "RealGetWindowClassA"))) |
74729
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
1445 EnumWindows (w32_find_emacs_process, (LPARAM) 0); |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
1446 } |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
1447 #endif |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
1448 |
100312
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1449 /* Start the emacs daemon and try to connect to it. */ |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1450 |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1451 void |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1452 start_daemon_and_retry_set_socket (void) |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1453 { |
100318
00d91c609c41
(EMACS_DAEMON): Remove definition.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100314
diff
changeset
|
1454 #ifndef WINDOWSNT |
100312
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1455 pid_t dpid; |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1456 int status; |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1457 |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1458 dpid = fork (); |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1459 |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1460 if (dpid > 0) |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1461 { |
100485
fd10c7ef5447
* emacs.c (main): Print and error and exit when no data is read
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100418
diff
changeset
|
1462 pid_t w; |
fd10c7ef5447
* emacs.c (main): Print and error and exit when no data is read
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100418
diff
changeset
|
1463 w = waitpid (dpid, &status, WUNTRACED | WCONTINUED); |
100312
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1464 |
109516
68ca98ae70fb
Make building under stricter warning flags somewhat cleaner.
Juanma Barranquero <lekktu@gmail.com>
parents:
109511
diff
changeset
|
1465 if ((w == -1) || !WIFEXITED (status) || WEXITSTATUS (status)) |
100485
fd10c7ef5447
* emacs.c (main): Print and error and exit when no data is read
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100418
diff
changeset
|
1466 { |
fd10c7ef5447
* emacs.c (main): Print and error and exit when no data is read
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100418
diff
changeset
|
1467 message (TRUE, "Error: Could not start the Emacs daemon\n"); |
fd10c7ef5447
* emacs.c (main): Print and error and exit when no data is read
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100418
diff
changeset
|
1468 exit (EXIT_FAILURE); |
fd10c7ef5447
* emacs.c (main): Print and error and exit when no data is read
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100418
diff
changeset
|
1469 } |
fd10c7ef5447
* emacs.c (main): Print and error and exit when no data is read
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100418
diff
changeset
|
1470 |
fd10c7ef5447
* emacs.c (main): Print and error and exit when no data is read
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100418
diff
changeset
|
1471 /* Try connecting, the daemon should have started by now. */ |
fd10c7ef5447
* emacs.c (main): Print and error and exit when no data is read
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100418
diff
changeset
|
1472 message (TRUE, "Emacs daemon should have started, trying to connect again\n"); |
100312
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1473 if ((emacs_socket = set_socket (1)) == INVALID_SOCKET) |
100485
fd10c7ef5447
* emacs.c (main): Print and error and exit when no data is read
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100418
diff
changeset
|
1474 { |
fd10c7ef5447
* emacs.c (main): Print and error and exit when no data is read
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100418
diff
changeset
|
1475 message (TRUE, "Error: Cannot connect even after starting the Emacs daemon\n"); |
fd10c7ef5447
* emacs.c (main): Print and error and exit when no data is read
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100418
diff
changeset
|
1476 exit (EXIT_FAILURE); |
fd10c7ef5447
* emacs.c (main): Print and error and exit when no data is read
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100418
diff
changeset
|
1477 } |
100312
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1478 } |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1479 else if (dpid < 0) |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1480 { |
100485
fd10c7ef5447
* emacs.c (main): Print and error and exit when no data is read
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100418
diff
changeset
|
1481 fprintf (stderr, "Error: Cannot fork!\n"); |
110643
12f445671c17
* emacsclient.c (main): Remove unused variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
109744
diff
changeset
|
1482 exit (EXIT_FAILURE); |
100312
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1483 } |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1484 else |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1485 { |
109744
fdbd24f8d999
Fix warnings produced by compiling with -Wwrite_strings (i.e. use const char *).
Jan D <jan.h.d@swipnet.se>
parents:
109652
diff
changeset
|
1486 char emacs[] = "emacs"; |
fdbd24f8d999
Fix warnings produced by compiling with -Wwrite_strings (i.e. use const char *).
Jan D <jan.h.d@swipnet.se>
parents:
109652
diff
changeset
|
1487 char daemon[] = "--daemon"; |
fdbd24f8d999
Fix warnings produced by compiling with -Wwrite_strings (i.e. use const char *).
Jan D <jan.h.d@swipnet.se>
parents:
109652
diff
changeset
|
1488 char *d_argv[] = {emacs, daemon, 0 }; |
100312
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1489 if (socket_name != NULL) |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1490 { |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1491 /* Pass --daemon=socket_name as argument. */ |
109744
fdbd24f8d999
Fix warnings produced by compiling with -Wwrite_strings (i.e. use const char *).
Jan D <jan.h.d@swipnet.se>
parents:
109652
diff
changeset
|
1492 const char *deq = "--daemon="; |
100312
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1493 char *daemon_arg = alloca (strlen (deq) |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1494 + strlen (socket_name) + 1); |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1495 strcpy (daemon_arg, deq); |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1496 strcat (daemon_arg, socket_name); |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1497 d_argv[1] = daemon_arg; |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1498 } |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1499 execvp ("emacs", d_argv); |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1500 message (TRUE, "%s: error starting emacs daemon\n", progname); |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1501 } |
100318
00d91c609c41
(EMACS_DAEMON): Remove definition.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100314
diff
changeset
|
1502 #endif /* WINDOWSNT */ |
100312
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1503 } |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1504 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1505 int |
109111
52b76722152a
Convert function definitions to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
108828
diff
changeset
|
1506 main (int argc, char **argv) |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1507 { |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1508 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
|
1509 char *cwd, *str; |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1510 char string[BUFSIZ+1]; |
100318
00d91c609c41
(EMACS_DAEMON): Remove definition.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100314
diff
changeset
|
1511 int null_socket_name, null_server_file, start_daemon_if_needed; |
110706
ab3815920cc5
* emacsclient.c (main): Return EXIT_FAILURE if Emacs sends us an error string
Chong Yidong <cyd@stupidchicken.com>
parents:
110660
diff
changeset
|
1512 int exit_status = EXIT_SUCCESS; |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1513 |
83548
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
1514 main_argv = argv; |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1515 progname = argv[0]; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1516 |
103641
48d529d3a5a4
bug#1849 - Windows 7 Taskbar Support
Jason Rumney <jasonr@gnu.org>
parents:
103026
diff
changeset
|
1517 #ifdef WINDOWSNT |
48d529d3a5a4
bug#1849 - Windows 7 Taskbar Support
Jason Rumney <jasonr@gnu.org>
parents:
103026
diff
changeset
|
1518 /* On Windows 7 and later, we need to explicitly associate emacsclient |
48d529d3a5a4
bug#1849 - Windows 7 Taskbar Support
Jason Rumney <jasonr@gnu.org>
parents:
103026
diff
changeset
|
1519 with emacs so the UI behaves sensibly. */ |
48d529d3a5a4
bug#1849 - Windows 7 Taskbar Support
Jason Rumney <jasonr@gnu.org>
parents:
103026
diff
changeset
|
1520 w32_set_user_model_id (); |
48d529d3a5a4
bug#1849 - Windows 7 Taskbar Support
Jason Rumney <jasonr@gnu.org>
parents:
103026
diff
changeset
|
1521 #endif |
48d529d3a5a4
bug#1849 - Windows 7 Taskbar Support
Jason Rumney <jasonr@gnu.org>
parents:
103026
diff
changeset
|
1522 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1523 /* Process options. */ |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1524 decode_options (argc, argv); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1525 |
99333
a999ab783eff
(window_system): Delete redundant variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
99311
diff
changeset
|
1526 if ((argc - optind < 1) && !eval && current_frame) |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1527 { |
83548
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
1528 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
|
1529 "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
|
1530 progname, progname); |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1531 exit (EXIT_FAILURE); |
412 | 1532 } |
1533 | |
100312
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1534 /* If alternate_editor is the empty string, start the emacs daemon |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1535 in case of failure to connect. */ |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1536 start_daemon_if_needed = (alternate_editor |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1537 && (alternate_editor[0] == '\0')); |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1538 if (start_daemon_if_needed) |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1539 { |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1540 /* set_socket changes the values for socket_name and |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1541 server_file, we need to reset them, if they were NULL before |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1542 for the second call to set_socket. */ |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1543 null_socket_name = (socket_name == NULL); |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1544 null_server_file = (server_file == NULL); |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1545 } |
15758
7e712d42d371
(main) [HAVE_SOCKETS]: Use two separate stdio
Richard M. Stallman <rms@gnu.org>
parents:
14610
diff
changeset
|
1546 |
100312
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1547 if ((emacs_socket = set_socket (alternate_editor |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1548 || start_daemon_if_needed)) == INVALID_SOCKET) |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1549 if (start_daemon_if_needed) |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1550 { |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1551 /* Reset socket_name and server_file if they were NULL |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1552 before the set_socket call. */ |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1553 if (null_socket_name) |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1554 socket_name = NULL; |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1555 if (null_server_file) |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1556 server_file = NULL; |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1557 |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1558 start_daemon_and_retry_set_socket (); |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1559 } |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1560 else |
6da82f7dfa67
* misc.texi (emacsclient Options): Describe what an empty string
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100154
diff
changeset
|
1561 fail (); |
83548
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
1562 |
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
1563 cwd = get_current_dir_name (); |
412 | 1564 if (cwd == 0) |
1565 { | |
1566 /* 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
|
1567 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
|
1568 "Cannot get current working directory"); |
82988
f82e3a6f5ccb
A few more bugfixes and new features.
Karoly Lorentey <lorentey@elte.hu>
parents:
82987
diff
changeset
|
1569 fail (); |
412 | 1570 } |
1571 | |
74342
c6cb776ffbb7
(emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
74341
diff
changeset
|
1572 #ifdef WINDOWSNT |
74729
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
1573 w32_give_focus (); |
74342
c6cb776ffbb7
(emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
74341
diff
changeset
|
1574 #endif |
c6cb776ffbb7
(emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
74341
diff
changeset
|
1575 |
99333
a999ab783eff
(window_system): Delete redundant variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
99311
diff
changeset
|
1576 /* Send over our environment and current directory. */ |
83403
51eb0aa362f3
Store client's environment in terminal parameters, not server parameters.
Karoly Lorentey <lorentey@elte.hu>
parents:
83371
diff
changeset
|
1577 if (!current_frame) |
51eb0aa362f3
Store client's environment in terminal parameters, not server parameters.
Karoly Lorentey <lorentey@elte.hu>
parents:
83371
diff
changeset
|
1578 { |
51eb0aa362f3
Store client's environment in terminal parameters, not server parameters.
Karoly Lorentey <lorentey@elte.hu>
parents:
83371
diff
changeset
|
1579 extern char **environ; |
51eb0aa362f3
Store client's environment in terminal parameters, not server parameters.
Karoly Lorentey <lorentey@elte.hu>
parents:
83371
diff
changeset
|
1580 int i; |
51eb0aa362f3
Store client's environment in terminal parameters, not server parameters.
Karoly Lorentey <lorentey@elte.hu>
parents:
83371
diff
changeset
|
1581 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
|
1582 { |
83603
54df157e987d
(emacs_socket): Rename from s.
Jason Rumney <jasonr@gnu.org>
parents:
83601
diff
changeset
|
1583 send_to_emacs (emacs_socket, "-env "); |
54df157e987d
(emacs_socket): Rename from s.
Jason Rumney <jasonr@gnu.org>
parents:
83601
diff
changeset
|
1584 quote_argument (emacs_socket, environ[i]); |
54df157e987d
(emacs_socket): Rename from s.
Jason Rumney <jasonr@gnu.org>
parents:
83601
diff
changeset
|
1585 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
|
1586 } |
83499
0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
Karoly Lorentey <lorentey@elte.hu>
parents:
83468
diff
changeset
|
1587 } |
102471
02f766280fad
* server.el (server-process-filter): Use expand-file-name rather than
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
101397
diff
changeset
|
1588 send_to_emacs (emacs_socket, "-dir "); |
02f766280fad
* server.el (server-process-filter): Use expand-file-name rather than
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
101397
diff
changeset
|
1589 quote_argument (emacs_socket, cwd); |
02f766280fad
* server.el (server-process-filter): Use expand-file-name rather than
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
101397
diff
changeset
|
1590 send_to_emacs (emacs_socket, "/"); |
02f766280fad
* server.el (server-process-filter): Use expand-file-name rather than
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
101397
diff
changeset
|
1591 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
|
1592 |
83246
5bc762f84335
Prevent emacsclient errors when Emacs is compiled without X support.
Karoly Lorentey <lorentey@elte.hu>
parents:
83165
diff
changeset
|
1593 retry: |
16061
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
1594 if (nowait) |
83603
54df157e987d
(emacs_socket): Rename from s.
Jason Rumney <jasonr@gnu.org>
parents:
83601
diff
changeset
|
1595 send_to_emacs (emacs_socket, "-nowait "); |
16061
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
1596 |
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
|
1597 if (current_frame) |
83603
54df157e987d
(emacs_socket): Rename from s.
Jason Rumney <jasonr@gnu.org>
parents:
83601
diff
changeset
|
1598 send_to_emacs (emacs_socket, "-current-frame "); |
47647
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
1599 |
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
1600 if (display) |
412 | 1601 { |
83603
54df157e987d
(emacs_socket): Rename from s.
Jason Rumney <jasonr@gnu.org>
parents:
83601
diff
changeset
|
1602 send_to_emacs (emacs_socket, "-display "); |
54df157e987d
(emacs_socket): Rename from s.
Jason Rumney <jasonr@gnu.org>
parents:
83601
diff
changeset
|
1603 quote_argument (emacs_socket, display); |
54df157e987d
(emacs_socket): Rename from s.
Jason Rumney <jasonr@gnu.org>
parents:
83601
diff
changeset
|
1604 send_to_emacs (emacs_socket, " "); |
52635
9963e9da5850
(quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents:
52532
diff
changeset
|
1605 } |
9963e9da5850
(quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents:
52532
diff
changeset
|
1606 |
108828
87dad1e1c860
Add --parent-id argument to emacsclient.
Chong Yidong <cyd@stupidchicken.com>
parents:
107737
diff
changeset
|
1607 if (parent_id) |
87dad1e1c860
Add --parent-id argument to emacsclient.
Chong Yidong <cyd@stupidchicken.com>
parents:
107737
diff
changeset
|
1608 { |
87dad1e1c860
Add --parent-id argument to emacsclient.
Chong Yidong <cyd@stupidchicken.com>
parents:
107737
diff
changeset
|
1609 send_to_emacs (emacs_socket, "-parent-id "); |
87dad1e1c860
Add --parent-id argument to emacsclient.
Chong Yidong <cyd@stupidchicken.com>
parents:
107737
diff
changeset
|
1610 quote_argument (emacs_socket, parent_id); |
87dad1e1c860
Add --parent-id argument to emacsclient.
Chong Yidong <cyd@stupidchicken.com>
parents:
107737
diff
changeset
|
1611 send_to_emacs (emacs_socket, " "); |
87dad1e1c860
Add --parent-id argument to emacsclient.
Chong Yidong <cyd@stupidchicken.com>
parents:
107737
diff
changeset
|
1612 } |
87dad1e1c860
Add --parent-id argument to emacsclient.
Chong Yidong <cyd@stupidchicken.com>
parents:
107737
diff
changeset
|
1613 |
99254
8cade16f7427
(main): If using the current frame, send tty information to Emacs in
Chong Yidong <cyd@stupidchicken.com>
parents:
99215
diff
changeset
|
1614 /* If using the current frame, send tty information to Emacs anyway. |
8cade16f7427
(main): If using the current frame, send tty information to Emacs in
Chong Yidong <cyd@stupidchicken.com>
parents:
99215
diff
changeset
|
1615 In daemon mode, Emacs may need to occupy this tty if no other |
8cade16f7427
(main): If using the current frame, send tty information to Emacs in
Chong Yidong <cyd@stupidchicken.com>
parents:
99215
diff
changeset
|
1616 frame is available. */ |
99297
4069e1395eca
(main): Don't force sending tty when in eval mode.
Andreas Schwab <schwab@suse.de>
parents:
99254
diff
changeset
|
1617 if (tty || (current_frame && !eval)) |
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
|
1618 { |
99333
a999ab783eff
(window_system): Delete redundant variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
99311
diff
changeset
|
1619 char *tty_type, *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
|
1620 |
99333
a999ab783eff
(window_system): Delete redundant variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
99311
diff
changeset
|
1621 if (find_tty (&tty_type, &tty_name, !tty)) |
a999ab783eff
(window_system): Delete redundant variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
99311
diff
changeset
|
1622 { |
83590 | 1623 #if !defined (NO_SOCKETS_IN_FILE_SYSTEM) |
99333
a999ab783eff
(window_system): Delete redundant variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
99311
diff
changeset
|
1624 init_signals (); |
83590 | 1625 #endif |
99333
a999ab783eff
(window_system): Delete redundant variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
99311
diff
changeset
|
1626 send_to_emacs (emacs_socket, "-tty "); |
a999ab783eff
(window_system): Delete redundant variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
99311
diff
changeset
|
1627 quote_argument (emacs_socket, tty_name); |
a999ab783eff
(window_system): Delete redundant variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
99311
diff
changeset
|
1628 send_to_emacs (emacs_socket, " "); |
a999ab783eff
(window_system): Delete redundant variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
99311
diff
changeset
|
1629 quote_argument (emacs_socket, tty_type); |
a999ab783eff
(window_system): Delete redundant variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
99311
diff
changeset
|
1630 send_to_emacs (emacs_socket, " "); |
a999ab783eff
(window_system): Delete redundant variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
99311
diff
changeset
|
1631 } |
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
|
1632 } |
83043
78a785f205ea
Added -w option to emacsclient for opening a new X frame.
Karoly Lorentey <lorentey@elte.hu>
parents:
83037
diff
changeset
|
1633 |
99333
a999ab783eff
(window_system): Delete redundant variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
99311
diff
changeset
|
1634 if (!current_frame && !tty) |
83603
54df157e987d
(emacs_socket): Rename from s.
Jason Rumney <jasonr@gnu.org>
parents:
83601
diff
changeset
|
1635 send_to_emacs (emacs_socket, "-window-system "); |
83065
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1636 |
52635
9963e9da5850
(quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents:
52532
diff
changeset
|
1637 if ((argc - optind > 0)) |
9963e9da5850
(quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents:
52532
diff
changeset
|
1638 { |
9963e9da5850
(quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents:
52532
diff
changeset
|
1639 for (i = optind; i < argc; i++) |
412 | 1640 { |
83065
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1641 |
52635
9963e9da5850
(quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents:
52532
diff
changeset
|
1642 if (eval) |
83065
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1643 { |
83548
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
1644 /* Don't prepend cwd or anything like that. */ |
83603
54df157e987d
(emacs_socket): Rename from s.
Jason Rumney <jasonr@gnu.org>
parents:
83601
diff
changeset
|
1645 send_to_emacs (emacs_socket, "-eval "); |
54df157e987d
(emacs_socket): Rename from s.
Jason Rumney <jasonr@gnu.org>
parents:
83601
diff
changeset
|
1646 quote_argument (emacs_socket, argv[i]); |
54df157e987d
(emacs_socket): Rename from s.
Jason Rumney <jasonr@gnu.org>
parents:
83601
diff
changeset
|
1647 send_to_emacs (emacs_socket, " "); |
83065
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1648 continue; |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1649 } |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1650 |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1651 if (*argv[i] == '+') |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1652 { |
52635
9963e9da5850
(quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents:
52532
diff
changeset
|
1653 char *p = argv[i] + 1; |
9963e9da5850
(quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents:
52532
diff
changeset
|
1654 while (isdigit ((unsigned char) *p) || *p == ':') p++; |
83065
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1655 if (*p == 0) |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1656 { |
83603
54df157e987d
(emacs_socket): Rename from s.
Jason Rumney <jasonr@gnu.org>
parents:
83601
diff
changeset
|
1657 send_to_emacs (emacs_socket, "-position "); |
54df157e987d
(emacs_socket): Rename from s.
Jason Rumney <jasonr@gnu.org>
parents:
83601
diff
changeset
|
1658 quote_argument (emacs_socket, argv[i]); |
54df157e987d
(emacs_socket): Rename from s.
Jason Rumney <jasonr@gnu.org>
parents:
83601
diff
changeset
|
1659 send_to_emacs (emacs_socket, " "); |
83065
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1660 continue; |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1661 } |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1662 } |
102474
10dc40769985
* emacsclient.c (main): Revert part of last change,
Juanma Barranquero <lekktu@gmail.com>
parents:
102471
diff
changeset
|
1663 #ifdef WINDOWSNT |
10dc40769985
* emacsclient.c (main): Revert part of last change,
Juanma Barranquero <lekktu@gmail.com>
parents:
102471
diff
changeset
|
1664 else if (! file_name_absolute_p (argv[i]) |
10dc40769985
* emacsclient.c (main): Revert part of last change,
Juanma Barranquero <lekktu@gmail.com>
parents:
102471
diff
changeset
|
1665 && (isalpha (argv[i][0]) && argv[i][1] == ':')) |
10dc40769985
* emacsclient.c (main): Revert part of last change,
Juanma Barranquero <lekktu@gmail.com>
parents:
102471
diff
changeset
|
1666 /* Windows can have a different default directory for each |
10dc40769985
* emacsclient.c (main): Revert part of last change,
Juanma Barranquero <lekktu@gmail.com>
parents:
102471
diff
changeset
|
1667 drive, so the cwd passed via "-dir" is not sufficient |
10dc40769985
* emacsclient.c (main): Revert part of last change,
Juanma Barranquero <lekktu@gmail.com>
parents:
102471
diff
changeset
|
1668 to account for that. |
10dc40769985
* emacsclient.c (main): Revert part of last change,
Juanma Barranquero <lekktu@gmail.com>
parents:
102471
diff
changeset
|
1669 If the user uses <drive>:<relpath>, we hence need to be |
10dc40769985
* emacsclient.c (main): Revert part of last change,
Juanma Barranquero <lekktu@gmail.com>
parents:
102471
diff
changeset
|
1670 careful to expand <relpath> with the default directory |
10dc40769985
* emacsclient.c (main): Revert part of last change,
Juanma Barranquero <lekktu@gmail.com>
parents:
102471
diff
changeset
|
1671 corresponding to <drive>. */ |
10dc40769985
* emacsclient.c (main): Revert part of last change,
Juanma Barranquero <lekktu@gmail.com>
parents:
102471
diff
changeset
|
1672 { |
10dc40769985
* emacsclient.c (main): Revert part of last change,
Juanma Barranquero <lekktu@gmail.com>
parents:
102471
diff
changeset
|
1673 char *filename = (char *) xmalloc (MAX_PATH); |
10dc40769985
* emacsclient.c (main): Revert part of last change,
Juanma Barranquero <lekktu@gmail.com>
parents:
102471
diff
changeset
|
1674 DWORD size; |
10dc40769985
* emacsclient.c (main): Revert part of last change,
Juanma Barranquero <lekktu@gmail.com>
parents:
102471
diff
changeset
|
1675 |
10dc40769985
* emacsclient.c (main): Revert part of last change,
Juanma Barranquero <lekktu@gmail.com>
parents:
102471
diff
changeset
|
1676 size = GetFullPathName (argv[i], MAX_PATH, filename, NULL); |
10dc40769985
* emacsclient.c (main): Revert part of last change,
Juanma Barranquero <lekktu@gmail.com>
parents:
102471
diff
changeset
|
1677 if (size > 0 && size < MAX_PATH) |
10dc40769985
* emacsclient.c (main): Revert part of last change,
Juanma Barranquero <lekktu@gmail.com>
parents:
102471
diff
changeset
|
1678 argv[i] = filename; |
10dc40769985
* emacsclient.c (main): Revert part of last change,
Juanma Barranquero <lekktu@gmail.com>
parents:
102471
diff
changeset
|
1679 else |
10dc40769985
* emacsclient.c (main): Revert part of last change,
Juanma Barranquero <lekktu@gmail.com>
parents:
102471
diff
changeset
|
1680 free (filename); |
10dc40769985
* emacsclient.c (main): Revert part of last change,
Juanma Barranquero <lekktu@gmail.com>
parents:
102471
diff
changeset
|
1681 } |
10dc40769985
* emacsclient.c (main): Revert part of last change,
Juanma Barranquero <lekktu@gmail.com>
parents:
102471
diff
changeset
|
1682 #endif |
52635
9963e9da5850
(quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents:
52532
diff
changeset
|
1683 |
83603
54df157e987d
(emacs_socket): Rename from s.
Jason Rumney <jasonr@gnu.org>
parents:
83601
diff
changeset
|
1684 send_to_emacs (emacs_socket, "-file "); |
54df157e987d
(emacs_socket): Rename from s.
Jason Rumney <jasonr@gnu.org>
parents:
83601
diff
changeset
|
1685 quote_argument (emacs_socket, argv[i]); |
54df157e987d
(emacs_socket): Rename from s.
Jason Rumney <jasonr@gnu.org>
parents:
83601
diff
changeset
|
1686 send_to_emacs (emacs_socket, " "); |
83065
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1687 } |
412 | 1688 } |
99333
a999ab783eff
(window_system): Delete redundant variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
99311
diff
changeset
|
1689 else if (eval) |
52635
9963e9da5850
(quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents:
52532
diff
changeset
|
1690 { |
99333
a999ab783eff
(window_system): Delete redundant variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
99311
diff
changeset
|
1691 /* Read expressions interactively. */ |
a999ab783eff
(window_system): Delete redundant variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
99311
diff
changeset
|
1692 while ((str = fgets (string, BUFSIZ, stdin))) |
a999ab783eff
(window_system): Delete redundant variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
99311
diff
changeset
|
1693 { |
a999ab783eff
(window_system): Delete redundant variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
99311
diff
changeset
|
1694 send_to_emacs (emacs_socket, "-eval "); |
a999ab783eff
(window_system): Delete redundant variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
99311
diff
changeset
|
1695 quote_argument (emacs_socket, str); |
a999ab783eff
(window_system): Delete redundant variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
99311
diff
changeset
|
1696 } |
a999ab783eff
(window_system): Delete redundant variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
99311
diff
changeset
|
1697 send_to_emacs (emacs_socket, " "); |
52635
9963e9da5850
(quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents:
52532
diff
changeset
|
1698 } |
55442
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
53813
diff
changeset
|
1699 |
83603
54df157e987d
(emacs_socket): Rename from s.
Jason Rumney <jasonr@gnu.org>
parents:
83601
diff
changeset
|
1700 send_to_emacs (emacs_socket, "\n"); |
412 | 1701 |
83165
ed82e09208c9
Fix --no-wait in emacsclient (reported by Dan Nicolaescu).
Karoly Lorentey <lorentey@elte.hu>
parents:
83121
diff
changeset
|
1702 /* Wait for an answer. */ |
ed82e09208c9
Fix --no-wait in emacsclient (reported by Dan Nicolaescu).
Karoly Lorentey <lorentey@elte.hu>
parents:
83121
diff
changeset
|
1703 if (!eval && !tty && !nowait) |
47647
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
1704 { |
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
1705 printf ("Waiting for Emacs..."); |
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
1706 needlf = 2; |
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
1707 } |
412 | 1708 fflush (stdout); |
83065
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1709 fsync (1); |
412 | 1710 |
47515
6ee937dcfe16
(quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42412
diff
changeset
|
1711 /* Now, wait for an answer and print any messages. */ |
110706
ab3815920cc5
* emacsclient.c (main): Return EXIT_FAILURE if Emacs sends us an error string
Chong Yidong <cyd@stupidchicken.com>
parents:
110660
diff
changeset
|
1712 while (exit_status == EXIT_SUCCESS |
ab3815920cc5
* emacsclient.c (main): Return EXIT_FAILURE if Emacs sends us an error string
Chong Yidong <cyd@stupidchicken.com>
parents:
110660
diff
changeset
|
1713 && (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
|
1714 { |
83548
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
1715 char *p; |
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
1716 string[rl] = '\0'; |
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
1717 |
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
1718 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
|
1719 while (p > string && *p == '\n') |
83065
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1720 *p-- = 0; |
412 | 1721 |
84667
f2c11a35b0e3
(current_frame): Change the default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
83666
diff
changeset
|
1722 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
|
1723 { |
83246
5bc762f84335
Prevent emacsclient errors when Emacs is compiled without X support.
Karoly Lorentey <lorentey@elte.hu>
parents:
83165
diff
changeset
|
1724 /* -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
|
1725 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
|
1726 } |
83548
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
1727 else if (strprefix ("-window-system-unsupported ", string)) |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1728 { |
83246
5bc762f84335
Prevent emacsclient errors when Emacs is compiled without X support.
Karoly Lorentey <lorentey@elte.hu>
parents:
83165
diff
changeset
|
1729 /* -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
|
1730 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
|
1731 nowait = 0; |
5bc762f84335
Prevent emacsclient errors when Emacs is compiled without X support.
Karoly Lorentey <lorentey@elte.hu>
parents:
83165
diff
changeset
|
1732 tty = 1; |
5bc762f84335
Prevent emacsclient errors when Emacs is compiled without X support.
Karoly Lorentey <lorentey@elte.hu>
parents:
83165
diff
changeset
|
1733 goto retry; |
5bc762f84335
Prevent emacsclient errors when Emacs is compiled without X support.
Karoly Lorentey <lorentey@elte.hu>
parents:
83165
diff
changeset
|
1734 } |
83548
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
1735 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
|
1736 { |
83246
5bc762f84335
Prevent emacsclient errors when Emacs is compiled without X support.
Karoly Lorentey <lorentey@elte.hu>
parents:
83165
diff
changeset
|
1737 /* -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
|
1738 str = unquote_argument (string + strlen ("-print ")); |
83065
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1739 if (needlf) |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1740 printf ("\n"); |
83065
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1741 printf ("%s", str); |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1742 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
|
1743 } |
83548
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
1744 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
|
1745 { |
83246
5bc762f84335
Prevent emacsclient errors when Emacs is compiled without X support.
Karoly Lorentey <lorentey@elte.hu>
parents:
83165
diff
changeset
|
1746 /* -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
|
1747 str = unquote_argument (string + strlen ("-error ")); |
83065
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1748 if (needlf) |
83043
78a785f205ea
Added -w option to emacsclient for opening a new X frame.
Karoly Lorentey <lorentey@elte.hu>
parents:
83037
diff
changeset
|
1749 printf ("\n"); |
83548
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
1750 fprintf (stderr, "*ERROR*: %s", str); |
83065
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1751 needlf = str[0] == '\0' ? needlf : str[strlen (str) - 1] != '\n'; |
110706
ab3815920cc5
* emacsclient.c (main): Return EXIT_FAILURE if Emacs sends us an error string
Chong Yidong <cyd@stupidchicken.com>
parents:
110660
diff
changeset
|
1752 exit_status = EXIT_FAILURE; |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1753 } |
84677
421e6c54ace8
(main) [SIGSTOP]: Change conditional from WINDOWSNT.
Jason Rumney <jasonr@gnu.org>
parents:
84667
diff
changeset
|
1754 #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
|
1755 else if (strprefix ("-suspend ", string)) |
83065
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1756 { |
83246
5bc762f84335
Prevent emacsclient errors when Emacs is compiled without X support.
Karoly Lorentey <lorentey@elte.hu>
parents:
83165
diff
changeset
|
1757 /* -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
|
1758 if (needlf) |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1759 printf ("\n"); |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1760 needlf = 0; |
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1761 kill (0, SIGSTOP); |
82995
039bd6989d29
Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents:
82994
diff
changeset
|
1762 } |
83590 | 1763 #endif |
82995
039bd6989d29
Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents:
82994
diff
changeset
|
1764 else |
039bd6989d29
Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents:
82994
diff
changeset
|
1765 { |
83246
5bc762f84335
Prevent emacsclient errors when Emacs is compiled without X support.
Karoly Lorentey <lorentey@elte.hu>
parents:
83165
diff
changeset
|
1766 /* Unknown command. */ |
83065
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1767 if (needlf) |
82995
039bd6989d29
Portability fixes (now it compiles & runs fine on Solaris).
Karoly Lorentey <lorentey@elte.hu>
parents:
82994
diff
changeset
|
1768 printf ("\n"); |
83548
c71725faff1a
Merged from emacs@sv.gnu.org. Last-minute emacsclient rewrites be damned!
Karoly Lorentey <lorentey@elte.hu>
diff
changeset
|
1769 printf ("*ERROR*: Unknown message: %s", string); |
110706
ab3815920cc5
* emacsclient.c (main): Return EXIT_FAILURE if Emacs sends us an error string
Chong Yidong <cyd@stupidchicken.com>
parents:
110660
diff
changeset
|
1770 needlf = string[0] |
ab3815920cc5
* emacsclient.c (main): Return EXIT_FAILURE if Emacs sends us an error string
Chong Yidong <cyd@stupidchicken.com>
parents:
110660
diff
changeset
|
1771 == '\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
|
1772 } |
47515
6ee937dcfe16
(quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42412
diff
changeset
|
1773 } |
42176
1f5dbeefa536
Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents:
39723
diff
changeset
|
1774 |
47515
6ee937dcfe16
(quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42412
diff
changeset
|
1775 if (needlf) |
6ee937dcfe16
(quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42412
diff
changeset
|
1776 printf ("\n"); |
6ee937dcfe16
(quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42412
diff
changeset
|
1777 fflush (stdout); |
83065
a871be7b26a5
Implemented suspending of emacsclient frames.
Karoly Lorentey <lorentey@elte.hu>
parents:
83064
diff
changeset
|
1778 fsync (1); |
42176
1f5dbeefa536
Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents:
39723
diff
changeset
|
1779 |
110706
ab3815920cc5
* emacsclient.c (main): Return EXIT_FAILURE if Emacs sends us an error string
Chong Yidong <cyd@stupidchicken.com>
parents:
110660
diff
changeset
|
1780 if (rl < 0) |
ab3815920cc5
* emacsclient.c (main): Return EXIT_FAILURE if Emacs sends us an error string
Chong Yidong <cyd@stupidchicken.com>
parents:
110660
diff
changeset
|
1781 exit_status = EXIT_FAILURE; |
ab3815920cc5
* emacsclient.c (main): Return EXIT_FAILURE if Emacs sends us an error string
Chong Yidong <cyd@stupidchicken.com>
parents:
110660
diff
changeset
|
1782 |
83601
8365dbf64d14
(emacs_socket): Rename from s.
Jason Rumney <jasonr@gnu.org>
parents:
83600
diff
changeset
|
1783 CLOSE_SOCKET (emacs_socket); |
110706
ab3815920cc5
* emacsclient.c (main): Return EXIT_FAILURE if Emacs sends us an error string
Chong Yidong <cyd@stupidchicken.com>
parents:
110660
diff
changeset
|
1784 return exit_status; |
412 | 1785 } |
1786 | |
73617
7af864af10b6
[WINDOWSNT]: Define HAVE_INET_SOCKETS.
Juanma Barranquero <lekktu@gmail.com>
parents:
73601
diff
changeset
|
1787 #endif /* HAVE_SOCKETS && HAVE_INET_SOCKETS */ |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1788 |
5527
51451a050975
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5522
diff
changeset
|
1789 |
51451a050975
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5522
diff
changeset
|
1790 #ifndef HAVE_STRERROR |
51451a050975
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5522
diff
changeset
|
1791 char * |
51451a050975
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5522
diff
changeset
|
1792 strerror (errnum) |
51451a050975
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5522
diff
changeset
|
1793 int errnum; |
51451a050975
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5522
diff
changeset
|
1794 { |
51451a050975
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5522
diff
changeset
|
1795 extern char *sys_errlist[]; |
51451a050975
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5522
diff
changeset
|
1796 extern int sys_nerr; |
51451a050975
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5522
diff
changeset
|
1797 |
51451a050975
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5522
diff
changeset
|
1798 if (errnum >= 0 && errnum < sys_nerr) |
51451a050975
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5522
diff
changeset
|
1799 return sys_errlist[errnum]; |
51451a050975
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5522
diff
changeset
|
1800 return (char *) "Unknown error"; |
51451a050975
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5522
diff
changeset
|
1801 } |
51451a050975
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5522
diff
changeset
|
1802 |
51451a050975
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5522
diff
changeset
|
1803 #endif /* ! HAVE_STRERROR */ |
52401 | 1804 |
1805 /* arch-tag: f39bb9c4-73eb-477e-896d-50832e2ca9a7 | |
1806 (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
|
1807 |
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
53813
diff
changeset
|
1808 /* emacsclient.c ends here */ |