mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-04-23 07:45:38 +00:00
Update for SDL3 coding style (#6717)
I updated .clang-format and ran clang-format 14 over the src and test directories to standardize the code base.
In general I let clang-format have it's way, and added markup to prevent formatting of code that would break or be completely unreadable if formatted.
The script I ran for the src directory is added as build-scripts/clang-format-src.sh
This fixes:
#6592
#6593
#6594
(cherry picked from commit 5750bcb174)
This commit is contained in:
@@ -23,8 +23,7 @@
|
||||
|
||||
extern int SDL_SYS_OpenURL(const char *url);
|
||||
|
||||
int
|
||||
SDL_OpenURL(const char *url)
|
||||
int SDL_OpenURL(const char *url)
|
||||
{
|
||||
if (url == NULL) {
|
||||
return SDL_InvalidParamError("url");
|
||||
|
||||
@@ -22,11 +22,9 @@
|
||||
#include "../SDL_sysurl.h"
|
||||
#include "../../core/android/SDL_android.h"
|
||||
|
||||
int
|
||||
SDL_SYS_OpenURL(const char *url)
|
||||
int SDL_SYS_OpenURL(const char *url)
|
||||
{
|
||||
return Android_JNI_OpenURL(url);
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
|
||||
@@ -21,11 +21,9 @@
|
||||
|
||||
#include "../SDL_sysurl.h"
|
||||
|
||||
int
|
||||
SDL_SYS_OpenURL(const char *url)
|
||||
int SDL_SYS_OpenURL(const char *url)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
|
||||
@@ -23,15 +23,14 @@
|
||||
|
||||
#include <emscripten/emscripten.h>
|
||||
|
||||
int
|
||||
SDL_SYS_OpenURL(const char *url)
|
||||
int SDL_SYS_OpenURL(const char *url)
|
||||
{
|
||||
EM_ASM({
|
||||
window.open(UTF8ToString($0), "_blank");
|
||||
}, url);
|
||||
},
|
||||
url);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
|
||||
@@ -23,14 +23,14 @@
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
int
|
||||
SDL_SYS_OpenURL(const char *url)
|
||||
{ @autoreleasepool {
|
||||
int SDL_SYS_OpenURL(const char *url)
|
||||
{
|
||||
@autoreleasepool {
|
||||
|
||||
NSString *nsstr = [NSString stringWithUTF8String:url];
|
||||
NSURL *nsurl = [NSURL URLWithString:nsstr];
|
||||
return [[UIApplication sharedApplication] openURL:nsurl] ? 0 : -1;
|
||||
}}
|
||||
NSString *nsstr = [NSString stringWithUTF8String:url];
|
||||
NSURL *nsurl = [NSURL URLWithString:nsstr];
|
||||
return [[UIApplication sharedApplication] openURL:nsurl] ? 0 : -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
|
||||
@@ -23,14 +23,14 @@
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
int
|
||||
SDL_SYS_OpenURL(const char *url)
|
||||
{ @autoreleasepool
|
||||
int SDL_SYS_OpenURL(const char *url)
|
||||
{
|
||||
CFURLRef cfurl = CFURLCreateWithBytes(NULL, (const UInt8 *) url, SDL_strlen(url), kCFStringEncodingUTF8, NULL);
|
||||
OSStatus status = LSOpenCFURLRef(cfurl, NULL);
|
||||
CFRelease(cfurl);
|
||||
return status == noErr ? 0 : -1;
|
||||
}}
|
||||
@autoreleasepool {
|
||||
CFURLRef cfurl = CFURLCreateWithBytes(NULL, (const UInt8 *)url, SDL_strlen(url), kCFStringEncodingUTF8, NULL);
|
||||
OSStatus status = LSOpenCFURLRef(cfurl, NULL);
|
||||
CFRelease(cfurl);
|
||||
return status == noErr ? 0 : -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
@@ -28,8 +28,7 @@
|
||||
#define URI_Dispatch 0x4e381
|
||||
#endif
|
||||
|
||||
int
|
||||
SDL_SYS_OpenURL(const char *url)
|
||||
int SDL_SYS_OpenURL(const char *url)
|
||||
{
|
||||
_kernel_swi_regs regs;
|
||||
_kernel_oserror *error;
|
||||
@@ -46,4 +45,3 @@ SDL_SYS_OpenURL(const char *url)
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
|
||||
@@ -28,20 +28,19 @@
|
||||
#include <sys/wait.h>
|
||||
#include <errno.h>
|
||||
|
||||
int
|
||||
SDL_SYS_OpenURL(const char *url)
|
||||
int SDL_SYS_OpenURL(const char *url)
|
||||
{
|
||||
const pid_t pid1 = fork();
|
||||
if (pid1 == 0) { /* child process */
|
||||
if (pid1 == 0) { /* child process */
|
||||
pid_t pid2;
|
||||
/* Clear LD_PRELOAD so Chrome opens correctly when this application is launched by Steam */
|
||||
unsetenv("LD_PRELOAD");
|
||||
/* Notice this is vfork and not fork! */
|
||||
pid2 = vfork();
|
||||
if (pid2 == 0) { /* Grandchild process will try to launch the url */
|
||||
if (pid2 == 0) { /* Grandchild process will try to launch the url */
|
||||
execlp("xdg-open", "xdg-open", url, NULL);
|
||||
_exit(EXIT_FAILURE);
|
||||
} else if (pid2 < 0) { /* There was an error forking */
|
||||
} else if (pid2 < 0) { /* There was an error forking */
|
||||
_exit(EXIT_FAILURE);
|
||||
} else {
|
||||
/* Child process doesn't wait for possibly-blocking grandchild. */
|
||||
@@ -53,14 +52,14 @@ SDL_SYS_OpenURL(const char *url)
|
||||
int status;
|
||||
if (waitpid(pid1, &status, 0) == pid1) {
|
||||
if (WIFEXITED(status)) {
|
||||
if (WEXITSTATUS(status) == 0) {
|
||||
return 0; /* success! */
|
||||
} else {
|
||||
return SDL_SetError("xdg-open reported error or failed to launch: %d", WEXITSTATUS(status));
|
||||
}
|
||||
} else {
|
||||
if (WEXITSTATUS(status) == 0) {
|
||||
return 0; /* success! */
|
||||
} else {
|
||||
return SDL_SetError("xdg-open reported error or failed to launch: %d", WEXITSTATUS(status));
|
||||
}
|
||||
} else {
|
||||
return SDL_SetError("xdg-open failed for some reason");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return SDL_SetError("Waiting on xdg-open failed: %s", strerror(errno));
|
||||
}
|
||||
@@ -68,4 +67,3 @@ SDL_SYS_OpenURL(const char *url)
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
|
||||
@@ -24,8 +24,7 @@
|
||||
#include <string.h>
|
||||
#include <psp2/apputil.h>
|
||||
|
||||
int
|
||||
SDL_SYS_OpenURL(const char *url)
|
||||
int SDL_SYS_OpenURL(const char *url)
|
||||
{
|
||||
SceAppUtilInitParam init_param;
|
||||
SceAppUtilBootParam boot_param;
|
||||
@@ -41,4 +40,3 @@ SDL_SYS_OpenURL(const char *url)
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
|
||||
@@ -25,18 +25,16 @@
|
||||
#include <shellapi.h>
|
||||
|
||||
#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
|
||||
int
|
||||
SDL_SYS_OpenURL(const char *url)
|
||||
int SDL_SYS_OpenURL(const char *url)
|
||||
{
|
||||
/* Not supported */
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
#else
|
||||
/* https://msdn.microsoft.com/en-us/library/windows/desktop/bb762153%28v=vs.85%29.aspx */
|
||||
int
|
||||
SDL_SYS_OpenURL(const char *url)
|
||||
int SDL_SYS_OpenURL(const char *url)
|
||||
{
|
||||
WCHAR* wurl;
|
||||
WCHAR *wurl;
|
||||
HINSTANCE rc;
|
||||
|
||||
/* MSDN says for safety's sake, make sure COM is initialized. */
|
||||
@@ -55,9 +53,8 @@ SDL_SYS_OpenURL(const char *url)
|
||||
rc = ShellExecuteW(NULL, L"open", wurl, NULL, NULL, SW_SHOWNORMAL);
|
||||
SDL_free(wurl);
|
||||
WIN_CoUninitialize();
|
||||
return (rc > ((HINSTANCE) 32)) ? 0 : WIN_SetError("Couldn't open given URL.");
|
||||
return (rc > ((HINSTANCE)32)) ? 0 : WIN_SetError("Couldn't open given URL.");
|
||||
}
|
||||
#endif
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
|
||||
@@ -22,8 +22,7 @@
|
||||
#include "../SDL_sysurl.h"
|
||||
#include "../../core/windows/SDL_windows.h"
|
||||
|
||||
int
|
||||
SDL_SYS_OpenURL(const char *url)
|
||||
int SDL_SYS_OpenURL(const char *url)
|
||||
{
|
||||
WCHAR *wurl = WIN_UTF8ToStringW(url);
|
||||
if (!wurl) {
|
||||
@@ -34,8 +33,7 @@ SDL_SYS_OpenURL(const char *url)
|
||||
|
||||
auto uri = ref new Windows::Foundation::Uri(strurl);
|
||||
Windows::System::Launcher::LaunchUriAsync(uri);
|
||||
return 0; // oh well, we're not waiting on an async task here.
|
||||
return 0; // oh well, we're not waiting on an async task here.
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user