GFX2_OpenURL()
This commit is contained in:
parent
663ddf39aa
commit
2fdceab6bc
33
src/help.c
33
src/help.c
@ -361,38 +361,7 @@ static void Window_help_follow_link(const char * line)
|
||||
buffer[i++] = *link++;
|
||||
buffer[i] = '\0';
|
||||
GFX2_Log(GFX2_DEBUG, "WWW link found : \"%s\"\n", buffer);
|
||||
#if defined(WIN32)
|
||||
/*HINSTANCE hInst = */ShellExecuteA(NULL, "open", buffer, NULL, NULL, SW_SHOWNORMAL);
|
||||
#elif defined(__macosx__)
|
||||
{
|
||||
OSStatus ret;
|
||||
CFURLRef url = CFURLCreateWithBytes (
|
||||
NULL, // allocator
|
||||
(UInt8*)buffer, // URLBytes
|
||||
i, // length
|
||||
kCFStringEncodingASCII, // encoding
|
||||
NULL // baseURL
|
||||
);
|
||||
ret = LSOpenCFURLRef(url,0);
|
||||
if (ret != noErr)
|
||||
GFX2_Log(GFX2_ERROR, "LSOpenCFURLRef() returned %d\n", ret);
|
||||
CFRelease(url);
|
||||
}
|
||||
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
|
||||
{
|
||||
int ret;
|
||||
char command[80]; // use the xdg-open command to open the url in the default browser
|
||||
snprintf(command, sizeof(command), "xdg-open \"%s\"", buffer);
|
||||
ret = system(command);
|
||||
if (ret < 0)
|
||||
GFX2_Log(GFX2_ERROR, "system('%s') FAILED\n", command);
|
||||
else if (ret == 127)
|
||||
GFX2_Log(GFX2_ERROR, "system() FAILED to execute shell\n");
|
||||
}
|
||||
#else
|
||||
// TODO : HAIKU, MINT, etc.
|
||||
GFX2_Log(GFX2_WARNING, "URL open not supported yet on this system.\n");
|
||||
#endif
|
||||
GFX2_OpenURL(buffer, i);
|
||||
}
|
||||
|
||||
///
|
||||
|
||||
37
src/osdep.c
37
src/osdep.c
@ -49,6 +49,43 @@ dword GFX2_GetTicks(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
void GFX2_OpenURL(const char * buffer, unsigned int len)
|
||||
{
|
||||
#if defined(WIN32)
|
||||
(void)len;
|
||||
/*HINSTANCE hInst = */ShellExecuteA(NULL, "open", buffer, NULL, NULL, SW_SHOWNORMAL);
|
||||
#elif defined(__macosx__)
|
||||
OSStatus ret;
|
||||
|
||||
CFURLRef url = CFURLCreateWithBytes (
|
||||
NULL, // allocator
|
||||
(UInt8*)buffer, // URLBytes
|
||||
len, // length
|
||||
kCFStringEncodingASCII, // encoding
|
||||
NULL // baseURL
|
||||
);
|
||||
ret = LSOpenCFURLRef(url,0);
|
||||
if (ret != noErr)
|
||||
GFX2_Log(GFX2_ERROR, "LSOpenCFURLRef() returned %d\n", ret);
|
||||
CFRelease(url);
|
||||
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
|
||||
int ret;
|
||||
char command[256]; // use the xdg-open command to open the url in the default browser
|
||||
(void)len;
|
||||
|
||||
snprintf(command, sizeof(command), "xdg-open \"%s\"", buffer);
|
||||
ret = system(command);
|
||||
if (ret < 0)
|
||||
GFX2_Log(GFX2_ERROR, "system('%s') FAILED\n", command);
|
||||
else if (ret == 127)
|
||||
GFX2_Log(GFX2_ERROR, "system() FAILED to execute shell\n");
|
||||
#else
|
||||
// TODO : HAIKU, MINT, etc.
|
||||
(void)len; (void)buffer;
|
||||
GFX2_Log(GFX2_WARNING, "URL open not supported yet on this system.\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(__macosx__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__SWITCH__)
|
||||
#if defined(__OpenBSD__)
|
||||
#include <sys/param.h>
|
||||
|
||||
@ -33,6 +33,13 @@
|
||||
/// Return a number of milliseconds
|
||||
dword GFX2_GetTicks(void);
|
||||
|
||||
/**
|
||||
* Open an URL in the system default browser
|
||||
* @param url URL (ascii)
|
||||
* @param len URL length in bytes
|
||||
*/
|
||||
void GFX2_OpenURL(const char * url, unsigned int len);
|
||||
|
||||
#if defined (__MINT__)
|
||||
void Atari_Memory_free(unsigned long *stRam, unsigned long *ttRam);
|
||||
#else
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user