Mercurial > emacs
annotate lib-src/emacsclient.c @ 77034:e9e14fdaee2c
** Kevin Rodgers missing assignment
Resolved.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Sat, 07 Apr 2007 16:56:06 +0000 |
parents | 6ef0c279b18c |
children | 1f2482de3237 07774e5c3ff5 dd7c098af727 |
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, |
75348 | 3 2005, 2006, 2007 Free Software Foundation, Inc. |
412 | 4 |
5 This file is part of GNU Emacs. | |
6 | |
7 GNU Emacs is free software; you can redistribute it and/or modify | |
8 it under the terms of the GNU General Public License as published by | |
5522
64a936b21f74
Don't declare sys_errlist; declare strerror instead.
Roland McGrath <roland@gnu.org>
parents:
4696
diff
changeset
|
9 the Free Software Foundation; either version 2, or (at your option) |
412 | 10 any later version. |
11 | |
12 GNU Emacs is distributed in the hope that it will be useful, | |
13 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 GNU General Public License for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
18 along with GNU Emacs; see the file COPYING. If not, write to | |
64083 | 19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
20 Boston, MA 02110-1301, USA. */ | |
412 | 21 |
22 | |
23 #define NO_SHORTNAMES | |
42176
1f5dbeefa536
Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents:
39723
diff
changeset
|
24 |
1f5dbeefa536
Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents:
39723
diff
changeset
|
25 #ifdef HAVE_CONFIG_H |
42412 | 26 #include <config.h> |
42176
1f5dbeefa536
Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents:
39723
diff
changeset
|
27 #endif |
1f5dbeefa536
Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents:
39723
diff
changeset
|
28 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
29 #ifdef WINDOWSNT |
73585
7d264c036b25
[WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73583
diff
changeset
|
30 |
73973
a36e68eb4ae8
[WINDOWSNT]: Undef _WINSOCKAPI_ and _WINSOCK_H.
Juanma Barranquero <lekktu@gmail.com>
parents:
73896
diff
changeset
|
31 /* config.h defines these, which disables sockets altogether! */ |
a36e68eb4ae8
[WINDOWSNT]: Undef _WINSOCKAPI_ and _WINSOCK_H.
Juanma Barranquero <lekktu@gmail.com>
parents:
73896
diff
changeset
|
32 # undef _WINSOCKAPI_ |
a36e68eb4ae8
[WINDOWSNT]: Undef _WINSOCKAPI_ and _WINSOCK_H.
Juanma Barranquero <lekktu@gmail.com>
parents:
73896
diff
changeset
|
33 # undef _WINSOCK_H |
a36e68eb4ae8
[WINDOWSNT]: Undef _WINSOCKAPI_ and _WINSOCK_H.
Juanma Barranquero <lekktu@gmail.com>
parents:
73896
diff
changeset
|
34 |
73585
7d264c036b25
[WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73583
diff
changeset
|
35 # include <malloc.h> |
7d264c036b25
[WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73583
diff
changeset
|
36 # include <stdlib.h> |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
37 # include <windows.h> |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
38 |
73585
7d264c036b25
[WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73583
diff
changeset
|
39 # define NO_SOCKETS_IN_FILE_SYSTEM |
7d264c036b25
[WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73583
diff
changeset
|
40 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
41 # define HSOCKET SOCKET |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
42 # define CLOSE_SOCKET closesocket |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
43 # define INITIALIZE() (initialize_sockets ()) |
73585
7d264c036b25
[WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73583
diff
changeset
|
44 |
7d264c036b25
[WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73583
diff
changeset
|
45 #else /* !WINDOWSNT */ |
7d264c036b25
[WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73583
diff
changeset
|
46 |
73896
09dabd95380c
[!WINDOWSNT]: Include <sys/types.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73816
diff
changeset
|
47 # include <sys/types.h> |
09dabd95380c
[!WINDOWSNT]: Include <sys/types.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73816
diff
changeset
|
48 |
73617
7af864af10b6
[WINDOWSNT]: Define HAVE_INET_SOCKETS.
Juanma Barranquero <lekktu@gmail.com>
parents:
73601
diff
changeset
|
49 # ifdef HAVE_INET_SOCKETS |
7af864af10b6
[WINDOWSNT]: Define HAVE_INET_SOCKETS.
Juanma Barranquero <lekktu@gmail.com>
parents:
73601
diff
changeset
|
50 # include <netinet/in.h> |
7af864af10b6
[WINDOWSNT]: Define HAVE_INET_SOCKETS.
Juanma Barranquero <lekktu@gmail.com>
parents:
73601
diff
changeset
|
51 # endif |
73585
7d264c036b25
[WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73583
diff
changeset
|
52 |
73578
e193b6a3f379
Fixes to emacsclient.c for GNU/Linux.
Juanma Barranquero <lekktu@gmail.com>
parents:
73562
diff
changeset
|
53 # define INVALID_SOCKET -1 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
54 # define HSOCKET int |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
55 # define CLOSE_SOCKET close |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
56 # define INITIALIZE() |
73585
7d264c036b25
[WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73583
diff
changeset
|
57 |
7d264c036b25
[WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73583
diff
changeset
|
58 #endif /* !WINDOWSNT */ |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
59 |
3595
e10f7473d2e3
* emacsserver.c (main): When we're passing a `struct sockaddr_un'
Jim Blandy <jimb@redhat.com>
parents:
1031
diff
changeset
|
60 #undef signal |
412 | 61 |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
62 #include <stdarg.h> |
42176
1f5dbeefa536
Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents:
39723
diff
changeset
|
63 #include <ctype.h> |
16030
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
64 #include <stdio.h> |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
65 #include "getopt.h" |
21431
a080769e8f7d
Move inclusion of unistd.h to top, else fails on
Dave Love <fx@gnu.org>
parents:
21387
diff
changeset
|
66 #ifdef HAVE_UNISTD_H |
a080769e8f7d
Move inclusion of unistd.h to top, else fails on
Dave Love <fx@gnu.org>
parents:
21387
diff
changeset
|
67 #include <unistd.h> |
a080769e8f7d
Move inclusion of unistd.h to top, else fails on
Dave Love <fx@gnu.org>
parents:
21387
diff
changeset
|
68 #endif |
412 | 69 |
27474
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
70 #ifdef VMS |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
71 # include "vms-pwd.h" |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
72 #else /* not VMS */ |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
73 #ifdef WINDOWSNT |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
74 # include <io.h> |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
75 #else /* not WINDOWSNT */ |
27474
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
76 # include <pwd.h> |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
77 #endif /* not WINDOWSNT */ |
27474
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
78 #endif /* not VMS */ |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
79 |
16030
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
80 char *getenv (), *getwd (); |
60718
96023ae0af92
* emacsclient.c: Avoid expansion of getcwd when defined as a macro.
Jan Djärv <jan.h.d@swipnet.se>
parents:
56446
diff
changeset
|
81 char *(getcwd) (); |
16030
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
82 |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
83 #ifndef VERSION |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
84 #define VERSION "unspecified" |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
85 #endif |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
86 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
87 #define SEND_STRING(data) (send_to_emacs (s, (data))) |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
88 #define SEND_QUOTED(data) (quote_file_name (s, (data))) |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
89 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
90 #ifndef EXIT_SUCCESS |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
91 #define EXIT_SUCCESS 0 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
92 #endif |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
93 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
94 #ifndef EXIT_FAILURE |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
95 #define EXIT_FAILURE 1 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
96 #endif |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
97 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
98 #ifndef FALSE |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
99 #define FALSE 0 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
100 #endif |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
101 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
102 #ifndef TRUE |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
103 #define TRUE 1 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
104 #endif |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
105 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
106 #ifndef NO_RETURN |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
107 #define NO_RETURN |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
108 #endif |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
109 |
16030
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
110 /* Name used to invoke this program. */ |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
111 char *progname; |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
112 |
16146
a649abfefbb1
(longopts): Change nowait to no-wait.
Richard M. Stallman <rms@gnu.org>
parents:
16074
diff
changeset
|
113 /* 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
|
114 int nowait = 0; |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
115 |
47647
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
116 /* Nonzero means args are expressions to be evaluated. --eval. */ |
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
117 int eval = 0; |
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
118 |
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
119 /* The display on which Emacs should work. --display. */ |
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
120 char *display = NULL; |
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
121 |
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
122 /* 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
|
123 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
|
124 const char *alternate_editor = NULL; |
47647
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
125 |
52532 | 126 /* 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
|
127 char *socket_name = NULL; |
bc2610a13fbf
(socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
128 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
129 /* If non-NULL, the filename of the authentication file. */ |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
130 char *server_file = NULL; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
131 |
74342
c6cb776ffbb7
(emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
74341
diff
changeset
|
132 /* PID of the Emacs server process. */ |
c6cb776ffbb7
(emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
74341
diff
changeset
|
133 int emacs_pid = 0; |
c6cb776ffbb7
(emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
74341
diff
changeset
|
134 |
72005
da0099bc0ba4
* ebrowse.c (usage, version): Mark as NO_RETURN.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
68647
diff
changeset
|
135 void print_help_and_exit () NO_RETURN; |
21387
4812cf228971
Include <stdlib.h> and <unistd.h> if available.
Andreas Schwab <schwab@suse.de>
parents:
19582
diff
changeset
|
136 |
16030
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
137 struct option longopts[] = |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
138 { |
16146
a649abfefbb1
(longopts): Change nowait to no-wait.
Richard M. Stallman <rms@gnu.org>
parents:
16074
diff
changeset
|
139 { "no-wait", no_argument, NULL, 'n' }, |
47647
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
140 { "eval", no_argument, NULL, 'e' }, |
16030
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
141 { "help", no_argument, NULL, 'H' }, |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
142 { "version", no_argument, NULL, 'V' }, |
47515
6ee937dcfe16
(quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42412
diff
changeset
|
143 { "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
|
144 #ifndef NO_SOCKETS_IN_FILE_SYSTEM |
52479
bc2610a13fbf
(socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
145 { "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
|
146 #endif |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
147 { "server-file", required_argument, NULL, 'f' }, |
47647
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
148 { "display", required_argument, NULL, 'd' }, |
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
149 { 0, 0, 0, 0 } |
16030
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
150 }; |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
151 |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
152 /* Message functions. */ |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
153 |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
154 #ifdef WINDOWSNT |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
155 int |
74645
aa3039743d63
Comment and whitespace changes.
Richard M. Stallman <rms@gnu.org>
parents:
74644
diff
changeset
|
156 w32_window_app () |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
157 { |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
158 static int window_app = -1; |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
159 char szTitle[MAX_PATH]; |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
160 |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
161 if (window_app < 0) |
74644
4142abafc7b4
Rework a few comments.
Juanma Barranquero <lekktu@gmail.com>
parents:
74637
diff
changeset
|
162 /* Checking for STDOUT does not work; it's a valid handle also in |
4142abafc7b4
Rework a few comments.
Juanma Barranquero <lekktu@gmail.com>
parents:
74637
diff
changeset
|
163 nonconsole apps. Testing for the console title seems to work. */ |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
164 window_app = (GetConsoleTitleA (szTitle, MAX_PATH) == 0); |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
165 |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
166 return window_app; |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
167 } |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
168 #endif |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
169 |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
170 void |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
171 message (int is_error, char *message, ...) |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
172 { |
74342
c6cb776ffbb7
(emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
74341
diff
changeset
|
173 char msg [2048]; |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
174 va_list args; |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
175 |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
176 va_start (args, message); |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
177 vsprintf (msg, message, args); |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
178 va_end (args); |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
179 |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
180 #ifdef WINDOWSNT |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
181 if (w32_window_app ()) |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
182 { |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
183 if (is_error) |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
184 MessageBox (NULL, msg, "Emacsclient ERROR", MB_ICONERROR); |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
185 else |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
186 MessageBox (NULL, msg, "Emacsclient", MB_ICONINFORMATION); |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
187 } |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
188 else |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
189 #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
|
190 { |
32079f79e240
(message): Make sure the message is properly written even if it contains printf
Juanma Barranquero <lekktu@gmail.com>
parents:
74176
diff
changeset
|
191 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
|
192 |
32079f79e240
(message): Make sure the message is properly written even if it contains printf
Juanma Barranquero <lekktu@gmail.com>
parents:
74176
diff
changeset
|
193 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
|
194 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
|
195 } |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
196 } |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
197 |
16030
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
198 /* Decode the options from argv and argc. |
16061
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
199 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
|
200 |
16061
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
201 void |
16030
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
202 decode_options (argc, argv) |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
203 int argc; |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
204 char **argv; |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
205 { |
53813
ddc4b99f4f8c
(decode_options): Fix handling of alternate editor.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
53734
diff
changeset
|
206 alternate_editor = getenv ("ALTERNATE_EDITOR"); |
ddc4b99f4f8c
(decode_options): Fix handling of alternate editor.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
53734
diff
changeset
|
207 |
16030
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
208 while (1) |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
209 { |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
210 int opt = getopt_long (argc, argv, |
73765
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
211 #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
|
212 "VHnea:s:f:d:", |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
213 #else |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
214 "VHnea:f:d:", |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
215 #endif |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
216 longopts, 0); |
16030
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
217 |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
218 if (opt == EOF) |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
219 break; |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
220 |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
221 switch (opt) |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
222 { |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
223 case 0: |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
224 /* 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
|
225 long-named option. We should do nothing. */ |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
226 break; |
42176
1f5dbeefa536
Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents:
39723
diff
changeset
|
227 |
27305
4161adef5fd3
Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
228 case 'a': |
4161adef5fd3
Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
229 alternate_editor = optarg; |
4161adef5fd3
Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
230 break; |
42176
1f5dbeefa536
Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents:
39723
diff
changeset
|
231 |
73765
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
232 #ifndef NO_SOCKETS_IN_FILE_SYSTEM |
52479
bc2610a13fbf
(socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
233 case 's': |
bc2610a13fbf
(socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
234 socket_name = optarg; |
bc2610a13fbf
(socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
235 break; |
73765
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
236 #endif |
52479
bc2610a13fbf
(socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
237 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
238 case 'f': |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
239 server_file = optarg; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
240 break; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
241 |
47647
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
242 case 'd': |
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
243 display = optarg; |
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
244 break; |
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
245 |
16030
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
246 case 'n': |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
247 nowait = 1; |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
248 break; |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
249 |
47647
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
250 case 'e': |
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
251 eval = 1; |
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
252 break; |
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
253 |
16030
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
254 case 'V': |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
255 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
|
256 exit (EXIT_SUCCESS); |
16030
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
257 break; |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
258 |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
259 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
|
260 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
|
261 break; |
e5f56d47b52c
(print_help_and_exit): Print to stdout. Exit successfully. Added some blank
Juanma Barranquero <lekktu@gmail.com>
parents:
48627
diff
changeset
|
262 |
16030
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
263 default: |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
264 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
|
265 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
|
266 break; |
16030
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
267 } |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
268 } |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
269 } |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
270 |
21387
4812cf228971
Include <stdlib.h> and <unistd.h> if available.
Andreas Schwab <schwab@suse.de>
parents:
19582
diff
changeset
|
271 void |
16030
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
272 print_help_and_exit () |
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
273 { |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
274 message (FALSE, |
50101
e5f56d47b52c
(print_help_and_exit): Print to stdout. Exit successfully. Added some blank
Juanma Barranquero <lekktu@gmail.com>
parents:
48627
diff
changeset
|
275 "Usage: %s [OPTIONS] FILE...\n\ |
47647
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
276 Tell the Emacs server to visit the specified files.\n\ |
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
277 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
|
278 \n\ |
47647
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
279 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
|
280 \n\ |
46dc2e041725
(print_help_and_exit): Tweak message contents and tabs/spaces
Juanma Barranquero <lekktu@gmail.com>
parents:
74118
diff
changeset
|
281 -V, --version Just print version info and return\n\ |
46dc2e041725
(print_help_and_exit): Tweak message contents and tabs/spaces
Juanma Barranquero <lekktu@gmail.com>
parents:
74118
diff
changeset
|
282 -H, --help Print this usage information message\n\ |
46dc2e041725
(print_help_and_exit): Tweak message contents and tabs/spaces
Juanma Barranquero <lekktu@gmail.com>
parents:
74118
diff
changeset
|
283 -e, --eval Evaluate FILE arguments as Lisp expressions\n\ |
46dc2e041725
(print_help_and_exit): Tweak message contents and tabs/spaces
Juanma Barranquero <lekktu@gmail.com>
parents:
74118
diff
changeset
|
284 -n, --no-wait Don't wait for the server to return\n\ |
46dc2e041725
(print_help_and_exit): Tweak message contents and tabs/spaces
Juanma Barranquero <lekktu@gmail.com>
parents:
74118
diff
changeset
|
285 -d, --display=DISPLAY Visit the file in the given display\n" |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
286 #ifndef NO_SOCKETS_IN_FILE_SYSTEM |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
287 "-s, --socket-name=FILENAME\n\ |
74127
46dc2e041725
(print_help_and_exit): Tweak message contents and tabs/spaces
Juanma Barranquero <lekktu@gmail.com>
parents:
74118
diff
changeset
|
288 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
|
289 #endif |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
290 "-f, --server-file=FILENAME\n\ |
74127
46dc2e041725
(print_help_and_exit): Tweak message contents and tabs/spaces
Juanma Barranquero <lekktu@gmail.com>
parents:
74118
diff
changeset
|
291 Set filename of the TCP authentication file\n\ |
47647
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
292 -a, --alternate-editor=EDITOR\n\ |
74127
46dc2e041725
(print_help_and_exit): Tweak message contents and tabs/spaces
Juanma Barranquero <lekktu@gmail.com>
parents:
74118
diff
changeset
|
293 Editor to fallback to if server is not running\n\ |
50101
e5f56d47b52c
(print_help_and_exit): Print to stdout. Exit successfully. Added some blank
Juanma Barranquero <lekktu@gmail.com>
parents:
48627
diff
changeset
|
294 \n\ |
47647
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
295 Report bugs to bug-gnu-emacs@gnu.org.\n", progname); |
55442
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
53813
diff
changeset
|
296 exit (EXIT_SUCCESS); |
16030
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
297 } |
16061
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
298 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
299 |
74637
fe8bd1af34c4
(w32_execvp): New function; wrapper for `execvp'.
Juanma Barranquero <lekktu@gmail.com>
parents:
74342
diff
changeset
|
300 #ifdef WINDOWSNT |
fe8bd1af34c4
(w32_execvp): New function; wrapper for `execvp'.
Juanma Barranquero <lekktu@gmail.com>
parents:
74342
diff
changeset
|
301 |
fe8bd1af34c4
(w32_execvp): New function; wrapper for `execvp'.
Juanma Barranquero <lekktu@gmail.com>
parents:
74342
diff
changeset
|
302 /* |
74645
aa3039743d63
Comment and whitespace changes.
Richard M. Stallman <rms@gnu.org>
parents:
74644
diff
changeset
|
303 execvp wrapper for Windows. Quotes arguments with embedded spaces. |
74637
fe8bd1af34c4
(w32_execvp): New function; wrapper for `execvp'.
Juanma Barranquero <lekktu@gmail.com>
parents:
74342
diff
changeset
|
304 |
fe8bd1af34c4
(w32_execvp): New function; wrapper for `execvp'.
Juanma Barranquero <lekktu@gmail.com>
parents:
74342
diff
changeset
|
305 This is necessary due to the broken implementation of exec* routines in |
fe8bd1af34c4
(w32_execvp): New function; wrapper for `execvp'.
Juanma Barranquero <lekktu@gmail.com>
parents:
74342
diff
changeset
|
306 the Microsoft libraries: they concatenate the arguments together without |
fe8bd1af34c4
(w32_execvp): New function; wrapper for `execvp'.
Juanma Barranquero <lekktu@gmail.com>
parents:
74342
diff
changeset
|
307 quoting special characters, and pass the result to CreateProcess, with |
fe8bd1af34c4
(w32_execvp): New function; wrapper for `execvp'.
Juanma Barranquero <lekktu@gmail.com>
parents:
74342
diff
changeset
|
308 predictably bad results. By contrast, Posix execvp passes the arguments |
74645
aa3039743d63
Comment and whitespace changes.
Richard M. Stallman <rms@gnu.org>
parents:
74644
diff
changeset
|
309 directly into the argv array of the child process. |
74637
fe8bd1af34c4
(w32_execvp): New function; wrapper for `execvp'.
Juanma Barranquero <lekktu@gmail.com>
parents:
74342
diff
changeset
|
310 */ |
fe8bd1af34c4
(w32_execvp): New function; wrapper for `execvp'.
Juanma Barranquero <lekktu@gmail.com>
parents:
74342
diff
changeset
|
311 int |
fe8bd1af34c4
(w32_execvp): New function; wrapper for `execvp'.
Juanma Barranquero <lekktu@gmail.com>
parents:
74342
diff
changeset
|
312 w32_execvp (path, argv) |
fe8bd1af34c4
(w32_execvp): New function; wrapper for `execvp'.
Juanma Barranquero <lekktu@gmail.com>
parents:
74342
diff
changeset
|
313 char *path; |
fe8bd1af34c4
(w32_execvp): New function; wrapper for `execvp'.
Juanma Barranquero <lekktu@gmail.com>
parents:
74342
diff
changeset
|
314 char **argv; |
fe8bd1af34c4
(w32_execvp): New function; wrapper for `execvp'.
Juanma Barranquero <lekktu@gmail.com>
parents:
74342
diff
changeset
|
315 { |
fe8bd1af34c4
(w32_execvp): New function; wrapper for `execvp'.
Juanma Barranquero <lekktu@gmail.com>
parents:
74342
diff
changeset
|
316 int i; |
fe8bd1af34c4
(w32_execvp): New function; wrapper for `execvp'.
Juanma Barranquero <lekktu@gmail.com>
parents:
74342
diff
changeset
|
317 |
74644
4142abafc7b4
Rework a few comments.
Juanma Barranquero <lekktu@gmail.com>
parents:
74637
diff
changeset
|
318 /* Required to allow a .BAT script as alternate editor. */ |
74637
fe8bd1af34c4
(w32_execvp): New function; wrapper for `execvp'.
Juanma Barranquero <lekktu@gmail.com>
parents:
74342
diff
changeset
|
319 argv[0] = (char *) alternate_editor; |
fe8bd1af34c4
(w32_execvp): New function; wrapper for `execvp'.
Juanma Barranquero <lekktu@gmail.com>
parents:
74342
diff
changeset
|
320 |
fe8bd1af34c4
(w32_execvp): New function; wrapper for `execvp'.
Juanma Barranquero <lekktu@gmail.com>
parents:
74342
diff
changeset
|
321 for (i = 0; argv[i]; i++) |
fe8bd1af34c4
(w32_execvp): New function; wrapper for `execvp'.
Juanma Barranquero <lekktu@gmail.com>
parents:
74342
diff
changeset
|
322 if (strchr (argv[i], ' ')) |
fe8bd1af34c4
(w32_execvp): New function; wrapper for `execvp'.
Juanma Barranquero <lekktu@gmail.com>
parents:
74342
diff
changeset
|
323 { |
fe8bd1af34c4
(w32_execvp): New function; wrapper for `execvp'.
Juanma Barranquero <lekktu@gmail.com>
parents:
74342
diff
changeset
|
324 char *quoted = alloca (strlen (argv[i]) + 3); |
fe8bd1af34c4
(w32_execvp): New function; wrapper for `execvp'.
Juanma Barranquero <lekktu@gmail.com>
parents:
74342
diff
changeset
|
325 sprintf (quoted, "\"%s\"", argv[i]); |
fe8bd1af34c4
(w32_execvp): New function; wrapper for `execvp'.
Juanma Barranquero <lekktu@gmail.com>
parents:
74342
diff
changeset
|
326 argv[i] = quoted; |
fe8bd1af34c4
(w32_execvp): New function; wrapper for `execvp'.
Juanma Barranquero <lekktu@gmail.com>
parents:
74342
diff
changeset
|
327 } |
fe8bd1af34c4
(w32_execvp): New function; wrapper for `execvp'.
Juanma Barranquero <lekktu@gmail.com>
parents:
74342
diff
changeset
|
328 |
fe8bd1af34c4
(w32_execvp): New function; wrapper for `execvp'.
Juanma Barranquero <lekktu@gmail.com>
parents:
74342
diff
changeset
|
329 return execvp (path, argv); |
fe8bd1af34c4
(w32_execvp): New function; wrapper for `execvp'.
Juanma Barranquero <lekktu@gmail.com>
parents:
74342
diff
changeset
|
330 } |
fe8bd1af34c4
(w32_execvp): New function; wrapper for `execvp'.
Juanma Barranquero <lekktu@gmail.com>
parents:
74342
diff
changeset
|
331 |
fe8bd1af34c4
(w32_execvp): New function; wrapper for `execvp'.
Juanma Barranquero <lekktu@gmail.com>
parents:
74342
diff
changeset
|
332 #undef execvp |
fe8bd1af34c4
(w32_execvp): New function; wrapper for `execvp'.
Juanma Barranquero <lekktu@gmail.com>
parents:
74342
diff
changeset
|
333 #define execvp w32_execvp |
fe8bd1af34c4
(w32_execvp): New function; wrapper for `execvp'.
Juanma Barranquero <lekktu@gmail.com>
parents:
74342
diff
changeset
|
334 |
fe8bd1af34c4
(w32_execvp): New function; wrapper for `execvp'.
Juanma Barranquero <lekktu@gmail.com>
parents:
74342
diff
changeset
|
335 #endif /* WINDOWSNT */ |
fe8bd1af34c4
(w32_execvp): New function; wrapper for `execvp'.
Juanma Barranquero <lekktu@gmail.com>
parents:
74342
diff
changeset
|
336 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
337 /* |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
338 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
|
339 defined-- exit with an errorcode. |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
340 */ |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
341 void |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
342 fail (argc, argv) |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
343 int argc; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
344 char **argv; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
345 { |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
346 if (alternate_editor) |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
347 { |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
348 int i = optind - 1; |
74637
fe8bd1af34c4
(w32_execvp): New function; wrapper for `execvp'.
Juanma Barranquero <lekktu@gmail.com>
parents:
74342
diff
changeset
|
349 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
350 execvp (alternate_editor, argv + i); |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
351 message (TRUE, "%s: error executing alternate editor \"%s\"\n", |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
352 progname, alternate_editor); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
353 } |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
354 exit (EXIT_FAILURE); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
355 } |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
356 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
357 |
73617
7af864af10b6
[WINDOWSNT]: Define HAVE_INET_SOCKETS.
Juanma Barranquero <lekktu@gmail.com>
parents:
73601
diff
changeset
|
358 #if !defined (HAVE_SOCKETS) || !defined (HAVE_INET_SOCKETS) |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
359 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
360 int |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
361 main (argc, argv) |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
362 int argc; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
363 char **argv; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
364 { |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
365 message (TRUE, "%s: Sorry, the Emacs server is supported only\non systems with Berkely sockets.\n", |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
366 argv[0]); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
367 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
368 fail (argc, argv); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
369 } |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
370 |
73617
7af864af10b6
[WINDOWSNT]: Define HAVE_INET_SOCKETS.
Juanma Barranquero <lekktu@gmail.com>
parents:
73601
diff
changeset
|
371 #else /* HAVE_SOCKETS && HAVE_INET_SOCKETS */ |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
372 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
373 #ifdef WINDOWSNT |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
374 # include <winsock2.h> |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
375 #else |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
376 # include <sys/types.h> |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
377 # include <sys/socket.h> |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
378 # include <sys/un.h> |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
379 # include <sys/stat.h> |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
380 # include <errno.h> |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
381 #endif |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
382 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
383 #define AUTH_KEY_LENGTH 64 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
384 #define SEND_BUFFER_SIZE 4096 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
385 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
386 extern char *strerror (); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
387 extern int errno; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
388 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
389 /* Buffer to accumulate data to send in TCP connections. */ |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
390 char send_buffer[SEND_BUFFER_SIZE + 1]; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
391 int sblen = 0; /* Fill pointer for the send buffer. */ |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
392 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
393 /* Let's send the data to Emacs when either |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
394 - the data ends in "\n", or |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
395 - the buffer is full (but this shouldn't happen) |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
396 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
|
397 void |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
398 send_to_emacs (s, data) |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
399 HSOCKET s; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
400 char *data; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
401 { |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
402 while (data) |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
403 { |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
404 int dlen = strlen (data); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
405 if (dlen + sblen >= SEND_BUFFER_SIZE) |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
406 { |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
407 int part = SEND_BUFFER_SIZE - sblen; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
408 strncpy (&send_buffer[sblen], data, part); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
409 data += part; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
410 sblen = SEND_BUFFER_SIZE; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
411 } |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
412 else if (dlen) |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
413 { |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
414 strcpy (&send_buffer[sblen], data); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
415 data = NULL; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
416 sblen += dlen; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
417 } |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
418 else |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
419 break; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
420 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
421 if (sblen == SEND_BUFFER_SIZE |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
422 || (sblen > 0 && send_buffer[sblen-1] == '\n')) |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
423 { |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
424 int sent = send (s, send_buffer, sblen, 0); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
425 if (sent != sblen) |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
426 strcpy (send_buffer, &send_buffer[sent]); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
427 sblen -= sent; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
428 } |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
429 } |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
430 } |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
431 |
52848 | 432 /* In NAME, insert a & before each &, each space, each newline, and |
433 any initial -. Change spaces to underscores, too, so that the | |
16061
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
434 return value never contains a space. */ |
52635
9963e9da5850
(quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents:
52532
diff
changeset
|
435 void |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
436 quote_file_name (s, name) |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
437 HSOCKET s; |
16061
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
438 char *name; |
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
439 { |
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
440 char *copy = (char *) malloc (strlen (name) * 2 + 1); |
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
441 char *p, *q; |
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
442 |
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
443 p = name; |
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
444 q = copy; |
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
445 while (*p) |
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
446 { |
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
447 if (*p == ' ') |
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
448 { |
16074
25cfff7ffced
(quote_file_name): Quote with &, not \.
Richard M. Stallman <rms@gnu.org>
parents:
16061
diff
changeset
|
449 *q++ = '&'; |
16061
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
450 *q++ = '_'; |
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
451 p++; |
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
452 } |
47515
6ee937dcfe16
(quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42412
diff
changeset
|
453 else if (*p == '\n') |
6ee937dcfe16
(quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42412
diff
changeset
|
454 { |
6ee937dcfe16
(quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42412
diff
changeset
|
455 *q++ = '&'; |
6ee937dcfe16
(quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42412
diff
changeset
|
456 *q++ = 'n'; |
6ee937dcfe16
(quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42412
diff
changeset
|
457 p++; |
6ee937dcfe16
(quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42412
diff
changeset
|
458 } |
16061
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
459 else |
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
460 { |
16074
25cfff7ffced
(quote_file_name): Quote with &, not \.
Richard M. Stallman <rms@gnu.org>
parents:
16061
diff
changeset
|
461 if (*p == '&' || (*p == '-' && p == name)) |
25cfff7ffced
(quote_file_name): Quote with &, not \.
Richard M. Stallman <rms@gnu.org>
parents:
16061
diff
changeset
|
462 *q++ = '&'; |
16061
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
463 *q++ = *p++; |
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
464 } |
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
465 } |
16074
25cfff7ffced
(quote_file_name): Quote with &, not \.
Richard M. Stallman <rms@gnu.org>
parents:
16061
diff
changeset
|
466 *q++ = 0; |
16061
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
467 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
468 SEND_STRING (copy); |
52635
9963e9da5850
(quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents:
52532
diff
changeset
|
469 |
9963e9da5850
(quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents:
52532
diff
changeset
|
470 free (copy); |
16061
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
471 } |
18701
9c7e0c926ed5
[C_ALLOCA] (xmalloc): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
472 |
73765
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
473 int |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
474 file_name_absolute_p (filename) |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
475 const unsigned char *filename; |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
476 { |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
477 /* 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
|
478 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
|
479 |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
480 /* /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
|
481 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
|
482 |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
483 /* 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
|
484 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
|
485 |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
486 #ifdef WINDOWSNT |
75956
6ef0c279b18c
Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents:
75348
diff
changeset
|
487 /* X:\xxx is always absolute. */ |
74176
6eee550d3bda
(file_name_absolute_p) [WINDOWSNT]: Use isalpha().
Jason Rumney <jasonr@gnu.org>
parents:
74172
diff
changeset
|
488 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
|
489 && 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
|
490 return TRUE; |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
491 |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
492 /* 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
|
493 if (filename[0] == '\\') return TRUE; |
75956
6ef0c279b18c
Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents:
75348
diff
changeset
|
494 |
6ef0c279b18c
Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents:
75348
diff
changeset
|
495 /* |
6ef0c279b18c
Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents:
75348
diff
changeset
|
496 FIXME: There's a corner case not dealt with, "x:y", where: |
6ef0c279b18c
Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents:
75348
diff
changeset
|
497 |
6ef0c279b18c
Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents:
75348
diff
changeset
|
498 1) x is a valid drive designation (usually a letter in the A-Z range) |
6ef0c279b18c
Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents:
75348
diff
changeset
|
499 and y is a path, relative to the current directory on drive x. This |
6ef0c279b18c
Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents:
75348
diff
changeset
|
500 is absolute, *after* fixing the y part to include the current |
6ef0c279b18c
Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents:
75348
diff
changeset
|
501 directory in x. |
6ef0c279b18c
Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents:
75348
diff
changeset
|
502 |
6ef0c279b18c
Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents:
75348
diff
changeset
|
503 2) x is a relative file name, and y is an NTFS stream name. This is a |
6ef0c279b18c
Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents:
75348
diff
changeset
|
504 correct relative path, but it is very unusual. |
6ef0c279b18c
Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents:
75348
diff
changeset
|
505 |
6ef0c279b18c
Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents:
75348
diff
changeset
|
506 The trouble is that first case items are also valid examples of the |
6ef0c279b18c
Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents:
75348
diff
changeset
|
507 second case, i.e., "c:test" can be understood as drive:path or as |
6ef0c279b18c
Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents:
75348
diff
changeset
|
508 file:stream. |
6ef0c279b18c
Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents:
75348
diff
changeset
|
509 |
6ef0c279b18c
Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents:
75348
diff
changeset
|
510 The "right" fix would involve checking whether |
6ef0c279b18c
Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents:
75348
diff
changeset
|
511 - the current drive/partition is NTFS, |
6ef0c279b18c
Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents:
75348
diff
changeset
|
512 - x is a valid (and accesible) drive designator, |
6ef0c279b18c
Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents:
75348
diff
changeset
|
513 - x:y already exists as a file:stream in the current directory, |
6ef0c279b18c
Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents:
75348
diff
changeset
|
514 - y already exists on the current directory of drive x, |
6ef0c279b18c
Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents:
75348
diff
changeset
|
515 - the auspices are favorable, |
6ef0c279b18c
Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents:
75348
diff
changeset
|
516 and then taking an "informed decision" based on the above. |
6ef0c279b18c
Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents:
75348
diff
changeset
|
517 |
6ef0c279b18c
Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents:
75348
diff
changeset
|
518 Whatever the result, Emacs currently does a very bad job of dealing |
6ef0c279b18c
Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents:
75348
diff
changeset
|
519 with NTFS file:streams: it cannot visit them, and the only way to |
6ef0c279b18c
Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents:
75348
diff
changeset
|
520 create one is by setting `buffer-file-name' to point to it (either |
6ef0c279b18c
Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents:
75348
diff
changeset
|
521 manually or with emacsclient). So perhaps resorting to 1) and ignoring |
6ef0c279b18c
Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents:
75348
diff
changeset
|
522 2) for now is the right thing to do. |
6ef0c279b18c
Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents:
75348
diff
changeset
|
523 |
6ef0c279b18c
Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents:
75348
diff
changeset
|
524 Anyway, something to decide After the Release. |
6ef0c279b18c
Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents:
75348
diff
changeset
|
525 */ |
73765
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
526 #endif |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
527 |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
528 return FALSE; |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
529 } |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
530 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
531 #ifdef WINDOWSNT |
74645
aa3039743d63
Comment and whitespace changes.
Richard M. Stallman <rms@gnu.org>
parents:
74644
diff
changeset
|
532 /* Wrapper to make WSACleanup a cdecl, as required by atexit. */ |
73765
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
533 void |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
534 __cdecl close_winsock () |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
535 { |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
536 WSACleanup (); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
537 } |
18701
9c7e0c926ed5
[C_ALLOCA] (xmalloc): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
538 |
73765
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
539 /* 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
|
540 void |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
541 initialize_sockets () |
18701
9c7e0c926ed5
[C_ALLOCA] (xmalloc): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
542 { |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
543 WSADATA wsaData; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
544 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
545 if (WSAStartup (MAKEWORD (2, 0), &wsaData)) |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
546 { |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
547 message (TRUE, "%s: error initializing WinSock2", progname); |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
548 exit (EXIT_FAILURE); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
549 } |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
550 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
551 atexit (close_winsock); |
73578
e193b6a3f379
Fixes to emacsclient.c for GNU/Linux.
Juanma Barranquero <lekktu@gmail.com>
parents:
73562
diff
changeset
|
552 } |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
553 #endif /* WINDOWSNT */ |
16030
fb38057473c8
(decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents:
15995
diff
changeset
|
554 |
27305
4161adef5fd3
Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
555 /* |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
556 * Read the information needed to set up a TCP comm channel with |
73806
fbfa7d8c0a64
(get_server_config): Extract also the Emacs pid from the server file.
Juanma Barranquero <lekktu@gmail.com>
parents:
73765
diff
changeset
|
557 * the Emacs server: host, port, pid and authentication string. |
74729
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
558 */ |
73765
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
559 int |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
560 get_server_config (server, authentication) |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
561 struct sockaddr_in *server; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
562 char *authentication; |
27305
4161adef5fd3
Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
563 { |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
564 char dotted[32]; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
565 char *port; |
73806
fbfa7d8c0a64
(get_server_config): Extract also the Emacs pid from the server file.
Juanma Barranquero <lekktu@gmail.com>
parents:
73765
diff
changeset
|
566 char *pid; |
73765
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
567 FILE *config = NULL; |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
568 |
73765
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
569 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
|
570 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
|
571 else |
27305
4161adef5fd3
Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
572 { |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
573 char *home = getenv ("HOME"); |
73809
cbc1f46b6590
(get_server_config) [WINDOWSNT]: Search the server file on APPDATA
Juanma Barranquero <lekktu@gmail.com>
parents:
73806
diff
changeset
|
574 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
575 if (home) |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
576 { |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
577 char *path = alloca (32 + strlen (home) + strlen (server_file)); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
578 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
|
579 config = fopen (path, "rb"); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
580 } |
73809
cbc1f46b6590
(get_server_config) [WINDOWSNT]: Search the server file on APPDATA
Juanma Barranquero <lekktu@gmail.com>
parents:
73806
diff
changeset
|
581 #ifdef WINDOWSNT |
cbc1f46b6590
(get_server_config) [WINDOWSNT]: Search the server file on APPDATA
Juanma Barranquero <lekktu@gmail.com>
parents:
73806
diff
changeset
|
582 if (!config && (home = getenv ("APPDATA"))) |
cbc1f46b6590
(get_server_config) [WINDOWSNT]: Search the server file on APPDATA
Juanma Barranquero <lekktu@gmail.com>
parents:
73806
diff
changeset
|
583 { |
cbc1f46b6590
(get_server_config) [WINDOWSNT]: Search the server file on APPDATA
Juanma Barranquero <lekktu@gmail.com>
parents:
73806
diff
changeset
|
584 char *path = alloca (32 + strlen (home) + strlen (server_file)); |
cbc1f46b6590
(get_server_config) [WINDOWSNT]: Search the server file on APPDATA
Juanma Barranquero <lekktu@gmail.com>
parents:
73806
diff
changeset
|
585 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
|
586 config = fopen (path, "rb"); |
cbc1f46b6590
(get_server_config) [WINDOWSNT]: Search the server file on APPDATA
Juanma Barranquero <lekktu@gmail.com>
parents:
73806
diff
changeset
|
587 } |
cbc1f46b6590
(get_server_config) [WINDOWSNT]: Search the server file on APPDATA
Juanma Barranquero <lekktu@gmail.com>
parents:
73806
diff
changeset
|
588 #endif |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
589 } |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
590 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
591 if (! config) |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
592 return FALSE; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
593 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
594 if (fgets (dotted, sizeof dotted, config) |
73806
fbfa7d8c0a64
(get_server_config): Extract also the Emacs pid from the server file.
Juanma Barranquero <lekktu@gmail.com>
parents:
73765
diff
changeset
|
595 && (port = strchr (dotted, ':')) |
fbfa7d8c0a64
(get_server_config): Extract also the Emacs pid from the server file.
Juanma Barranquero <lekktu@gmail.com>
parents:
73765
diff
changeset
|
596 && (pid = strchr (port, ' '))) |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
597 { |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
598 *port++ = '\0'; |
73806
fbfa7d8c0a64
(get_server_config): Extract also the Emacs pid from the server file.
Juanma Barranquero <lekktu@gmail.com>
parents:
73765
diff
changeset
|
599 *pid++ = '\0'; |
27305
4161adef5fd3
Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
600 } |
4161adef5fd3
Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
601 else |
4161adef5fd3
Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
602 { |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
603 message (TRUE, "%s: invalid configuration info", progname); |
55442
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
53813
diff
changeset
|
604 exit (EXIT_FAILURE); |
27305
4161adef5fd3
Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
605 } |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
606 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
607 server->sin_family = AF_INET; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
608 server->sin_addr.s_addr = inet_addr (dotted); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
609 server->sin_port = htons (atoi (port)); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
610 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
611 if (! fread (authentication, AUTH_KEY_LENGTH, 1, config)) |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
612 { |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
613 message (TRUE, "%s: cannot read authentication info", progname); |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
614 exit (EXIT_FAILURE); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
615 } |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
616 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
617 fclose (config); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
618 |
74342
c6cb776ffbb7
(emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
74341
diff
changeset
|
619 emacs_pid = atoi (pid); |
73806
fbfa7d8c0a64
(get_server_config): Extract also the Emacs pid from the server file.
Juanma Barranquero <lekktu@gmail.com>
parents:
73765
diff
changeset
|
620 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
621 return TRUE; |
27305
4161adef5fd3
Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
622 } |
4161adef5fd3
Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
623 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
624 HSOCKET |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
625 set_tcp_socket () |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
626 { |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
627 HSOCKET s; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
628 struct sockaddr_in server; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
629 struct linger l_arg = {1, 1}; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
630 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
|
631 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
632 if (! get_server_config (&server, auth_string)) |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
633 return INVALID_SOCKET; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
634 |
73765
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
635 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
|
636 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
|
637 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
|
638 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
639 /* |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
640 * Open up an AF_INET socket |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
641 */ |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
642 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
|
643 { |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
644 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
|
645 return INVALID_SOCKET; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
646 } |
412 | 647 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
648 /* |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
649 * Set up the socket |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
650 */ |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
651 if (connect (s, (struct sockaddr *) &server, sizeof server) < 0) |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
652 { |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
653 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
|
654 return INVALID_SOCKET; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
655 } |
27305
4161adef5fd3
Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
656 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
657 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
|
658 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
659 /* |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
660 * Send the authentication |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
661 */ |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
662 auth_string[AUTH_KEY_LENGTH] = '\0'; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
663 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
664 SEND_STRING ("-auth "); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
665 SEND_STRING (auth_string); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
666 SEND_STRING ("\n"); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
667 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
668 return s; |
412 | 669 } |
670 | |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
671 #if !defined (NO_SOCKETS_IN_FILE_SYSTEM) |
412 | 672 |
27474
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
673 /* Three possibilities: |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
674 2 - can't be `stat'ed (sets errno) |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
675 1 - isn't owned by us |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
676 0 - success: none of the above */ |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
677 |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
678 static int |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
679 socket_status (socket_name) |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
680 char *socket_name; |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
681 { |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
682 struct stat statbfr; |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
683 |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
684 if (stat (socket_name, &statbfr) == -1) |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
685 return 2; |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
686 |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
687 if (statbfr.st_uid != geteuid ()) |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
688 return 1; |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
689 |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
690 return 0; |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
691 } |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
692 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
693 HSOCKET |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
694 set_local_socket () |
412 | 695 { |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
696 HSOCKET s; |
412 | 697 struct sockaddr_un server; |
698 | |
42176
1f5dbeefa536
Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents:
39723
diff
changeset
|
699 /* |
412 | 700 * Open up an AF_UNIX socket in this person's home directory |
701 */ | |
702 | |
703 if ((s = socket (AF_UNIX, SOCK_STREAM, 0)) < 0) | |
704 { | |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
705 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
|
706 return INVALID_SOCKET; |
412 | 707 } |
42176
1f5dbeefa536
Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents:
39723
diff
changeset
|
708 |
412 | 709 server.sun_family = AF_UNIX; |
25261
89be69860eeb
(main): Move the dynamic allocation of
Karl Heuer <kwzh@gnu.org>
parents:
24652
diff
changeset
|
710 |
493 | 711 { |
27474
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
712 int sock_status = 0; |
53646
8c55b1b400d5
(main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
53543
diff
changeset
|
713 int default_sock = !socket_name; |
53543
fec82b542db2
(main): Save errno from socket_status.
Andreas Schwab <schwab@suse.de>
parents:
53497
diff
changeset
|
714 int saved_errno; |
53734
132739917566
(main): Don't use the hostname in the socket name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
53693
diff
changeset
|
715 char *server_name = "server"; |
132739917566
(main): Don't use the hostname in the socket name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
53693
diff
changeset
|
716 |
132739917566
(main): Don't use the hostname in the socket name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
53693
diff
changeset
|
717 if (socket_name && !index (socket_name, '/') && !index (socket_name, '\\')) |
132739917566
(main): Don't use the hostname in the socket name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
53693
diff
changeset
|
718 { /* socket_name is a file name component. */ |
132739917566
(main): Don't use the hostname in the socket name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
53693
diff
changeset
|
719 server_name = socket_name; |
132739917566
(main): Don't use the hostname in the socket name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
53693
diff
changeset
|
720 socket_name = NULL; |
132739917566
(main): Don't use the hostname in the socket name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
53693
diff
changeset
|
721 default_sock = 1; /* Try both UIDs. */ |
132739917566
(main): Don't use the hostname in the socket name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
53693
diff
changeset
|
722 } |
24084
c0b0893dd5a6
(main): Eliminate arbitrary limit on length of system_name.
Richard M. Stallman <rms@gnu.org>
parents:
23412
diff
changeset
|
723 |
53646
8c55b1b400d5
(main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
53543
diff
changeset
|
724 if (default_sock) |
52479
bc2610a13fbf
(socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
725 { |
53734
132739917566
(main): Don't use the hostname in the socket name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
53693
diff
changeset
|
726 socket_name = alloca (100 + strlen (server_name)); |
132739917566
(main): Don't use the hostname in the socket name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
53693
diff
changeset
|
727 sprintf (socket_name, "/tmp/emacs%d/%s", |
132739917566
(main): Don't use the hostname in the socket name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
53693
diff
changeset
|
728 (int) geteuid (), server_name); |
52479
bc2610a13fbf
(socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
729 } |
bc2610a13fbf
(socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
730 |
bc2610a13fbf
(socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
731 if (strlen (socket_name) < sizeof (server.sun_path)) |
bc2610a13fbf
(socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
732 strcpy (server.sun_path, socket_name); |
bc2610a13fbf
(socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
733 else |
53646
8c55b1b400d5
(main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
53543
diff
changeset
|
734 { |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
735 message (TRUE, "%s: socket-name %s too long", |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
736 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
|
737 exit (EXIT_FAILURE); |
53646
8c55b1b400d5
(main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
53543
diff
changeset
|
738 } |
412 | 739 |
27474
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
740 /* 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
|
741 sock_status = socket_status (server.sun_path); |
53543
fec82b542db2
(main): Save errno from socket_status.
Andreas Schwab <schwab@suse.de>
parents:
53497
diff
changeset
|
742 saved_errno = errno; |
53646
8c55b1b400d5
(main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
53543
diff
changeset
|
743 if (sock_status && default_sock) |
493 | 744 { |
27474
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
745 /* 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
|
746 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
|
747 associated with the name. This is reminiscent of the logic |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
748 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
|
749 |
27474
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
750 char *user_name = (char *) getenv ("LOGNAME"); |
53693
04e9ebd16fcd
(main): Restore errno from saved_errno,
Richard M. Stallman <rms@gnu.org>
parents:
53646
diff
changeset
|
751 |
27474
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
752 if (!user_name) |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
753 user_name = (char *) getenv ("USER"); |
42176
1f5dbeefa536
Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents:
39723
diff
changeset
|
754 |
27474
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
755 if (user_name) |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
756 { |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
757 struct passwd *pw = getpwnam (user_name); |
53693
04e9ebd16fcd
(main): Restore errno from saved_errno,
Richard M. Stallman <rms@gnu.org>
parents:
53646
diff
changeset
|
758 |
27474
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
759 if (pw && (pw->pw_uid != geteuid ())) |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
760 { |
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
761 /* We're running under su, apparently. */ |
53734
132739917566
(main): Don't use the hostname in the socket name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
53693
diff
changeset
|
762 socket_name = alloca (100 + strlen (server_name)); |
132739917566
(main): Don't use the hostname in the socket name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
53693
diff
changeset
|
763 sprintf (socket_name, "/tmp/emacs%d/%s", |
132739917566
(main): Don't use the hostname in the socket name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
53693
diff
changeset
|
764 (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
|
765 |
8c55b1b400d5
(main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
53543
diff
changeset
|
766 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
|
767 strcpy (server.sun_path, socket_name); |
8c55b1b400d5
(main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
53543
diff
changeset
|
768 else |
8c55b1b400d5
(main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
53543
diff
changeset
|
769 { |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
770 message (TRUE, "%s: socket-name %s too long", |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
771 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
|
772 exit (EXIT_FAILURE); |
53646
8c55b1b400d5
(main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
53543
diff
changeset
|
773 } |
8c55b1b400d5
(main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
53543
diff
changeset
|
774 |
27474
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
775 sock_status = socket_status (server.sun_path); |
53543
fec82b542db2
(main): Save errno from socket_status.
Andreas Schwab <schwab@suse.de>
parents:
53497
diff
changeset
|
776 saved_errno = errno; |
27474
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
777 } |
53693
04e9ebd16fcd
(main): Restore errno from saved_errno,
Richard M. Stallman <rms@gnu.org>
parents:
53646
diff
changeset
|
778 else |
04e9ebd16fcd
(main): Restore errno from saved_errno,
Richard M. Stallman <rms@gnu.org>
parents:
53646
diff
changeset
|
779 errno = saved_errno; |
27474
ed3668c0295a
(socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27305
diff
changeset
|
780 } |
493 | 781 } |
42176
1f5dbeefa536
Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents:
39723
diff
changeset
|
782 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
783 switch (sock_status) |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
784 { |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
785 case 1: |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
786 /* There's a socket, but it isn't owned by us. This is OK if |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
787 we are root. */ |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
788 if (0 != geteuid ()) |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
789 { |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
790 message (TRUE, "%s: Invalid socket owner\n", progname); |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
791 return INVALID_SOCKET; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
792 } |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
793 break; |
42176
1f5dbeefa536
Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents:
39723
diff
changeset
|
794 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
795 case 2: |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
796 /* `stat' failed */ |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
797 if (saved_errno == ENOENT) |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
798 message (TRUE, |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
799 "%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
|
800 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
|
801 progname); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
802 else |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
803 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
|
804 progname, server.sun_path, strerror (saved_errno)); |
73765
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
805 return INVALID_SOCKET; |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
806 } |
493 | 807 } |
412 | 808 |
3595
e10f7473d2e3
* emacsserver.c (main): When we're passing a `struct sockaddr_un'
Jim Blandy <jimb@redhat.com>
parents:
1031
diff
changeset
|
809 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
|
810 < 0) |
412 | 811 { |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
812 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
|
813 return INVALID_SOCKET; |
412 | 814 } |
15758
7e712d42d371
(main) [HAVE_SOCKETS]: Use two separate stdio
Richard M. Stallman <rms@gnu.org>
parents:
14610
diff
changeset
|
815 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
816 return s; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
817 } |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
818 #endif /* ! NO_SOCKETS_IN_FILE_SYSTEM */ |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
819 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
820 HSOCKET |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
821 set_socket () |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
822 { |
73765
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
823 HSOCKET s; |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
824 |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
825 INITIALIZE (); |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
826 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
827 #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
|
828 /* 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
|
829 if (socket_name) |
412 | 830 { |
73765
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
831 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
|
832 if ((s != INVALID_SOCKET) || alternate_editor) |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
833 return s; |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
834 |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
835 message (TRUE, "%s: error accessing socket \"%s\"", |
73765
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
836 progname, socket_name); |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
837 exit (EXIT_FAILURE); |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
838 } |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
839 #endif |
73765
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
840 |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
841 /* 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
|
842 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
|
843 server_file = getenv ("EMACS_SERVER_FILE"); |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
844 |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
845 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
|
846 { |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
847 s = set_tcp_socket (); |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
848 if ((s != INVALID_SOCKET) || alternate_editor) |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
849 return s; |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
850 |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
851 message (TRUE, "%s: error accessing server file \"%s\"", |
73765
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
852 progname, server_file); |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
853 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
|
854 } |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
855 |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
856 #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
|
857 /* 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
|
858 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
|
859 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
|
860 return s; |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
861 #endif |
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 /* 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
|
864 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
|
865 s = set_tcp_socket (); |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
866 if ((s != INVALID_SOCKET) || alternate_editor) |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
867 return s; |
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 /* No implicit or explicit socket, and no alternate editor. */ |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
870 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
|
871 #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
|
872 "\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
|
873 #endif |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
874 "\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
|
875 \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
|
876 progname); |
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
877 exit (EXIT_FAILURE); |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
878 } |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
879 |
74729
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
880 #ifdef WINDOWSNT |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
881 FARPROC set_fg; /* Pointer to AllowSetForegroundWindow. */ |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
882 FARPROC get_wc; /* Pointer to RealGetWindowClassA. */ |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
883 |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
884 BOOL CALLBACK |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
885 w32_find_emacs_process (hWnd, lParam) |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
886 HWND hWnd; |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
887 LPARAM lParam; |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
888 { |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
889 DWORD pid; |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
890 char class[6]; |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
891 |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
892 /* Reject any window not of class "Emacs". */ |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
893 if (! get_wc (hWnd, class, sizeof (class)) |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
894 || strcmp (class, "Emacs")) |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
895 return TRUE; |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
896 |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
897 /* 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
|
898 (void) GetWindowThreadProcessId (hWnd, &pid); |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
899 |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
900 /* Not the one we're looking for. */ |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
901 if (pid != (DWORD) emacs_pid) return TRUE; |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
902 |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
903 /* OK, let's raise it. */ |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
904 set_fg (emacs_pid); |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
905 |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
906 /* Stop enumeration. */ |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
907 return FALSE; |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
908 } |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
909 |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
910 /* |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
911 * 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
|
912 * 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
|
913 */ |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
914 void |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
915 w32_give_focus () |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
916 { |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
917 HMODULE hUser32; |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
918 |
75956
6ef0c279b18c
Comment changes and clarifications.
Juanma Barranquero <lekktu@gmail.com>
parents:
75348
diff
changeset
|
919 /* 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
|
920 if (!emacs_pid) return; |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
921 |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
922 if (!(hUser32 = LoadLibrary ("user32.dll"))) return; |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
923 |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
924 /* 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
|
925 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
|
926 AllowSetForegroundWindow. Unfortunately, older Windows (W95, W98 and |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
927 NT) lack this function, so we have to check its availability. */ |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
928 if ((set_fg = GetProcAddress (hUser32, "AllowSetForegroundWindow")) |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
929 && (get_wc = GetProcAddress (hUser32, "RealGetWindowClassA"))) |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
930 EnumWindows (w32_find_emacs_process, (LPARAM) 0); |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
931 |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
932 FreeLibrary (hUser32); |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
933 } |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
934 #endif |
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
935 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
936 int |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
937 main (argc, argv) |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
938 int argc; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
939 char **argv; |
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 HSOCKET s; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
942 int i, rl, needlf = 0; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
943 char *cwd; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
944 char string[BUFSIZ+1]; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
945 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
946 progname = argv[0]; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
947 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
948 /* Process options. */ |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
949 decode_options (argc, argv); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
950 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
951 if ((argc - optind < 1) && !eval) |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
952 { |
74118
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
953 message (TRUE, "%s: file name or argument required\nTry `%s --help' for more information\n", |
bee73d83d967
Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents:
73978
diff
changeset
|
954 progname, progname); |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
955 exit (EXIT_FAILURE); |
412 | 956 } |
957 | |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
958 if ((s = set_socket ()) == INVALID_SOCKET) |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
959 fail (argc, argv); |
15758
7e712d42d371
(main) [HAVE_SOCKETS]: Use two separate stdio
Richard M. Stallman <rms@gnu.org>
parents:
14610
diff
changeset
|
960 |
48617
802b2a15e451
(main): Test HAVE_GETCWD rather than BSD_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents:
47717
diff
changeset
|
961 #ifdef HAVE_GETCWD |
802b2a15e451
(main): Test HAVE_GETCWD rather than BSD_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents:
47717
diff
changeset
|
962 cwd = getcwd (string, sizeof string); |
802b2a15e451
(main): Test HAVE_GETCWD rather than BSD_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents:
47717
diff
changeset
|
963 #else |
412 | 964 cwd = getwd (string); |
11030
3345f6426f49
Use BSD sockets whenever available, even if HAVE_SYSVIPC.
Richard M. Stallman <rms@gnu.org>
parents:
10124
diff
changeset
|
965 #endif |
412 | 966 if (cwd == 0) |
967 { | |
968 /* getwd puts message in STRING if it fails. */ | |
74342
c6cb776ffbb7
(emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
74341
diff
changeset
|
969 message (TRUE, "%s: %s (%s)\n", progname, |
48617
802b2a15e451
(main): Test HAVE_GETCWD rather than BSD_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents:
47717
diff
changeset
|
970 #ifdef HAVE_GETCWD |
74342
c6cb776ffbb7
(emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
74341
diff
changeset
|
971 "Cannot get current working directory", |
48617
802b2a15e451
(main): Test HAVE_GETCWD rather than BSD_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents:
47717
diff
changeset
|
972 #else |
74342
c6cb776ffbb7
(emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
74341
diff
changeset
|
973 string, |
19582
1289a4779e68
[HAVE_SYSVIPC]: Include errno.h, as in the other case.
Richard M. Stallman <rms@gnu.org>
parents:
18701
diff
changeset
|
974 #endif |
74342
c6cb776ffbb7
(emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
74341
diff
changeset
|
975 strerror (errno)); |
27305
4161adef5fd3
Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
976 fail (argc, argv); |
412 | 977 } |
978 | |
74342
c6cb776ffbb7
(emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
74341
diff
changeset
|
979 #ifdef WINDOWSNT |
74729
303099bc66d9
[WINDOWSNT] (set_fg, get_wc): New variables.
Juanma Barranquero <lekktu@gmail.com>
parents:
74645
diff
changeset
|
980 w32_give_focus (); |
74342
c6cb776ffbb7
(emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
74341
diff
changeset
|
981 #endif |
c6cb776ffbb7
(emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
74341
diff
changeset
|
982 |
16061
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
983 if (nowait) |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
984 SEND_STRING ("-nowait "); |
16061
a1290c4159b5
(quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16030
diff
changeset
|
985 |
47647
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
986 if (eval) |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
987 SEND_STRING ("-eval "); |
47647
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
988 |
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
989 if (display) |
412 | 990 { |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
991 SEND_STRING ("-display "); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
992 SEND_QUOTED (display); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
993 SEND_STRING (" "); |
52635
9963e9da5850
(quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents:
52532
diff
changeset
|
994 } |
9963e9da5850
(quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents:
52532
diff
changeset
|
995 |
9963e9da5850
(quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents:
52532
diff
changeset
|
996 if ((argc - optind > 0)) |
9963e9da5850
(quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents:
52532
diff
changeset
|
997 { |
9963e9da5850
(quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents:
52532
diff
changeset
|
998 for (i = optind; i < argc; i++) |
412 | 999 { |
52635
9963e9da5850
(quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents:
52532
diff
changeset
|
1000 if (eval) |
9963e9da5850
(quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents:
52532
diff
changeset
|
1001 ; /* Don't prepend any cwd or anything like that. */ |
9963e9da5850
(quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents:
52532
diff
changeset
|
1002 else if (*argv[i] == '+') |
9963e9da5850
(quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents:
52532
diff
changeset
|
1003 { |
9963e9da5850
(quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents:
52532
diff
changeset
|
1004 char *p = argv[i] + 1; |
9963e9da5850
(quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents:
52532
diff
changeset
|
1005 while (isdigit ((unsigned char) *p) || *p == ':') p++; |
9963e9da5850
(quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents:
52532
diff
changeset
|
1006 if (*p != 0) |
9963e9da5850
(quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents:
52532
diff
changeset
|
1007 { |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1008 SEND_QUOTED (cwd); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1009 SEND_STRING ("/"); |
52635
9963e9da5850
(quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents:
52532
diff
changeset
|
1010 } |
9963e9da5850
(quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents:
52532
diff
changeset
|
1011 } |
73765
bcb5c0f9a466
(longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents:
73657
diff
changeset
|
1012 else if (! file_name_absolute_p (argv[i])) |
52635
9963e9da5850
(quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents:
52532
diff
changeset
|
1013 { |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1014 SEND_QUOTED (cwd); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1015 SEND_STRING ("/"); |
52635
9963e9da5850
(quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents:
52532
diff
changeset
|
1016 } |
9963e9da5850
(quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents:
52532
diff
changeset
|
1017 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1018 SEND_QUOTED (argv[i]); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1019 SEND_STRING (" "); |
412 | 1020 } |
1021 } | |
52635
9963e9da5850
(quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents:
52532
diff
changeset
|
1022 else |
9963e9da5850
(quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents:
52532
diff
changeset
|
1023 { |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1024 while (fgets (string, BUFSIZ, stdin)) |
52635
9963e9da5850
(quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents:
52532
diff
changeset
|
1025 { |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1026 SEND_QUOTED (string); |
52635
9963e9da5850
(quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents:
52532
diff
changeset
|
1027 } |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1028 SEND_STRING (" "); |
52635
9963e9da5850
(quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents:
52532
diff
changeset
|
1029 } |
55442
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
53813
diff
changeset
|
1030 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1031 SEND_STRING ("\n"); |
412 | 1032 |
15995
7284f973fc42
(both versions): Handle -nowait and --nowait by sending data to the server.
Richard M. Stallman <rms@gnu.org>
parents:
15758
diff
changeset
|
1033 /* Maybe wait for an answer. */ |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1034 if (!nowait) |
47647
5498210ad40d
Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47515
diff
changeset
|
1035 { |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1036 if (!eval) |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1037 { |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1038 printf ("Waiting for Emacs..."); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1039 needlf = 2; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1040 } |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1041 fflush (stdout); |
412 | 1042 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1043 /* Now, wait for an answer and print any messages. */ |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1044 while ((rl = recv (s, string, BUFSIZ, 0)) > 0) |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1045 { |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1046 string[rl] = '\0'; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1047 if (needlf == 2) |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1048 printf ("\n"); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1049 printf ("%s", string); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1050 needlf = string[0] == '\0' ? needlf : string[strlen (string) - 1] != '\n'; |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1051 } |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1052 |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1053 if (needlf) |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1054 printf ("\n"); |
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1055 fflush (stdout); |
47515
6ee937dcfe16
(quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42412
diff
changeset
|
1056 } |
42176
1f5dbeefa536
Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents:
39723
diff
changeset
|
1057 |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1058 CLOSE_SOCKET (s); |
55442
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
53813
diff
changeset
|
1059 return EXIT_SUCCESS; |
412 | 1060 } |
1061 | |
73617
7af864af10b6
[WINDOWSNT]: Define HAVE_INET_SOCKETS.
Juanma Barranquero <lekktu@gmail.com>
parents:
73601
diff
changeset
|
1062 #endif /* HAVE_SOCKETS && HAVE_INET_SOCKETS */ |
73562
368665ce6f35
Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents:
72005
diff
changeset
|
1063 |
5527
51451a050975
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5522
diff
changeset
|
1064 #ifndef HAVE_STRERROR |
51451a050975
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5522
diff
changeset
|
1065 char * |
51451a050975
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5522
diff
changeset
|
1066 strerror (errnum) |
51451a050975
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5522
diff
changeset
|
1067 int errnum; |
51451a050975
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5522
diff
changeset
|
1068 { |
51451a050975
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5522
diff
changeset
|
1069 extern char *sys_errlist[]; |
51451a050975
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5522
diff
changeset
|
1070 extern int sys_nerr; |
51451a050975
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5522
diff
changeset
|
1071 |
51451a050975
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5522
diff
changeset
|
1072 if (errnum >= 0 && errnum < sys_nerr) |
51451a050975
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5522
diff
changeset
|
1073 return sys_errlist[errnum]; |
51451a050975
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5522
diff
changeset
|
1074 return (char *) "Unknown error"; |
51451a050975
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5522
diff
changeset
|
1075 } |
51451a050975
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5522
diff
changeset
|
1076 |
51451a050975
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5522
diff
changeset
|
1077 #endif /* ! HAVE_STRERROR */ |
52401 | 1078 |
1079 /* arch-tag: f39bb9c4-73eb-477e-896d-50832e2ca9a7 | |
1080 (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
|
1081 |
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
53813
diff
changeset
|
1082 /* emacsclient.c ends here */ |