From: nhmall Date: Sat, 2 Jan 2016 01:33:14 +0000 (-0500) Subject: SYSCF_FILE corrections for windows X-Git-Tag: NetHack-3.6.1_RC01~1084 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=61148f05bb156e2a7480a8f224a11c68bf120531;p=nethack SYSCF_FILE corrections for windows Changes to be committed: modified: src/files.c modified: sys/share/pcmain.c Related to #H4170, bz274 The current startup code seeks out the SYSCONFPREFIX using: envp = nh_getenv("COMMONPROGRAMFILES"); which is fine and usually translates to something like "C:\\Program Files (x86)\\Common Files\\ NetHack then tacks on the NetHack subfolder to the path "C:\\Program Files (x86)\\Common Files\\NetHack\\" That should always be the definitive location. However, in the event that there is no SYSCF_FILE actually located at that system-wide spot (and ONLY in that event), fall back to a secondary location of HACKDIR for locating the SYSCF_FILE. Also, there's some explicit tweaking added for the Microsoft visual studio compiler debug execution to all a debug session to correctly locate things. By default, on a visual studio build, the executables are linked down in subfolders of the build directory (Release, or Debug, depending on visual studio build configuration options). --- diff --git a/src/files.c b/src/files.c index a524af027..059090b1f 100644 --- a/src/files.c +++ b/src/files.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 files.c $NHDT-Date: 1451001643 2015/12/25 00:00:43 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.197 $ */ +/* NetHack 3.6 files.c $NHDT-Date: 1451697801 2016/01/02 01:23:21 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.199 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -3355,7 +3355,11 @@ assure_syscf_file() * VMS overrides open() usage with a macro which requires it. */ #ifndef VMS +# if defined(NOCWD_ASSUMPTIONS) && defined(WIN32) + fd = open(fqname(SYSCF_FILE, SYSCONFPREFIX, 0), O_RDONLY); +# else fd = open(SYSCF_FILE, O_RDONLY); +# endif #else fd = open(SYSCF_FILE, O_RDONLY, 0); #endif diff --git a/sys/share/pcmain.c b/sys/share/pcmain.c index b8cad7718..a42c49233 100644 --- a/sys/share/pcmain.c +++ b/sys/share/pcmain.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 pcmain.c $NHDT-Date: 1449893255 2015/12/12 04:07:35 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.67 $ */ +/* NetHack 3.6 pcmain.c $NHDT-Date: 1451697809 2016/01/02 01:23:29 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.68 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -178,7 +178,33 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/ if (dir == (char *) 0) dir = exepath(argv[0]); #endif - if (dir != (char *) 0) { +#ifdef _MSC_VER + if (IsDebuggerPresent()) { + static char exepath[_MAX_PATH]; + /* check if we're running under the debugger so we can get to the right folder anyway */ + if (dir != (char *)0) { + char *top = (char *)0; + + if (strlen(dir) < (_MAX_PATH - 1)) + strcpy(exepath, dir); + top = strstr(exepath, "\\build\\.\\Debug"); + if (!top) top = strstr(exepath, "\\build\\.\\Release"); + if (top) { + *top = '\0'; + if (strlen(exepath) < (_MAX_PATH - (strlen("\\binary\\") + 1))) { + Strcat(exepath, "\\binary\\"); + if (strlen(exepath) < (PATHLEN - 1)) { + dir = exepath; + } + } + } + } + } +#endif + if (dir != (char *)0) { + int fd; + boolean have_syscf = FALSE; + (void) strncpy(hackdir, dir, PATHLEN - 1); hackdir[PATHLEN - 1] = '\0'; #ifdef NOCWD_ASSUMPTIONS @@ -206,6 +232,34 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/ } } + /* okay so we have the overriding and definitive locaton + for sysconf, but only in the event that there is not a + sysconf file there (for whatever reason), check a secondary + location rather than abort. */ + + /* Is there a SYSCF_FILE there? */ + fd = open(fqname(SYSCF_FILE, SYSCONFPREFIX, 0), O_RDONLY); + if (fd >= 0) { + /* readable */ + close(fd); + have_syscf = TRUE; + } + + if (!have_syscf) { + /* No SYSCF_FILE where there should be one, and + without an installer, a user may not be able + to place one there. So, let's try somewhere else... */ + fqn_prefix[SYSCONFPREFIX] = fqn_prefix[0]; + + /* Is there a SYSCF_FILE there? */ + fd = open(fqname(SYSCF_FILE, SYSCONFPREFIX, 0), O_RDONLY); + if (fd >= 0) { + /* readable */ + close(fd); + have_syscf = TRUE; + } + } + /* user's home directory should default to this - unless * overridden */ envp = nh_getenv("USERPROFILE");