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:
Sam Lantinga 2022-11-30 12:51:59 -08:00
parent 5c4bc807f7
commit b8d85c6939
764 changed files with 50598 additions and 54407 deletions

View file

@ -41,14 +41,13 @@
#include "stdlib/SDL_vacopy.h"
/* The size of the stack buffer to use for rendering log messages. */
#define SDL_MAX_LOG_MESSAGE_STACK 256
#define DEFAULT_PRIORITY SDL_LOG_PRIORITY_CRITICAL
#define DEFAULT_ASSERT_PRIORITY SDL_LOG_PRIORITY_WARN
#define DEFAULT_APPLICATION_PRIORITY SDL_LOG_PRIORITY_INFO
#define DEFAULT_TEST_PRIORITY SDL_LOG_PRIORITY_VERBOSE
#define DEFAULT_PRIORITY SDL_LOG_PRIORITY_CRITICAL
#define DEFAULT_ASSERT_PRIORITY SDL_LOG_PRIORITY_WARN
#define DEFAULT_APPLICATION_PRIORITY SDL_LOG_PRIORITY_INFO
#define DEFAULT_TEST_PRIORITY SDL_LOG_PRIORITY_VERBOSE
typedef struct SDL_LogLevel
{
@ -105,8 +104,7 @@ static int SDL_android_priority[SDL_NUM_LOG_PRIORITIES] = {
};
#endif /* __ANDROID__ */
void
SDL_LogInit(void)
void SDL_LogInit(void)
{
if (log_function_mutex == NULL) {
/* if this fails we'll try to continue without it. */
@ -114,8 +112,7 @@ SDL_LogInit(void)
}
}
void
SDL_LogQuit(void)
void SDL_LogQuit(void)
{
SDL_LogResetPriorities();
if (log_function_mutex) {
@ -124,8 +121,7 @@ SDL_LogQuit(void)
}
}
void
SDL_LogSetAllPriority(SDL_LogPriority priority)
void SDL_LogSetAllPriority(SDL_LogPriority priority)
{
SDL_LogLevel *entry;
@ -137,8 +133,7 @@ SDL_LogSetAllPriority(SDL_LogPriority priority)
SDL_application_priority = priority;
}
void
SDL_LogSetPriority(int category, SDL_LogPriority priority)
void SDL_LogSetPriority(int category, SDL_LogPriority priority)
{
SDL_LogLevel *entry;
@ -181,8 +176,7 @@ SDL_LogGetPriority(int category)
}
}
void
SDL_LogResetPriorities(void)
void SDL_LogResetPriorities(void)
{
SDL_LogLevel *entry;
@ -198,8 +192,7 @@ SDL_LogResetPriorities(void)
SDL_test_priority = DEFAULT_TEST_PRIORITY;
}
void
SDL_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
void SDL_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{
va_list ap;
@ -208,8 +201,7 @@ SDL_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
va_end(ap);
}
void
SDL_LogVerbose(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
void SDL_LogVerbose(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{
va_list ap;
@ -218,8 +210,7 @@ SDL_LogVerbose(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
va_end(ap);
}
void
SDL_LogDebug(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
void SDL_LogDebug(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{
va_list ap;
@ -228,8 +219,7 @@ SDL_LogDebug(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
va_end(ap);
}
void
SDL_LogInfo(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
void SDL_LogInfo(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{
va_list ap;
@ -238,8 +228,7 @@ SDL_LogInfo(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
va_end(ap);
}
void
SDL_LogWarn(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
void SDL_LogWarn(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{
va_list ap;
@ -248,8 +237,7 @@ SDL_LogWarn(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
va_end(ap);
}
void
SDL_LogError(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
void SDL_LogError(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{
va_list ap;
@ -258,8 +246,7 @@ SDL_LogError(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
va_end(ap);
}
void
SDL_LogCritical(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
void SDL_LogCritical(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{
va_list ap;
@ -268,8 +255,7 @@ SDL_LogCritical(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
va_end(ap);
}
void
SDL_LogMessage(int category, SDL_LogPriority priority, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
void SDL_LogMessage(int category, SDL_LogPriority priority, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{
va_list ap;
@ -279,8 +265,7 @@ SDL_LogMessage(int category, SDL_LogPriority priority, SDL_PRINTF_FORMAT_STRING
}
#ifdef __ANDROID__
static const char *
GetCategoryPrefix(int category)
static const char *GetCategoryPrefix(int category)
{
if (category < SDL_LOG_CATEGORY_RESERVED1) {
return SDL_category_prefixes[category];
@ -292,8 +277,7 @@ GetCategoryPrefix(int category)
}
#endif /* __ANDROID__ */
void
SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va_list ap)
void SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va_list ap)
{
char *message = NULL;
char stack_buf[SDL_MAX_LOG_MESSAGE_STACK];
@ -345,9 +329,9 @@ SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va_list
}
/* Chop off final endline. */
if ((len > 0) && (message[len-1] == '\n')) {
if ((len > 0) && (message[len - 1] == '\n')) {
message[--len] = '\0';
if ((len > 0) && (message[len-1] == '\r')) { /* catch "\r\n", too. */
if ((len > 0) && (message[len - 1] == '\r')) { /* catch "\r\n", too. */
message[--len] = '\0';
}
}
@ -376,9 +360,8 @@ static int consoleAttached = 0;
static HANDLE stderrHandle = NULL;
#endif
static void SDLCALL
SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority,
const char *message)
static void SDLCALL SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority,
const char *message)
{
#if defined(__WIN32__) || defined(__WINRT__) || defined(__GDK__)
/* Way too many allocations here, urgh */
@ -399,34 +382,34 @@ SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority,
if (consoleAttached == 0) {
attachResult = AttachConsole(ATTACH_PARENT_PROCESS);
if (!attachResult) {
attachError = GetLastError();
if (attachError == ERROR_INVALID_HANDLE) {
/* This is expected when running from Visual Studio */
/*OutputDebugString(TEXT("Parent process has no console\r\n"));*/
consoleAttached = -1;
} else if (attachError == ERROR_GEN_FAILURE) {
OutputDebugString(TEXT("Could not attach to console of parent process\r\n"));
consoleAttached = -1;
} else if (attachError == ERROR_ACCESS_DENIED) {
/* Already attached */
consoleAttached = 1;
} else {
OutputDebugString(TEXT("Error attaching console\r\n"));
consoleAttached = -1;
}
} else {
/* Newly attached */
attachError = GetLastError();
if (attachError == ERROR_INVALID_HANDLE) {
/* This is expected when running from Visual Studio */
/*OutputDebugString(TEXT("Parent process has no console\r\n"));*/
consoleAttached = -1;
} else if (attachError == ERROR_GEN_FAILURE) {
OutputDebugString(TEXT("Could not attach to console of parent process\r\n"));
consoleAttached = -1;
} else if (attachError == ERROR_ACCESS_DENIED) {
/* Already attached */
consoleAttached = 1;
} else {
OutputDebugString(TEXT("Error attaching console\r\n"));
consoleAttached = -1;
}
} else {
/* Newly attached */
consoleAttached = 1;
}
if (consoleAttached == 1) {
stderrHandle = GetStdHandle(STD_ERROR_HANDLE);
if (consoleAttached == 1) {
stderrHandle = GetStdHandle(STD_ERROR_HANDLE);
if (GetConsoleMode(stderrHandle, &consoleMode) == 0) {
/* WriteConsole fails if the output is redirected to a file. Must use WriteFile instead. */
consoleAttached = 2;
}
if (GetConsoleMode(stderrHandle, &consoleMode) == 0) {
/* WriteConsole fails if the output is redirected to a file. Must use WriteFile instead. */
consoleAttached = 2;
}
}
}
#endif /* !defined(HAVE_STDIO_H) && !defined(__WINRT__) && !defined(__GDK__) */
@ -434,22 +417,22 @@ SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority,
output = SDL_small_alloc(char, length, &isstack);
SDL_snprintf(output, length, "%s: %s\r\n", SDL_priority_prefixes[priority], message);
tstr = WIN_UTF8ToString(output);
/* Output to debugger */
OutputDebugString(tstr);
#if !defined(HAVE_STDIO_H) && !defined(__WINRT__) && !defined(__GDK__)
/* Screen output to stderr, if console was attached. */
if (consoleAttached == 1) {
if (!WriteConsole(stderrHandle, tstr, (DWORD) SDL_tcslen(tstr), &charsWritten, NULL)) {
OutputDebugString(TEXT("Error calling WriteConsole\r\n"));
if (GetLastError() == ERROR_NOT_ENOUGH_MEMORY) {
OutputDebugString(TEXT("Insufficient heap memory to write message\r\n"));
}
if (!WriteConsole(stderrHandle, tstr, (DWORD)SDL_tcslen(tstr), &charsWritten, NULL)) {
OutputDebugString(TEXT("Error calling WriteConsole\r\n"));
if (GetLastError() == ERROR_NOT_ENOUGH_MEMORY) {
OutputDebugString(TEXT("Insufficient heap memory to write message\r\n"));
}
}
} else if (consoleAttached == 2) {
if (!WriteFile(stderrHandle, output, (DWORD) SDL_strlen(output), &charsWritten, NULL)) {
if (!WriteFile(stderrHandle, output, (DWORD)SDL_strlen(output), &charsWritten, NULL)) {
OutputDebugString(TEXT("Error calling WriteFile\r\n"));
}
}
@ -467,7 +450,7 @@ SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority,
}
#elif defined(__APPLE__) && (defined(SDL_VIDEO_DRIVER_COCOA) || defined(SDL_VIDEO_DRIVER_UIKIT))
/* Technically we don't need Cocoa/UIKit, but that's where this function is defined for now.
*/
*/
extern void SDL_NSLog(const char *prefix, const char *text);
{
SDL_NSLog(SDL_priority_prefixes[priority], message);
@ -475,17 +458,17 @@ SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority,
}
#elif defined(__PSP__) || defined(__PS2__)
{
FILE* pFile;
pFile = fopen ("SDL_Log.txt", "a");
FILE *pFile;
pFile = fopen("SDL_Log.txt", "a");
fprintf(pFile, "%s: %s\n", SDL_priority_prefixes[priority], message);
fclose (pFile);
fclose(pFile);
}
#elif defined(__VITA__)
{
FILE* pFile;
pFile = fopen ("ux0:/data/SDL_Log.txt", "a");
FILE *pFile;
pFile = fopen("ux0:/data/SDL_Log.txt", "a");
fprintf(pFile, "%s: %s\n", SDL_priority_prefixes[priority], message);
fclose (pFile);
fclose(pFile);
}
#elif defined(__3DS__)
{
@ -504,8 +487,7 @@ SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority,
#endif
}
void
SDL_LogGetOutputFunction(SDL_LogOutputFunction *callback, void **userdata)
void SDL_LogGetOutputFunction(SDL_LogOutputFunction *callback, void **userdata)
{
if (callback) {
*callback = SDL_log_function;
@ -515,8 +497,7 @@ SDL_LogGetOutputFunction(SDL_LogOutputFunction *callback, void **userdata)
}
}
void
SDL_LogSetOutputFunction(SDL_LogOutputFunction callback, void *userdata)
void SDL_LogSetOutputFunction(SDL_LogOutputFunction callback, void *userdata)
{
SDL_log_function = callback;
SDL_log_userdata = userdata;