From aa0b6932977826d7effb3e4509cf70fee33670bc Mon Sep 17 00:00:00 2001 From: Juanma Barranquero Date: Tue, 31 Oct 2006 00:21:19 +0000 Subject: 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. --- lib-src/emacsclient.c | 555 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 400 insertions(+), 155 deletions(-) (limited to 'lib-src/emacsclient.c') diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index b0bf50c2c7..943053b3c0 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c @@ -26,19 +26,42 @@ Boston, MA 02110-1301, USA. */ #include #endif +#ifdef WINDOWSNT +#define HAVE_SOCKETS +#define NO_SOCKETS_IN_FILE_SYSTEM +#endif + +#ifdef WINDOWSNT +# define HSOCKET SOCKET +# define CLOSE_SOCKET closesocket +# define IOCTL ioctlsocket +# define INITIALIZE() (initialize_sockets ()) +typedef unsigned long IOCTL_BOOL_ARG; +#else +# define HSOCKET int +# define CLOSE_SOCKET close +# define IOCTL ioctl +# define INITIALIZE() +typedef int IOCTL_BOOL_ARG; +#endif + #undef signal #include #include -#include +#include "getopt.h" #ifdef HAVE_UNISTD_H #include #endif #ifdef VMS # include "vms-pwd.h" -#else +#else /* not VMS */ +#ifdef WINDOWSNT +# include +#else /* not WINDOWSNT */ # include +#endif /* not WINDOWSNT */ #endif /* not VMS */ char *getenv (), *getwd (); @@ -48,6 +71,29 @@ char *(getcwd) (); #define VERSION "unspecified" #endif +#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 + /* Name used to invoke this program. */ char *progname; @@ -67,6 +113,9 @@ const char * alternate_editor = NULL; /* If non-NULL, the filename of the UNIX socket. */ char *socket_name = NULL; +/* If non-NULL, the filename of the authentication file. */ +char *server_file = NULL; + void print_help_and_exit () NO_RETURN; struct option longopts[] = @@ -77,6 +126,7 @@ struct option longopts[] = { "version", no_argument, NULL, 'V' }, { "alternate-editor", required_argument, NULL, 'a' }, { "socket-name", required_argument, NULL, 's' }, + { "server-file", required_argument, NULL, 'f' }, { "display", required_argument, NULL, 'd' }, { 0, 0, 0, 0 } }; @@ -90,11 +140,12 @@ decode_options (argc, argv) char **argv; { alternate_editor = getenv ("ALTERNATE_EDITOR"); + server_file = getenv ("EMACS_SERVER_FILE"); while (1) { int opt = getopt_long (argc, argv, - "VHnea:s:d:", longopts, 0); + "VHnea:s:f:d:", longopts, 0); if (opt == EOF) break; @@ -114,6 +165,10 @@ decode_options (argc, argv) socket_name = optarg; break; + case 'f': + server_file = optarg; + break; + case 'd': display = optarg; break; @@ -156,9 +211,13 @@ The following OPTIONS are accepted:\n\ -H, --help Print this usage information message\n\ -n, --no-wait Don't wait for the server to return\n\ -e, --eval Evaluate the FILE arguments as ELisp expressions\n\ --d, --display=DISPLAY Visit the file in the given display\n\ --s, --socket-name=FILENAME\n\ - Set the filename of the UNIX socket for communication\n\ +-d, --display=DISPLAY Visit the file in the given display\n" +#ifndef NO_SOCKETS_IN_FILE_SYSTEM +"-s, --socket-name=FILENAME\n\ + Set the filename of the UNIX socket for communication\n" +#endif +"-f, --server-file=FILENAME\n\ + Set the filename of the TCP configuration file\n\ -a, --alternate-editor=EDITOR\n\ Editor to fallback to if the server is not running\n\ \n\ @@ -166,14 +225,118 @@ Report bugs to bug-gnu-emacs@gnu.org.\n", progname); exit (EXIT_SUCCESS); } + +/* + 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; + execvp (alternate_editor, argv + i); + fprintf (stderr, "%s: error executing alternate editor \"%s\"\n", + progname, alternate_editor); + } + else + { + fprintf (stderr, "%s: No socket or alternate editor. Please use:\n\n" +#if !defined (NO_SOCKETS_IN_FILE_SYSTEM) +"\t--socket-name\n" +#endif +"\t--server-file (or environment variable EMACS_SERVER_FILE)\n\ +\t--alternate-editor (or environment variable ALTERNATE_EDITOR)\n", + progname); + } + exit (EXIT_FAILURE); +} + + +#if !defined (HAVE_SOCKETS) + +int +main (argc, argv) + int argc; + char **argv; +{ + fprintf (stderr, "%s: Sorry, the Emacs server is supported only\n", + argv[0]); + fprintf (stderr, "on systems with Berkeley sockets.\n"); + + fail (argc, argv); +} + +#else /* HAVE_SOCKETS */ + +#ifdef WINDOWSNT +# include +#else +# include +# include +# include +# include +# include +#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. */ +void send_to_emacs (s, data) + 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; + } + } +} + /* In NAME, insert a & before each &, each space, each newline, and any initial -. Change spaces to underscores, too, so that the return value never contains a space. */ - void -quote_file_name (name, stream) +quote_file_name (s, name) + HSOCKET s; char *name; - FILE *stream; { char *copy = (char *) malloc (strlen (name) * 2 + 1); char *p, *q; @@ -203,73 +366,139 @@ quote_file_name (name, stream) } *q++ = 0; - fprintf (stream, "%s", copy); + SEND_STRING (copy); free (copy); } -/* Like malloc but get fatal error if memory is exhausted. */ +#ifdef WINDOWSNT +/* Wrapper to make WSACleanup a cdecl, as required by atexit(). */ +void close_winsock () +{ + WSACleanup (); +} -long * -xmalloc (size) - unsigned int size; +void initialize_sockets () { - long *result = (long *) malloc (size); - if (result == NULL) - { - perror ("malloc"); - exit (EXIT_FAILURE); - } - return result; + WSADATA wsaData; + + /* Initialize the WinSock2 library. */ + if (WSAStartup (MAKEWORD (2, 0), &wsaData)) + { + fprintf (stderr, "%s: error initializing WinSock2", progname); + exit (EXIT_FAILURE); + } + + atexit (close_winsock); +#endif /* WINDOWSNT */ } /* - Try to run a different command, or --if no alternate editor is - defined-- exit with an errorcode. + * Read the information needed to set up a TCP comm channel with + * the Emacs server: host, port and authentication string. */ -void -fail (argc, argv) - int argc; - char **argv; +int get_server_config (server, authentication) + struct sockaddr_in *server; + char *authentication; { - if (alternate_editor) + FILE *config; + char dotted[32]; + char *port; + + if (! (config = fopen (server_file, "rb"))) { - int i = optind - 1; - execvp (alternate_editor, argv + i); - return; + char *home = getenv ("HOME"); +#ifdef WINDOWSNT + if (! home) + home = getenv ("APPDATA"); +#endif + 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"); + } + } + + if (! config) + return FALSE; + + if (fgets (dotted, sizeof dotted, config) + && (port = strchr (dotted, ':'))) + { + *port++ = '\0'; } else { + fprintf (stderr, "%s: invalid configuration info", progname); exit (EXIT_FAILURE); } -} + server->sin_family = AF_INET; + server->sin_addr.s_addr = inet_addr (dotted); + server->sin_port = htons (atoi (port)); - -#if !defined (HAVE_SOCKETS) || defined (NO_SOCKETS_IN_FILE_SYSTEM) + if (! fread (authentication, AUTH_KEY_LENGTH, 1, config)) + { + fprintf (stderr, "%s: cannot read authentication info", progname); + exit (EXIT_FAILURE); + } -int -main (argc, argv) - int argc; - char **argv; -{ - fprintf (stderr, "%s: Sorry, the Emacs server is supported only\n", - argv[0]); - fprintf (stderr, "on systems with Berkeley sockets.\n"); + fclose (config); - fail (argc, argv); + return TRUE; } -#else /* HAVE_SOCKETS */ +HSOCKET +set_tcp_socket () +{ + HSOCKET s; + struct sockaddr_in server; + IOCTL_BOOL_ARG c_arg = 0; + struct linger l_arg = {1, 1}; + char auth_string[AUTH_KEY_LENGTH + 1]; -#include -#include -#include -#include -#include + INITIALIZE (); -extern char *strerror (); -extern int errno; + if (! get_server_config (&server, auth_string)) + return INVALID_SOCKET; + + /* + * Open up an AF_INET socket + */ + if ((s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) + { + fprintf (stderr, "%s: ", progname); + perror ("socket"); + return INVALID_SOCKET; + } + + /* + * Set up the socket + */ + if (connect (s, (struct sockaddr *) &server, sizeof server) < 0) + { + fprintf (stderr, "%s: ", progname); + perror ("connect"); + return INVALID_SOCKET; + } + + IOCTL (s, FIONBIO, &c_arg); + 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) /* Three possibilities: 2 - can't be `stat'ed (sets errno) @@ -291,28 +520,11 @@ socket_status (socket_name) return 0; } -int -main (argc, argv) - int argc; - char **argv; +HSOCKET +set_local_socket () { - int s, i, needlf = 0; - FILE *out, *in; + HSOCKET s; struct sockaddr_un server; - char *cwd, *str; - char string[BUFSIZ]; - - progname = argv[0]; - - /* Process options. */ - decode_options (argc, argv); - - if ((argc - optind < 1) && !eval) - { - fprintf (stderr, "%s: file name or argument required\n", progname); - fprintf (stderr, "Try `%s --help' for more information\n", progname); - exit (EXIT_FAILURE); - } /* * Open up an AF_UNIX socket in this person's home directory @@ -320,9 +532,9 @@ main (argc, argv) if ((s = socket (AF_UNIX, SOCK_STREAM, 0)) < 0) { - fprintf (stderr, "%s: ", argv[0]); + fprintf (stderr, "%s: ", progname); perror ("socket"); - fail (argc, argv); + return INVALID_SOCKET; } server.sun_family = AF_UNIX; @@ -352,7 +564,7 @@ main (argc, argv) else { fprintf (stderr, "%s: socket-name %s too long", - argv[0], socket_name); + progname, socket_name); exit (EXIT_FAILURE); } @@ -387,7 +599,7 @@ main (argc, argv) else { fprintf (stderr, "%s: socket-name %s too long", - argv[0], socket_name); + progname, socket_name); exit (EXIT_FAILURE); } @@ -399,61 +611,85 @@ main (argc, argv) } } - 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 ()) - { - fprintf (stderr, "%s: Invalid socket owner\n", argv[0]); - fail (argc, argv); - } - break; - - case 2: - /* `stat' failed */ - if (saved_errno == ENOENT) - fprintf (stderr, - "%s: can't find socket; have you started the server?\n\ + 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 ()) + { + fprintf (stderr, "%s: Invalid socket owner\n", argv[0]); + return INVALID_SOCKET; + } + break; + + case 2: + /* `stat' failed */ + if (saved_errno == ENOENT) + fprintf (stderr, + "%s: can't find socket; have you started the server?\n\ To start the server in Emacs, type \"M-x server-start\".\n", - argv[0]); - else - fprintf (stderr, "%s: can't stat %s: %s\n", - argv[0], server.sun_path, strerror (saved_errno)); - fail (argc, argv); - break; - } + progname); + else + fprintf (stderr, "%s: can't stat %s: %s\n", + progname, server.sun_path, strerror (saved_errno)); + return INVALID_SOCKET; + } } if (connect (s, (struct sockaddr *) &server, strlen (server.sun_path) + 2) < 0) { - fprintf (stderr, "%s: ", argv[0]); + fprintf (stderr, "%s: ", progname); perror ("connect"); - fail (argc, argv); + return INVALID_SOCKET; } - /* We use the stream OUT to send our command to the server. */ - if ((out = fdopen (s, "r+")) == NULL) + return s; +} +#endif /* ! NO_SOCKETS_IN_FILE_SYSTEM */ + +HSOCKET +set_socket () +{ + if (server_file) + return set_tcp_socket (); + else +#ifndef NO_SOCKETS_IN_FILE_SYSTEM + return set_local_socket (); +#else { - fprintf (stderr, "%s: ", argv[0]); - perror ("fdopen"); - fail (argc, argv); + server_file = "server"; + return set_tcp_socket (); } +#endif +} - /* We use the stream IN to read the response. - We used to use just one stream for both output and input - on the socket, but reversing direction works nonportably: - on some systems, the output appears as the first input; - on other systems it does not. */ - if ((in = fdopen (s, "r+")) == NULL) +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) { - fprintf (stderr, "%s: ", argv[0]); - perror ("fdopen"); - fail (argc, argv); + fprintf (stderr, "%s: file name or argument required\n", progname); + fprintf (stderr, "Try `%s --help' for more information\n", progname); + exit (EXIT_FAILURE); } + if ((s = set_socket ()) == INVALID_SOCKET) + fail (argc, argv); + #ifdef HAVE_GETCWD cwd = getcwd (string, sizeof string); #else @@ -462,27 +698,26 @@ To start the server in Emacs, type \"M-x server-start\".\n", if (cwd == 0) { /* getwd puts message in STRING if it fails. */ - #ifdef HAVE_GETCWD - fprintf (stderr, "%s: %s (%s)\n", argv[0], + fprintf (stderr, "%s: %s (%s)\n", progname, "Cannot get current working directory", strerror (errno)); #else - fprintf (stderr, "%s: %s (%s)\n", argv[0], string, strerror (errno)); + fprintf (stderr, "%s: %s (%s)\n", progname, string, strerror (errno)); #endif fail (argc, argv); } if (nowait) - fprintf (out, "-nowait "); + SEND_STRING ("-nowait "); if (eval) - fprintf (out, "-eval "); + SEND_STRING ("-eval "); if (display) { - fprintf (out, "-display "); - quote_file_name (display, out); - fprintf (out, " "); + SEND_STRING ("-display "); + SEND_QUOTED (display); + SEND_STRING (" "); } if ((argc - optind > 0)) @@ -497,61 +732,71 @@ To start the server in Emacs, type \"M-x server-start\".\n", while (isdigit ((unsigned char) *p) || *p == ':') p++; if (*p != 0) { - quote_file_name (cwd, out); - fprintf (out, "/"); + SEND_QUOTED (cwd); + SEND_STRING ("/"); } } +#ifndef WINDOWSNT else if (*argv[i] != '/') +#else + else if ((*argv[i] != '/') + /* Absolute paths can also start with backslash + or drive letters. */ + && (*argv[i] != '\\') + && (!islower (tolower (*argv[i])) + || (argv[i][1] != ':'))) +#endif { - quote_file_name (cwd, out); - fprintf (out, "/"); + SEND_QUOTED (cwd); + SEND_STRING ("/"); } - quote_file_name (argv[i], out); - fprintf (out, " "); + SEND_QUOTED (argv[i]); + SEND_STRING (" "); } } else { - while ((str = fgets (string, BUFSIZ, stdin))) + while (fgets (string, BUFSIZ, stdin)) { - quote_file_name (str, out); + SEND_QUOTED (string); } - fprintf (out, " "); + SEND_STRING (" "); } - fprintf (out, "\n"); - fflush (out); + SEND_STRING ("\n"); /* Maybe wait for an answer. */ - if (nowait) - return EXIT_SUCCESS; - - if (!eval) + if (!nowait) { - printf ("Waiting for Emacs..."); - needlf = 2; + 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); } - fflush (stdout); - - /* Now, wait for an answer and print any messages. */ - while ((str = fgets (string, BUFSIZ, in))) - { - if (needlf == 2) - printf ("\n"); - printf ("%s", str); - needlf = str[0] == '\0' ? needlf : str[strlen (str) - 1] != '\n'; - } - - if (needlf) - printf ("\n"); - fflush (stdout); + CLOSE_SOCKET (s); return EXIT_SUCCESS; } #endif /* HAVE_SOCKETS */ - + #ifndef HAVE_STRERROR char * strerror (errnum) -- cgit v1.2.3 From e35fc9628ced2eafed2073622bbab1eec010d82a Mon Sep 17 00:00:00 2001 From: Juanma Barranquero Date: Tue, 31 Oct 2006 09:08:24 +0000 Subject: Fixes to emacsclient.c for GNU/Linux. [!WINDOWSNT] : Include and . (INVALID_SOCKET): Define. (initialize_sockets): Put #endif at the right place. (set_local_socket): Use progname, not argv[0]. --- lib-src/ChangeLog | 10 ++++++++++ lib-src/emacsclient.c | 7 +++++-- 2 files changed, 15 insertions(+), 2 deletions(-) (limited to 'lib-src/emacsclient.c') diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog index d36646065e..0a6b4b35be 100644 --- a/lib-src/ChangeLog +++ b/lib-src/ChangeLog @@ -1,3 +1,12 @@ +2006-10-31 Tim Van Holder (tiny change) + + Fixes to emacsclient.c for GNU/Linux. + * emacsclient.c [!WINDOWSNT] : Include and + . + (INVALID_SOCKET): Define. + (initialize_sockets): Put #endif at the right place. + (set_local_socket): Use progname, not argv[0]. + 2006-10-31 Juanma Barranquero * makefile.w32-in (ALL): Add emacsclient. @@ -32,6 +41,7 @@ set_local_socket. Use set_socket. Get answers from server.el with recv(), not file stream functions. + 2006-10-09 Eli Zaretskii * makefile.w32-in (../src/config.h): Fix error message. diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index 943053b3c0..b3a5180653 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c @@ -38,6 +38,9 @@ Boston, MA 02110-1301, USA. */ # define INITIALIZE() (initialize_sockets ()) typedef unsigned long IOCTL_BOOL_ARG; #else +# include +# include +# define INVALID_SOCKET -1 # define HSOCKET int # define CLOSE_SOCKET close # define IOCTL ioctl @@ -390,8 +393,8 @@ void initialize_sockets () } atexit (close_winsock); -#endif /* WINDOWSNT */ } +#endif /* WINDOWSNT */ /* * Read the information needed to set up a TCP comm channel with @@ -618,7 +621,7 @@ set_local_socket () we are root. */ if (0 != geteuid ()) { - fprintf (stderr, "%s: Invalid socket owner\n", argv[0]); + fprintf (stderr, "%s: Invalid socket owner\n", progname); return INVALID_SOCKET; } break; -- cgit v1.2.3 From 95d0feaa4a914e897f202c5c0b1d8ea14524620a Mon Sep 17 00:00:00 2001 From: Juanma Barranquero Date: Tue, 31 Oct 2006 13:52:32 +0000 Subject: [!WINDOWSNT]: Include if available. (set_tcp_socket): Prefer O_NONBLOCK, then O_NDELAY, then FIONBIO to set the socket in non-blocking mode. --- lib-src/ChangeLog | 6 ++++++ lib-src/emacsclient.c | 11 +++++++++++ 2 files changed, 17 insertions(+) (limited to 'lib-src/emacsclient.c') diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog index b3ac07ec26..939cb1b24c 100644 --- a/lib-src/ChangeLog +++ b/lib-src/ChangeLog @@ -1,3 +1,9 @@ +2006-10-31 Jan Dj,Ad(Brv + + * emacsclient.c [!WINDOWSNT]: Include if available. + (set_tcp_socket): Prefer O_NONBLOCK, then O_NDELAY, then FIONBIO + to set the socket in non-blocking mode. + 2006-10-31 Tim Van Holder (tiny change) * emacsclient.c [!WINDOWSNT]: Include and . diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index b3a5180653..b7f3dd592a 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c @@ -38,6 +38,9 @@ Boston, MA 02110-1301, USA. */ # define INITIALIZE() (initialize_sockets ()) typedef unsigned long IOCTL_BOOL_ARG; #else +#ifdef HAVE_FCNTL_H +# include +#endif # include # include # define INVALID_SOCKET -1 @@ -486,7 +489,15 @@ set_tcp_socket () return INVALID_SOCKET; } +#ifdef O_NONBLOCK + IOCTL (s, O_NONBLOCK, &c_arg); +#else +#ifdef O_NDELAY + IOCTL (s, O_NDELAY, &c_arg); +#else IOCTL (s, FIONBIO, &c_arg); +#endif +#endif setsockopt (s, SOL_SOCKET, SO_LINGER, (char *) &l_arg, sizeof l_arg); /* -- cgit v1.2.3 From 411b80a566ce95fe19f40d296de1c89549bd4c7a Mon Sep 17 00:00:00 2001 From: Juanma Barranquero Date: Tue, 31 Oct 2006 16:40:11 +0000 Subject: [WINDOWSNT]: Include and . (close_winsock): Declare as __cdecl. --- lib-src/ChangeLog | 5 +++++ lib-src/emacsclient.c | 22 ++++++++++++++-------- 2 files changed, 19 insertions(+), 8 deletions(-) (limited to 'lib-src/emacsclient.c') diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog index 939cb1b24c..3a5071ddb0 100644 --- a/lib-src/ChangeLog +++ b/lib-src/ChangeLog @@ -1,3 +1,8 @@ +2006-10-31 ,bS(Bscar Fuentes (tiny change) + + * emacsclient.c [WINDOWSNT]: Include and . + (close_winsock): Declare as __cdecl. + 2006-10-31 Jan Dj,Ad(Brv * emacsclient.c [!WINDOWSNT]: Include if available. diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index b7f3dd592a..a155073c07 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c @@ -27,29 +27,35 @@ Boston, MA 02110-1301, USA. */ #endif #ifdef WINDOWSNT -#define HAVE_SOCKETS -#define NO_SOCKETS_IN_FILE_SYSTEM -#endif -#ifdef WINDOWSNT +# include +# include + +# define HAVE_SOCKETS +# define NO_SOCKETS_IN_FILE_SYSTEM + # define HSOCKET SOCKET # define CLOSE_SOCKET closesocket # define IOCTL ioctlsocket # define INITIALIZE() (initialize_sockets ()) typedef unsigned long IOCTL_BOOL_ARG; -#else + +#else /* !WINDOWSNT */ + #ifdef HAVE_FCNTL_H # include #endif # include # include + # define INVALID_SOCKET -1 # define HSOCKET int # define CLOSE_SOCKET close # define IOCTL ioctl # define INITIALIZE() typedef int IOCTL_BOOL_ARG; -#endif + +#endif /* !WINDOWSNT */ #undef signal @@ -379,7 +385,7 @@ quote_file_name (s, name) #ifdef WINDOWSNT /* Wrapper to make WSACleanup a cdecl, as required by atexit(). */ -void close_winsock () +void __cdecl close_winsock () { WSACleanup (); } @@ -497,7 +503,7 @@ set_tcp_socket () #else IOCTL (s, FIONBIO, &c_arg); #endif -#endif +#endif setsockopt (s, SOL_SOCKET, SO_LINGER, (char *) &l_arg, sizeof l_arg); /* -- cgit v1.2.3 From b73ea44bb76b1b8b08ba6fea548107e20945413d Mon Sep 17 00:00:00 2001 From: Juanma Barranquero Date: Wed, 1 Nov 2006 19:26:14 +0000 Subject: [WINDOWSNT]: Force the first argv passed to execvp to point to alternate_editor (otherwise .BAT scripts can't run). --- lib-src/emacsclient.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib-src/emacsclient.c') diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index a155073c07..28e626f77d 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c @@ -250,6 +250,9 @@ fail (argc, argv) if (alternate_editor) { int i = optind - 1; +#ifdef WINDOWSNT + argv[i] = (char *)alternate_editor; +#endif execvp (alternate_editor, argv + i); fprintf (stderr, "%s: error executing alternate editor \"%s\"\n", progname, alternate_editor); -- cgit v1.2.3 From 1e7823d0610945d420922081f678e60e5cf6df2a Mon Sep 17 00:00:00 2001 From: Juanma Barranquero Date: Thu, 2 Nov 2006 09:55:33 +0000 Subject: [WINDOWSNT]: Define HAVE_INET_SOCKETS. [!WINDOWSNT]: Include if available. [HAVE_SOCKETS]: Also require HAVE_INET_SOCKETS. (IOCTL, IOCTL_BOOL_ARG): Remove. (set_tcp_socket): Don't set the socket in blocking mode. Remove c_arg. --- lib-src/ChangeLog | 9 +++++++++ lib-src/emacsclient.c | 29 +++++++---------------------- 2 files changed, 16 insertions(+), 22 deletions(-) (limited to 'lib-src/emacsclient.c') diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog index 2c8ee548bd..d187697226 100644 --- a/lib-src/ChangeLog +++ b/lib-src/ChangeLog @@ -1,3 +1,12 @@ +2006-11-02 Tim Van Holder (tiny change) + + * emacsclient.c [WINDOWSNT]: Define HAVE_INET_SOCKETS. + [!WINDOWSNT]: Include if available. + [HAVE_SOCKETS]: Also require HAVE_INET_SOCKETS. + (IOCTL, IOCTL_BOOL_ARG): Remove. + (set_tcp_socket): Don't set the socket in blocking mode. + Remove c_arg. + 2006-11-01 Juanma Barranquero * emacsclient.c (fail) [WINDOWSNT]: Force the first argv passed to diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index 28e626f77d..bede01aaa0 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c @@ -32,28 +32,23 @@ Boston, MA 02110-1301, USA. */ # include # define HAVE_SOCKETS +# define HAVE_INET_SOCKETS # define NO_SOCKETS_IN_FILE_SYSTEM # define HSOCKET SOCKET # define CLOSE_SOCKET closesocket -# define IOCTL ioctlsocket # define INITIALIZE() (initialize_sockets ()) -typedef unsigned long IOCTL_BOOL_ARG; #else /* !WINDOWSNT */ -#ifdef HAVE_FCNTL_H -# include -#endif -# include -# include +# ifdef HAVE_INET_SOCKETS +# include +# endif # define INVALID_SOCKET -1 # define HSOCKET int # define CLOSE_SOCKET close -# define IOCTL ioctl # define INITIALIZE() -typedef int IOCTL_BOOL_ARG; #endif /* !WINDOWSNT */ @@ -271,7 +266,7 @@ fail (argc, argv) } -#if !defined (HAVE_SOCKETS) +#if !defined (HAVE_SOCKETS) || !defined (HAVE_INET_SOCKETS) int main (argc, argv) @@ -285,7 +280,7 @@ main (argc, argv) fail (argc, argv); } -#else /* HAVE_SOCKETS */ +#else /* HAVE_SOCKETS && HAVE_INET_SOCKETS */ #ifdef WINDOWSNT # include @@ -469,7 +464,6 @@ set_tcp_socket () { HSOCKET s; struct sockaddr_in server; - IOCTL_BOOL_ARG c_arg = 0; struct linger l_arg = {1, 1}; char auth_string[AUTH_KEY_LENGTH + 1]; @@ -498,15 +492,6 @@ set_tcp_socket () return INVALID_SOCKET; } -#ifdef O_NONBLOCK - IOCTL (s, O_NONBLOCK, &c_arg); -#else -#ifdef O_NDELAY - IOCTL (s, O_NDELAY, &c_arg); -#else - IOCTL (s, FIONBIO, &c_arg); -#endif -#endif setsockopt (s, SOL_SOCKET, SO_LINGER, (char *) &l_arg, sizeof l_arg); /* @@ -818,7 +803,7 @@ main (argc, argv) return EXIT_SUCCESS; } -#endif /* HAVE_SOCKETS */ +#endif /* HAVE_SOCKETS && HAVE_INET_SOCKETS */ #ifndef HAVE_STRERROR char * -- cgit v1.2.3 From 5796dab79d3da052f4916a2c37d20c32775184f0 Mon Sep 17 00:00:00 2001 From: Juanma Barranquero Date: Fri, 3 Nov 2006 16:24:53 +0000 Subject: (initialize_sockets): Don't initialize Winsock more than once. --- lib-src/emacsclient.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib-src/emacsclient.c') diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index bede01aaa0..af7c10cac7 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c @@ -390,8 +390,11 @@ void __cdecl close_winsock () void initialize_sockets () { + static done = FALSE; WSADATA wsaData; + if (done) return; + /* Initialize the WinSock2 library. */ if (WSAStartup (MAKEWORD (2, 0), &wsaData)) { @@ -400,6 +403,7 @@ void initialize_sockets () } atexit (close_winsock); + done = TRUE; } #endif /* WINDOWSNT */ -- cgit v1.2.3 From b03d27bdc16d871cd12e612818a5b1bfab6be13d Mon Sep 17 00:00:00 2001 From: Juanma Barranquero Date: Mon, 6 Nov 2006 12:41:49 +0000 Subject: (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name. (decode_options): Don't get EMACS_SERVER_FILE here, it could override command line options. (decode_options) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't parse "-s" option. (fail): Don't check for missing arguments, it is now done in set_socket. (file_name_absolute_p): New function (loosely based on the one in fileio.c). (initialize_sockets): Don't check for duplicate loading of Winsock. (get_server_config): Only try relative paths in the default directory locations. (set_tcp_socket): Don't call INITIALIZE(). Warn when connecting to a remote server. (set_socket): Call INITIALIZE(). Search explicit command-line arguments, then environment variable EMACS_SERVER_FILE, then implicit socket paths, before trying the alternate editor. (main): Use file_name_absolute_p. --- lib-src/ChangeLog | 20 +++++++ lib-src/emacsclient.c | 151 +++++++++++++++++++++++++++++++++++--------------- 2 files changed, 127 insertions(+), 44 deletions(-) (limited to 'lib-src/emacsclient.c') diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog index d25c4710cc..c240cfb956 100644 --- a/lib-src/ChangeLog +++ b/lib-src/ChangeLog @@ -1,3 +1,23 @@ +2006-11-06 Juanma Barranquero + + * emacsclient.c (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show + option --socket-name. + (decode_options): Don't get EMACS_SERVER_FILE here, it could override + command line options. + (decode_options) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't parse "-s" option. + (fail): Don't check for missing arguments, it is now done in set_socket. + (file_name_absolute_p): New function (loosely based on the one in + fileio.c). + (initialize_sockets): Don't check for duplicate loading of Winsock. + (get_server_config): Only try relative paths in the default + directory locations. + (set_tcp_socket): Don't call INITIALIZE(). Warn when connecting to + a remote server. + (set_socket): Call INITIALIZE(). Search explicit command-line + arguments, then environment variable EMACS_SERVER_FILE, then implicit + socket paths, before trying the alternate editor. + (main): Use file_name_absolute_p. + 2006-11-04 Eli Zaretskii * makefile.w32-in (../src/$(BLD)/temacs.exe): Create as temporary diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index af7c10cac7..aeb221dfed 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c @@ -115,7 +115,7 @@ char *display = NULL; /* If non-NULL, the name of an editor to fallback to if the server is not running. --alternate-editor. */ -const char * alternate_editor = NULL; +const char *alternate_editor = NULL; /* If non-NULL, the filename of the UNIX socket. */ char *socket_name = NULL; @@ -132,7 +132,9 @@ struct option longopts[] = { "help", no_argument, NULL, 'H' }, { "version", no_argument, NULL, 'V' }, { "alternate-editor", required_argument, NULL, 'a' }, +#ifndef NO_SOCKETS_IN_FILE_SYSTEM { "socket-name", required_argument, NULL, 's' }, +#endif { "server-file", required_argument, NULL, 'f' }, { "display", required_argument, NULL, 'd' }, { 0, 0, 0, 0 } @@ -147,12 +149,16 @@ decode_options (argc, argv) char **argv; { alternate_editor = getenv ("ALTERNATE_EDITOR"); - server_file = getenv ("EMACS_SERVER_FILE"); while (1) { int opt = getopt_long (argc, argv, - "VHnea:s:f:d:", longopts, 0); +#ifndef NO_SOCKETS_IN_FILE_SYSTEM + "VHnea:s:f:d:", +#else + "VHnea:f:d:", +#endif + longopts, 0); if (opt == EOF) break; @@ -168,9 +174,11 @@ decode_options (argc, argv) alternate_editor = optarg; break; +#ifndef NO_SOCKETS_IN_FILE_SYSTEM case 's': socket_name = optarg; break; +#endif case 'f': server_file = optarg; @@ -252,16 +260,6 @@ fail (argc, argv) fprintf (stderr, "%s: error executing alternate editor \"%s\"\n", progname, alternate_editor); } - else - { - fprintf (stderr, "%s: No socket or alternate editor. Please use:\n\n" -#if !defined (NO_SOCKETS_IN_FILE_SYSTEM) -"\t--socket-name\n" -#endif -"\t--server-file (or environment variable EMACS_SERVER_FILE)\n\ -\t--alternate-editor (or environment variable ALTERNATE_EDITOR)\n", - progname); - } exit (EXIT_FAILURE); } @@ -306,7 +304,8 @@ int sblen = 0; /* Fill pointer for the send buffer. */ - the data ends in "\n", or - the buffer is full (but this shouldn't happen) Otherwise, we just accumulate it. */ -void send_to_emacs (s, data) +void +send_to_emacs (s, data) HSOCKET s; char *data; { @@ -381,21 +380,46 @@ quote_file_name (s, name) free (copy); } +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. */ + if (islower (tolower (filename[0])) + && filename[1] == ':' && filename[2] == '\\') + return TRUE; + + /* Both \xxx and \\xxx\yyy are absolute. */ + if (filename[0] == '\\') return TRUE; +#endif + + return FALSE; +} + #ifdef WINDOWSNT /* Wrapper to make WSACleanup a cdecl, as required by atexit(). */ -void __cdecl close_winsock () +void +__cdecl close_winsock () { WSACleanup (); } -void initialize_sockets () +/* Initialize the WinSock2 library. */ +void +initialize_sockets () { - static done = FALSE; WSADATA wsaData; - if (done) return; - - /* Initialize the WinSock2 library. */ if (WSAStartup (MAKEWORD (2, 0), &wsaData)) { fprintf (stderr, "%s: error initializing WinSock2", progname); @@ -403,7 +427,6 @@ void initialize_sockets () } atexit (close_winsock); - done = TRUE; } #endif /* WINDOWSNT */ @@ -411,15 +434,18 @@ void initialize_sockets () * Read the information needed to set up a TCP comm channel with * the Emacs server: host, port and authentication string. */ -int get_server_config (server, authentication) +int +get_server_config (server, authentication) struct sockaddr_in *server; char *authentication; { - FILE *config; char dotted[32]; char *port; + FILE *config = NULL; - if (! (config = fopen (server_file, "rb"))) + if (file_name_absolute_p (server_file)) + config = fopen (server_file, "rb"); + else { char *home = getenv ("HOME"); #ifdef WINDOWSNT @@ -471,11 +497,13 @@ set_tcp_socket () struct linger l_arg = {1, 1}; char auth_string[AUTH_KEY_LENGTH + 1]; - INITIALIZE (); - if (! get_server_config (&server, auth_string)) return INVALID_SOCKET; + if (server.sin_addr.s_addr != inet_addr ("127.0.0.1")) + fprintf (stderr, "%s: connected to remote socket at %s\n", + progname, inet_ntoa (server.sin_addr)); + /* * Open up an AF_INET socket */ @@ -645,7 +673,7 @@ To start the server in Emacs, type \"M-x server-start\".\n", else fprintf (stderr, "%s: can't stat %s: %s\n", progname, server.sun_path, strerror (saved_errno)); - return INVALID_SOCKET; + return INVALID_SOCKET; } } @@ -664,17 +692,61 @@ To start the server in Emacs, type \"M-x server-start\".\n", HSOCKET set_socket () { - if (server_file) - return set_tcp_socket (); - else + HSOCKET s; + + INITIALIZE (); + #ifndef NO_SOCKETS_IN_FILE_SYSTEM - return set_local_socket (); -#else + /* Explicit --socket-name argument. */ + if (socket_name) + { + s = set_local_socket (); + if ((s != INVALID_SOCKET) || alternate_editor) + return s; + + fprintf (stderr, "%s: error accessing socket \"%s\"", + 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) { - server_file = "server"; - return set_tcp_socket (); + s = set_tcp_socket (); + if ((s != INVALID_SOCKET) || alternate_editor) + return s; + + fprintf (stderr, "%s: error accessing server file \"%s\"", + progname, server_file); + exit (EXIT_FAILURE); } + +#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. */ + fprintf (stderr, "%s: No socket or alternate editor. Please use:\n\n" +#ifndef NO_SOCKETS_IN_FILE_SYSTEM +"\t--socket-name\n" #endif +"\t--server-file (or environment variable EMACS_SERVER_FILE)\n\ +\t--alternate-editor (or environment variable ALTERNATE_EDITOR)\n", + progname); + exit (EXIT_FAILURE); } int @@ -748,16 +820,7 @@ main (argc, argv) SEND_STRING ("/"); } } -#ifndef WINDOWSNT - else if (*argv[i] != '/') -#else - else if ((*argv[i] != '/') - /* Absolute paths can also start with backslash - or drive letters. */ - && (*argv[i] != '\\') - && (!islower (tolower (*argv[i])) - || (argv[i][1] != ':'))) -#endif + else if (! file_name_absolute_p (argv[i])) { SEND_QUOTED (cwd); SEND_STRING ("/"); -- cgit v1.2.3 From 434a6c5d78587690f7b052fa1af83a9c800a1e8f Mon Sep 17 00:00:00 2001 From: Juanma Barranquero Date: Tue, 7 Nov 2006 10:43:45 +0000 Subject: (get_server_config): Extract also the Emacs pid from the server file. On Windows, try to force the Emacs frame to the foreground. --- lib-src/emacsclient.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'lib-src/emacsclient.c') diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index aeb221dfed..76ed21b29f 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c @@ -432,7 +432,7 @@ initialize_sockets () /* * Read the information needed to set up a TCP comm channel with - * the Emacs server: host, port and authentication string. + * the Emacs server: host, port, pid and authentication string. */ int get_server_config (server, authentication) @@ -441,6 +441,7 @@ get_server_config (server, authentication) { char dotted[32]; char *port; + char *pid; FILE *config = NULL; if (file_name_absolute_p (server_file)) @@ -464,9 +465,11 @@ get_server_config (server, authentication) return FALSE; if (fgets (dotted, sizeof dotted, config) - && (port = strchr (dotted, ':'))) + && (port = strchr (dotted, ':')) + && (pid = strchr (port, ' '))) { *port++ = '\0'; + *pid++ = '\0'; } else { @@ -486,6 +489,30 @@ get_server_config (server, authentication) fclose (config); +#ifdef WINDOWSNT + /* + Modern Windows restrict which processes can set the foreground window. + So, for emacsclient to be able to force Emacs into the foreground, we + have to call AllowSetForegroundWindow(). Unfortunately, older Windows + (W95, W98 and NT) don't have this function, so we have to check first. + + We're doing this here because it has to be done before sending info + to Emacs, and otherwise we'll need a global variable just to pass around + the pid, which is also inelegant. + */ + { + HMODULE hUser32; + + if (hUser32 = LoadLibrary ("user32.dll")) + { + void (*set_fg)(DWORD); + if (set_fg = GetProcAddress (hUser32, "AllowSetForegroundWindow")) + set_fg (atoi (pid)); + FreeLibrary (hUser32); + } + } +#endif + return TRUE; } -- cgit v1.2.3 From 88b46d84315d9a03b22467eccdcc620db05993bf Mon Sep 17 00:00:00 2001 From: Juanma Barranquero Date: Tue, 7 Nov 2006 11:23:12 +0000 Subject: (get_server_config) [WINDOWSNT]: Search the server file on APPDATA if it doesn't exist on HOME, even if HOME is defined. --- lib-src/ChangeLog | 3 +++ lib-src/emacsclient.c | 13 +++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) (limited to 'lib-src/emacsclient.c') diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog index 9210fa6afb..c2319d6486 100644 --- a/lib-src/ChangeLog +++ b/lib-src/ChangeLog @@ -1,5 +1,8 @@ 2006-11-07 Juanma Barranquero + * emacsclient.c (get_server_config) [WINDOWSNT]: Look for the server + file on APPDATA if it doesn't exist on HOME, even if HOME is defined. + * emacsclient.c (get_server_config): Extract also the Emacs pid from the server file. On Windows, try to force the Emacs frame to the foreground. diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index 76ed21b29f..3c3b27374f 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c @@ -449,16 +449,21 @@ get_server_config (server, authentication) else { char *home = getenv ("HOME"); -#ifdef WINDOWSNT - if (! home) - home = getenv ("APPDATA"); -#endif + 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"); } +#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 } if (! config) -- cgit v1.2.3 From 2dc07a1273fe9057a4c934dc8474fd0432213455 Mon Sep 17 00:00:00 2001 From: Juanma Barranquero Date: Wed, 8 Nov 2006 01:06:45 +0000 Subject: (get_server_config): Declare set_fg as FARPROC to avoid a compiler warning. --- lib-src/emacsclient.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib-src/emacsclient.c') diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index 3c3b27374f..2ad3701e07 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c @@ -510,7 +510,7 @@ get_server_config (server, authentication) if (hUser32 = LoadLibrary ("user32.dll")) { - void (*set_fg)(DWORD); + FARPROC set_fg; if (set_fg = GetProcAddress (hUser32, "AllowSetForegroundWindow")) set_fg (atoi (pid)); FreeLibrary (hUser32); -- cgit v1.2.3 From ed4a37304a10eb09a945f442bb761cde5fed6be7 Mon Sep 17 00:00:00 2001 From: Juanma Barranquero Date: Fri, 10 Nov 2006 15:44:40 +0000 Subject: [!WINDOWSNT]: Include . --- lib-src/ChangeLog | 8 ++++++-- lib-src/emacsclient.c | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'lib-src/emacsclient.c') diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog index f0784ab5e4..6873b16eb3 100644 --- a/lib-src/ChangeLog +++ b/lib-src/ChangeLog @@ -1,7 +1,11 @@ +2006-11-10 Juanma Barranquero + + * emacsclient.c [!WINDOWSNT]: Include . + 2006-11-08 Juanma Barranquero - * emacsclient.c (get_server_config): Declare set_fg as FARPROC to - avoid a compiler warning. + * emacsclient.c (get_server_config) [WINDOWSNT]: Declare set_fg as + FARPROC to avoid a compiler warning. 2006-11-07 Juanma Barranquero diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index 2ad3701e07..7cf703d40d 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c @@ -41,6 +41,8 @@ Boston, MA 02110-1301, USA. */ #else /* !WINDOWSNT */ +# include + # ifdef HAVE_INET_SOCKETS # include # endif -- cgit v1.2.3 From bc28de715d58aa574f93a5a2a28a72ca8bb724dc Mon Sep 17 00:00:00 2001 From: Juanma Barranquero Date: Mon, 13 Nov 2006 10:59:04 +0000 Subject: [WINDOWSNT]: Undef _WINSOCKAPI_ and _WINSOCK_H. --- lib-src/emacsclient.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'lib-src/emacsclient.c') diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index 7cf703d40d..a22fd1a813 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c @@ -28,10 +28,17 @@ Boston, MA 02110-1301, USA. */ #ifdef WINDOWSNT +/* config.h defines these, which disables sockets altogether! */ +# undef _WINSOCKAPI_ +# undef _WINSOCK_H + # include # include -# define HAVE_SOCKETS +# ifndef HAVE_SOCKETS +# define HAVE_SOCKETS +# endif + # define HAVE_INET_SOCKETS # define NO_SOCKETS_IN_FILE_SYSTEM -- cgit v1.2.3 From 32dd92836c26e7378293d691c25ab68435128a37 Mon Sep 17 00:00:00 2001 From: Jason Rumney Date: Mon, 13 Nov 2006 11:32:11 +0000 Subject: Let config.h define HAVE_SOCKETS and HAVE_INET_SOCKETS. --- lib-src/ChangeLog | 4 ++++ lib-src/emacsclient.c | 5 ----- 2 files changed, 4 insertions(+), 5 deletions(-) (limited to 'lib-src/emacsclient.c') diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog index 149f23ff91..f318008d73 100644 --- a/lib-src/ChangeLog +++ b/lib-src/ChangeLog @@ -1,3 +1,7 @@ +2006-11-13 Jason Rumney + * emacsclient.c [WINDOWSNT]: Let config.h define HAVE_SOCKETS and + HAVE_INET_SOCKETS. + 2006-11-13 Juanma Barranquero * makefile.w32-in (emacsclient): Depend also on emacsclientw.exe. diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index a22fd1a813..3e8c56f2ce 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c @@ -35,11 +35,6 @@ Boston, MA 02110-1301, USA. */ # include # include -# ifndef HAVE_SOCKETS -# define HAVE_SOCKETS -# endif - -# define HAVE_INET_SOCKETS # define NO_SOCKETS_IN_FILE_SYSTEM # define HSOCKET SOCKET -- cgit v1.2.3 From 42073bfb9e0c7136dd2e5d0feb6ffb6ed3b9d1ca Mon Sep 17 00:00:00 2001 From: Juanma Barranquero Date: Wed, 22 Nov 2006 14:19:35 +0000 Subject: Include . [WINDOWSNT]: Include . (w32_check_console_app): New function. (message): New function. (decode_options, print_help_and_exit, fail, main, initialize_sockets, get_server_config, set_tcp_socket, set_local_socket, set_socket): Use message(). --- lib-src/ChangeLog | 10 +++++ lib-src/emacsclient.c | 107 ++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 87 insertions(+), 30 deletions(-) (limited to 'lib-src/emacsclient.c') diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog index 70bd5bb6ed..5c6629f79d 100644 --- a/lib-src/ChangeLog +++ b/lib-src/ChangeLog @@ -1,3 +1,13 @@ +2006-11-22 Lennart Borgman + + * emacsclient.c: Include . + [WINDOWSNT]: Include . + (w32_check_console_app): New function. + (message): New function. + (decode_options, print_help_and_exit, fail, main) + (initialize_sockets, get_server_config, set_tcp_socket) + (set_local_socket, set_socket): Use message(). + 2006-11-13 Jason Rumney * emacsclient.c [WINDOWSNT]: Let config.h define HAVE_SOCKETS and diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index 3e8c56f2ce..4cd960d9ea 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c @@ -34,6 +34,7 @@ Boston, MA 02110-1301, USA. */ # include # include +# include # define NO_SOCKETS_IN_FILE_SYSTEM @@ -58,6 +59,7 @@ Boston, MA 02110-1301, USA. */ #undef signal +#include #include #include #include "getopt.h" @@ -144,6 +146,56 @@ struct option longopts[] = { 0, 0, 0, 0 } }; +/* 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, ...) +{ + char buf [2048]; + char *msg = buf; + va_list args; + + va_start (args, message); + + if (is_error) + { + sprintf (buf, "%s: ", progname); + msg = strchr (buf, '\0'); + } + + 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 + fprintf (is_error ? stderr : stdout, msg); +} + /* Decode the options from argv and argc. The global variable `optind' will say how many arguments we used up. */ @@ -201,7 +253,7 @@ decode_options (argc, argv) break; case 'V': - printf ("emacsclient %s\n", VERSION); + message (FALSE, "emacsclient %s\n", VERSION); exit (EXIT_SUCCESS); break; @@ -210,7 +262,7 @@ decode_options (argc, argv) break; default: - fprintf (stderr, "Try `%s --help' for more information\n", progname); + message (TRUE, "Try `%s --help' for more information\n", progname); exit (EXIT_FAILURE); break; } @@ -220,7 +272,7 @@ decode_options (argc, argv) void print_help_and_exit () { - printf ( + message (FALSE, "Usage: %s [OPTIONS] FILE...\n\ Tell the Emacs server to visit the specified files.\n\ Every FILE can be either just a FILENAME or [+LINE[:COLUMN]] FILENAME.\n\ @@ -261,7 +313,7 @@ fail (argc, argv) argv[i] = (char *)alternate_editor; #endif execvp (alternate_editor, argv + i); - fprintf (stderr, "%s: error executing alternate editor \"%s\"\n", + message (TRUE, "%s: error executing alternate editor \"%s\"\n", progname, alternate_editor); } exit (EXIT_FAILURE); @@ -275,9 +327,8 @@ main (argc, argv) int argc; char **argv; { - fprintf (stderr, "%s: Sorry, the Emacs server is supported only\n", + message (TRUE, "%s: Sorry, the Emacs server is supported only\non systems with Berkely sockets.\n", argv[0]); - fprintf (stderr, "on systems with Berkeley sockets.\n"); fail (argc, argv); } @@ -426,7 +477,7 @@ initialize_sockets () if (WSAStartup (MAKEWORD (2, 0), &wsaData)) { - fprintf (stderr, "%s: error initializing WinSock2", progname); + message (TRUE, "%s: error initializing WinSock2", progname); exit (EXIT_FAILURE); } @@ -482,7 +533,7 @@ get_server_config (server, authentication) } else { - fprintf (stderr, "%s: invalid configuration info", progname); + message (TRUE, "%s: invalid configuration info", progname); exit (EXIT_FAILURE); } @@ -492,7 +543,7 @@ get_server_config (server, authentication) if (! fread (authentication, AUTH_KEY_LENGTH, 1, config)) { - fprintf (stderr, "%s: cannot read authentication info", progname); + message (TRUE, "%s: cannot read authentication info", progname); exit (EXIT_FAILURE); } @@ -537,7 +588,7 @@ set_tcp_socket () return INVALID_SOCKET; if (server.sin_addr.s_addr != inet_addr ("127.0.0.1")) - fprintf (stderr, "%s: connected to remote socket at %s\n", + message (TRUE, "%s: connected to remote socket at %s\n", progname, inet_ntoa (server.sin_addr)); /* @@ -545,8 +596,7 @@ set_tcp_socket () */ if ((s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { - fprintf (stderr, "%s: ", progname); - perror ("socket"); + message (TRUE, "%s: socket: %s\n", progname, strerror (errno)); return INVALID_SOCKET; } @@ -555,8 +605,7 @@ set_tcp_socket () */ if (connect (s, (struct sockaddr *) &server, sizeof server) < 0) { - fprintf (stderr, "%s: ", progname); - perror ("connect"); + message (TRUE, "%s: connect: %s\n", progname, strerror (errno)); return INVALID_SOCKET; } @@ -608,8 +657,7 @@ set_local_socket () if ((s = socket (AF_UNIX, SOCK_STREAM, 0)) < 0) { - fprintf (stderr, "%s: ", progname); - perror ("socket"); + message (TRUE, "%s: socket: %s\n", progname, strerror (errno)); return INVALID_SOCKET; } @@ -639,7 +687,7 @@ set_local_socket () strcpy (server.sun_path, socket_name); else { - fprintf (stderr, "%s: socket-name %s too long", + message (TRUE, "%s: socket-name %s too long", progname, socket_name); exit (EXIT_FAILURE); } @@ -674,7 +722,7 @@ set_local_socket () strcpy (server.sun_path, socket_name); else { - fprintf (stderr, "%s: socket-name %s too long", + message (TRUE, "%s: socket-name %s too long", progname, socket_name); exit (EXIT_FAILURE); } @@ -694,7 +742,7 @@ set_local_socket () we are root. */ if (0 != geteuid ()) { - fprintf (stderr, "%s: Invalid socket owner\n", progname); + message (TRUE, "%s: Invalid socket owner\n", progname); return INVALID_SOCKET; } break; @@ -702,12 +750,12 @@ set_local_socket () case 2: /* `stat' failed */ if (saved_errno == ENOENT) - fprintf (stderr, + message (TRUE, "%s: can't find socket; have you started the server?\n\ To start the server in Emacs, type \"M-x server-start\".\n", progname); else - fprintf (stderr, "%s: can't stat %s: %s\n", + message (TRUE, "%s: can't stat %s: %s\n", progname, server.sun_path, strerror (saved_errno)); return INVALID_SOCKET; } @@ -716,8 +764,7 @@ To start the server in Emacs, type \"M-x server-start\".\n", if (connect (s, (struct sockaddr *) &server, strlen (server.sun_path) + 2) < 0) { - fprintf (stderr, "%s: ", progname); - perror ("connect"); + message (TRUE, "%s: connect: %s\n", progname, strerror (errno)); return INVALID_SOCKET; } @@ -740,7 +787,7 @@ set_socket () if ((s != INVALID_SOCKET) || alternate_editor) return s; - fprintf (stderr, "%s: error accessing socket \"%s\"", + message (TRUE, "%s: error accessing socket \"%s\"", progname, socket_name); exit (EXIT_FAILURE); } @@ -756,7 +803,7 @@ set_socket () if ((s != INVALID_SOCKET) || alternate_editor) return s; - fprintf (stderr, "%s: error accessing server file \"%s\"", + message (TRUE, "%s: error accessing server file \"%s\"", progname, server_file); exit (EXIT_FAILURE); } @@ -775,7 +822,7 @@ set_socket () return s; /* No implicit or explicit socket, and no alternate editor. */ - fprintf (stderr, "%s: No socket or alternate editor. Please use:\n\n" + message (TRUE, "%s: No socket or alternate editor. Please use:\n\n" #ifndef NO_SOCKETS_IN_FILE_SYSTEM "\t--socket-name\n" #endif @@ -802,8 +849,8 @@ main (argc, argv) if ((argc - optind < 1) && !eval) { - fprintf (stderr, "%s: file name or argument required\n", progname); - fprintf (stderr, "Try `%s --help' for more information\n", progname); + message (TRUE, "%s: file name or argument required\nTry `%s --help' for more information\n", + progname, progname); exit (EXIT_FAILURE); } @@ -819,10 +866,10 @@ main (argc, argv) { /* getwd puts message in STRING if it fails. */ #ifdef HAVE_GETCWD - fprintf (stderr, "%s: %s (%s)\n", progname, + message (TRUE, "%s: %s (%s)\n", progname, "Cannot get current working directory", strerror (errno)); #else - fprintf (stderr, "%s: %s (%s)\n", progname, string, strerror (errno)); + message (TRUE, "%s: %s (%s)\n", progname, string, strerror (errno)); #endif fail (argc, argv); } -- cgit v1.2.3 From 30aa95cea6439bc6742977a80b33f3e788d6574d Mon Sep 17 00:00:00 2001 From: Juanma Barranquero Date: Thu, 23 Nov 2006 01:51:38 +0000 Subject: (print_help_and_exit): Tweak message contents and tabs/spaces to improve alignment in message boxes. --- lib-src/ChangeLog | 5 +++++ lib-src/emacsclient.c | 17 +++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) (limited to 'lib-src/emacsclient.c') diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog index 5c6629f79d..b756e6a540 100644 --- a/lib-src/ChangeLog +++ b/lib-src/ChangeLog @@ -1,3 +1,8 @@ +2006-11-23 Juanma Barranquero + + * emacsclient.c (print_help_and_exit): Tweak message contents and + tabs/spaces to improve alignment in message boxes. + 2006-11-22 Lennart Borgman * emacsclient.c: Include . diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index 4cd960d9ea..4bb9af6635 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c @@ -278,19 +278,20 @@ Tell the Emacs server to visit the specified files.\n\ Every FILE can be either just a FILENAME or [+LINE[:COLUMN]] FILENAME.\n\ \n\ The following OPTIONS are accepted:\n\ --V, --version Just print a version info and return\n\ --H, --help Print this usage information message\n\ --n, --no-wait Don't wait for the server to return\n\ --e, --eval Evaluate the FILE arguments as ELisp expressions\n\ --d, --display=DISPLAY Visit the file in the given display\n" +\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" #ifndef NO_SOCKETS_IN_FILE_SYSTEM "-s, --socket-name=FILENAME\n\ - Set the filename of the UNIX socket for communication\n" + Set filename of the UNIX socket for communication\n" #endif "-f, --server-file=FILENAME\n\ - Set the filename of the TCP configuration file\n\ + Set filename of the TCP authentication file\n\ -a, --alternate-editor=EDITOR\n\ - Editor to fallback to if the server is not running\n\ + Editor to fallback to if server is not running\n\ \n\ Report bugs to bug-gnu-emacs@gnu.org.\n", progname); exit (EXIT_SUCCESS); -- cgit v1.2.3 From db9cd97ad4957831331b4ef2ad79dd20545f67a8 Mon Sep 17 00:00:00 2001 From: Juanma Barranquero Date: Fri, 24 Nov 2006 10:31:26 +0000 Subject: Space/tab mixup. --- lib-src/emacsclient.c | 2 +- lisp/play/gomoku.el | 8 ++++---- src/keyboard.c | 6 +++--- src/m/ibmrs6000.h | 6 +++--- src/m/pfa50.h | 2 +- src/msdos.c | 2 +- src/syntax.c | 2 +- src/sysdep.c | 2 +- src/w32term.c | 2 +- src/xdisp.c | 2 +- src/xselect.c | 8 ++++---- 11 files changed, 21 insertions(+), 21 deletions(-) (limited to 'lib-src/emacsclient.c') diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index 4bb9af6635..3040206ef3 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c @@ -463,7 +463,7 @@ file_name_absolute_p (filename) } #ifdef WINDOWSNT -/* Wrapper to make WSACleanup a cdecl, as required by atexit(). */ +/* Wrapper to make WSACleanup a cdecl, as required by atexit(). */ void __cdecl close_winsock () { diff --git a/lisp/play/gomoku.el b/lisp/play/gomoku.el index ee321b44d3..8b23cbb59d 100644 --- a/lisp/play/gomoku.el +++ b/lisp/play/gomoku.el @@ -29,7 +29,7 @@ ;; RULES: ;; -;; Gomoku is a game played between two players on a rectangular board. Each +;; Gomoku is a game played between two players on a rectangular board. Each ;; player, in turn, marks a free square of its choice. The winner is the first ;; one to mark five contiguous squares in any direction (horizontally, ;; vertically or diagonally). @@ -212,9 +212,9 @@ is non-nil." ;;; ;; The board is a rectangular grid. We code empty squares with 0, X's with 1 -;; and O's with 6. The rectangle is recorded in a one dimensional vector -;; containing padding squares (coded with -1). These squares allow us to -;; detect when we are trying to move out of the board. We denote a square by +;; and O's with 6. The rectangle is recorded in a one dimensional vector +;; containing padding squares (coded with -1). These squares allow us to +;; detect when we are trying to move out of the board. We denote a square by ;; its (X,Y) coords, or by the INDEX corresponding to them in the vector. The ;; leftmost topmost square has coords (1,1) and index gomoku-board-width + 2. ;; Similarly, vectors between squares may be given by two DX, DY coords or by diff --git a/src/keyboard.c b/src/keyboard.c index 364fa89353..384fc888e3 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -5706,7 +5706,7 @@ make_lispy_event (event) position = make_lispy_position (f, &event->x, &event->y, event->timestamp); - /* Set double or triple modifiers to indicate the wheel speed. */ + /* Set double or triple modifiers to indicate the wheel speed. */ { /* On window-system frames, use the value of double-click-fuzz as is. On other frames, interpret it @@ -5760,7 +5760,7 @@ make_lispy_event (event) if (event->modifiers & up_modifier) { - /* Emit a wheel-up event. */ + /* Emit a wheel-up event. */ event->modifiers &= ~up_modifier; symbol_num = 0; } @@ -5775,7 +5775,7 @@ make_lispy_event (event) the up_modifier set. */ abort (); - /* Get the symbol we should use for the wheel event. */ + /* Get the symbol we should use for the wheel event. */ head = modify_event_symbol (symbol_num, event->modifiers, Qmouse_click, diff --git a/src/m/ibmrs6000.h b/src/m/ibmrs6000.h index 3d3e45eda8..10b43bf824 100644 --- a/src/m/ibmrs6000.h +++ b/src/m/ibmrs6000.h @@ -44,7 +44,7 @@ Boston, MA 02110-1301, USA. */ #define IBMR2AIX /* Use type int rather than a union, to represent Lisp_Object */ -/* This is desirable for most machines. */ +/* This is desirable for most machines. */ #define NO_UNION_TYPE @@ -72,7 +72,7 @@ Boston, MA 02110-1301, USA. */ /* The data segment in this machine always starts at address 0x20000000. An address of data cannot be stored correctly in a Lisp object; - we always lose the high bits. We must tell XPNTR to add them back. */ + we always lose the high bits. We must tell XPNTR to add them back. */ #ifndef USG5_4 #define DATA_SEG_BITS 0x20000000 @@ -86,7 +86,7 @@ Boston, MA 02110-1301, USA. */ #define PURE_SEG_BITS 0x30000000 /* Use shared memory. */ -/* This is turned off because it does not always work. See etc/AIX.DUMP. */ +/* This is turned off because it does not always work. See etc/AIX.DUMP. */ /* #define HAVE_SHM */ #define SHMKEY 5305035 /* used for shared memory code segments */ #endif /* CANNOT_DUMP */ diff --git a/src/m/pfa50.h b/src/m/pfa50.h index 85d281073f..0b1511fd8e 100644 --- a/src/m/pfa50.h +++ b/src/m/pfa50.h @@ -50,7 +50,7 @@ Boston, MA 02110-1301, USA. */ #define NO_REMAP /* Define TEXT_START_ADDR if your linker don't set execute point to _start. - If it needed, temacs always CORE-DUMP. */ + If it needed, temacs always CORE-DUMP. */ #define TEXT_START_ADDR __start diff --git a/src/msdos.c b/src/msdos.c index 61e167a194..00ef84dc18 100644 --- a/src/msdos.c +++ b/src/msdos.c @@ -2639,7 +2639,7 @@ check_x (void) #define Ctrl 0x0200 /* ctrl scan-code */ #define Shift 0x0400 /* shift scan-code */ -static int extended_kbd; /* 101 (102) keyboard present. */ +static int extended_kbd; /* 101 (102) keyboard present. */ struct kbd_translate { unsigned char sc; diff --git a/src/syntax.c b/src/syntax.c index 052191d5fe..55f73d6d10 100644 --- a/src/syntax.c +++ b/src/syntax.c @@ -1470,7 +1470,7 @@ skip_chars (forwardp, syntaxp, string, lim, handle_iso_classes) const unsigned char *class_beg = str + i_byte + 1; const unsigned char *class_end = class_beg; const unsigned char *class_limit = str + size_byte - 2; - /* Leave room for the null. */ + /* Leave room for the null. */ unsigned char class_name[CHAR_CLASS_MAX_LENGTH + 1]; re_wctype_t cc; diff --git a/src/sysdep.c b/src/sysdep.c index 3fd134e476..625b5d619a 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -3756,7 +3756,7 @@ set_file_times (filename, atime, mtime) * sdcsvax!rmr or rmr@uscd * * Severely hacked over by John Gilmore to make a 4.2BSD compatible - * subroutine. 11Mar86; hoptoad!gnu + * subroutine. 11Mar86; hoptoad!gnu * * Modified by rmtodd@uokmax 6-28-87 -- when making an already existing dir, * subroutine didn't return EEXIST. It does now. diff --git a/src/w32term.c b/src/w32term.c index e22a9dbe1a..1316738523 100644 --- a/src/w32term.c +++ b/src/w32term.c @@ -4439,7 +4439,7 @@ w32_read_socket (sd, expected, hold_quit) /* Ignore any mouse motion that happened before this event; any subsequent mouse-movement Emacs events should reflect only motion after the - ButtonPress. */ + ButtonPress. */ f->mouse_moved = 0; } last_mouse_frame = f; diff --git a/src/xdisp.c b/src/xdisp.c index 8dc34b776c..909ec688af 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -17384,7 +17384,7 @@ pint2str (buf, width, d) /* Write a null-terminated, right justified decimal and "human readable" representation of the nonnegative integer D to BUF using - a minimal field width WIDTH. D should be smaller than 999.5e24. */ + a minimal field width WIDTH. D should be smaller than 999.5e24. */ static const char power_letter[] = { diff --git a/src/xselect.c b/src/xselect.c index cb76e229e5..72d6aa071c 100644 --- a/src/xselect.c +++ b/src/xselect.c @@ -835,7 +835,7 @@ x_reply_selection_request (event, format, data, size, type) break; /* Now wait for the requester to ack this chunk by deleting the - property. This can run random lisp code or signal. */ + property. This can run random lisp code or signal. */ TRACE1 ("Waiting for increment ACK (deletion of %s)", XGetAtomName (display, reply.property)); wait_for_property_change (wait_object); @@ -2710,11 +2710,11 @@ FRAME is on. If FRAME is nil, the selected frame is used. */) else error ("ATOM must be a symbol or a string"); - for (i = 0; i < dpyinfo->x_dnd_atoms_length; ++i) + for (i = 0; i < dpyinfo->x_dnd_atoms_length; ++i) if (dpyinfo->x_dnd_atoms[i] == x_atom) return Qnil; - if (dpyinfo->x_dnd_atoms_length == dpyinfo->x_dnd_atoms_size) + if (dpyinfo->x_dnd_atoms_length == dpyinfo->x_dnd_atoms_size) { dpyinfo->x_dnd_atoms_size *= 2; dpyinfo->x_dnd_atoms = xrealloc (dpyinfo->x_dnd_atoms, @@ -2744,7 +2744,7 @@ x_handle_dnd_message (f, event, dpyinfo, bufp) int idata[5]; size_t i; - for (i = 0; i < dpyinfo->x_dnd_atoms_length; ++i) + for (i = 0; i < dpyinfo->x_dnd_atoms_length; ++i) if (dpyinfo->x_dnd_atoms[i] == event->message_type) break; if (i == dpyinfo->x_dnd_atoms_length) return 0; -- cgit v1.2.3 From cb0297bb1a6c3f5ce7fcebcda08a29554a993d12 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Fri, 24 Nov 2006 20:59:01 +0000 Subject: (file_name_absolute_p) [WINDOWSNT]: Support absolute file names with forward slashes. --- lib-src/ChangeLog | 5 +++++ lib-src/emacsclient.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'lib-src/emacsclient.c') diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog index b756e6a540..a81852057b 100644 --- a/lib-src/ChangeLog +++ b/lib-src/ChangeLog @@ -1,3 +1,8 @@ +2006-11-24 Michael Mauger + + * emacsclient.c (file_name_absolute_p) [WINDOWSNT]: Support + absolute file names with forward slashes. + 2006-11-23 Juanma Barranquero * emacsclient.c (print_help_and_exit): Tweak message contents and diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index 3040206ef3..5e8b563984 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c @@ -452,7 +452,7 @@ file_name_absolute_p (filename) #ifdef WINDOWSNT /* X:\xxx is always absolute; X:xxx is an error and will fail. */ if (islower (tolower (filename[0])) - && filename[1] == ':' && filename[2] == '\\') + && filename[1] == ':' && (filename[2] == '\\' || filename[2] == '/')) return TRUE; /* Both \xxx and \\xxx\yyy are absolute. */ -- cgit v1.2.3 From 5f7a4874864fd6db81383554dabda16bc58fe899 Mon Sep 17 00:00:00 2001 From: Jason Rumney Date: Sat, 25 Nov 2006 00:32:40 +0000 Subject: (file_name_absolute_p) [WINDOWSNT]: Use isalpha(). --- lib-src/emacsclient.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib-src/emacsclient.c') diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index 5e8b563984..6970c1ab9a 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c @@ -451,7 +451,7 @@ file_name_absolute_p (filename) #ifdef WINDOWSNT /* X:\xxx is always absolute; X:xxx is an error and will fail. */ - if (islower (tolower (filename[0])) + if (isalpha (filename[0]) && filename[1] == ':' && (filename[2] == '\\' || filename[2] == '/')) return TRUE; -- cgit v1.2.3 From 9219db75bfd2185408cfe4fea6fef0a424b853b4 Mon Sep 17 00:00:00 2001 From: Juanma Barranquero Date: Thu, 30 Nov 2006 21:58:53 +0000 Subject: (message): Make sure the message is properly written even if it contains printf escapes, and flush the result. (set_tcp_socket): Make the message for non-local connections informational rather than an error. --- lib-src/emacsclient.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'lib-src/emacsclient.c') diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index 6970c1ab9a..5985a98c39 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c @@ -193,7 +193,12 @@ message (int is_error, char *message, ...) } else #endif - fprintf (is_error ? stderr : stdout, msg); + { + FILE *f = is_error ? stderr : stdout; + + fputs (msg, f); + fflush (f); + } } /* Decode the options from argv and argc. @@ -589,7 +594,7 @@ set_tcp_socket () return INVALID_SOCKET; if (server.sin_addr.s_addr != inet_addr ("127.0.0.1")) - message (TRUE, "%s: connected to remote socket at %s\n", + message (FALSE, "%s: connected to remote socket at %s\n", progname, inet_ntoa (server.sin_addr)); /* -- cgit v1.2.3 From c66648e0c761739084ff5a6bafa1943363bb6c3e Mon Sep 17 00:00:00 2001 From: Juanma Barranquero Date: Thu, 30 Nov 2006 22:49:38 +0000 Subject: (emacs_pid): New variable. (message): Remove leftover code. (get_server_config): Set emacs_pid. Don't allow Emacs to grab the focus yet; emacsclient can still display an informational message before sending requests to Emacs. (main): Allow Emacs to grab the focus. Simplify message() call. --- lib-src/emacsclient.c | 65 ++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 35 deletions(-) (limited to 'lib-src/emacsclient.c') diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index 5985a98c39..f05b98ecce 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c @@ -129,6 +129,9 @@ char *socket_name = NULL; /* If non-NULL, the filename of the authentication file. */ char *server_file = NULL; +/* PID of the Emacs server process. */ +int emacs_pid = 0; + void print_help_and_exit () NO_RETURN; struct option longopts[] = @@ -168,18 +171,10 @@ w32_window_app() void message (int is_error, char *message, ...) { - char buf [2048]; - char *msg = buf; + char msg [2048]; va_list args; va_start (args, message); - - if (is_error) - { - sprintf (buf, "%s: ", progname); - msg = strchr (buf, '\0'); - } - vsprintf (msg, message, args); va_end (args); @@ -555,29 +550,7 @@ get_server_config (server, authentication) fclose (config); -#ifdef WINDOWSNT - /* - Modern Windows restrict which processes can set the foreground window. - So, for emacsclient to be able to force Emacs into the foreground, we - have to call AllowSetForegroundWindow(). Unfortunately, older Windows - (W95, W98 and NT) don't have this function, so we have to check first. - - We're doing this here because it has to be done before sending info - to Emacs, and otherwise we'll need a global variable just to pass around - the pid, which is also inelegant. - */ - { - HMODULE hUser32; - - if (hUser32 = LoadLibrary ("user32.dll")) - { - FARPROC set_fg; - if (set_fg = GetProcAddress (hUser32, "AllowSetForegroundWindow")) - set_fg (atoi (pid)); - FreeLibrary (hUser32); - } - } -#endif + emacs_pid = atoi (pid); return TRUE; } @@ -871,15 +844,37 @@ main (argc, argv) if (cwd == 0) { /* getwd puts message in STRING if it fails. */ -#ifdef HAVE_GETCWD message (TRUE, "%s: %s (%s)\n", progname, - "Cannot get current working directory", strerror (errno)); +#ifdef HAVE_GETCWD + "Cannot get current working directory", #else - message (TRUE, "%s: %s (%s)\n", progname, string, strerror (errno)); + string, #endif + strerror (errno)); fail (argc, argv); } +#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 + if (nowait) SEND_STRING ("-nowait "); -- cgit v1.2.3