From 7d9fb4de782c3ff316c6ffc26f6ea291be2f653b Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Mon, 15 Apr 2013 16:39:41 +0300 Subject: [PATCH] Fixed problems with default paths and with shell-file-name. --- nt/Makefile.in | 2 +- nt/addpm.c | 17 ++++++++++++ nt/makefile.w32-in | 2 ++ src/w32.c | 67 ++++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 82 insertions(+), 6 deletions(-) diff --git a/nt/Makefile.in b/nt/Makefile.in index 0f7b3463d42..7085a5c0595 100644 --- a/nt/Makefile.in +++ b/nt/Makefile.in @@ -195,7 +195,7 @@ TAGS: ${EXE_FILES:${EXEEXT}=.c} addsection${EXEEXT}: ${srcdir}/addsection.c $(CC) ${ALL_CFLAGS} ${srcdir}/addsection.c -o addsection${EXEEXT} -addpm${EXEEXT}: ${srcdir}/addpm.c +addpm${EXEEXT}: ${srcdir}/addpm.c ${srcdir}/../src/epaths.h $(CC) ${ALL_CFLAGS} ${srcdir}/addpm.c $(LIBS_ADDPM) -o addpm${EXEEXT} ddeclient${EXEEXT}: ${srcdir}/ddeclient.c diff --git a/nt/addpm.c b/nt/addpm.c index 688e0167334..48c77821c8c 100644 --- a/nt/addpm.c +++ b/nt/addpm.c @@ -50,6 +50,10 @@ along with GNU Emacs. If not, see . */ #include #include +#ifndef OLD_PATHS +#include "../src/epaths.h" +#endif + HDDEDATA CALLBACK DdeCallback (UINT uType, UINT uFmt, HCONV hconv, HSZ hsz1, HSZ hsz2, HDDEDATA hdata, @@ -76,6 +80,7 @@ static struct entry } env_vars[] = { +#ifdef OLD_PATHS {"emacs_dir", NULL}, {"EMACSLOADPATH", "%emacs_dir%/site-lisp;%emacs_dir%/../site-lisp;%emacs_dir%/lisp;%emacs_dir%/leim"}, {"SHELL", "%emacs_dir%/bin/cmdproxy.exe"}, @@ -86,6 +91,18 @@ env_vars[] = /* {"INFOPATH", "%emacs_dir%/info"}, */ {"EMACSDOC", "%emacs_dir%/etc"}, {"TERM", "cmd"} +#else /* !OLD_PATHS */ + {"emacs_dir", NULL}, + {"EMACSLOADPATH", PATH_SITELOADSEARCH ";" PATH_LOADSEARCH}, + {"SHELL", PATH_EXEC "/cmdproxy.exe"}, + {"EMACSDATA", PATH_DATA}, + {"EMACSPATH", PATH_EXEC}, + /* We no longer set INFOPATH because Info-default-directory-list + is then ignored. */ + /* {"INFOPATH", "%emacs_dir%/info"}, */ + {"EMACSDOC", PATH_DOC}, + {"TERM", "cmd"} +#endif }; BOOL diff --git a/nt/makefile.w32-in b/nt/makefile.w32-in index d3e1c8e2228..0c2f6324188 100644 --- a/nt/makefile.w32-in +++ b/nt/makefile.w32-in @@ -29,6 +29,8 @@ TMP_DIST_DIR = emacs-$(VERSION) TRES = $(BLD)/emacs.res CLIENTRES = $(BLD)/emacsclient.res +LOCAL_FLAGS = -DOLD_PATHS=1 + XMFLAGS = ALL = $(BLD)/addpm.exe $(BLD)/ddeclient.exe $(BLD)/runemacs.exe \ diff --git a/src/w32.c b/src/w32.c index 0fa5970124a..7d63c73eb18 100644 --- a/src/w32.c +++ b/src/w32.c @@ -65,6 +65,7 @@ along with GNU Emacs. If not, see . */ #undef localtime #include "lisp.h" +#include "epaths.h" /* for SHELL */ #include #include @@ -2018,7 +2019,7 @@ init_environment (char ** argv) {"PRELOAD_WINSOCK", NULL}, {"emacs_dir", "C:/emacs"}, {"EMACSLOADPATH", NULL}, - {"SHELL", "%emacs_dir%/bin/cmdproxy.exe"}, + {"SHELL", "cmdproxy.exe"}, /* perhaps it is somewhere on PATH */ {"EMACSDATA", NULL}, {"EMACSPATH", NULL}, {"INFOPATH", NULL}, @@ -2094,9 +2095,12 @@ init_environment (char ** argv) emacs_abort (); *p = 0; - if ((p = _mbsrchr (modname, '\\')) && xstrcasecmp (p, "\\bin") == 0) + if ((p = _mbsrchr (modname, '\\')) + /* From bin means installed Emacs, from src means uninstalled. */ + && (xstrcasecmp (p, "\\bin") == 0 || xstrcasecmp (p, "\\src") == 0)) { char buf[SET_ENV_BUF_SIZE]; + int within_build_tree = xstrcasecmp (p, "\\src") == 0; *p = 0; for (p = modname; *p; p = CharNext (p)) @@ -2104,6 +2108,15 @@ init_environment (char ** argv) _snprintf (buf, sizeof (buf)-1, "emacs_dir=%s", modname); _putenv (strdup (buf)); + /* If we are running from the Posix-like build tree, define + SHELL to point to our own cmdproxy. The loop below will + then disregard PATH_EXEC and the default value. */ + if (within_build_tree) + { + _snprintf (buf, sizeof (buf) - 1, + "SHELL=%s/nt/cmdproxy.exe", modname); + _putenv (strdup (buf)); + } } /* Handle running emacs from the build directory: src/oo-spd/i386/ */ @@ -2139,16 +2152,60 @@ init_environment (char ** argv) if (!getenv (env_vars[i].name)) { int dont_free = 0; + char bufc[SET_ENV_BUF_SIZE]; if ((lpval = w32_get_resource (env_vars[i].name, &dwType)) == NULL /* Also ignore empty environment variables. */ || *lpval == 0) { xfree (lpval); - lpval = env_vars[i].def_value; - dwType = REG_EXPAND_SZ; dont_free = 1; - if (!strcmp (env_vars[i].name, "HOME") && !appdata) + if (strcmp (env_vars[i].name, "SHELL") == 0) + { + /* Look for cmdproxy.exe in every directory in + PATH_EXEC. FIXME: This does not find cmdproxy + in nt/ when we run uninstalled. */ + char fname[MAX_PATH]; + const char *pstart = PATH_EXEC, *pend; + + do { + pend = _mbschr (pstart, ';'); + if (!pend) + pend = pstart + strlen (pstart); + /* Be defensive against series of ;;; characters. */ + if (pend > pstart) + { + strncpy (fname, pstart, pend - pstart); + fname[pend - pstart] = '/'; + strcpy (&fname[pend - pstart + 1], "cmdproxy.exe"); + ExpandEnvironmentStrings ((LPSTR) fname, bufc, + sizeof (bufc)); + if (check_existing (bufc)) + { + lpval = bufc; + dwType = REG_SZ; + break; + } + } + if (*pend) + pstart = pend + 1; + else + pstart = pend; + if (!*pstart) + { + /* If not found in any directory, use the + default as the last resort. */ + lpval = env_vars[i].def_value; + dwType = REG_EXPAND_SZ; + } + } while (*pstart); + } + else + { + lpval = env_vars[i].def_value; + dwType = REG_EXPAND_SZ; + } + if (strcmp (env_vars[i].name, "HOME") == 0 && !appdata) Vdelayed_warnings_list = Fcons (listn (CONSTYPE_HEAP, 2, intern ("initialization"), -- 2.39.2