From 08c7b3edd1e8a09e7f7702a8e5918eed1ba05189 Mon Sep 17 00:00:00 2001 From: kichikuou Date: Sat, 25 Dec 2021 21:44:59 +0900 Subject: [PATCH] Use SDL_OpenURL for system.OpenWeb It opens a URL in an appropriate way for the platform. --- src/system4.c | 13 ------------- src/vm.c | 23 ++++------------------- 2 files changed, 4 insertions(+), 32 deletions(-) diff --git a/src/system4.c b/src/system4.c index d5ded40..48f58f9 100644 --- a/src/system4.c +++ b/src/system4.c @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -328,14 +327,6 @@ static void config_init_with_ain(const char *ain_path) config_init(); } -#if (!defined(_WIN32) && !defined(__WIN32__)) -#include -void cleanup(possibly_unused int signal) -{ - while (waitpid((pid_t)-1, 0, WNOHANG) > 0); -} -#endif - static void ain_audit(FILE *f, struct ain *ain) { link_libraries(); @@ -491,10 +482,6 @@ int main(int argc, char *argv[]) } ainfile = gamedir_path(config.ain_filename); -#if (!defined(_WIN32) && !defined(__WIN32__)) - signal(SIGCHLD, cleanup); -#endif - read_user_config(); // NOTE: some command line options are handled here so that they diff --git a/src/vm.c b/src/vm.c index eced83f..49baf13 100644 --- a/src/vm.c +++ b/src/vm.c @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include // for system.MsgBox @@ -41,12 +40,6 @@ #include "vm/page.h" #include "xsystem4.h" -#if (!defined(_WIN32) && !defined(__WIN32__)) -#include -#endif - -extern char **environ; - static inline int32_t lint_clamp(int64_t n) { if (n < 0) @@ -484,20 +477,12 @@ static void system_call(enum syscall_code code) break; } case SYS_OPEN_WEB: { -#if (defined(_WIN32) || defined(__WIN32__)) - WARNING("system.OpenWeb not implemented on Windows"); +#if !SDL_VERSION_ATLEAST(2, 0, 14) + WARNING("SDL_OpenURL not available"); #else struct string *url = stack_peek_string(0); - char *browser = getenv("BROWSER"); - if (!browser || !*browser) { - WARNING("$BROWSER not set, assuming Firefox"); - browser = "firefox"; - } - int err; - pid_t child; - char *argv[] = { browser, url->text, NULL }; - if ((err = posix_spawnp(&child, browser, NULL, NULL, argv, environ))) { - WARNING("posix_spawn failed: %s", strerror(err)); + if (SDL_OpenURL(url->text) < 0) { + WARNING("SDL_OpenURL failed: %s", SDL_GetError()); } #endif heap_unref(stack_pop().i);