diff options
| author | Miles Bader | 2007-10-27 09:12:07 +0000 |
|---|---|---|
| committer | Miles Bader | 2007-10-27 09:12:07 +0000 |
| commit | 18cd1f1a08833b0baad21c1d7b13a6845d95cf57 (patch) | |
| tree | 03f33df7513d15bd5de0348aec35ef82bd061508 /lib-src | |
| parent | 74863e7a78b1c8da1094a8250660a009c3b23015 (diff) | |
| parent | fdc9061358d3654e14bfc1419632e1d6c6c5c13e (diff) | |
| download | emacs-18cd1f1a08833b0baad21c1d7b13a6845d95cf57.tar.gz emacs-18cd1f1a08833b0baad21c1d7b13a6845d95cf57.zip | |
Merge from emacs--devo--0
Patches applied:
* emacs--devo--0 (patch 902-908)
- Update from CVS
- Merge from emacs--rel--22
* emacs--rel--22 (patch 131-137)
- Update from CVS
- Merge from gnus--rel--5.10
* gnus--rel--5.10 (patch 261-262)
- Update from CVS
Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-278
Diffstat (limited to 'lib-src')
| -rw-r--r-- | lib-src/ChangeLog | 17 | ||||
| -rw-r--r-- | lib-src/emacsclient.c | 138 |
2 files changed, 143 insertions, 12 deletions
diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog index 6ea05fb9e9a..14b668d2d24 100644 --- a/lib-src/ChangeLog +++ b/lib-src/ChangeLog | |||
| @@ -1,3 +1,18 @@ | |||
| 1 | 2007-10-26 Juanma Barranquero <lekktu@gmail.com> | ||
| 2 | |||
| 3 | * emacsclient.c: Add a wrapper for getenv so it also checks the | ||
| 4 | registry on Windows. Suggestion and algorithm by Eli Zaretskii. | ||
| 5 | Code partially based on w32_get_resource and init_environment (w32.c). | ||
| 6 | (egetenv): New wrapper for getenv. | ||
| 7 | (get_current_dir_name, decode_options, get_server_config) | ||
| 8 | (set_local_socket, set_socket, main): Use egetenv, not getenv. | ||
| 9 | (w32_get_resource, w32_getenv) [WINDOWSNT]: New functions. | ||
| 10 | |||
| 11 | 2007-10-25 Jason Rumney <jasonr@gnu.org> | ||
| 12 | |||
| 13 | * emacsclient.c (sock_err_message): New function. | ||
| 14 | (set_tcp_socket): Use it. | ||
| 15 | |||
| 1 | 2007-10-09 Juanma Barranquero <lekktu@gmail.com> | 16 | 2007-10-09 Juanma Barranquero <lekktu@gmail.com> |
| 2 | 17 | ||
| 3 | * emacsclient.c (print_help_and_exit): Fix space to improve | 18 | * emacsclient.c (print_help_and_exit): Fix space to improve |
| @@ -60,7 +75,7 @@ | |||
| 60 | option. | 75 | option. |
| 61 | (main) [NO_SOCKETS_IN_FILE_SYSTEM]: Don't call init_signals. | 76 | (main) [NO_SOCKETS_IN_FILE_SYSTEM]: Don't call init_signals. |
| 62 | 77 | ||
| 63 | 2007-08-29 Karoly Lorentey <lorentey@elte.hu> | 78 | 2007-08-29 K,Aa(Broly L$,1 q(Brentey <lorentey@elte.hu> |
| 64 | 79 | ||
| 65 | * emacsclient.c (signal.h): New include. | 80 | * emacsclient.c (signal.h): New include. |
| 66 | (sys/stat.h, errno.h): Always include, even on WINDOWSNT. | 81 | (sys/stat.h, errno.h): Always include, even on WINDOWSNT. |
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index bfa4f9c01d7..99e0dc3ce3d 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c | |||
| @@ -86,6 +86,13 @@ Boston, MA 02110-1301, USA. */ | |||
| 86 | char *getenv (), *getwd (); | 86 | char *getenv (), *getwd (); |
| 87 | char *(getcwd) (); | 87 | char *(getcwd) (); |
| 88 | 88 | ||
| 89 | #ifdef WINDOWSNT | ||
| 90 | char *w32_getenv (); | ||
| 91 | #define egetenv(VAR) w32_getenv(VAR) | ||
| 92 | #else | ||
| 93 | #define egetenv(VAR) getenv(VAR) | ||
| 94 | #endif | ||
| 95 | |||
| 89 | #ifndef VERSION | 96 | #ifndef VERSION |
| 90 | #define VERSION "unspecified" | 97 | #define VERSION "unspecified" |
| 91 | #endif | 98 | #endif |
| @@ -231,7 +238,7 @@ get_current_dir_name () | |||
| 231 | /* If PWD is accurate, use it instead of calling getwd. PWD is | 238 | /* If PWD is accurate, use it instead of calling getwd. PWD is |
| 232 | sometimes a nicer name, and using it may avoid a fatal error if a | 239 | sometimes a nicer name, and using it may avoid a fatal error if a |
| 233 | parent directory is searchable but not readable. */ | 240 | parent directory is searchable but not readable. */ |
| 234 | if ((pwd = getenv ("PWD")) != 0 | 241 | if ((pwd = egetenv ("PWD")) != 0 |
| 235 | && (IS_DIRECTORY_SEP (*pwd) || (*pwd && IS_DEVICE_SEP (pwd[1]))) | 242 | && (IS_DIRECTORY_SEP (*pwd) || (*pwd && IS_DEVICE_SEP (pwd[1]))) |
| 236 | && stat (pwd, &pwdstat) == 0 | 243 | && stat (pwd, &pwdstat) == 0 |
| 237 | && stat (".", &dotstat) == 0 | 244 | && stat (".", &dotstat) == 0 |
| @@ -294,6 +301,92 @@ get_current_dir_name () | |||
| 294 | /* Message functions. */ | 301 | /* Message functions. */ |
| 295 | 302 | ||
| 296 | #ifdef WINDOWSNT | 303 | #ifdef WINDOWSNT |
| 304 | |||
| 305 | #define REG_ROOT "SOFTWARE\\GNU\\Emacs" | ||
| 306 | |||
| 307 | /* Retrieve an environment variable from the Emacs subkeys of the registry. | ||
| 308 | Return NULL if the variable was not found, or it was empty. | ||
| 309 | This code is based on w32_get_resource (w32.c). */ | ||
| 310 | char * | ||
| 311 | w32_get_resource (predefined, key, type) | ||
| 312 | HKEY predefined; | ||
| 313 | char *key; | ||
| 314 | LPDWORD type; | ||
| 315 | { | ||
| 316 | HKEY hrootkey = NULL; | ||
| 317 | char *result = NULL; | ||
| 318 | DWORD cbData; | ||
| 319 | |||
| 320 | if (RegOpenKeyEx (predefined, REG_ROOT, 0, KEY_READ, &hrootkey) == ERROR_SUCCESS) | ||
| 321 | { | ||
| 322 | if (RegQueryValueEx (hrootkey, key, NULL, NULL, NULL, &cbData) == ERROR_SUCCESS) | ||
| 323 | { | ||
| 324 | result = (char *) xmalloc (cbData); | ||
| 325 | |||
| 326 | if ((RegQueryValueEx (hrootkey, key, NULL, type, result, &cbData) != ERROR_SUCCESS) || | ||
| 327 | (*result == 0)) | ||
| 328 | { | ||
| 329 | free (result); | ||
| 330 | result = NULL; | ||
| 331 | } | ||
| 332 | } | ||
| 333 | |||
| 334 | RegCloseKey (hrootkey); | ||
| 335 | } | ||
| 336 | |||
| 337 | return result; | ||
| 338 | } | ||
| 339 | |||
| 340 | /* | ||
| 341 | getenv wrapper for Windows | ||
| 342 | |||
| 343 | This is needed to duplicate Emacs's behavior, which is to look for enviroment | ||
| 344 | variables in the registry if they don't appear in the environment. | ||
| 345 | */ | ||
| 346 | char * | ||
| 347 | w32_getenv (envvar) | ||
| 348 | char *envvar; | ||
| 349 | { | ||
| 350 | char *value; | ||
| 351 | DWORD dwType; | ||
| 352 | |||
| 353 | if (value = getenv (envvar)) | ||
| 354 | /* Found in the environment. */ | ||
| 355 | return value; | ||
| 356 | |||
| 357 | if (! (value = w32_get_resource (HKEY_CURRENT_USER, envvar, &dwType)) && | ||
| 358 | ! (value = w32_get_resource (HKEY_LOCAL_MACHINE, envvar, &dwType))) | ||
| 359 | /* Not found in the registry. */ | ||
| 360 | return NULL; | ||
| 361 | |||
| 362 | if (dwType == REG_SZ) | ||
| 363 | /* Registry; no need to expand. */ | ||
| 364 | return value; | ||
| 365 | |||
| 366 | if (dwType == REG_EXPAND_SZ) | ||
| 367 | { | ||
| 368 | DWORD size; | ||
| 369 | |||
| 370 | if (size = ExpandEnvironmentStrings (value, NULL, 0)) | ||
| 371 | { | ||
| 372 | char *buffer = (char *) xmalloc (size); | ||
| 373 | if (ExpandEnvironmentStrings (value, buffer, size)) | ||
| 374 | { | ||
| 375 | /* Found and expanded. */ | ||
| 376 | free (value); | ||
| 377 | return buffer; | ||
| 378 | } | ||
| 379 | |||
| 380 | /* Error expanding. */ | ||
| 381 | free (buffer); | ||
| 382 | } | ||
| 383 | } | ||
| 384 | |||
| 385 | /* Not the right type, or not correctly expanded. */ | ||
| 386 | free (value); | ||
| 387 | return NULL; | ||
| 388 | } | ||
| 389 | |||
| 297 | int | 390 | int |
| 298 | w32_window_app () | 391 | w32_window_app () |
| 299 | { | 392 | { |
| @@ -383,8 +476,8 @@ decode_options (argc, argv) | |||
| 383 | int argc; | 476 | int argc; |
| 384 | char **argv; | 477 | char **argv; |
| 385 | { | 478 | { |
| 386 | alternate_editor = getenv ("ALTERNATE_EDITOR"); | 479 | alternate_editor = egetenv ("ALTERNATE_EDITOR"); |
| 387 | display = getenv ("DISPLAY"); | 480 | display = egetenv ("DISPLAY"); |
| 388 | if (display && strlen (display) == 0) | 481 | if (display && strlen (display) == 0) |
| 389 | display = NULL; | 482 | display = NULL; |
| 390 | 483 | ||
| @@ -573,6 +666,29 @@ int sblen = 0; /* Fill pointer for the send buffer. */ | |||
| 573 | /* Socket used to communicate with the Emacs server process. */ | 666 | /* Socket used to communicate with the Emacs server process. */ |
| 574 | HSOCKET emacs_socket = 0; | 667 | HSOCKET emacs_socket = 0; |
| 575 | 668 | ||
| 669 | /* On Windows, the socket library was historically separate from the standard | ||
| 670 | C library, so errors are handled differently. */ | ||
| 671 | void | ||
| 672 | sock_err_message (function_name) | ||
| 673 | char *function_name; | ||
| 674 | { | ||
| 675 | #ifdef WINDOWSNT | ||
| 676 | char* msg = NULL; | ||
| 677 | |||
| 678 | FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM | ||
| 679 | | FORMAT_MESSAGE_ALLOCATE_BUFFER | ||
| 680 | | FORMAT_MESSAGE_ARGUMENT_ARRAY, | ||
| 681 | NULL, WSAGetLastError (), 0, (LPTSTR)&msg, 0, NULL); | ||
| 682 | |||
| 683 | message (TRUE, "%s: %s: %s\n", progname, function_name, msg); | ||
| 684 | |||
| 685 | LocalFree (msg); | ||
| 686 | #else | ||
| 687 | message (TRUE, "%s: %s: %s\n", progname, function_name, strerror (errno)); | ||
| 688 | #endif | ||
| 689 | } | ||
| 690 | |||
| 691 | |||
| 576 | /* Let's send the data to Emacs when either | 692 | /* Let's send the data to Emacs when either |
| 577 | - the data ends in "\n", or | 693 | - the data ends in "\n", or |
| 578 | - the buffer is full (but this shouldn't happen) | 694 | - the buffer is full (but this shouldn't happen) |
| @@ -793,7 +909,7 @@ get_server_config (server, authentication) | |||
| 793 | config = fopen (server_file, "rb"); | 909 | config = fopen (server_file, "rb"); |
| 794 | else | 910 | else |
| 795 | { | 911 | { |
| 796 | char *home = getenv ("HOME"); | 912 | char *home = egetenv ("HOME"); |
| 797 | 913 | ||
| 798 | if (home) | 914 | if (home) |
| 799 | { | 915 | { |
| @@ -802,7 +918,7 @@ get_server_config (server, authentication) | |||
| 802 | config = fopen (path, "rb"); | 918 | config = fopen (path, "rb"); |
| 803 | } | 919 | } |
| 804 | #ifdef WINDOWSNT | 920 | #ifdef WINDOWSNT |
| 805 | if (!config && (home = getenv ("APPDATA"))) | 921 | if (!config && (home = egetenv ("APPDATA"))) |
| 806 | { | 922 | { |
| 807 | char *path = alloca (32 + strlen (home) + strlen (server_file)); | 923 | char *path = alloca (32 + strlen (home) + strlen (server_file)); |
| 808 | sprintf (path, "%s/.emacs.d/server/%s", home, server_file); | 924 | sprintf (path, "%s/.emacs.d/server/%s", home, server_file); |
| @@ -864,7 +980,7 @@ set_tcp_socket () | |||
| 864 | */ | 980 | */ |
| 865 | if ((s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) | 981 | if ((s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) |
| 866 | { | 982 | { |
| 867 | message (TRUE, "%s: socket: %s\n", progname, strerror (errno)); | 983 | sock_err_message ("socket"); |
| 868 | return INVALID_SOCKET; | 984 | return INVALID_SOCKET; |
| 869 | } | 985 | } |
| 870 | 986 | ||
| @@ -873,7 +989,7 @@ set_tcp_socket () | |||
| 873 | */ | 989 | */ |
| 874 | if (connect (s, (struct sockaddr *) &server, sizeof server) < 0) | 990 | if (connect (s, (struct sockaddr *) &server, sizeof server) < 0) |
| 875 | { | 991 | { |
| 876 | message (TRUE, "%s: connect: %s\n", progname, strerror (errno)); | 992 | sock_err_message ("connect"); |
| 877 | return INVALID_SOCKET; | 993 | return INVALID_SOCKET; |
| 878 | } | 994 | } |
| 879 | 995 | ||
| @@ -1066,10 +1182,10 @@ set_local_socket () | |||
| 1066 | associated with the name. This is reminiscent of the logic | 1182 | associated with the name. This is reminiscent of the logic |
| 1067 | that init_editfns uses to set the global Vuser_full_name. */ | 1183 | that init_editfns uses to set the global Vuser_full_name. */ |
| 1068 | 1184 | ||
| 1069 | char *user_name = (char *) getenv ("LOGNAME"); | 1185 | char *user_name = (char *) egetenv ("LOGNAME"); |
| 1070 | 1186 | ||
| 1071 | if (!user_name) | 1187 | if (!user_name) |
| 1072 | user_name = (char *) getenv ("USER"); | 1188 | user_name = (char *) egetenv ("USER"); |
| 1073 | 1189 | ||
| 1074 | if (user_name) | 1190 | if (user_name) |
| 1075 | { | 1191 | { |
| @@ -1158,7 +1274,7 @@ set_socket () | |||
| 1158 | 1274 | ||
| 1159 | /* Explicit --server-file arg or EMACS_SERVER_FILE variable. */ | 1275 | /* Explicit --server-file arg or EMACS_SERVER_FILE variable. */ |
| 1160 | if (!server_file) | 1276 | if (!server_file) |
| 1161 | server_file = getenv ("EMACS_SERVER_FILE"); | 1277 | server_file = egetenv ("EMACS_SERVER_FILE"); |
| 1162 | 1278 | ||
| 1163 | if (server_file) | 1279 | if (server_file) |
| 1164 | { | 1280 | { |
| @@ -1331,7 +1447,7 @@ main (argc, argv) | |||
| 1331 | 1447 | ||
| 1332 | if (tty) | 1448 | if (tty) |
| 1333 | { | 1449 | { |
| 1334 | char *type = getenv ("TERM"); | 1450 | char *type = egetenv ("TERM"); |
| 1335 | char *tty_name = NULL; | 1451 | char *tty_name = NULL; |
| 1336 | #ifndef WINDOWSNT | 1452 | #ifndef WINDOWSNT |
| 1337 | tty_name = ttyname (fileno (stdin)); | 1453 | tty_name = ttyname (fileno (stdin)); |