preserve change from old branch

This commit is contained in:
nhmall
2018-05-18 21:42:41 -04:00
parent 546321d055
commit 3b77543bcc

View File

@@ -1,83 +0,0 @@
diff --git a/sys/unix/unixmain.c b/sys/unix/unixmain.c
index c1069144..1d51de1b 100644
--- a/sys/unix/unixmain.c
+++ b/sys/unix/unixmain.c
@@ -44,6 +44,39 @@ static void NDECL(wd_message);
static boolean wiz_error_flag = FALSE;
static struct passwd *NDECL(get_unix_pw);
+#if defined(__APPLE__) /* a much more convoluted version of this
+ * code used to be inline within main() */
+static void FDECL(osx_finder, (const char *));
+
+/* special hack to change working directory to a resource fork when running
+ from 'Finder' on MacOSX (recognized via "/" as current dir) --sam */
+static void
+osx_finder(arg0)
+const char *arg0;
+{
+ /* #define MAC_PATH_VALUE ".app/Contents/MacOS/" */
+ char mac_cwd[1024], *mac_path, *p;
+
+ /*
+ * If current working directory is "/", switch to same directory
+ * as nethack. [This overrides !CHDIR config.]
+ */
+ getcwd(mac_cwd, 1024);
+ if (*arg0 == '/' && !strcmp(mac_cwd, "/")) {
+ /* copy executable path/name into modifiable buffer
+ [we know there's a path since the value starts with '/'] */
+ mac_path = dupstr(arg0);
+ /* strip off the name portion, leaving path */
+ p = rindex(mac_path, '/');
+ *(p + 1) = '\0';
+ /* change working directory */
+ chdir(mac_path);
+ /* done */
+ free((genericptr_t) mac_path);
+ }
+}
+#endif /* __APPLE__ */
+
int
main(argc, argv)
int argc;
@@ -57,37 +90,8 @@ char *argv[];
boolean resuming = FALSE; /* assume new game */
sys_early_init();
-
#if defined(__APPLE__)
- {
-/* special hack to change working directory to a resource fork when
- running from finder --sam */
-#define MAC_PATH_VALUE ".app/Contents/MacOS/"
- char mac_cwd[1024], *mac_exe = argv[0], *mac_tmp;
- int arg0_len = strlen(mac_exe), mac_tmp_len, mac_lhs_len = 0;
- getcwd(mac_cwd, 1024);
- if (mac_exe[0] == '/' && !strcmp(mac_cwd, "/")) {
- if ((mac_exe = strrchr(mac_exe, '/')))
- mac_exe++;
- else
- mac_exe = argv[0];
- mac_tmp_len = (strlen(mac_exe) * 2) + strlen(MAC_PATH_VALUE);
- if (mac_tmp_len <= arg0_len) {
- mac_tmp = malloc(mac_tmp_len + 1);
- sprintf(mac_tmp, "%s%s%s", mac_exe, MAC_PATH_VALUE, mac_exe);
- if (!strcmp(argv[0] + (arg0_len - mac_tmp_len), mac_tmp)) {
- mac_lhs_len =
- (arg0_len - mac_tmp_len) + strlen(mac_exe) + 5;
- if (mac_lhs_len > mac_tmp_len - 1)
- mac_tmp = realloc(mac_tmp, mac_lhs_len);
- strncpy(mac_tmp, argv[0], mac_lhs_len);
- mac_tmp[mac_lhs_len] = '\0';
- chdir(mac_tmp);
- }
- free(mac_tmp);
- }
- }
- }
+ osx_finder(argv[0]);
#endif
hname = argv[0];