diff --git a/misc/os2/Makefile b/misc/os2/Makefile index 967bd65ae..265e98a44 100644 --- a/misc/os2/Makefile +++ b/misc/os2/Makefile @@ -41,7 +41,7 @@ APP_AUTHOR := UnknownShadow200 # options for code generation #--------------------------------------------------------------------------------- CC := gcc -CFLAGS := -pipe -fno-math-errno -O0 -g -mtune=pentium4 -msse2 -march=i686 -idirafter /@unixroot/usr/include/os2tk45 -DOS2 +CFLAGS := -pipe -fno-math-errno -O3 -g -mtune=pentium4 -msse2 -march=i686 -idirafter /@unixroot/usr/include/os2tk45 -DOS2 LDFLAGS := -Zhigh-mem -Zomf -Zargs-wild -Zargs-resp -Zlinker DISABLE -Zlinker 1121 LIBS := -lcx -lmmpm2 -lpthread -lSDL2 diff --git a/src/Platform_Posix.c b/src/Platform_Posix.c index 4959c00bc..14812d22b 100644 --- a/src/Platform_Posix.c +++ b/src/Platform_Posix.c @@ -63,7 +63,9 @@ cc_bool Platform_SingleProcess; #include #elif defined CC_BUILD_OS2 #include -#define INCL_DOSPROCESS +#define INCL_DOS +#define INCL_DOSERRORS +#define INCL_PM #include #endif @@ -408,7 +410,7 @@ struct WaitData { pthread_cond_t cond; pthread_mutex_t mutex; int signalled; /* For when Waitable_Signal is called before Waitable_Wait */ -}; +}; void* Waitable_Create(void) { struct WaitData* ptr = (struct WaitData*)Mem_Alloc(1, sizeof(struct WaitData), "waitable"); @@ -786,6 +788,69 @@ cc_result Process_StartOpen(const cc_string* args) { } #elif defined CC_BUILD_HAIKU || defined CC_BUILD_BEOS /* Implemented in interop_BeOS.cpp */ +#elif defined CC_BUILD_OS2 +inline static void ShowErrorMessage(const char *url) { + static char errorMsg[] = "Could not open browser. Please go to: "; + cc_string message = String_Init(errorMsg, strlen(errorMsg), 500); + String_AppendConst(&message, url); + Logger_DialogWarn(&message); +} + +cc_result Process_StartOpen(const cc_string* args) { + char str[NATIVE_STR_LEN]; + APIRET rc; + UCHAR path[CCHMAXPATH], parameter[NATIVE_STR_LEN]; + UCHAR userPath[CCHMAXPATH], sysPath[CCHMAXPATH]; + PRFPROFILE profile = { sizeof(userPath), userPath, sizeof(sysPath), sysPath }; + HINI os2Ini; + HAB hAnchor = WinQueryAnchorBlock(WinQueryActiveWindow(HWND_DESKTOP)); + RESULTCODES result = { 0 }; + + // We get URL + String_EncodeUtf8(str, args); + + // Initialize buffers + Mem_Set(path, 0, sizeof(path)); + Mem_Set(parameter, 0, sizeof(parameter)); + + // We have to look in the OS/2 configuration for the default browser. + // First step: Find the configuration files + if (!PrfQueryProfile(hAnchor, &profile)) { + ShowErrorMessage(str); + return 0; + } + + // Second step: Open the configuration files and read exe path and parameters + os2Ini = PrfOpenProfile(hAnchor, userPath); + if (os2Ini == NULLHANDLE) { + ShowErrorMessage(str); + return 0; + } + if (!PrfQueryProfileString(os2Ini, "WPURLDEFAULTSETTINGS", "DefaultBrowserExe", + NULL, path, sizeof(path))) { + PrfCloseProfile(os2Ini); + ShowErrorMessage(str); + return 0; + } + + PrfQueryProfileString(os2Ini, "WPURLDEFAULTSETTINGS", "DefaultBrowserParameters", + NULL, parameter, sizeof(parameter)); + PrfCloseProfile(os2Ini); + + // concat arguments + strncat(parameter, " ", 20); + strncat(parameter, str, sizeof(str)); + + // Last step: Execute detached browser + rc = DosExecPgm(userPath, sizeof(userPath), EXEC_ASYNC, + parameter, NULL, &result, path); + if (rc != NO_ERROR) { + ShowErrorMessage(str); + return 0; + } + + return 0; +} #else cc_result Process_StartOpen(const cc_string* args) { char str[NATIVE_STR_LEN];