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

@ -20,8 +20,7 @@
#if !defined SDL_JOYSTICK_DISABLED && !defined SDL_HAPTIC_DISABLED
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
SDL_Joystick *joystick = NULL;
SDL_Haptic *haptic = NULL;
@ -30,7 +29,7 @@ main(int argc, char *argv[])
int i;
SDL_bool enable_haptic = SDL_TRUE;
Uint32 init_subsystems = SDL_INIT_VIDEO | SDL_INIT_JOYSTICK;
for (i = 1; i < argc; ++i) {
if (SDL_strcasecmp(argv[i], "--nohaptic") == 0) {
enable_haptic = SDL_FALSE;
@ -40,7 +39,7 @@ main(int argc, char *argv[])
if (enable_haptic) {
init_subsystems |= SDL_INIT_HAPTIC;
}
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
@ -64,72 +63,71 @@ main(int argc, char *argv[])
while (keepGoing) {
SDL_Event event;
while (SDL_PollEvent(&event)) {
switch(event.type)
{
case SDL_QUIT:
keepGoing = SDL_FALSE;
break;
case SDL_JOYDEVICEADDED:
if (joystick != NULL) {
SDL_Log("Only one joystick supported by this test\n");
} else {
joystick = SDL_JoystickOpen(event.jdevice.which);
instance = SDL_JoystickInstanceID(joystick);
SDL_Log("Joy Added : %" SDL_PRIs32 " : %s\n", event.jdevice.which, SDL_JoystickName(joystick));
if (enable_haptic) {
if (SDL_JoystickIsHaptic(joystick)) {
haptic = SDL_HapticOpenFromJoystick(joystick);
if (haptic) {
SDL_Log("Joy Haptic Opened\n");
if (SDL_HapticRumbleInit( haptic ) != 0) {
SDL_Log("Could not init Rumble!: %s\n", SDL_GetError());
SDL_HapticClose(haptic);
haptic = NULL;
}
} else {
SDL_Log("Joy haptic open FAILED!: %s\n", SDL_GetError());
switch (event.type) {
case SDL_QUIT:
keepGoing = SDL_FALSE;
break;
case SDL_JOYDEVICEADDED:
if (joystick != NULL) {
SDL_Log("Only one joystick supported by this test\n");
} else {
joystick = SDL_JoystickOpen(event.jdevice.which);
instance = SDL_JoystickInstanceID(joystick);
SDL_Log("Joy Added : %" SDL_PRIs32 " : %s\n", event.jdevice.which, SDL_JoystickName(joystick));
if (enable_haptic) {
if (SDL_JoystickIsHaptic(joystick)) {
haptic = SDL_HapticOpenFromJoystick(joystick);
if (haptic) {
SDL_Log("Joy Haptic Opened\n");
if (SDL_HapticRumbleInit(haptic) != 0) {
SDL_Log("Could not init Rumble!: %s\n", SDL_GetError());
SDL_HapticClose(haptic);
haptic = NULL;
}
} else {
SDL_Log("No haptic found\n");
SDL_Log("Joy haptic open FAILED!: %s\n", SDL_GetError());
}
} else {
SDL_Log("No haptic found\n");
}
}
break;
case SDL_JOYDEVICEREMOVED:
if (instance == event.jdevice.which) {
SDL_Log("Joy Removed: %" SDL_PRIs32 "\n", event.jdevice.which);
instance = -1;
if (enable_haptic && haptic) {
SDL_HapticClose(haptic);
haptic = NULL;
}
SDL_JoystickClose(joystick);
joystick = NULL;
} else {
SDL_Log("Unknown joystick diconnected\n");
}
break;
case SDL_JOYAXISMOTION:
/*
// SDL_Log("Axis Move: %d\n", event.jaxis.axis);
*/
if (enable_haptic) {
SDL_HapticRumblePlay(haptic, 0.25, 250);
}
break;
case SDL_JOYBUTTONDOWN:
SDL_Log("Button Press: %d\n", event.jbutton.button);
}
break;
case SDL_JOYDEVICEREMOVED:
if (instance == event.jdevice.which) {
SDL_Log("Joy Removed: %" SDL_PRIs32 "\n", event.jdevice.which);
instance = -1;
if (enable_haptic && haptic) {
SDL_HapticRumblePlay(haptic, 0.25, 250);
SDL_HapticClose(haptic);
haptic = NULL;
}
if (event.jbutton.button == 0) {
SDL_Log("Exiting due to button press of button 0\n");
keepGoing = SDL_FALSE;
}
break;
case SDL_JOYBUTTONUP:
SDL_Log("Button Release: %d\n", event.jbutton.button);
break;
SDL_JoystickClose(joystick);
joystick = NULL;
} else {
SDL_Log("Unknown joystick diconnected\n");
}
break;
case SDL_JOYAXISMOTION:
/*
// SDL_Log("Axis Move: %d\n", event.jaxis.axis);
*/
if (enable_haptic) {
SDL_HapticRumblePlay(haptic, 0.25, 250);
}
break;
case SDL_JOYBUTTONDOWN:
SDL_Log("Button Press: %d\n", event.jbutton.button);
if (enable_haptic && haptic) {
SDL_HapticRumblePlay(haptic, 0.25, 250);
}
if (event.jbutton.button == 0) {
SDL_Log("Exiting due to button press of button 0\n");
keepGoing = SDL_FALSE;
}
break;
case SDL_JOYBUTTONUP:
SDL_Log("Button Release: %d\n", event.jbutton.button);
break;
}
}
}