comparison src/w32.c @ 90428:a8190f7e546e

Merge from emacs--devo--0 Patches applied: * emacs--devo--0 (patch 285-296) - Update from CVS - Merge from gnus--rel--5.10 - Update from CVS: admin/FOR-RELEASE: Update refcard section. * gnus--rel--5.10 (patch 102-104) - Update from CVS Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-64
author Miles Bader <miles@gnu.org>
date Wed, 07 Jun 2006 18:05:10 +0000
parents 5754737d1e04 f263eba56074
children 8a8e69664178
comparison
equal deleted inserted replaced
90427:ddb25860d044 90428:a8190f7e546e
948 DWORD dwType; 948 DWORD dwType;
949 char locale_name[32]; 949 char locale_name[32];
950 struct stat ignored; 950 struct stat ignored;
951 char default_home[MAX_PATH]; 951 char default_home[MAX_PATH];
952 952
953 static struct env_entry 953 static const struct env_entry
954 { 954 {
955 char * name; 955 char * name;
956 char * def_value; 956 char * def_value;
957 } env_vars[] = 957 } dflt_envvars[] =
958 { 958 {
959 {"HOME", "C:/"}, 959 {"HOME", "C:/"},
960 {"PRELOAD_WINSOCK", NULL}, 960 {"PRELOAD_WINSOCK", NULL},
961 {"emacs_dir", "C:/emacs"}, 961 {"emacs_dir", "C:/emacs"},
962 {"EMACSLOADPATH", "%emacs_dir%/site-lisp;%emacs_dir%/../site-lisp;%emacs_dir%/lisp;%emacs_dir%/leim"}, 962 {"EMACSLOADPATH", "%emacs_dir%/site-lisp;%emacs_dir%/../site-lisp;%emacs_dir%/lisp;%emacs_dir%/leim"},
969 {"EMACSDOC", "%emacs_dir%/etc"}, 969 {"EMACSDOC", "%emacs_dir%/etc"},
970 {"TERM", "cmd"}, 970 {"TERM", "cmd"},
971 {"LANG", NULL}, 971 {"LANG", NULL},
972 }; 972 };
973 973
974 #define N_ENV_VARS sizeof(dflt_envvars)/sizeof(dflt_envvars[0])
975
976 /* We need to copy dflt_envvars[] and work on the copy because we
977 don't want the dumped Emacs to inherit the values of
978 environment variables we saw during dumping (which could be on
979 a different system). The defaults above must be left intact. */
980 struct env_entry env_vars[N_ENV_VARS];
981
982 for (i = 0; i < N_ENV_VARS; i++)
983 env_vars[i] = dflt_envvars[i];
984
974 /* For backwards compatibility, check if a .emacs file exists in C:/ 985 /* For backwards compatibility, check if a .emacs file exists in C:/
975 If not, then we can try to default to the appdata directory under the 986 If not, then we can try to default to the appdata directory under the
976 user's profile, which is more likely to be writable. */ 987 user's profile, which is more likely to be writable. */
977 if (stat ("C:/.emacs", &ignored) < 0) 988 if (stat ("C:/.emacs", &ignored) < 0)
978 { 989 {
1003 /* Get default locale info and use it for LANG. */ 1014 /* Get default locale info and use it for LANG. */
1004 if (GetLocaleInfo (LOCALE_USER_DEFAULT, 1015 if (GetLocaleInfo (LOCALE_USER_DEFAULT,
1005 LOCALE_SABBREVLANGNAME | LOCALE_USE_CP_ACP, 1016 LOCALE_SABBREVLANGNAME | LOCALE_USE_CP_ACP,
1006 locale_name, sizeof (locale_name))) 1017 locale_name, sizeof (locale_name)))
1007 { 1018 {
1008 for (i = 0; i < (sizeof (env_vars) / sizeof (env_vars[0])); i++) 1019 for (i = 0; i < N_ENV_VARS; i++)
1009 { 1020 {
1010 if (strcmp (env_vars[i].name, "LANG") == 0) 1021 if (strcmp (env_vars[i].name, "LANG") == 0)
1011 { 1022 {
1012 env_vars[i].def_value = locale_name; 1023 env_vars[i].def_value = locale_name;
1013 break; 1024 break;
1067 } 1078 }
1068 } 1079 }
1069 } 1080 }
1070 } 1081 }
1071 1082
1072 for (i = 0; i < (sizeof (env_vars) / sizeof (env_vars[0])); i++) 1083 for (i = 0; i < N_ENV_VARS; i++)
1073 { 1084 {
1074 if (!getenv (env_vars[i].name)) 1085 if (!getenv (env_vars[i].name))
1075 { 1086 {
1076 int dont_free = 0; 1087 int dont_free = 0;
1077 1088
1082 dont_free = 1; 1093 dont_free = 1;
1083 } 1094 }
1084 1095
1085 if (lpval) 1096 if (lpval)
1086 { 1097 {
1098 char buf1[SET_ENV_BUF_SIZE], buf2[SET_ENV_BUF_SIZE];
1099
1087 if (dwType == REG_EXPAND_SZ) 1100 if (dwType == REG_EXPAND_SZ)
1101 ExpandEnvironmentStrings ((LPSTR) lpval, buf1, sizeof(buf1));
1102 else if (dwType == REG_SZ)
1103 strcpy (buf1, lpval);
1104 if (dwType == REG_EXPAND_SZ || dwType == REG_SZ)
1088 { 1105 {
1089 char buf1[SET_ENV_BUF_SIZE], buf2[SET_ENV_BUF_SIZE]; 1106 _snprintf (buf2, sizeof(buf2)-1, "%s=%s", env_vars[i].name,
1090 1107 buf1);
1091 ExpandEnvironmentStrings ((LPSTR) lpval, buf1, sizeof(buf1));
1092 _snprintf (buf2, sizeof(buf2)-1, "%s=%s", env_vars[i].name, buf1);
1093 _putenv (strdup (buf2)); 1108 _putenv (strdup (buf2));
1094 }
1095 else if (dwType == REG_SZ)
1096 {
1097 char buf[SET_ENV_BUF_SIZE];
1098
1099 _snprintf (buf, sizeof(buf)-1, "%s=%s", env_vars[i].name, lpval);
1100 _putenv (strdup (buf));
1101 } 1109 }
1102 1110
1103 if (!dont_free) 1111 if (!dont_free)
1104 xfree (lpval); 1112 xfree (lpval);
1105 } 1113 }