aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/ChangeLog12
-rw-r--r--lib-src/emacsclient.c111
2 files changed, 113 insertions, 10 deletions
diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog
index 6ea05fb9e9a..d4a05722a3c 100644
--- a/lib-src/ChangeLog
+++ b/lib-src/ChangeLog
@@ -1,3 +1,13 @@
12007-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
12007-10-09 Juanma Barranquero <lekktu@gmail.com> 112007-10-09 Juanma Barranquero <lekktu@gmail.com>
2 12
3 * emacsclient.c (print_help_and_exit): Fix space to improve 13 * emacsclient.c (print_help_and_exit): Fix space to improve
@@ -60,7 +70,7 @@
60 option. 70 option.
61 (main) [NO_SOCKETS_IN_FILE_SYSTEM]: Don't call init_signals. 71 (main) [NO_SOCKETS_IN_FILE_SYSTEM]: Don't call init_signals.
62 72
632007-08-29 Karoly Lorentey <lorentey@elte.hu> 732007-08-29 K,Aa(Broly L$,1 q(Brentey <lorentey@elte.hu>
64 74
65 * emacsclient.c (signal.h): New include. 75 * emacsclient.c (signal.h): New include.
66 (sys/stat.h, errno.h): Always include, even on WINDOWSNT. 76 (sys/stat.h, errno.h): Always include, even on WINDOWSNT.
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index bfa4f9c01d7..a48a33f68b8 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -86,6 +86,13 @@ Boston, MA 02110-1301, USA. */
86char *getenv (), *getwd (); 86char *getenv (), *getwd ();
87char *(getcwd) (); 87char *(getcwd) ();
88 88
89#ifdef WINDOWSNT
90char *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). */
310char *
311w32_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*/
346char *
347w32_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
297int 390int
298w32_window_app () 391w32_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
@@ -793,7 +886,7 @@ get_server_config (server, authentication)
793 config = fopen (server_file, "rb"); 886 config = fopen (server_file, "rb");
794 else 887 else
795 { 888 {
796 char *home = getenv ("HOME"); 889 char *home = egetenv ("HOME");
797 890
798 if (home) 891 if (home)
799 { 892 {
@@ -802,7 +895,7 @@ get_server_config (server, authentication)
802 config = fopen (path, "rb"); 895 config = fopen (path, "rb");
803 } 896 }
804#ifdef WINDOWSNT 897#ifdef WINDOWSNT
805 if (!config && (home = getenv ("APPDATA"))) 898 if (!config && (home = egetenv ("APPDATA")))
806 { 899 {
807 char *path = alloca (32 + strlen (home) + strlen (server_file)); 900 char *path = alloca (32 + strlen (home) + strlen (server_file));
808 sprintf (path, "%s/.emacs.d/server/%s", home, server_file); 901 sprintf (path, "%s/.emacs.d/server/%s", home, server_file);
@@ -1066,10 +1159,10 @@ set_local_socket ()
1066 associated with the name. This is reminiscent of the logic 1159 associated with the name. This is reminiscent of the logic
1067 that init_editfns uses to set the global Vuser_full_name. */ 1160 that init_editfns uses to set the global Vuser_full_name. */
1068 1161
1069 char *user_name = (char *) getenv ("LOGNAME"); 1162 char *user_name = (char *) egetenv ("LOGNAME");
1070 1163
1071 if (!user_name) 1164 if (!user_name)
1072 user_name = (char *) getenv ("USER"); 1165 user_name = (char *) egetenv ("USER");
1073 1166
1074 if (user_name) 1167 if (user_name)
1075 { 1168 {
@@ -1158,7 +1251,7 @@ set_socket ()
1158 1251
1159 /* Explicit --server-file arg or EMACS_SERVER_FILE variable. */ 1252 /* Explicit --server-file arg or EMACS_SERVER_FILE variable. */
1160 if (!server_file) 1253 if (!server_file)
1161 server_file = getenv ("EMACS_SERVER_FILE"); 1254 server_file = egetenv ("EMACS_SERVER_FILE");
1162 1255
1163 if (server_file) 1256 if (server_file)
1164 { 1257 {
@@ -1331,7 +1424,7 @@ main (argc, argv)
1331 1424
1332 if (tty) 1425 if (tty)
1333 { 1426 {
1334 char *type = getenv ("TERM"); 1427 char *type = egetenv ("TERM");
1335 char *tty_name = NULL; 1428 char *tty_name = NULL;
1336#ifndef WINDOWSNT 1429#ifndef WINDOWSNT
1337 tty_name = ttyname (fileno (stdin)); 1430 tty_name = ttyname (fileno (stdin));