diff options
| author | Stefan Monnier | 2010-07-23 17:23:09 +0200 |
|---|---|---|
| committer | Stefan Monnier | 2010-07-23 17:23:09 +0200 |
| commit | 0ee81a0ce066375eac701c06cdfbdebefe594fdc (patch) | |
| tree | f0dccd24163316cfe688f927681a3032a9b1fe2f /lib-src/emacsclient.c | |
| parent | 894e369ddf48e191638b8e66ce732f24ff9abe2a (diff) | |
| parent | 94da839793affa2a270bc26cee9c4d95d4dc4708 (diff) | |
| download | emacs-0ee81a0ce066375eac701c06cdfbdebefe594fdc.tar.gz emacs-0ee81a0ce066375eac701c06cdfbdebefe594fdc.zip | |
Merge from trunk
Diffstat (limited to 'lib-src/emacsclient.c')
| -rw-r--r-- | lib-src/emacsclient.c | 87 |
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 | ||
| 84 | char *getenv (), *getwd (); | 84 | char *getenv (const char *), *getwd (char *); |
| 85 | char *(getcwd) (); | 85 | char *(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. */ |
| 158 | int emacs_pid = 0; | 158 | int emacs_pid = 0; |
| 159 | 159 | ||
| 160 | void print_help_and_exit () NO_RETURN; | 160 | void print_help_and_exit (void) NO_RETURN; |
| 161 | 161 | ||
| 162 | struct option longopts[] = | 162 | struct 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 | ||
| 186 | long * | 186 | long * |
| 187 | xmalloc (size) | 187 | xmalloc (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. */ |
| 238 | char* | 237 | char* |
| 239 | get_current_dir_name () | 238 | get_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). */ |
| 314 | char * | 313 | char * |
| 315 | w32_get_resource (predefined, key, type) | 314 | w32_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 | */ |
| 350 | char * | 346 | char * |
| 351 | w32_getenv (envvar) | 347 | w32_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 | ||
| 399 | void | 394 | void |
| 400 | w32_set_user_model_id () | 395 | w32_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 | ||
| 426 | int | 421 | int |
| 427 | w32_window_app () | 422 | w32_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 | */ |
| 453 | int | 448 | int |
| 454 | w32_execvp (path, argv) | 449 | w32_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 | ||
| 519 | void | 512 | void |
| 520 | decode_options (argc, argv) | 513 | decode_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 | ||
| 647 | void | 638 | void |
| 648 | print_help_and_exit () | 639 | print_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 | ||
| 735 | extern char *strerror (); | 726 | extern 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. */ |
| 738 | char send_buffer[SEND_BUFFER_SIZE + 1]; | 729 | char 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. */ |
| 745 | void | 736 | void |
| 746 | sock_err_message (function_name) | 737 | sock_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. */ |
| 770 | void | 760 | void |
| 771 | send_to_emacs (s, data) | 761 | send_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. */ |
| 811 | void | 799 | void |
| 812 | quote_argument (s, str) | 800 | quote_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 | ||
| 853 | char * | 839 | char * |
| 854 | unquote_argument (str) | 840 | unquote_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 | ||
| 885 | int | 870 | int |
| 886 | file_name_absolute_p (filename) | 871 | file_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. */ |
| 913 | void | 897 | void __cdecl |
| 914 | __cdecl close_winsock () | 898 | close_winsock (void) |
| 915 | { | 899 | { |
| 916 | WSACleanup (); | 900 | WSACleanup (); |
| 917 | } | 901 | } |
| 918 | 902 | ||
| 919 | /* Initialize the WinSock2 library. */ | 903 | /* Initialize the WinSock2 library. */ |
| 920 | void | 904 | void |
| 921 | initialize_sockets () | 905 | initialize_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 | */ |
| 940 | int | 924 | int |
| 941 | get_server_config (server, authentication) | 925 | get_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 | ||
| 1007 | HSOCKET | 989 | HSOCKET |
| 1008 | set_tcp_socket () | 990 | set_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 | ||
| 1121 | static int | 1103 | static int |
| 1122 | socket_status (socket_name) | 1104 | socket_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 | ||
| 1225 | HSOCKET | 1206 | HSOCKET |
| 1226 | set_local_socket () | 1207 | set_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. */ | |||
| 1419 | FARPROC get_wc; /* Pointer to RealGetWindowClassA. */ | 1402 | FARPROC get_wc; /* Pointer to RealGetWindowClassA. */ |
| 1420 | 1403 | ||
| 1421 | BOOL CALLBACK | 1404 | BOOL CALLBACK |
| 1422 | w32_find_emacs_process (hWnd, lParam) | 1405 | w32_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 | */ |
| 1451 | void | 1432 | void |
| 1452 | w32_give_focus () | 1433 | w32_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 | ||
| 1528 | int | 1509 | int |
| 1529 | main (argc, argv) | 1510 | main (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; |