1992-01-14 08:05:08 +00:00
|
|
|
|
/* Client process that communicates with GNU Emacs acting as server.
|
2005-08-07 10:56:27 +00:00
|
|
|
|
Copyright (C) 1986, 1987, 1994, 1999, 2000, 2001, 2002, 2003, 2004,
|
2006-02-06 11:28:28 +00:00
|
|
|
|
2005, 2006 Free Software Foundation, Inc.
|
1991-09-02 20:23:32 +00:00
|
|
|
|
|
|
|
|
|
This file is part of GNU Emacs.
|
|
|
|
|
|
|
|
|
|
GNU Emacs is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
1994-01-08 21:43:57 +00:00
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
1991-09-02 20:23:32 +00:00
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
|
|
GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with GNU Emacs; see the file COPYING. If not, write to
|
2005-07-04 15:47:28 +00:00
|
|
|
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
|
Boston, MA 02110-1301, USA. */
|
1991-09-02 20:23:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define NO_SHORTNAMES
|
2001-12-19 07:21:17 +00:00
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
2001-12-29 22:25:06 +00:00
|
|
|
|
#include <config.h>
|
2001-12-19 07:21:17 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
#ifdef WINDOWSNT
|
|
|
|
|
|
2006-11-13 10:59:04 +00:00
|
|
|
|
/* config.h defines these, which disables sockets altogether! */
|
|
|
|
|
# undef _WINSOCKAPI_
|
|
|
|
|
# undef _WINSOCK_H
|
|
|
|
|
|
2006-10-31 16:40:11 +00:00
|
|
|
|
# include <malloc.h>
|
|
|
|
|
# include <stdlib.h>
|
2006-11-22 14:19:35 +00:00
|
|
|
|
# include <windows.h>
|
2006-10-31 16:40:11 +00:00
|
|
|
|
|
|
|
|
|
# define NO_SOCKETS_IN_FILE_SYSTEM
|
|
|
|
|
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
# define HSOCKET SOCKET
|
|
|
|
|
# define CLOSE_SOCKET closesocket
|
|
|
|
|
# define INITIALIZE() (initialize_sockets ())
|
2006-10-31 16:40:11 +00:00
|
|
|
|
|
|
|
|
|
#else /* !WINDOWSNT */
|
|
|
|
|
|
2006-11-10 15:44:40 +00:00
|
|
|
|
# include <sys/types.h>
|
|
|
|
|
|
2006-11-02 09:55:33 +00:00
|
|
|
|
# ifdef HAVE_INET_SOCKETS
|
|
|
|
|
# include <netinet/in.h>
|
|
|
|
|
# endif
|
2006-10-31 16:40:11 +00:00
|
|
|
|
|
2006-10-31 09:08:24 +00:00
|
|
|
|
# define INVALID_SOCKET -1
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
# define HSOCKET int
|
|
|
|
|
# define CLOSE_SOCKET close
|
|
|
|
|
# define INITIALIZE()
|
2006-10-31 16:40:11 +00:00
|
|
|
|
|
|
|
|
|
#endif /* !WINDOWSNT */
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
|
1993-06-09 12:45:26 +00:00
|
|
|
|
#undef signal
|
1991-09-02 20:23:32 +00:00
|
|
|
|
|
2006-11-22 14:19:35 +00:00
|
|
|
|
#include <stdarg.h>
|
2001-12-19 07:21:17 +00:00
|
|
|
|
#include <ctype.h>
|
1996-09-01 18:25:21 +00:00
|
|
|
|
#include <stdio.h>
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
#include "getopt.h"
|
1998-04-08 17:31:45 +00:00
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#endif
|
1996-09-01 18:25:21 +00:00
|
|
|
|
|
2000-01-28 15:02:20 +00:00
|
|
|
|
#ifdef VMS
|
|
|
|
|
# include "vms-pwd.h"
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
#else /* not VMS */
|
|
|
|
|
#ifdef WINDOWSNT
|
|
|
|
|
# include <io.h>
|
|
|
|
|
#else /* not WINDOWSNT */
|
2000-01-28 15:02:20 +00:00
|
|
|
|
# include <pwd.h>
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
#endif /* not WINDOWSNT */
|
2000-01-28 15:02:20 +00:00
|
|
|
|
#endif /* not VMS */
|
|
|
|
|
|
1996-09-01 18:25:21 +00:00
|
|
|
|
char *getenv (), *getwd ();
|
2005-03-18 20:44:50 +00:00
|
|
|
|
char *(getcwd) ();
|
1996-09-01 18:25:21 +00:00
|
|
|
|
|
|
|
|
|
#ifndef VERSION
|
|
|
|
|
#define VERSION "unspecified"
|
|
|
|
|
#endif
|
|
|
|
|
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
#define SEND_STRING(data) (send_to_emacs (s, (data)))
|
|
|
|
|
#define SEND_QUOTED(data) (quote_file_name (s, (data)))
|
|
|
|
|
|
|
|
|
|
#ifndef EXIT_SUCCESS
|
|
|
|
|
#define EXIT_SUCCESS 0
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef EXIT_FAILURE
|
|
|
|
|
#define EXIT_FAILURE 1
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef FALSE
|
|
|
|
|
#define FALSE 0
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef TRUE
|
|
|
|
|
#define TRUE 1
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef NO_RETURN
|
|
|
|
|
#define NO_RETURN
|
|
|
|
|
#endif
|
|
|
|
|
|
1996-09-01 18:25:21 +00:00
|
|
|
|
/* Name used to invoke this program. */
|
|
|
|
|
char *progname;
|
|
|
|
|
|
1996-09-10 02:00:27 +00:00
|
|
|
|
/* Nonzero means don't wait for a response from Emacs. --no-wait. */
|
1996-09-01 18:25:21 +00:00
|
|
|
|
int nowait = 0;
|
|
|
|
|
|
2002-09-27 18:21:44 +00:00
|
|
|
|
/* Nonzero means args are expressions to be evaluated. --eval. */
|
|
|
|
|
int eval = 0;
|
|
|
|
|
|
|
|
|
|
/* The display on which Emacs should work. --display. */
|
|
|
|
|
char *display = NULL;
|
|
|
|
|
|
|
|
|
|
/* If non-NULL, the name of an editor to fallback to if the server
|
|
|
|
|
is not running. --alternate-editor. */
|
2006-11-06 12:41:49 +00:00
|
|
|
|
const char *alternate_editor = NULL;
|
2002-09-27 18:21:44 +00:00
|
|
|
|
|
2003-09-19 14:27:47 +00:00
|
|
|
|
/* If non-NULL, the filename of the UNIX socket. */
|
2003-09-12 00:48:03 +00:00
|
|
|
|
char *socket_name = NULL;
|
|
|
|
|
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
/* If non-NULL, the filename of the authentication file. */
|
|
|
|
|
char *server_file = NULL;
|
|
|
|
|
|
2006-11-30 22:49:38 +00:00
|
|
|
|
/* PID of the Emacs server process. */
|
|
|
|
|
int emacs_pid = 0;
|
|
|
|
|
|
2006-07-18 16:33:45 +00:00
|
|
|
|
void print_help_and_exit () NO_RETURN;
|
1998-04-06 10:13:46 +00:00
|
|
|
|
|
1996-09-01 18:25:21 +00:00
|
|
|
|
struct option longopts[] =
|
|
|
|
|
{
|
1996-09-10 02:00:27 +00:00
|
|
|
|
{ "no-wait", no_argument, NULL, 'n' },
|
2002-09-27 18:21:44 +00:00
|
|
|
|
{ "eval", no_argument, NULL, 'e' },
|
1996-09-01 18:25:21 +00:00
|
|
|
|
{ "help", no_argument, NULL, 'H' },
|
|
|
|
|
{ "version", no_argument, NULL, 'V' },
|
2002-09-18 01:44:54 +00:00
|
|
|
|
{ "alternate-editor", required_argument, NULL, 'a' },
|
2006-11-06 12:41:49 +00:00
|
|
|
|
#ifndef NO_SOCKETS_IN_FILE_SYSTEM
|
2003-09-12 00:48:03 +00:00
|
|
|
|
{ "socket-name", required_argument, NULL, 's' },
|
2006-11-06 12:41:49 +00:00
|
|
|
|
#endif
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
{ "server-file", required_argument, NULL, 'f' },
|
2002-09-27 18:21:44 +00:00
|
|
|
|
{ "display", required_argument, NULL, 'd' },
|
|
|
|
|
{ 0, 0, 0, 0 }
|
1996-09-01 18:25:21 +00:00
|
|
|
|
};
|
|
|
|
|
|
2006-11-22 14:19:35 +00:00
|
|
|
|
/* Message functions. */
|
|
|
|
|
|
|
|
|
|
#ifdef WINDOWSNT
|
|
|
|
|
/* I first tried to check for STDOUT. The check did not work,
|
|
|
|
|
I get a valid handle also in nonconsole apps.
|
|
|
|
|
Instead I test for console title, which seems to work. */
|
|
|
|
|
int
|
|
|
|
|
w32_window_app()
|
|
|
|
|
{
|
|
|
|
|
static int window_app = -1;
|
|
|
|
|
char szTitle[MAX_PATH];
|
|
|
|
|
|
|
|
|
|
if (window_app < 0)
|
|
|
|
|
window_app = (GetConsoleTitleA (szTitle, MAX_PATH) == 0);
|
|
|
|
|
|
|
|
|
|
return window_app;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
message (int is_error, char *message, ...)
|
|
|
|
|
{
|
2006-11-30 22:49:38 +00:00
|
|
|
|
char msg [2048];
|
2006-11-22 14:19:35 +00:00
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
|
|
va_start (args, message);
|
|
|
|
|
vsprintf (msg, message, args);
|
|
|
|
|
va_end (args);
|
|
|
|
|
|
|
|
|
|
#ifdef WINDOWSNT
|
|
|
|
|
if (w32_window_app ())
|
|
|
|
|
{
|
|
|
|
|
if (is_error)
|
|
|
|
|
MessageBox (NULL, msg, "Emacsclient ERROR", MB_ICONERROR);
|
|
|
|
|
else
|
|
|
|
|
MessageBox (NULL, msg, "Emacsclient", MB_ICONINFORMATION);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
#endif
|
2006-11-30 21:58:53 +00:00
|
|
|
|
{
|
|
|
|
|
FILE *f = is_error ? stderr : stdout;
|
|
|
|
|
|
|
|
|
|
fputs (msg, f);
|
|
|
|
|
fflush (f);
|
|
|
|
|
}
|
2006-11-22 14:19:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-09-01 18:25:21 +00:00
|
|
|
|
/* Decode the options from argv and argc.
|
1996-09-02 00:05:56 +00:00
|
|
|
|
The global variable `optind' will say how many arguments we used up. */
|
1996-09-01 18:25:21 +00:00
|
|
|
|
|
1996-09-02 00:05:56 +00:00
|
|
|
|
void
|
1996-09-01 18:25:21 +00:00
|
|
|
|
decode_options (argc, argv)
|
|
|
|
|
int argc;
|
|
|
|
|
char **argv;
|
|
|
|
|
{
|
2004-02-05 00:02:04 +00:00
|
|
|
|
alternate_editor = getenv ("ALTERNATE_EDITOR");
|
|
|
|
|
|
1996-09-01 18:25:21 +00:00
|
|
|
|
while (1)
|
|
|
|
|
{
|
|
|
|
|
int opt = getopt_long (argc, argv,
|
2006-11-06 12:41:49 +00:00
|
|
|
|
#ifndef NO_SOCKETS_IN_FILE_SYSTEM
|
|
|
|
|
"VHnea:s:f:d:",
|
|
|
|
|
#else
|
|
|
|
|
"VHnea:f:d:",
|
|
|
|
|
#endif
|
|
|
|
|
longopts, 0);
|
1996-09-01 18:25:21 +00:00
|
|
|
|
|
|
|
|
|
if (opt == EOF)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
switch (opt)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
/* If getopt returns 0, then it has already processed a
|
|
|
|
|
long-named option. We should do nothing. */
|
|
|
|
|
break;
|
2001-12-19 07:21:17 +00:00
|
|
|
|
|
2000-01-12 13:38:54 +00:00
|
|
|
|
case 'a':
|
|
|
|
|
alternate_editor = optarg;
|
|
|
|
|
break;
|
2001-12-19 07:21:17 +00:00
|
|
|
|
|
2006-11-06 12:41:49 +00:00
|
|
|
|
#ifndef NO_SOCKETS_IN_FILE_SYSTEM
|
2003-09-12 00:48:03 +00:00
|
|
|
|
case 's':
|
|
|
|
|
socket_name = optarg;
|
|
|
|
|
break;
|
2006-11-06 12:41:49 +00:00
|
|
|
|
#endif
|
2003-09-12 00:48:03 +00:00
|
|
|
|
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
case 'f':
|
|
|
|
|
server_file = optarg;
|
|
|
|
|
break;
|
|
|
|
|
|
2002-09-27 18:21:44 +00:00
|
|
|
|
case 'd':
|
|
|
|
|
display = optarg;
|
|
|
|
|
break;
|
|
|
|
|
|
1996-09-01 18:25:21 +00:00
|
|
|
|
case 'n':
|
|
|
|
|
nowait = 1;
|
|
|
|
|
break;
|
|
|
|
|
|
2002-09-27 18:21:44 +00:00
|
|
|
|
case 'e':
|
|
|
|
|
eval = 1;
|
|
|
|
|
break;
|
|
|
|
|
|
1996-09-01 18:25:21 +00:00
|
|
|
|
case 'V':
|
2006-11-22 14:19:35 +00:00
|
|
|
|
message (FALSE, "emacsclient %s\n", VERSION);
|
2004-05-08 15:26:33 +00:00
|
|
|
|
exit (EXIT_SUCCESS);
|
1996-09-01 18:25:21 +00:00
|
|
|
|
break;
|
1991-09-02 20:23:32 +00:00
|
|
|
|
|
1996-09-01 18:25:21 +00:00
|
|
|
|
case 'H':
|
|
|
|
|
print_help_and_exit ();
|
2003-03-12 21:36:29 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
2006-11-22 14:19:35 +00:00
|
|
|
|
message (TRUE, "Try `%s --help' for more information\n", progname);
|
2004-05-08 15:26:33 +00:00
|
|
|
|
exit (EXIT_FAILURE);
|
2003-03-12 21:36:29 +00:00
|
|
|
|
break;
|
1996-09-01 18:25:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1998-04-06 10:13:46 +00:00
|
|
|
|
void
|
1996-09-01 18:25:21 +00:00
|
|
|
|
print_help_and_exit ()
|
|
|
|
|
{
|
2006-11-22 14:19:35 +00:00
|
|
|
|
message (FALSE,
|
2003-03-12 21:36:29 +00:00
|
|
|
|
"Usage: %s [OPTIONS] FILE...\n\
|
2002-09-27 18:21:44 +00:00
|
|
|
|
Tell the Emacs server to visit the specified files.\n\
|
|
|
|
|
Every FILE can be either just a FILENAME or [+LINE[:COLUMN]] FILENAME.\n\
|
2003-03-12 21:36:29 +00:00
|
|
|
|
\n\
|
2002-09-27 18:21:44 +00:00
|
|
|
|
The following OPTIONS are accepted:\n\
|
2006-11-23 01:51:38 +00:00
|
|
|
|
\n\
|
|
|
|
|
-V, --version Just print version info and return\n\
|
|
|
|
|
-H, --help Print this usage information message\n\
|
|
|
|
|
-e, --eval Evaluate FILE arguments as Lisp expressions\n\
|
|
|
|
|
-n, --no-wait Don't wait for the server to return\n\
|
|
|
|
|
-d, --display=DISPLAY Visit the file in the given display\n"
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
#ifndef NO_SOCKETS_IN_FILE_SYSTEM
|
|
|
|
|
"-s, --socket-name=FILENAME\n\
|
2006-11-23 01:51:38 +00:00
|
|
|
|
Set filename of the UNIX socket for communication\n"
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
#endif
|
|
|
|
|
"-f, --server-file=FILENAME\n\
|
2006-11-23 01:51:38 +00:00
|
|
|
|
Set filename of the TCP authentication file\n\
|
2002-09-27 18:21:44 +00:00
|
|
|
|
-a, --alternate-editor=EDITOR\n\
|
2006-11-23 01:51:38 +00:00
|
|
|
|
Editor to fallback to if server is not running\n\
|
2003-03-12 21:36:29 +00:00
|
|
|
|
\n\
|
2002-09-27 18:21:44 +00:00
|
|
|
|
Report bugs to bug-gnu-emacs@gnu.org.\n", progname);
|
2004-05-08 15:26:33 +00:00
|
|
|
|
exit (EXIT_SUCCESS);
|
1996-09-01 18:25:21 +00:00
|
|
|
|
}
|
1996-09-02 00:05:56 +00:00
|
|
|
|
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
|
2006-12-15 14:53:44 +00:00
|
|
|
|
#ifdef WINDOWSNT
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
execvp() wrapper for Windows. Quotes arguments with embedded spaces.
|
|
|
|
|
|
|
|
|
|
This is necessary due to the broken implementation of exec* routines in
|
|
|
|
|
the Microsoft libraries: they concatenate the arguments together without
|
|
|
|
|
quoting special characters, and pass the result to CreateProcess, with
|
|
|
|
|
predictably bad results. By contrast, Posix execvp passes the arguments
|
|
|
|
|
directly into the argv[] array of the child process.
|
|
|
|
|
*/
|
|
|
|
|
int
|
|
|
|
|
w32_execvp (path, argv)
|
|
|
|
|
char *path;
|
|
|
|
|
char **argv;
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
argv[0] = (char *) alternate_editor;
|
|
|
|
|
|
|
|
|
|
for (i = 0; argv[i]; i++)
|
|
|
|
|
if (strchr (argv[i], ' '))
|
|
|
|
|
{
|
|
|
|
|
char *quoted = alloca (strlen (argv[i]) + 3);
|
|
|
|
|
sprintf (quoted, "\"%s\"", argv[i]);
|
|
|
|
|
argv[i] = quoted;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return execvp (path, argv);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#undef execvp
|
|
|
|
|
#define execvp w32_execvp
|
|
|
|
|
|
|
|
|
|
#endif /* WINDOWSNT */
|
|
|
|
|
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
/*
|
|
|
|
|
Try to run a different command, or --if no alternate editor is
|
|
|
|
|
defined-- exit with an errorcode.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
fail (argc, argv)
|
|
|
|
|
int argc;
|
|
|
|
|
char **argv;
|
|
|
|
|
{
|
|
|
|
|
if (alternate_editor)
|
|
|
|
|
{
|
|
|
|
|
int i = optind - 1;
|
2006-12-15 14:53:44 +00:00
|
|
|
|
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
execvp (alternate_editor, argv + i);
|
2006-11-22 14:19:35 +00:00
|
|
|
|
message (TRUE, "%s: error executing alternate editor \"%s\"\n",
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
progname, alternate_editor);
|
|
|
|
|
}
|
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-11-02 09:55:33 +00:00
|
|
|
|
#if !defined (HAVE_SOCKETS) || !defined (HAVE_INET_SOCKETS)
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
main (argc, argv)
|
|
|
|
|
int argc;
|
|
|
|
|
char **argv;
|
|
|
|
|
{
|
2006-11-22 14:19:35 +00:00
|
|
|
|
message (TRUE, "%s: Sorry, the Emacs server is supported only\non systems with Berkely sockets.\n",
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
argv[0]);
|
|
|
|
|
|
|
|
|
|
fail (argc, argv);
|
|
|
|
|
}
|
|
|
|
|
|
2006-11-02 09:55:33 +00:00
|
|
|
|
#else /* HAVE_SOCKETS && HAVE_INET_SOCKETS */
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
|
|
|
|
|
#ifdef WINDOWSNT
|
|
|
|
|
# include <winsock2.h>
|
|
|
|
|
#else
|
|
|
|
|
# include <sys/types.h>
|
|
|
|
|
# include <sys/socket.h>
|
|
|
|
|
# include <sys/un.h>
|
|
|
|
|
# include <sys/stat.h>
|
|
|
|
|
# include <errno.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#define AUTH_KEY_LENGTH 64
|
|
|
|
|
#define SEND_BUFFER_SIZE 4096
|
|
|
|
|
|
|
|
|
|
extern char *strerror ();
|
|
|
|
|
extern int errno;
|
|
|
|
|
|
|
|
|
|
/* Buffer to accumulate data to send in TCP connections. */
|
|
|
|
|
char send_buffer[SEND_BUFFER_SIZE + 1];
|
|
|
|
|
int sblen = 0; /* Fill pointer for the send buffer. */
|
|
|
|
|
|
|
|
|
|
/* Let's send the data to Emacs when either
|
|
|
|
|
- the data ends in "\n", or
|
|
|
|
|
- the buffer is full (but this shouldn't happen)
|
|
|
|
|
Otherwise, we just accumulate it. */
|
2006-11-06 12:41:49 +00:00
|
|
|
|
void
|
|
|
|
|
send_to_emacs (s, data)
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
HSOCKET s;
|
|
|
|
|
char *data;
|
|
|
|
|
{
|
|
|
|
|
while (data)
|
|
|
|
|
{
|
|
|
|
|
int dlen = strlen (data);
|
|
|
|
|
if (dlen + sblen >= SEND_BUFFER_SIZE)
|
|
|
|
|
{
|
|
|
|
|
int part = SEND_BUFFER_SIZE - sblen;
|
|
|
|
|
strncpy (&send_buffer[sblen], data, part);
|
|
|
|
|
data += part;
|
|
|
|
|
sblen = SEND_BUFFER_SIZE;
|
|
|
|
|
}
|
|
|
|
|
else if (dlen)
|
|
|
|
|
{
|
|
|
|
|
strcpy (&send_buffer[sblen], data);
|
|
|
|
|
data = NULL;
|
|
|
|
|
sblen += dlen;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (sblen == SEND_BUFFER_SIZE
|
|
|
|
|
|| (sblen > 0 && send_buffer[sblen-1] == '\n'))
|
|
|
|
|
{
|
|
|
|
|
int sent = send (s, send_buffer, sblen, 0);
|
|
|
|
|
if (sent != sblen)
|
|
|
|
|
strcpy (send_buffer, &send_buffer[sent]);
|
|
|
|
|
sblen -= sent;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-10-13 19:41:26 +00:00
|
|
|
|
/* In NAME, insert a & before each &, each space, each newline, and
|
|
|
|
|
any initial -. Change spaces to underscores, too, so that the
|
1996-09-02 00:05:56 +00:00
|
|
|
|
return value never contains a space. */
|
2003-09-28 08:24:56 +00:00
|
|
|
|
void
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
quote_file_name (s, name)
|
|
|
|
|
HSOCKET s;
|
1996-09-02 00:05:56 +00:00
|
|
|
|
char *name;
|
|
|
|
|
{
|
|
|
|
|
char *copy = (char *) malloc (strlen (name) * 2 + 1);
|
|
|
|
|
char *p, *q;
|
|
|
|
|
|
|
|
|
|
p = name;
|
|
|
|
|
q = copy;
|
|
|
|
|
while (*p)
|
|
|
|
|
{
|
|
|
|
|
if (*p == ' ')
|
|
|
|
|
{
|
1996-09-02 17:43:32 +00:00
|
|
|
|
*q++ = '&';
|
1996-09-02 00:05:56 +00:00
|
|
|
|
*q++ = '_';
|
|
|
|
|
p++;
|
|
|
|
|
}
|
2002-09-18 01:44:54 +00:00
|
|
|
|
else if (*p == '\n')
|
|
|
|
|
{
|
|
|
|
|
*q++ = '&';
|
|
|
|
|
*q++ = 'n';
|
|
|
|
|
p++;
|
|
|
|
|
}
|
1996-09-02 00:05:56 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
1996-09-02 17:43:32 +00:00
|
|
|
|
if (*p == '&' || (*p == '-' && p == name))
|
|
|
|
|
*q++ = '&';
|
1996-09-02 00:05:56 +00:00
|
|
|
|
*q++ = *p++;
|
|
|
|
|
}
|
|
|
|
|
}
|
1996-09-02 17:43:32 +00:00
|
|
|
|
*q++ = 0;
|
1996-09-02 00:05:56 +00:00
|
|
|
|
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
SEND_STRING (copy);
|
2003-09-28 08:24:56 +00:00
|
|
|
|
|
|
|
|
|
free (copy);
|
1996-09-02 00:05:56 +00:00
|
|
|
|
}
|
1997-07-09 19:20:34 +00:00
|
|
|
|
|
2006-11-06 12:41:49 +00:00
|
|
|
|
int
|
|
|
|
|
file_name_absolute_p (filename)
|
|
|
|
|
const unsigned char *filename;
|
|
|
|
|
{
|
|
|
|
|
/* Sanity check, it shouldn't happen. */
|
|
|
|
|
if (! filename) return FALSE;
|
|
|
|
|
|
|
|
|
|
/* /xxx is always an absolute path. */
|
|
|
|
|
if (filename[0] == '/') return TRUE;
|
|
|
|
|
|
|
|
|
|
/* Empty filenames (which shouldn't happen) are relative. */
|
|
|
|
|
if (filename[0] == '\0') return FALSE;
|
|
|
|
|
|
|
|
|
|
#ifdef WINDOWSNT
|
|
|
|
|
/* X:\xxx is always absolute; X:xxx is an error and will fail. */
|
2006-11-25 00:32:40 +00:00
|
|
|
|
if (isalpha (filename[0])
|
2006-11-24 20:59:01 +00:00
|
|
|
|
&& filename[1] == ':' && (filename[2] == '\\' || filename[2] == '/'))
|
2006-11-06 12:41:49 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
/* Both \xxx and \\xxx\yyy are absolute. */
|
|
|
|
|
if (filename[0] == '\\') return TRUE;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
#ifdef WINDOWSNT
|
2006-11-24 10:31:26 +00:00
|
|
|
|
/* Wrapper to make WSACleanup a cdecl, as required by atexit(). */
|
2006-11-06 12:41:49 +00:00
|
|
|
|
void
|
|
|
|
|
__cdecl close_winsock ()
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
{
|
|
|
|
|
WSACleanup ();
|
|
|
|
|
}
|
1997-07-09 19:20:34 +00:00
|
|
|
|
|
2006-11-06 12:41:49 +00:00
|
|
|
|
/* Initialize the WinSock2 library. */
|
|
|
|
|
void
|
|
|
|
|
initialize_sockets ()
|
1997-07-09 19:20:34 +00:00
|
|
|
|
{
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
WSADATA wsaData;
|
|
|
|
|
|
|
|
|
|
if (WSAStartup (MAKEWORD (2, 0), &wsaData))
|
|
|
|
|
{
|
2006-11-22 14:19:35 +00:00
|
|
|
|
message (TRUE, "%s: error initializing WinSock2", progname);
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
atexit (close_winsock);
|
1997-07-09 19:20:34 +00:00
|
|
|
|
}
|
2006-10-31 09:08:24 +00:00
|
|
|
|
#endif /* WINDOWSNT */
|
2000-01-12 13:38:54 +00:00
|
|
|
|
|
|
|
|
|
/*
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
* Read the information needed to set up a TCP comm channel with
|
2006-11-07 10:43:45 +00:00
|
|
|
|
* the Emacs server: host, port, pid and authentication string.
|
2000-01-12 13:38:54 +00:00
|
|
|
|
*/
|
2006-11-06 12:41:49 +00:00
|
|
|
|
int
|
|
|
|
|
get_server_config (server, authentication)
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
struct sockaddr_in *server;
|
|
|
|
|
char *authentication;
|
2000-01-12 13:38:54 +00:00
|
|
|
|
{
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
char dotted[32];
|
|
|
|
|
char *port;
|
2006-11-07 10:43:45 +00:00
|
|
|
|
char *pid;
|
2006-11-06 12:41:49 +00:00
|
|
|
|
FILE *config = NULL;
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
|
2006-11-06 12:41:49 +00:00
|
|
|
|
if (file_name_absolute_p (server_file))
|
|
|
|
|
config = fopen (server_file, "rb");
|
|
|
|
|
else
|
2000-01-12 13:38:54 +00:00
|
|
|
|
{
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
char *home = getenv ("HOME");
|
2006-11-07 11:23:12 +00:00
|
|
|
|
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
if (home)
|
|
|
|
|
{
|
|
|
|
|
char *path = alloca (32 + strlen (home) + strlen (server_file));
|
|
|
|
|
sprintf (path, "%s/.emacs.d/server/%s", home, server_file);
|
|
|
|
|
config = fopen (path, "rb");
|
|
|
|
|
}
|
2006-11-07 11:23:12 +00:00
|
|
|
|
#ifdef WINDOWSNT
|
|
|
|
|
if (!config && (home = getenv ("APPDATA")))
|
|
|
|
|
{
|
|
|
|
|
char *path = alloca (32 + strlen (home) + strlen (server_file));
|
|
|
|
|
sprintf (path, "%s/.emacs.d/server/%s", home, server_file);
|
|
|
|
|
config = fopen (path, "rb");
|
|
|
|
|
}
|
|
|
|
|
#endif
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (! config)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (fgets (dotted, sizeof dotted, config)
|
2006-11-07 10:43:45 +00:00
|
|
|
|
&& (port = strchr (dotted, ':'))
|
|
|
|
|
&& (pid = strchr (port, ' ')))
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
{
|
|
|
|
|
*port++ = '\0';
|
2006-11-07 10:43:45 +00:00
|
|
|
|
*pid++ = '\0';
|
2000-01-12 13:38:54 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2006-11-22 14:19:35 +00:00
|
|
|
|
message (TRUE, "%s: invalid configuration info", progname);
|
2004-05-08 15:26:33 +00:00
|
|
|
|
exit (EXIT_FAILURE);
|
2000-01-12 13:38:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
server->sin_family = AF_INET;
|
|
|
|
|
server->sin_addr.s_addr = inet_addr (dotted);
|
|
|
|
|
server->sin_port = htons (atoi (port));
|
2000-01-12 13:38:54 +00:00
|
|
|
|
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
if (! fread (authentication, AUTH_KEY_LENGTH, 1, config))
|
|
|
|
|
{
|
2006-11-22 14:19:35 +00:00
|
|
|
|
message (TRUE, "%s: cannot read authentication info", progname);
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
|
}
|
1991-09-02 20:23:32 +00:00
|
|
|
|
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
fclose (config);
|
2000-01-12 13:38:54 +00:00
|
|
|
|
|
2006-11-30 22:49:38 +00:00
|
|
|
|
emacs_pid = atoi (pid);
|
2006-11-07 10:43:45 +00:00
|
|
|
|
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
return TRUE;
|
1991-09-02 20:23:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
HSOCKET
|
|
|
|
|
set_tcp_socket ()
|
|
|
|
|
{
|
|
|
|
|
HSOCKET s;
|
|
|
|
|
struct sockaddr_in server;
|
|
|
|
|
struct linger l_arg = {1, 1};
|
|
|
|
|
char auth_string[AUTH_KEY_LENGTH + 1];
|
1991-09-02 20:23:32 +00:00
|
|
|
|
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
if (! get_server_config (&server, auth_string))
|
|
|
|
|
return INVALID_SOCKET;
|
|
|
|
|
|
2006-11-06 12:41:49 +00:00
|
|
|
|
if (server.sin_addr.s_addr != inet_addr ("127.0.0.1"))
|
2006-11-30 21:58:53 +00:00
|
|
|
|
message (FALSE, "%s: connected to remote socket at %s\n",
|
2006-11-06 12:41:49 +00:00
|
|
|
|
progname, inet_ntoa (server.sin_addr));
|
|
|
|
|
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
/*
|
|
|
|
|
* Open up an AF_INET socket
|
|
|
|
|
*/
|
|
|
|
|
if ((s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
|
|
|
|
|
{
|
2006-11-22 14:19:35 +00:00
|
|
|
|
message (TRUE, "%s: socket: %s\n", progname, strerror (errno));
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
return INVALID_SOCKET;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Set up the socket
|
|
|
|
|
*/
|
|
|
|
|
if (connect (s, (struct sockaddr *) &server, sizeof server) < 0)
|
|
|
|
|
{
|
2006-11-22 14:19:35 +00:00
|
|
|
|
message (TRUE, "%s: connect: %s\n", progname, strerror (errno));
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
return INVALID_SOCKET;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setsockopt (s, SOL_SOCKET, SO_LINGER, (char *) &l_arg, sizeof l_arg);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Send the authentication
|
|
|
|
|
*/
|
|
|
|
|
auth_string[AUTH_KEY_LENGTH] = '\0';
|
|
|
|
|
|
|
|
|
|
SEND_STRING ("-auth ");
|
|
|
|
|
SEND_STRING (auth_string);
|
|
|
|
|
SEND_STRING ("\n");
|
|
|
|
|
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if !defined (NO_SOCKETS_IN_FILE_SYSTEM)
|
1991-09-02 20:23:32 +00:00
|
|
|
|
|
2000-01-28 15:02:20 +00:00
|
|
|
|
/* Three possibilities:
|
|
|
|
|
2 - can't be `stat'ed (sets errno)
|
|
|
|
|
1 - isn't owned by us
|
|
|
|
|
0 - success: none of the above */
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
socket_status (socket_name)
|
|
|
|
|
char *socket_name;
|
|
|
|
|
{
|
|
|
|
|
struct stat statbfr;
|
|
|
|
|
|
|
|
|
|
if (stat (socket_name, &statbfr) == -1)
|
|
|
|
|
return 2;
|
|
|
|
|
|
|
|
|
|
if (statbfr.st_uid != geteuid ())
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
HSOCKET
|
|
|
|
|
set_local_socket ()
|
1991-09-02 20:23:32 +00:00
|
|
|
|
{
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
HSOCKET s;
|
1991-09-02 20:23:32 +00:00
|
|
|
|
struct sockaddr_un server;
|
|
|
|
|
|
2001-12-19 07:21:17 +00:00
|
|
|
|
/*
|
1991-09-02 20:23:32 +00:00
|
|
|
|
* Open up an AF_UNIX socket in this person's home directory
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if ((s = socket (AF_UNIX, SOCK_STREAM, 0)) < 0)
|
|
|
|
|
{
|
2006-11-22 14:19:35 +00:00
|
|
|
|
message (TRUE, "%s: socket: %s\n", progname, strerror (errno));
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
return INVALID_SOCKET;
|
1991-09-02 20:23:32 +00:00
|
|
|
|
}
|
2001-12-19 07:21:17 +00:00
|
|
|
|
|
1991-09-02 20:23:32 +00:00
|
|
|
|
server.sun_family = AF_UNIX;
|
1999-08-14 04:08:25 +00:00
|
|
|
|
|
|
|
|
|
{
|
2000-01-28 15:02:20 +00:00
|
|
|
|
int sock_status = 0;
|
2004-01-20 23:25:33 +00:00
|
|
|
|
int default_sock = !socket_name;
|
2004-01-08 12:20:43 +00:00
|
|
|
|
int saved_errno;
|
2004-01-27 23:07:13 +00:00
|
|
|
|
char *server_name = "server";
|
|
|
|
|
|
|
|
|
|
if (socket_name && !index (socket_name, '/') && !index (socket_name, '\\'))
|
|
|
|
|
{ /* socket_name is a file name component. */
|
|
|
|
|
server_name = socket_name;
|
|
|
|
|
socket_name = NULL;
|
|
|
|
|
default_sock = 1; /* Try both UIDs. */
|
|
|
|
|
}
|
1992-01-14 08:05:08 +00:00
|
|
|
|
|
2004-01-20 23:25:33 +00:00
|
|
|
|
if (default_sock)
|
2003-09-12 00:48:03 +00:00
|
|
|
|
{
|
2004-01-27 23:07:13 +00:00
|
|
|
|
socket_name = alloca (100 + strlen (server_name));
|
|
|
|
|
sprintf (socket_name, "/tmp/emacs%d/%s",
|
|
|
|
|
(int) geteuid (), server_name);
|
2003-09-12 00:48:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (strlen (socket_name) < sizeof (server.sun_path))
|
|
|
|
|
strcpy (server.sun_path, socket_name);
|
|
|
|
|
else
|
2004-01-20 23:25:33 +00:00
|
|
|
|
{
|
2006-11-22 14:19:35 +00:00
|
|
|
|
message (TRUE, "%s: socket-name %s too long",
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
progname, socket_name);
|
2004-05-08 15:26:33 +00:00
|
|
|
|
exit (EXIT_FAILURE);
|
2004-01-20 23:25:33 +00:00
|
|
|
|
}
|
1992-01-14 08:05:08 +00:00
|
|
|
|
|
2000-01-28 15:02:20 +00:00
|
|
|
|
/* See if the socket exists, and if it's owned by us. */
|
|
|
|
|
sock_status = socket_status (server.sun_path);
|
2004-01-08 12:20:43 +00:00
|
|
|
|
saved_errno = errno;
|
2004-01-20 23:25:33 +00:00
|
|
|
|
if (sock_status && default_sock)
|
1992-01-14 08:05:08 +00:00
|
|
|
|
{
|
2000-01-28 15:02:20 +00:00
|
|
|
|
/* Failing that, see if LOGNAME or USER exist and differ from
|
|
|
|
|
our euid. If so, look for a socket based on the UID
|
|
|
|
|
associated with the name. This is reminiscent of the logic
|
|
|
|
|
that init_editfns uses to set the global Vuser_full_name. */
|
2001-12-19 07:21:17 +00:00
|
|
|
|
|
2000-01-28 15:02:20 +00:00
|
|
|
|
char *user_name = (char *) getenv ("LOGNAME");
|
2004-01-24 21:57:57 +00:00
|
|
|
|
|
2000-01-28 15:02:20 +00:00
|
|
|
|
if (!user_name)
|
|
|
|
|
user_name = (char *) getenv ("USER");
|
2001-12-19 07:21:17 +00:00
|
|
|
|
|
2000-01-28 15:02:20 +00:00
|
|
|
|
if (user_name)
|
|
|
|
|
{
|
|
|
|
|
struct passwd *pw = getpwnam (user_name);
|
2004-01-24 21:57:57 +00:00
|
|
|
|
|
2000-01-28 15:02:20 +00:00
|
|
|
|
if (pw && (pw->pw_uid != geteuid ()))
|
|
|
|
|
{
|
|
|
|
|
/* We're running under su, apparently. */
|
2004-01-27 23:07:13 +00:00
|
|
|
|
socket_name = alloca (100 + strlen (server_name));
|
|
|
|
|
sprintf (socket_name, "/tmp/emacs%d/%s",
|
|
|
|
|
(int) pw->pw_uid, server_name);
|
2004-01-20 23:25:33 +00:00
|
|
|
|
|
|
|
|
|
if (strlen (socket_name) < sizeof (server.sun_path))
|
|
|
|
|
strcpy (server.sun_path, socket_name);
|
|
|
|
|
else
|
|
|
|
|
{
|
2006-11-22 14:19:35 +00:00
|
|
|
|
message (TRUE, "%s: socket-name %s too long",
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
progname, socket_name);
|
2004-05-08 15:26:33 +00:00
|
|
|
|
exit (EXIT_FAILURE);
|
2004-01-20 23:25:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-01-28 15:02:20 +00:00
|
|
|
|
sock_status = socket_status (server.sun_path);
|
2004-01-08 12:20:43 +00:00
|
|
|
|
saved_errno = errno;
|
2000-01-28 15:02:20 +00:00
|
|
|
|
}
|
2004-01-24 21:57:57 +00:00
|
|
|
|
else
|
|
|
|
|
errno = saved_errno;
|
2000-01-28 15:02:20 +00:00
|
|
|
|
}
|
1992-01-14 08:05:08 +00:00
|
|
|
|
}
|
2001-12-19 07:21:17 +00:00
|
|
|
|
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
switch (sock_status)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
/* There's a socket, but it isn't owned by us. This is OK if
|
|
|
|
|
we are root. */
|
|
|
|
|
if (0 != geteuid ())
|
|
|
|
|
{
|
2006-11-22 14:19:35 +00:00
|
|
|
|
message (TRUE, "%s: Invalid socket owner\n", progname);
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
return INVALID_SOCKET;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
/* `stat' failed */
|
|
|
|
|
if (saved_errno == ENOENT)
|
2006-11-22 14:19:35 +00:00
|
|
|
|
message (TRUE,
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
"%s: can't find socket; have you started the server?\n\
|
2002-12-02 20:57:42 +00:00
|
|
|
|
To start the server in Emacs, type \"M-x server-start\".\n",
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
progname);
|
|
|
|
|
else
|
2006-11-22 14:19:35 +00:00
|
|
|
|
message (TRUE, "%s: can't stat %s: %s\n",
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
progname, server.sun_path, strerror (saved_errno));
|
2006-11-06 12:41:49 +00:00
|
|
|
|
return INVALID_SOCKET;
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
}
|
1992-01-14 08:05:08 +00:00
|
|
|
|
}
|
1991-09-02 20:23:32 +00:00
|
|
|
|
|
1993-06-09 12:45:26 +00:00
|
|
|
|
if (connect (s, (struct sockaddr *) &server, strlen (server.sun_path) + 2)
|
|
|
|
|
< 0)
|
1991-09-02 20:23:32 +00:00
|
|
|
|
{
|
2006-11-22 14:19:35 +00:00
|
|
|
|
message (TRUE, "%s: connect: %s\n", progname, strerror (errno));
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
return INVALID_SOCKET;
|
1991-09-02 20:23:32 +00:00
|
|
|
|
}
|
1996-07-23 14:18:34 +00:00
|
|
|
|
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
#endif /* ! NO_SOCKETS_IN_FILE_SYSTEM */
|
|
|
|
|
|
|
|
|
|
HSOCKET
|
|
|
|
|
set_socket ()
|
|
|
|
|
{
|
2006-11-06 12:41:49 +00:00
|
|
|
|
HSOCKET s;
|
|
|
|
|
|
|
|
|
|
INITIALIZE ();
|
|
|
|
|
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
#ifndef NO_SOCKETS_IN_FILE_SYSTEM
|
2006-11-06 12:41:49 +00:00
|
|
|
|
/* Explicit --socket-name argument. */
|
|
|
|
|
if (socket_name)
|
|
|
|
|
{
|
|
|
|
|
s = set_local_socket ();
|
|
|
|
|
if ((s != INVALID_SOCKET) || alternate_editor)
|
|
|
|
|
return s;
|
|
|
|
|
|
2006-11-22 14:19:35 +00:00
|
|
|
|
message (TRUE, "%s: error accessing socket \"%s\"",
|
2006-11-06 12:41:49 +00:00
|
|
|
|
progname, socket_name);
|
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* Explicit --server-file arg or EMACS_SERVER_FILE variable. */
|
|
|
|
|
if (!server_file)
|
|
|
|
|
server_file = getenv ("EMACS_SERVER_FILE");
|
|
|
|
|
|
|
|
|
|
if (server_file)
|
1991-09-02 20:23:32 +00:00
|
|
|
|
{
|
2006-11-06 12:41:49 +00:00
|
|
|
|
s = set_tcp_socket ();
|
|
|
|
|
if ((s != INVALID_SOCKET) || alternate_editor)
|
|
|
|
|
return s;
|
|
|
|
|
|
2006-11-22 14:19:35 +00:00
|
|
|
|
message (TRUE, "%s: error accessing server file \"%s\"",
|
2006-11-06 12:41:49 +00:00
|
|
|
|
progname, server_file);
|
|
|
|
|
exit (EXIT_FAILURE);
|
1991-09-02 20:23:32 +00:00
|
|
|
|
}
|
2006-11-06 12:41:49 +00:00
|
|
|
|
|
|
|
|
|
#ifndef NO_SOCKETS_IN_FILE_SYSTEM
|
|
|
|
|
/* Implicit local socket. */
|
|
|
|
|
s = set_local_socket ();
|
|
|
|
|
if (s != INVALID_SOCKET)
|
|
|
|
|
return s;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* Implicit server file. */
|
|
|
|
|
server_file = "server";
|
|
|
|
|
s = set_tcp_socket ();
|
|
|
|
|
if ((s != INVALID_SOCKET) || alternate_editor)
|
|
|
|
|
return s;
|
|
|
|
|
|
|
|
|
|
/* No implicit or explicit socket, and no alternate editor. */
|
2006-11-22 14:19:35 +00:00
|
|
|
|
message (TRUE, "%s: No socket or alternate editor. Please use:\n\n"
|
2006-11-06 12:41:49 +00:00
|
|
|
|
#ifndef NO_SOCKETS_IN_FILE_SYSTEM
|
|
|
|
|
"\t--socket-name\n"
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
#endif
|
2006-11-06 12:41:49 +00:00
|
|
|
|
"\t--server-file (or environment variable EMACS_SERVER_FILE)\n\
|
|
|
|
|
\t--alternate-editor (or environment variable ALTERNATE_EDITOR)\n",
|
|
|
|
|
progname);
|
|
|
|
|
exit (EXIT_FAILURE);
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
}
|
1991-09-02 20:23:32 +00:00
|
|
|
|
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
int
|
|
|
|
|
main (argc, argv)
|
|
|
|
|
int argc;
|
|
|
|
|
char **argv;
|
|
|
|
|
{
|
|
|
|
|
HSOCKET s;
|
|
|
|
|
int i, rl, needlf = 0;
|
|
|
|
|
char *cwd;
|
|
|
|
|
char string[BUFSIZ+1];
|
|
|
|
|
|
|
|
|
|
progname = argv[0];
|
|
|
|
|
|
|
|
|
|
/* Process options. */
|
|
|
|
|
decode_options (argc, argv);
|
|
|
|
|
|
|
|
|
|
if ((argc - optind < 1) && !eval)
|
1996-07-23 14:18:34 +00:00
|
|
|
|
{
|
2006-11-22 14:19:35 +00:00
|
|
|
|
message (TRUE, "%s: file name or argument required\nTry `%s --help' for more information\n",
|
|
|
|
|
progname, progname);
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
exit (EXIT_FAILURE);
|
1996-07-23 14:18:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
if ((s = set_socket ()) == INVALID_SOCKET)
|
|
|
|
|
fail (argc, argv);
|
|
|
|
|
|
2002-12-02 16:14:35 +00:00
|
|
|
|
#ifdef HAVE_GETCWD
|
1995-03-15 23:31:02 +00:00
|
|
|
|
cwd = getcwd (string, sizeof string);
|
2002-12-02 16:14:35 +00:00
|
|
|
|
#else
|
|
|
|
|
cwd = getwd (string);
|
1995-03-15 23:31:02 +00:00
|
|
|
|
#endif
|
1991-09-02 20:23:32 +00:00
|
|
|
|
if (cwd == 0)
|
|
|
|
|
{
|
|
|
|
|
/* getwd puts message in STRING if it fails. */
|
2006-11-22 14:19:35 +00:00
|
|
|
|
message (TRUE, "%s: %s (%s)\n", progname,
|
2006-11-30 22:49:38 +00:00
|
|
|
|
#ifdef HAVE_GETCWD
|
|
|
|
|
"Cannot get current working directory",
|
2002-12-02 16:14:35 +00:00
|
|
|
|
#else
|
2006-11-30 22:49:38 +00:00
|
|
|
|
string,
|
1997-08-27 20:08:59 +00:00
|
|
|
|
#endif
|
2006-11-30 22:49:38 +00:00
|
|
|
|
strerror (errno));
|
2000-01-12 13:38:54 +00:00
|
|
|
|
fail (argc, argv);
|
1991-09-02 20:23:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-11-30 22:49:38 +00:00
|
|
|
|
#ifdef WINDOWSNT
|
|
|
|
|
/*
|
|
|
|
|
Modern Windows restrict which processes can set the foreground window.
|
|
|
|
|
emacsclient can allow Emacs to grab the focus by calling the function
|
|
|
|
|
AllowSetForegroundWindow(). Unfortunately, older Windows (W95, W98
|
|
|
|
|
and NT) lack this function, so we have to check its availability.
|
|
|
|
|
*/
|
|
|
|
|
if (emacs_pid)
|
|
|
|
|
{
|
|
|
|
|
HMODULE hUser32;
|
|
|
|
|
|
|
|
|
|
if (hUser32 = LoadLibrary ("user32.dll"))
|
|
|
|
|
{
|
|
|
|
|
FARPROC set_fg;
|
|
|
|
|
if (set_fg = GetProcAddress (hUser32, "AllowSetForegroundWindow"))
|
|
|
|
|
set_fg (emacs_pid);
|
|
|
|
|
FreeLibrary (hUser32);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
1996-09-02 00:05:56 +00:00
|
|
|
|
if (nowait)
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
SEND_STRING ("-nowait ");
|
1996-08-31 16:25:21 +00:00
|
|
|
|
|
2002-09-27 18:21:44 +00:00
|
|
|
|
if (eval)
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
SEND_STRING ("-eval ");
|
2002-09-27 18:21:44 +00:00
|
|
|
|
|
|
|
|
|
if (display)
|
2003-09-28 08:24:56 +00:00
|
|
|
|
{
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
SEND_STRING ("-display ");
|
|
|
|
|
SEND_QUOTED (display);
|
|
|
|
|
SEND_STRING (" ");
|
2003-09-28 08:24:56 +00:00
|
|
|
|
}
|
2002-09-27 18:21:44 +00:00
|
|
|
|
|
2003-09-28 08:24:56 +00:00
|
|
|
|
if ((argc - optind > 0))
|
1996-09-02 00:05:56 +00:00
|
|
|
|
{
|
2003-09-28 08:24:56 +00:00
|
|
|
|
for (i = optind; i < argc; i++)
|
1991-09-02 20:23:32 +00:00
|
|
|
|
{
|
2003-09-28 08:24:56 +00:00
|
|
|
|
if (eval)
|
|
|
|
|
; /* Don't prepend any cwd or anything like that. */
|
|
|
|
|
else if (*argv[i] == '+')
|
|
|
|
|
{
|
|
|
|
|
char *p = argv[i] + 1;
|
|
|
|
|
while (isdigit ((unsigned char) *p) || *p == ':') p++;
|
|
|
|
|
if (*p != 0)
|
|
|
|
|
{
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
SEND_QUOTED (cwd);
|
|
|
|
|
SEND_STRING ("/");
|
2003-09-28 08:24:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2006-11-06 12:41:49 +00:00
|
|
|
|
else if (! file_name_absolute_p (argv[i]))
|
2003-09-28 08:24:56 +00:00
|
|
|
|
{
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
SEND_QUOTED (cwd);
|
|
|
|
|
SEND_STRING ("/");
|
2003-09-28 08:24:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
SEND_QUOTED (argv[i]);
|
|
|
|
|
SEND_STRING (" ");
|
1991-09-02 20:23:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2003-09-28 08:24:56 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
while (fgets (string, BUFSIZ, stdin))
|
2003-09-28 08:24:56 +00:00
|
|
|
|
{
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
SEND_QUOTED (string);
|
2003-09-28 08:24:56 +00:00
|
|
|
|
}
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
SEND_STRING (" ");
|
2003-09-28 08:24:56 +00:00
|
|
|
|
}
|
2004-05-08 15:26:33 +00:00
|
|
|
|
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
SEND_STRING ("\n");
|
1991-09-02 20:23:32 +00:00
|
|
|
|
|
1996-08-31 16:25:21 +00:00
|
|
|
|
/* Maybe wait for an answer. */
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
if (!nowait)
|
2002-09-27 18:21:44 +00:00
|
|
|
|
{
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
if (!eval)
|
|
|
|
|
{
|
|
|
|
|
printf ("Waiting for Emacs...");
|
|
|
|
|
needlf = 2;
|
|
|
|
|
}
|
|
|
|
|
fflush (stdout);
|
|
|
|
|
|
|
|
|
|
/* Now, wait for an answer and print any messages. */
|
|
|
|
|
while ((rl = recv (s, string, BUFSIZ, 0)) > 0)
|
|
|
|
|
{
|
|
|
|
|
string[rl] = '\0';
|
|
|
|
|
if (needlf == 2)
|
|
|
|
|
printf ("\n");
|
|
|
|
|
printf ("%s", string);
|
|
|
|
|
needlf = string[0] == '\0' ? needlf : string[strlen (string) - 1] != '\n';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (needlf)
|
|
|
|
|
printf ("\n");
|
|
|
|
|
fflush (stdout);
|
2002-09-27 18:21:44 +00:00
|
|
|
|
}
|
1996-07-23 14:18:34 +00:00
|
|
|
|
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
CLOSE_SOCKET (s);
|
2004-05-08 15:26:33 +00:00
|
|
|
|
return EXIT_SUCCESS;
|
1991-09-02 20:23:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-11-02 09:55:33 +00:00
|
|
|
|
#endif /* HAVE_SOCKETS && HAVE_INET_SOCKETS */
|
Add support for TCP sockets.
(SEND_STRING, SEND_QUOTED, HSOCKET, CLOSE_SOCKET, IOCTL, INITIALIZE): New
macros.
(IOCTL_BOOL_ARG): New typedef.
(server_file): New global variable.
(longopts): New option --server-file.
(decode_options): Process new option --server-file and environment variable
EMACS_SERVER_FILE.
(print_help_and_exit): Document new option.
(fail): If no connection available and no alternate editor, suggest using
options to make them explicit.
(AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): New constants.
(send_buffer, sblen): New variables.
(send_to_emacs): New function to buffer output and send it with send().
(quote_file_name): Use SEND_STRING.
(close_winsock, initialize_sockets): New functions to load and unload Winsock.
(get_server_config, set_tcp_socket): New functions to create and set up TCP
sockets.
(set_local_socket): New function to create and set up Unix socket (code moved
from previous implementation).
(set_socket): New function to chose between TCP and Unix sockets.
(main): Use SEND_STRING and SEND_QUOTED. Most code moved to set_local_socket.
Use set_socket. Get answers from server.el with recv(), not file stream
functions.
2006-10-31 00:21:19 +00:00
|
|
|
|
|
1994-01-08 22:27:30 +00:00
|
|
|
|
#ifndef HAVE_STRERROR
|
|
|
|
|
char *
|
|
|
|
|
strerror (errnum)
|
|
|
|
|
int errnum;
|
|
|
|
|
{
|
|
|
|
|
extern char *sys_errlist[];
|
|
|
|
|
extern int sys_nerr;
|
|
|
|
|
|
|
|
|
|
if (errnum >= 0 && errnum < sys_nerr)
|
|
|
|
|
return sys_errlist[errnum];
|
|
|
|
|
return (char *) "Unknown error";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif /* ! HAVE_STRERROR */
|
2003-09-01 15:45:59 +00:00
|
|
|
|
|
|
|
|
|
/* arch-tag: f39bb9c4-73eb-477e-896d-50832e2ca9a7
|
|
|
|
|
(do not change this comment) */
|
2004-05-08 15:26:33 +00:00
|
|
|
|
|
|
|
|
|
/* emacsclient.c ends here */
|