aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src/emacsclient.c
diff options
context:
space:
mode:
authorStefan Monnier2010-07-23 17:23:09 +0200
committerStefan Monnier2010-07-23 17:23:09 +0200
commit0ee81a0ce066375eac701c06cdfbdebefe594fdc (patch)
treef0dccd24163316cfe688f927681a3032a9b1fe2f /lib-src/emacsclient.c
parent894e369ddf48e191638b8e66ce732f24ff9abe2a (diff)
parent94da839793affa2a270bc26cee9c4d95d4dc4708 (diff)
downloademacs-0ee81a0ce066375eac701c06cdfbdebefe594fdc.tar.gz
emacs-0ee81a0ce066375eac701c06cdfbdebefe594fdc.zip
Merge from trunk
Diffstat (limited to 'lib-src/emacsclient.c')
-rw-r--r--lib-src/emacsclient.c87
1 files changed, 33 insertions, 54 deletions
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index 3172ebb8cd1..bafc7e02720 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -81,7 +81,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
81#include <errno.h> 81#include <errno.h>
82 82
83 83
84char *getenv (), *getwd (); 84char *getenv (const char *), *getwd (char *);
85char *(getcwd) (); 85char *(getcwd) ();
86 86
87#ifdef WINDOWSNT 87#ifdef WINDOWSNT
@@ -157,7 +157,7 @@ char *server_file = NULL;
157/* PID of the Emacs server process. */ 157/* PID of the Emacs server process. */
158int emacs_pid = 0; 158int emacs_pid = 0;
159 159
160void print_help_and_exit () NO_RETURN; 160void print_help_and_exit (void) NO_RETURN;
161 161
162struct option longopts[] = 162struct option longopts[] =
163{ 163{
@@ -184,8 +184,7 @@ struct option longopts[] =
184/* Like malloc but get fatal error if memory is exhausted. */ 184/* Like malloc but get fatal error if memory is exhausted. */
185 185
186long * 186long *
187xmalloc (size) 187xmalloc (unsigned int size)
188 unsigned int size;
189{ 188{
190 long *result = (long *) malloc (size); 189 long *result = (long *) malloc (size);
191 if (result == NULL) 190 if (result == NULL)
@@ -236,7 +235,7 @@ xstrdup (const char *s)
236 Any other returned value must be freed with free. This is used 235 Any other returned value must be freed with free. This is used
237 only when get_current_dir_name is not defined on the system. */ 236 only when get_current_dir_name is not defined on the system. */
238char* 237char*
239get_current_dir_name () 238get_current_dir_name (void)
240{ 239{
241 char *buf; 240 char *buf;
242 char *pwd; 241 char *pwd;
@@ -312,10 +311,7 @@ get_current_dir_name ()
312 Return NULL if the variable was not found, or it was empty. 311 Return NULL if the variable was not found, or it was empty.
313 This code is based on w32_get_resource (w32.c). */ 312 This code is based on w32_get_resource (w32.c). */
314char * 313char *
315w32_get_resource (predefined, key, type) 314w32_get_resource (HKEY predefined, char *key, LPDWORD type)
316 HKEY predefined;
317 char *key;
318 LPDWORD type;
319{ 315{
320 HKEY hrootkey = NULL; 316 HKEY hrootkey = NULL;
321 char *result = NULL; 317 char *result = NULL;
@@ -348,8 +344,7 @@ w32_get_resource (predefined, key, type)
348 variables in the registry if they don't appear in the environment. 344 variables in the registry if they don't appear in the environment.
349*/ 345*/
350char * 346char *
351w32_getenv (envvar) 347w32_getenv (char *envvar)
352 char *envvar;
353{ 348{
354 char *value; 349 char *value;
355 DWORD dwType; 350 DWORD dwType;
@@ -397,7 +392,7 @@ w32_getenv (envvar)
397} 392}
398 393
399void 394void
400w32_set_user_model_id () 395w32_set_user_model_id (void)
401{ 396{
402 HMODULE shell; 397 HMODULE shell;
403 HRESULT (WINAPI * set_user_model) (wchar_t * id); 398 HRESULT (WINAPI * set_user_model) (wchar_t * id);
@@ -424,7 +419,7 @@ w32_set_user_model_id ()
424} 419}
425 420
426int 421int
427w32_window_app () 422w32_window_app (void)
428{ 423{
429 static int window_app = -1; 424 static int window_app = -1;
430 char szTitle[MAX_PATH]; 425 char szTitle[MAX_PATH];
@@ -447,13 +442,11 @@ w32_window_app ()
447 This is necessary due to the broken implementation of exec* routines in 442 This is necessary due to the broken implementation of exec* routines in
448 the Microsoft libraries: they concatenate the arguments together without 443 the Microsoft libraries: they concatenate the arguments together without
449 quoting special characters, and pass the result to CreateProcess, with 444 quoting special characters, and pass the result to CreateProcess, with
450 predictably bad results. By contrast, Posix execvp passes the arguments 445 predictably bad results. By contrast, POSIX execvp passes the arguments
451 directly into the argv array of the child process. 446 directly into the argv array of the child process.
452*/ 447*/
453int 448int
454w32_execvp (path, argv) 449w32_execvp (const char *path, char **argv)
455 char *path;
456 char **argv;
457{ 450{
458 int i; 451 int i;
459 452
@@ -517,9 +510,7 @@ message (int is_error, char *message, ...)
517 The global variable `optind' will say how many arguments we used up. */ 510 The global variable `optind' will say how many arguments we used up. */
518 511
519void 512void
520decode_options (argc, argv) 513decode_options (int argc, char **argv)
521 int argc;
522 char **argv;
523{ 514{
524 alternate_editor = egetenv ("ALTERNATE_EDITOR"); 515 alternate_editor = egetenv ("ALTERNATE_EDITOR");
525 516
@@ -645,7 +636,7 @@ an empty string");
645 636
646 637
647void 638void
648print_help_and_exit () 639print_help_and_exit (void)
649{ 640{
650 /* Spaces and tabs are significant in this message; they're chosen so the 641 /* Spaces and tabs are significant in this message; they're chosen so the
651 message aligns properly both in a tty and in a Windows message box. 642 message aligns properly both in a tty and in a Windows message box.
@@ -732,7 +723,7 @@ main (argc, argv)
732#define AUTH_KEY_LENGTH 64 723#define AUTH_KEY_LENGTH 64
733#define SEND_BUFFER_SIZE 4096 724#define SEND_BUFFER_SIZE 4096
734 725
735extern char *strerror (); 726extern char *strerror (int);
736 727
737/* Buffer to accumulate data to send in TCP connections. */ 728/* Buffer to accumulate data to send in TCP connections. */
738char send_buffer[SEND_BUFFER_SIZE + 1]; 729char send_buffer[SEND_BUFFER_SIZE + 1];
@@ -743,8 +734,7 @@ HSOCKET emacs_socket = 0;
743/* On Windows, the socket library was historically separate from the standard 734/* On Windows, the socket library was historically separate from the standard
744 C library, so errors are handled differently. */ 735 C library, so errors are handled differently. */
745void 736void
746sock_err_message (function_name) 737sock_err_message (char *function_name)
747 char *function_name;
748{ 738{
749#ifdef WINDOWSNT 739#ifdef WINDOWSNT
750 char* msg = NULL; 740 char* msg = NULL;
@@ -768,9 +758,7 @@ sock_err_message (function_name)
768 - the buffer is full (but this shouldn't happen) 758 - the buffer is full (but this shouldn't happen)
769 Otherwise, we just accumulate it. */ 759 Otherwise, we just accumulate it. */
770void 760void
771send_to_emacs (s, data) 761send_to_emacs (HSOCKET s, char *data)
772 HSOCKET s;
773 char *data;
774{ 762{
775 while (data) 763 while (data)
776 { 764 {
@@ -807,11 +795,9 @@ send_to_emacs (s, data)
807 any initial -. Change spaces to underscores, too, so that the 795 any initial -. Change spaces to underscores, too, so that the
808 return value never contains a space. 796 return value never contains a space.
809 797
810 Does not change the string. Outputs the result to STREAM. */ 798 Does not change the string. Outputs the result to S. */
811void 799void
812quote_argument (s, str) 800quote_argument (HSOCKET s, char *str)
813 HSOCKET s;
814 char *str;
815{ 801{
816 char *copy = (char *) xmalloc (strlen (str) * 2 + 1); 802 char *copy = (char *) xmalloc (strlen (str) * 2 + 1);
817 char *p, *q; 803 char *p, *q;
@@ -851,8 +837,7 @@ quote_argument (s, str)
851 modifying the string in place. Returns STR. */ 837 modifying the string in place. Returns STR. */
852 838
853char * 839char *
854unquote_argument (str) 840unquote_argument (char *str)
855 char *str;
856{ 841{
857 char *p, *q; 842 char *p, *q;
858 843
@@ -883,8 +868,7 @@ unquote_argument (str)
883 868
884 869
885int 870int
886file_name_absolute_p (filename) 871file_name_absolute_p (const unsigned char *filename)
887 const unsigned char *filename;
888{ 872{
889 /* Sanity check, it shouldn't happen. */ 873 /* Sanity check, it shouldn't happen. */
890 if (! filename) return FALSE; 874 if (! filename) return FALSE;
@@ -910,15 +894,15 @@ file_name_absolute_p (filename)
910 894
911#ifdef WINDOWSNT 895#ifdef WINDOWSNT
912/* Wrapper to make WSACleanup a cdecl, as required by atexit. */ 896/* Wrapper to make WSACleanup a cdecl, as required by atexit. */
913void 897void __cdecl
914__cdecl close_winsock () 898close_winsock (void)
915{ 899{
916 WSACleanup (); 900 WSACleanup ();
917} 901}
918 902
919/* Initialize the WinSock2 library. */ 903/* Initialize the WinSock2 library. */
920void 904void
921initialize_sockets () 905initialize_sockets (void)
922{ 906{
923 WSADATA wsaData; 907 WSADATA wsaData;
924 908
@@ -938,9 +922,7 @@ initialize_sockets ()
938 * the Emacs server: host, port, pid and authentication string. 922 * the Emacs server: host, port, pid and authentication string.
939 */ 923 */
940int 924int
941get_server_config (server, authentication) 925get_server_config (struct sockaddr_in *server, char *authentication)
942 struct sockaddr_in *server;
943 char *authentication;
944{ 926{
945 char dotted[32]; 927 char dotted[32];
946 char *port; 928 char *port;
@@ -1005,7 +987,7 @@ get_server_config (server, authentication)
1005} 987}
1006 988
1007HSOCKET 989HSOCKET
1008set_tcp_socket () 990set_tcp_socket (void)
1009{ 991{
1010 HSOCKET s; 992 HSOCKET s;
1011 struct sockaddr_in server; 993 struct sockaddr_in server;
@@ -1119,8 +1101,7 @@ find_tty (char **tty_type, char **tty_name, int noabort)
1119 0 - success: none of the above */ 1101 0 - success: none of the above */
1120 1102
1121static int 1103static int
1122socket_status (socket_name) 1104socket_status (char *socket_name)
1123 char *socket_name;
1124{ 1105{
1125 struct stat statbfr; 1106 struct stat statbfr;
1126 1107
@@ -1223,7 +1204,7 @@ init_signals (void)
1223 1204
1224 1205
1225HSOCKET 1206HSOCKET
1226set_local_socket () 1207set_local_socket (void)
1227{ 1208{
1228 HSOCKET s; 1209 HSOCKET s;
1229 struct sockaddr_un server; 1210 struct sockaddr_un server;
@@ -1247,8 +1228,10 @@ set_local_socket ()
1247 char *server_name = "server"; 1228 char *server_name = "server";
1248 char *tmpdir; 1229 char *tmpdir;
1249 1230
1250 if (socket_name && !index (socket_name, '/') && !index (socket_name, '\\')) 1231 if (socket_name && !strchr (socket_name, '/')
1251 { /* socket_name is a file name component. */ 1232 && !strchr (socket_name, '\\'))
1233 {
1234 /* socket_name is a file name component. */
1252 server_name = socket_name; 1235 server_name = socket_name;
1253 socket_name = NULL; 1236 socket_name = NULL;
1254 default_sock = 1; /* Try both UIDs. */ 1237 default_sock = 1; /* Try both UIDs. */
@@ -1419,9 +1402,7 @@ FARPROC set_fg; /* Pointer to AllowSetForegroundWindow. */
1419FARPROC get_wc; /* Pointer to RealGetWindowClassA. */ 1402FARPROC get_wc; /* Pointer to RealGetWindowClassA. */
1420 1403
1421BOOL CALLBACK 1404BOOL CALLBACK
1422w32_find_emacs_process (hWnd, lParam) 1405w32_find_emacs_process (HWND hWnd, LPARAM lParam)
1423 HWND hWnd;
1424 LPARAM lParam;
1425{ 1406{
1426 DWORD pid; 1407 DWORD pid;
1427 char class[6]; 1408 char class[6];
@@ -1449,7 +1430,7 @@ w32_find_emacs_process (hWnd, lParam)
1449 * process id = emacs_pid. If found, allow it to grab the focus. 1430 * process id = emacs_pid. If found, allow it to grab the focus.
1450 */ 1431 */
1451void 1432void
1452w32_give_focus () 1433w32_give_focus (void)
1453{ 1434{
1454 HANDLE user32; 1435 HANDLE user32;
1455 1436
@@ -1526,9 +1507,7 @@ start_daemon_and_retry_set_socket (void)
1526} 1507}
1527 1508
1528int 1509int
1529main (argc, argv) 1510main (int argc, char **argv)
1530 int argc;
1531 char **argv;
1532{ 1511{
1533 int i, rl, needlf = 0; 1512 int i, rl, needlf = 0;
1534 char *cwd, *str; 1513 char *cwd, *str;