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

@@ -27,15 +27,14 @@
/* Global for SDL_windowshaptic.c */
#if (defined(SDL_HAPTIC_DINPUT) && SDL_HAPTIC_DINPUT) || (defined(SDL_HAPTIC_XINPUT) && SDL_HAPTIC_XINPUT)
SDL_Haptic *SDL_haptics = NULL;
#else
#else
static SDL_Haptic *SDL_haptics = NULL;
#endif
/*
* Initializes the Haptic devices.
*/
int
SDL_HapticInit(void)
int SDL_HapticInit(void)
{
int status;
@@ -47,12 +46,10 @@ SDL_HapticInit(void)
return status;
}
/*
* Checks to see if the haptic device is valid
*/
static int
ValidHaptic(SDL_Haptic * haptic)
static int ValidHaptic(SDL_Haptic *haptic)
{
int valid;
SDL_Haptic *hapticlist;
@@ -60,7 +57,7 @@ ValidHaptic(SDL_Haptic * haptic)
valid = 0;
if (haptic != NULL) {
hapticlist = SDL_haptics;
while ( hapticlist ) {
while (hapticlist) {
if (hapticlist == haptic) {
valid = 1;
break;
@@ -77,17 +74,14 @@ ValidHaptic(SDL_Haptic * haptic)
return valid;
}
/*
* Returns the number of available devices.
*/
int
SDL_NumHaptics(void)
int SDL_NumHaptics(void)
{
return SDL_SYS_NumHaptics();
}
/*
* Gets the name of a Haptic device by index.
*/
@@ -102,7 +96,6 @@ SDL_HapticName(int device_index)
return SDL_SYS_HapticName(device_index);
}
/*
* Opens a Haptic device.
*/
@@ -120,9 +113,9 @@ SDL_HapticOpen(int device_index)
hapticlist = SDL_haptics;
/* If the haptic is already open, return it
* TODO: Should we create haptic instance IDs like the Joystick API?
*/
while ( hapticlist ) {
* TODO: Should we create haptic instance IDs like the Joystick API?
*/
while (hapticlist) {
if (device_index == hapticlist->index) {
haptic = hapticlist;
++haptic->ref_count;
@@ -132,7 +125,7 @@ SDL_HapticOpen(int device_index)
}
/* Create the haptic device */
haptic = (SDL_Haptic *) SDL_malloc((sizeof *haptic));
haptic = (SDL_Haptic *)SDL_malloc((sizeof *haptic));
if (haptic == NULL) {
SDL_OutOfMemory();
return NULL;
@@ -164,12 +157,10 @@ SDL_HapticOpen(int device_index)
return haptic;
}
/*
* Returns 1 if the device has been opened.
*/
int
SDL_HapticOpened(int device_index)
int SDL_HapticOpened(int device_index)
{
int opened;
SDL_Haptic *hapticlist;
@@ -184,8 +175,8 @@ SDL_HapticOpened(int device_index)
opened = 0;
hapticlist = SDL_haptics;
/* TODO Should this use an instance ID? */
while ( hapticlist ) {
if (hapticlist->index == (Uint8) device_index) {
while (hapticlist) {
if (hapticlist->index == (Uint8)device_index) {
opened = 1;
break;
}
@@ -194,12 +185,10 @@ SDL_HapticOpened(int device_index)
return opened;
}
/*
* Returns the index to a haptic device.
*/
int
SDL_HapticIndex(SDL_Haptic * haptic)
int SDL_HapticIndex(SDL_Haptic *haptic)
{
if (!ValidHaptic(haptic)) {
return -1;
@@ -208,12 +197,10 @@ SDL_HapticIndex(SDL_Haptic * haptic)
return haptic->index;
}
/*
* Returns SDL_TRUE if mouse is haptic, SDL_FALSE if it isn't.
*/
int
SDL_MouseIsHaptic(void)
int SDL_MouseIsHaptic(void)
{
if (SDL_SYS_HapticMouse() < 0) {
return SDL_FALSE;
@@ -221,7 +208,6 @@ SDL_MouseIsHaptic(void)
return SDL_TRUE;
}
/*
* Returns the haptic device if mouse is haptic or NULL elsewise.
*/
@@ -240,12 +226,10 @@ SDL_HapticOpenFromMouse(void)
return SDL_HapticOpen(device_index);
}
/*
* Returns SDL_TRUE if joystick has haptic features.
*/
int
SDL_JoystickIsHaptic(SDL_Joystick * joystick)
int SDL_JoystickIsHaptic(SDL_Joystick *joystick)
{
int ret;
@@ -264,12 +248,11 @@ SDL_JoystickIsHaptic(SDL_Joystick * joystick)
return -1;
}
/*
* Opens a haptic device from a joystick.
*/
SDL_Haptic *
SDL_HapticOpenFromJoystick(SDL_Joystick * joystick)
SDL_HapticOpenFromJoystick(SDL_Joystick *joystick)
{
SDL_Haptic *haptic;
SDL_Haptic *hapticlist;
@@ -295,7 +278,7 @@ SDL_HapticOpenFromJoystick(SDL_Joystick * joystick)
hapticlist = SDL_haptics;
/* Check to see if joystick's haptic is already open */
while ( hapticlist ) {
while (hapticlist) {
if (SDL_SYS_JoystickSameHaptic(hapticlist, joystick)) {
haptic = hapticlist;
++haptic->ref_count;
@@ -305,7 +288,7 @@ SDL_HapticOpenFromJoystick(SDL_Joystick * joystick)
}
/* Create the haptic device */
haptic = (SDL_Haptic *) SDL_malloc((sizeof *haptic));
haptic = (SDL_Haptic *)SDL_malloc((sizeof *haptic));
if (haptic == NULL) {
SDL_OutOfMemory();
return NULL;
@@ -329,12 +312,10 @@ SDL_HapticOpenFromJoystick(SDL_Joystick * joystick)
return haptic;
}
/*
* Closes a SDL_Haptic device.
*/
void
SDL_HapticClose(SDL_Haptic * haptic)
void SDL_HapticClose(SDL_Haptic *haptic)
{
int i;
SDL_Haptic *hapticlist;
@@ -361,9 +342,9 @@ SDL_HapticClose(SDL_Haptic * haptic)
/* Remove from the list */
hapticlist = SDL_haptics;
hapticlistprev = NULL;
while ( hapticlist ) {
while (hapticlist) {
if (haptic == hapticlist) {
if ( hapticlistprev ) {
if (hapticlistprev) {
/* unlink this entry */
hapticlistprev->next = hapticlist->next;
} else {
@@ -383,8 +364,7 @@ SDL_HapticClose(SDL_Haptic * haptic)
/*
* Cleans up after the subsystem.
*/
void
SDL_HapticQuit(void)
void SDL_HapticQuit(void)
{
while (SDL_haptics) {
SDL_HapticClose(SDL_haptics);
@@ -396,8 +376,7 @@ SDL_HapticQuit(void)
/*
* Returns the number of effects a haptic device has.
*/
int
SDL_HapticNumEffects(SDL_Haptic * haptic)
int SDL_HapticNumEffects(SDL_Haptic *haptic)
{
if (!ValidHaptic(haptic)) {
return -1;
@@ -406,12 +385,10 @@ SDL_HapticNumEffects(SDL_Haptic * haptic)
return haptic->neffects;
}
/*
* Returns the number of effects a haptic device can play.
*/
int
SDL_HapticNumEffectsPlaying(SDL_Haptic * haptic)
int SDL_HapticNumEffectsPlaying(SDL_Haptic *haptic)
{
if (!ValidHaptic(haptic)) {
return -1;
@@ -420,12 +397,11 @@ SDL_HapticNumEffectsPlaying(SDL_Haptic * haptic)
return haptic->nplaying;
}
/*
* Returns supported effects by the device.
*/
unsigned int
SDL_HapticQuery(SDL_Haptic * haptic)
SDL_HapticQuery(SDL_Haptic *haptic)
{
if (!ValidHaptic(haptic)) {
return 0; /* same as if no effects were supported */
@@ -434,12 +410,10 @@ SDL_HapticQuery(SDL_Haptic * haptic)
return haptic->supported;
}
/*
* Returns the number of axis on the device.
*/
int
SDL_HapticNumAxes(SDL_Haptic * haptic)
int SDL_HapticNumAxes(SDL_Haptic *haptic)
{
if (!ValidHaptic(haptic)) {
return -1;
@@ -451,8 +425,7 @@ SDL_HapticNumAxes(SDL_Haptic * haptic)
/*
* Checks to see if the device can support the effect.
*/
int
SDL_HapticEffectSupported(SDL_Haptic * haptic, SDL_HapticEffect * effect)
int SDL_HapticEffectSupported(SDL_Haptic *haptic, SDL_HapticEffect *effect)
{
if (!ValidHaptic(haptic)) {
return -1;
@@ -467,8 +440,7 @@ SDL_HapticEffectSupported(SDL_Haptic * haptic, SDL_HapticEffect * effect)
/*
* Creates a new haptic effect.
*/
int
SDL_HapticNewEffect(SDL_Haptic * haptic, SDL_HapticEffect * effect)
int SDL_HapticNewEffect(SDL_Haptic *haptic, SDL_HapticEffect *effect)
{
int i;
@@ -487,9 +459,8 @@ SDL_HapticNewEffect(SDL_Haptic * haptic, SDL_HapticEffect * effect)
if (haptic->effects[i].hweffect == NULL) {
/* Now let the backend create the real effect */
if (SDL_SYS_HapticNewEffect(haptic, &haptic->effects[i], effect)
!= 0) {
return -1; /* Backend failed to create effect */
if (SDL_SYS_HapticNewEffect(haptic, &haptic->effects[i], effect) != 0) {
return -1; /* Backend failed to create effect */
}
SDL_memcpy(&haptic->effects[i].effect, effect,
@@ -504,8 +475,7 @@ SDL_HapticNewEffect(SDL_Haptic * haptic, SDL_HapticEffect * effect)
/*
* Checks to see if an effect is valid.
*/
static int
ValidEffect(SDL_Haptic * haptic, int effect)
static int ValidEffect(SDL_Haptic *haptic, int effect)
{
if ((effect < 0) || (effect >= haptic->neffects)) {
SDL_SetError("Haptic: Invalid effect identifier.");
@@ -517,9 +487,8 @@ ValidEffect(SDL_Haptic * haptic, int effect)
/*
* Updates an effect.
*/
int
SDL_HapticUpdateEffect(SDL_Haptic * haptic, int effect,
SDL_HapticEffect * data)
int SDL_HapticUpdateEffect(SDL_Haptic *haptic, int effect,
SDL_HapticEffect *data)
{
if (!ValidHaptic(haptic) || !ValidEffect(haptic, effect)) {
return -1;
@@ -541,20 +510,17 @@ SDL_HapticUpdateEffect(SDL_Haptic * haptic, int effect,
return 0;
}
/*
* Runs the haptic effect on the device.
*/
int
SDL_HapticRunEffect(SDL_Haptic * haptic, int effect, Uint32 iterations)
int SDL_HapticRunEffect(SDL_Haptic *haptic, int effect, Uint32 iterations)
{
if (!ValidHaptic(haptic) || !ValidEffect(haptic, effect)) {
return -1;
}
/* Run the effect */
if (SDL_SYS_HapticRunEffect(haptic, &haptic->effects[effect], iterations)
< 0) {
if (SDL_SYS_HapticRunEffect(haptic, &haptic->effects[effect], iterations) < 0) {
return -1;
}
@@ -564,8 +530,7 @@ SDL_HapticRunEffect(SDL_Haptic * haptic, int effect, Uint32 iterations)
/*
* Stops the haptic effect on the device.
*/
int
SDL_HapticStopEffect(SDL_Haptic * haptic, int effect)
int SDL_HapticStopEffect(SDL_Haptic *haptic, int effect)
{
if (!ValidHaptic(haptic) || !ValidEffect(haptic, effect)) {
return -1;
@@ -582,8 +547,7 @@ SDL_HapticStopEffect(SDL_Haptic * haptic, int effect)
/*
* Gets rid of a haptic effect.
*/
void
SDL_HapticDestroyEffect(SDL_Haptic * haptic, int effect)
void SDL_HapticDestroyEffect(SDL_Haptic *haptic, int effect)
{
if (!ValidHaptic(haptic) || !ValidEffect(haptic, effect)) {
return;
@@ -600,8 +564,7 @@ SDL_HapticDestroyEffect(SDL_Haptic * haptic, int effect)
/*
* Gets the status of a haptic effect.
*/
int
SDL_HapticGetEffectStatus(SDL_Haptic * haptic, int effect)
int SDL_HapticGetEffectStatus(SDL_Haptic *haptic, int effect)
{
if (!ValidHaptic(haptic) || !ValidEffect(haptic, effect)) {
return -1;
@@ -617,8 +580,7 @@ SDL_HapticGetEffectStatus(SDL_Haptic * haptic, int effect)
/*
* Sets the global gain of the device.
*/
int
SDL_HapticSetGain(SDL_Haptic * haptic, int gain)
int SDL_HapticSetGain(SDL_Haptic *haptic, int gain)
{
const char *env;
int real_gain, max_gain;
@@ -663,8 +625,7 @@ SDL_HapticSetGain(SDL_Haptic * haptic, int gain)
/*
* Makes the device autocenter, 0 disables.
*/
int
SDL_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
int SDL_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter)
{
if (!ValidHaptic(haptic)) {
return -1;
@@ -688,8 +649,7 @@ SDL_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
/*
* Pauses the haptic device.
*/
int
SDL_HapticPause(SDL_Haptic * haptic)
int SDL_HapticPause(SDL_Haptic *haptic)
{
if (!ValidHaptic(haptic)) {
return -1;
@@ -705,15 +665,14 @@ SDL_HapticPause(SDL_Haptic * haptic)
/*
* Unpauses the haptic device.
*/
int
SDL_HapticUnpause(SDL_Haptic * haptic)
int SDL_HapticUnpause(SDL_Haptic *haptic)
{
if (!ValidHaptic(haptic)) {
return -1;
}
if ((haptic->supported & SDL_HAPTIC_PAUSE) == 0) {
return 0; /* Not going to be paused, so we pretend it's unpaused. */
return 0; /* Not going to be paused, so we pretend it's unpaused. */
}
return SDL_SYS_HapticUnpause(haptic);
@@ -722,8 +681,7 @@ SDL_HapticUnpause(SDL_Haptic * haptic)
/*
* Stops all the currently playing effects.
*/
int
SDL_HapticStopAll(SDL_Haptic * haptic)
int SDL_HapticStopAll(SDL_Haptic *haptic)
{
if (!ValidHaptic(haptic)) {
return -1;
@@ -735,8 +693,7 @@ SDL_HapticStopAll(SDL_Haptic * haptic)
/*
* Checks to see if rumble is supported.
*/
int
SDL_HapticRumbleSupported(SDL_Haptic * haptic)
int SDL_HapticRumbleSupported(SDL_Haptic *haptic)
{
if (!ValidHaptic(haptic)) {
return -1;
@@ -749,8 +706,7 @@ SDL_HapticRumbleSupported(SDL_Haptic * haptic)
/*
* Initializes the haptic device for simple rumble playback.
*/
int
SDL_HapticRumbleInit(SDL_Haptic * haptic)
int SDL_HapticRumbleInit(SDL_Haptic *haptic)
{
SDL_HapticEffect *efx = &haptic->rumble_effect;
@@ -772,7 +728,7 @@ SDL_HapticRumbleInit(SDL_Haptic * haptic)
efx->periodic.length = 5000;
efx->periodic.attack_length = 0;
efx->periodic.fade_length = 0;
} else if (haptic->supported & SDL_HAPTIC_LEFTRIGHT) { /* XInput? */
} else if (haptic->supported & SDL_HAPTIC_LEFTRIGHT) { /* XInput? */
efx->type = SDL_HAPTIC_LEFTRIGHT;
efx->leftright.length = 5000;
efx->leftright.large_magnitude = 0x4000;
@@ -791,8 +747,7 @@ SDL_HapticRumbleInit(SDL_Haptic * haptic)
/*
* Runs simple rumble on a haptic device
*/
int
SDL_HapticRumblePlay(SDL_Haptic * haptic, float strength, Uint32 length)
int SDL_HapticRumblePlay(SDL_Haptic *haptic, float strength, Uint32 length)
{
SDL_HapticEffect *efx;
Sint16 magnitude;
@@ -811,7 +766,7 @@ SDL_HapticRumblePlay(SDL_Haptic * haptic, float strength, Uint32 length)
} else if (strength < 0.0f) {
strength = 0.0f;
}
magnitude = (Sint16)(32767.0f*strength);
magnitude = (Sint16)(32767.0f * strength);
efx = &haptic->rumble_effect;
if (efx->type == SDL_HAPTIC_SINE) {
@@ -834,8 +789,7 @@ SDL_HapticRumblePlay(SDL_Haptic * haptic, float strength, Uint32 length)
/*
* Stops the simple rumble on a haptic device.
*/
int
SDL_HapticRumbleStop(SDL_Haptic * haptic)
int SDL_HapticRumbleStop(SDL_Haptic *haptic)
{
if (!ValidHaptic(haptic)) {
return -1;