aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGeoff Voelker1995-11-07 07:36:09 +0000
committerGeoff Voelker1995-11-07 07:36:09 +0000
commitf332b293c55b8b2b17a0b53e7ad4778afe50ba9d (patch)
tree0a2b86940210bfee36e1e3b5001a3ee803b2d548 /src
parent46c91229fab2761d3fe7cf4bd4f809e59f8923c5 (diff)
downloademacs-f332b293c55b8b2b17a0b53e7ad4778afe50ba9d.tar.gz
emacs-f332b293c55b8b2b17a0b53e7ad4778afe50ba9d.zip
(nt_get_resource, init_environment): Defined.
(prepare_standard_handles, restore_standard_handles) [HAVE_NTGUI]: Don't duplicate or restore standard handles.
Diffstat (limited to 'src')
-rw-r--r--src/w32.c107
1 files changed, 107 insertions, 0 deletions
diff --git a/src/w32.c b/src/w32.c
index da286ec7811..ae7f299dd03 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -458,6 +458,7 @@ prepare_standard_handles (int in, int out, int err, HANDLE handles[4])
458 stdout_save = GetStdHandle (STD_OUTPUT_HANDLE); 458 stdout_save = GetStdHandle (STD_OUTPUT_HANDLE);
459 stderr_save = GetStdHandle (STD_ERROR_HANDLE); 459 stderr_save = GetStdHandle (STD_ERROR_HANDLE);
460 460
461#ifndef HAVE_NTGUI
461 if (!DuplicateHandle (parent, 462 if (!DuplicateHandle (parent,
462 GetStdHandle (STD_INPUT_HANDLE), 463 GetStdHandle (STD_INPUT_HANDLE),
463 parent, 464 parent,
@@ -484,6 +485,7 @@ prepare_standard_handles (int in, int out, int err, HANDLE handles[4])
484 FALSE, 485 FALSE,
485 DUPLICATE_SAME_ACCESS)) 486 DUPLICATE_SAME_ACCESS))
486 report_file_error ("Duplicating parent's error handle", Qnil); 487 report_file_error ("Duplicating parent's error handle", Qnil);
488#endif /* !HAVE_NTGUI */
487 489
488 if (!SetStdHandle (STD_INPUT_HANDLE, (HANDLE) _get_osfhandle (in))) 490 if (!SetStdHandle (STD_INPUT_HANDLE, (HANDLE) _get_osfhandle (in)))
489 report_file_error ("Changing stdin handle", Qnil); 491 report_file_error ("Changing stdin handle", Qnil);
@@ -528,6 +530,7 @@ reset_standard_handles (int in, int out, int err, HANDLE handles[4])
528 HANDLE err_handle = handles[3]; 530 HANDLE err_handle = handles[3];
529 int i; 531 int i;
530 532
533#ifndef HAVE_NTGUI
531 if (!SetStdHandle (STD_INPUT_HANDLE, stdin_save)) 534 if (!SetStdHandle (STD_INPUT_HANDLE, stdin_save))
532 report_file_error ("Resetting input handle", Qnil); 535 report_file_error ("Resetting input handle", Qnil);
533 536
@@ -539,6 +542,7 @@ reset_standard_handles (int in, int out, int err, HANDLE handles[4])
539 542
540 if (!SetStdHandle (STD_ERROR_HANDLE, stderr_save)) 543 if (!SetStdHandle (STD_ERROR_HANDLE, stderr_save))
541 report_file_error ("Resetting error handle", Qnil); 544 report_file_error ("Resetting error handle", Qnil);
545#endif /* !HAVE_NTGUI */
542 546
543 if (out == err) 547 if (out == err)
544 { 548 {
@@ -662,6 +666,109 @@ crlf_to_lf (n, buf)
662 return np - startp; 666 return np - startp;
663} 667}
664 668
669#define REG_ROOT "SOFTWARE\\GNU\\Emacs\\"
670
671LPBYTE
672nt_get_resource (key, lpdwtype)
673 char *key;
674 LPDWORD lpdwtype;
675{
676 LPBYTE lpvalue;
677 HKEY hrootkey = NULL;
678 DWORD cbData;
679 BOOL ok = FALSE;
680
681 /* Check both the current user and the local machine to see if
682 we have any resources. */
683
684 if (RegOpenKeyEx (HKEY_CURRENT_USER, REG_ROOT, 0, KEY_READ, &hrootkey) == ERROR_SUCCESS)
685 {
686 lpvalue = NULL;
687
688 if (RegQueryValueEx (hrootkey, key, NULL, NULL, NULL, &cbData) == ERROR_SUCCESS
689 && (lpvalue = (LPBYTE) xmalloc (cbData)) != NULL
690 && RegQueryValueEx (hrootkey, key, NULL, lpdwtype, lpvalue, &cbData) == ERROR_SUCCESS)
691 {
692 return (lpvalue);
693 }
694
695 if (lpvalue) xfree (lpvalue);
696
697 RegCloseKey (hrootkey);
698 }
699
700 if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, REG_ROOT, 0, KEY_READ, &hrootkey) == ERROR_SUCCESS)
701 {
702 lpvalue = NULL;
703
704 if (RegQueryValueEx (hrootkey, key, NULL, NULL, NULL, &cbData) == ERROR_SUCCESS &&
705 (lpvalue = (LPBYTE) xmalloc (cbData)) != NULL &&
706 RegQueryValueEx (hrootkey, key, NULL, lpdwtype, lpvalue, &cbData) == ERROR_SUCCESS)
707 {
708 return (lpvalue);
709 }
710
711 if (lpvalue) xfree (lpvalue);
712
713 RegCloseKey (hrootkey);
714 }
715
716 return (NULL);
717}
718
719void
720init_environment ()
721{
722 /* Open a console window to display messages during dumping. */
723 if (!initialized)
724 AllocConsole ();
725
726 /* Check for environment variables and use registry if they don't exist */
727 {
728 int i;
729 LPBYTE lpval;
730 DWORD dwType;
731
732 static char * env_vars[] =
733 {
734 "emacs_path",
735 "EMACSLOADPATH",
736 "SHELL",
737 "EMACSDATA",
738 "EMACSPATH",
739 "EMACSLOCKDIR",
740 "INFOPATH",
741 "EMACSDOC",
742 "TERM",
743 };
744
745 for (i = 0; i < (sizeof (env_vars) / sizeof (env_vars[0])); i++)
746 {
747 if (!getenv (env_vars[i]) &&
748 (lpval = nt_get_resource (env_vars[i], &dwType)) != NULL)
749 {
750 if (dwType == REG_EXPAND_SZ)
751 {
752 char buf1[500], buf2[500];
753
754 ExpandEnvironmentStrings ((LPSTR) lpval, buf1, 500);
755 _snprintf (buf2, 499, "%s=%s", env_vars[i], buf1);
756 putenv (strdup (buf2));
757 }
758 else if (dwType == REG_SZ)
759 {
760 char buf[500];
761
762 _snprintf (buf, 499, "%s=%s", env_vars[i], lpval);
763 putenv (strdup (buf));
764 }
765
766 xfree (lpval);
767 }
768 }
769 }
770}
771
665#ifdef HAVE_TIMEVAL 772#ifdef HAVE_TIMEVAL
666#include <sys/timeb.h> 773#include <sys/timeb.h>
667 774