diff --git a/frontends/monkey/main.c b/frontends/monkey/main.c index 463f0bea6..04b0e1c9f 100644 --- a/frontends/monkey/main.c +++ b/frontends/monkey/main.c @@ -422,7 +422,32 @@ main(int argc, char **argv) setbuf(stderr, NULL); /* Prep the search paths */ +#if defined(__montauk__) + char bundle_res[PATH_MAX]; + char resource_path[PATH_MAX * 2]; + const char *exec_path = argv[0]; + const char *last_slash = strrchr(exec_path, '/'); + size_t bundle_dir_len = last_slash == NULL ? 0 : + (size_t)(last_slash - exec_path + 1); + + /* Locate res/ beside the running ELF so the app bundle is relocatable. + * MONKEY_RESPATH remains as a fallback for older startup environments. */ + if (bundle_dir_len > 0 && + bundle_dir_len + sizeof("res/") <= sizeof(bundle_res)) { + memcpy(bundle_res, exec_path, bundle_dir_len); + memcpy(bundle_res + bundle_dir_len, "res/", sizeof("res/")); + } else { + snprintf(bundle_res, sizeof(bundle_res), "%s", MONKEY_RESPATH); + } + + /* see NS_RESPATH_SEP: ':' is part of a MontaukOS drive path */ + snprintf(resource_path, sizeof(resource_path), + "${HOME}/.netsurf/;${NETSURFRES};%s;%s;./frontends/monkey/res", + bundle_res, MONKEY_RESPATH); + respaths = nsmonkey_init_resource(resource_path); +#else respaths = nsmonkey_init_resource("${HOME}/.netsurf/:${NETSURFRES}:"MONKEY_RESPATH":./frontends/monkey/res"); +#endif /* initialise logging. Not fatal if it fails but not much we can do * about it either. diff --git a/utils/filepath.c b/utils/filepath.c index b87e2bf0d..9c4bcd34b 100644 --- a/utils/filepath.c +++ b/utils/filepath.c @@ -325,7 +325,7 @@ filepath_path_to_strvec(const char *path) estart = eend = path; while (strc < (MAX_RESPATH - 2)) { - while ( (*eend != 0) && (*eend != ':') ) + while ( (*eend != 0) && (*eend != NS_RESPATH_SEP) ) eend++; elen = eend - estart; @@ -339,7 +339,7 @@ filepath_path_to_strvec(const char *path) } /* skip colons */ - while (*eend == ':') + while (*eend == NS_RESPATH_SEP) eend++; /* check for termination */ diff --git a/utils/filepath.h b/utils/filepath.h index 784264b33..469830a9d 100644 --- a/utils/filepath.h +++ b/utils/filepath.h @@ -24,6 +24,22 @@ #ifndef _NETSURF_UTILS_FILEPATH_H_ #define _NETSURF_UTILS_FILEPATH_H_ +/** + * Character separating elements of a resource path list. + * + * A colon cannot double as the list separator on platforms whose absolute + * paths already contain one -- MontaukOS names drives as "N:/dir", so + * "0:/os/netsurf/" would split into "0" and "/os/netsurf/", neither of which + * resolves. + */ +#ifndef NS_RESPATH_SEP +#if defined(__montauk__) +#define NS_RESPATH_SEP ';' +#else +#define NS_RESPATH_SEP ':' +#endif +#endif + #include #include "utils/errors.h"