diff --git a/src/instructions.c b/src/instructions.c index 98fa476..f5e7f03 100644 --- a/src/instructions.c +++ b/src/instructions.c @@ -47,7 +47,7 @@ const struct syscall syscalls[NR_SYSCALLS] = { SYS ( SYS_RESUME_SAVE, ResumeSave ), SYS ( SYS_RESUME_LOAD, ResumeLoad ), SYS ( SYS_EXISTS_FILE, ExistsFile ), - TODO ( SYS_OPEN_WEB, OpenWeb ), + SYS ( SYS_OPEN_WEB, OpenWeb ), SYS ( SYS_GET_SAVE_FOLDER_NAME, GetSaveFolderName ), SYS ( SYS_GET_TIME, GetTime ), TODO ( SYS_GET_GAME_NAME, GetGameName ), diff --git a/src/system4.c b/src/system4.c index 38f6f65..046f8b6 100644 --- a/src/system4.c +++ b/src/system4.c @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include "debugger.h" #include "file.h" #include "ini.h" @@ -195,6 +197,11 @@ static void config_init(void) mkdir_p(new_save_dir); } +void cleanup(int signal) +{ + while (waitpid((pid_t)-1, 0, WNOHANG) > 0); +} + int main(int argc, char *argv[]) { initialize_instructions(); @@ -226,6 +233,8 @@ int main(int argc, char *argv[]) ERROR("Not an AIN/INI file: %s", &argv[1][len - 4]); } + signal(SIGCHLD, cleanup); + config_init(); if (!(ain = ain_open(ainfile, &err))) { diff --git a/src/vm.c b/src/vm.c index ee2fe93..e66055e 100644 --- a/src/vm.c +++ b/src/vm.c @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include // for system.MsgBox #include "debugger.h" @@ -35,6 +37,8 @@ #include "vm/heap.h" #include "vm/page.h" +extern char **environ; + static inline int32_t lint_clamp(int64_t n) { if (n < 0) @@ -397,6 +401,22 @@ static void system_call(enum syscall_code code) free(path); break; } + case SYS_OPEN_WEB: { + 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)); + } + heap_unref(stack_pop().i); + break; + }; case SYS_GET_SAVE_FOLDER_NAME: {// system.GetSaveFolderName(void) if (config.save_dir) { char *sjis = utf2sjis(config.save_dir, strlen(config.save_dir));