Cleanup add brace (#6545)

* Add braces after if conditions

* More add braces after if conditions

* Add braces after while() conditions

* Fix compilation because of macro being modified

* Add braces to for loop

* Add braces after if/goto

* Move comments up

* Remove extra () in the 'return ...;' statements

* More remove extra () in the 'return ...;' statements

* More remove extra () in the 'return ...;' statements after merge

* Fix inconsistent patterns are xxx == NULL vs !xxx

* More "{}" for "if() break;"  and "if() continue;"

* More "{}" after if() short statement

* More "{}" after "if () return;" statement

* More fix inconsistent patterns are xxx == NULL vs !xxx

* Revert some modificaion on SDL_RLEaccel.c

* SDL_RLEaccel: no short statement

* Cleanup 'if' where the bracket is in a new line

* Cleanup 'while' where the bracket is in a new line

* Cleanup 'for' where the bracket is in a new line

* Cleanup 'else' where the bracket is in a new line

(cherry picked from commit 6a2200823c to reduce conflicts merging between SDL2 and SDL3)
This commit is contained in:
Sylvain Becker 2022-11-27 17:38:43 +01:00 committed by Sam Lantinga
parent 0739d237ad
commit fb0ce375f0
386 changed files with 6103 additions and 4637 deletions

View file

@ -239,17 +239,17 @@ LoadSprite(const char *file)
/* This does the SDL_LoadBMP step repeatedly, but that's OK for test code. */
sprites[i] = LoadTexture(state->renderers[i], file, SDL_TRUE, &sprite_w, &sprite_h);
if (!sprites[i]) {
return (-1);
return -1;
}
if (SDL_SetTextureBlendMode(sprites[i], blendMode) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set blend mode: %s\n", SDL_GetError());
SDL_DestroyTexture(sprites[i]);
return (-1);
return -1;
}
}
/* We're ready to roll. :) */
return (0);
return 0;
}
void
@ -364,8 +364,9 @@ loop()
#endif
}
for (i = 0; i < state->num_windows; ++i) {
if (state->windows[i] == NULL)
if (state->windows[i] == NULL) {
continue;
}
DrawSprites(state->renderers[i], sprites[i]);
}
}
@ -382,7 +383,7 @@ main(int argc, char *argv[])
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO | SDL_INIT_AUDIO);
if (!state) {
if (state == NULL) {
return 1;
}
@ -445,7 +446,7 @@ main(int argc, char *argv[])
/* Create the windows, initialize the renderers, and load the textures */
sprites =
(SDL_Texture **) SDL_malloc(state->num_windows * sizeof(*sprites));
if (!sprites) {
if (sprites == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
quit(2);
}

View file

@ -127,7 +127,7 @@ initializeTextures(SDL_Renderer *renderer)
/* create ship texture from surface */
ship = SDL_CreateTextureFromSurface(renderer, bmp_surface);
if (!ship) {
if (ship == NULL) {
fatalError("could not create ship texture");
}
SDL_SetTextureBlendMode(ship, SDL_BLENDMODE_BLEND);
@ -145,7 +145,7 @@ initializeTextures(SDL_Renderer *renderer)
}
/* create space texture from surface */
space = SDL_CreateTextureFromSurface(renderer, bmp_surface);
if (!space) {
if (space == NULL) {
fatalError("could not create space texture");
}
SDL_FreeSurface(bmp_surface);

View file

@ -84,14 +84,16 @@ stepParticles(double deltaTime)
/* is the particle actually active, or is it marked for deletion? */
if (curr->isActive) {
/* is the particle off the screen? */
if (curr->y > screen_h)
if (curr->y > screen_h) {
curr->isActive = 0;
else if (curr->y < 0)
} else if (curr->y < 0) {
curr->isActive = 0;
if (curr->x > screen_w)
}
if (curr->x > screen_w) {
curr->isActive = 0;
else if (curr->x < 0)
} else if (curr->x < 0) {
curr->isActive = 0;
}
/* step velocity, then step position */
curr->yvel += ACCEL * deltaMilliseconds;
@ -133,15 +135,17 @@ stepParticles(double deltaTime)
}
/* if we're a dust particle, shrink our size */
if (curr->type == dust)
if (curr->type == dust) {
curr->size -= deltaMilliseconds * 0.010f;
}
}
/* if we're still active, pack ourselves in the array next
to the last active guy (pack the array tightly) */
if (curr->isActive)
if (curr->isActive) {
*(slot++) = *curr;
}
} /* endif (curr->isActive) */
curr++;
}
@ -188,8 +192,9 @@ explodeEmitter(struct particle *emitter)
int i;
for (i = 0; i < 200; i++) {
if (num_active_particles >= MAX_PARTICLES)
if (num_active_particles >= MAX_PARTICLES) {
return;
}
/* come up with a random angle and speed for new particle */
float theta = randomFloat(0, 2.0f * 3.141592);
@ -226,8 +231,9 @@ void
spawnTrailFromEmitter(struct particle *emitter)
{
if (num_active_particles >= MAX_PARTICLES)
if (num_active_particles >= MAX_PARTICLES) {
return;
}
/* select the particle at the slot at the end of our array */
struct particle *p = &particles[num_active_particles];
@ -262,8 +268,9 @@ void
spawnEmitterParticle(GLfloat x, GLfloat y)
{
if (num_active_particles >= MAX_PARTICLES)
if (num_active_particles >= MAX_PARTICLES) {
return;
}
/* find particle at endpoint of array */
struct particle *p = &particles[num_active_particles];

View file

@ -117,7 +117,7 @@ initializeTexture(SDL_Renderer *renderer)
/* convert RGBA surface to texture */
texture = SDL_CreateTextureFromSurface(renderer, bmp_surface);
if (!texture) {
if (texture == NULL) {
fatalError("could not create texture");
}
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);

View file

@ -165,7 +165,7 @@ loadFont(void)
{
SDL_Surface *surface = SDL_LoadBMP("kromasky_16x16.bmp");
if (!surface) {
if (surface == NULL) {
printf("Error loading bitmap: %s\n", SDL_GetError());
return 0;
} else {
@ -183,7 +183,7 @@ loadFont(void)
SDL_BlitSurface(surface, NULL, converted, NULL);
/* create our texture */
texture = SDL_CreateTextureFromSurface(renderer, converted);
if (!texture) {
if (texture == NULL) {
printf("texture creation failed: %s\n", SDL_GetError());
} else {
/* set blend mode for our texture */

View file

@ -207,9 +207,9 @@ playSound(struct sound *s)
break;
}
/* if this channel's sound is older than the oldest so far, set it to oldest */
if (mixer.channels[i].timestamp <
mixer.channels[oldest_channel].timestamp)
if (mixer.channels[i].timestamp < mixer.channels[oldest_channel].timestamp) {
oldest_channel = i;
}
}
/* no empty channels, take the oldest one */

View file

@ -58,11 +58,11 @@ main(int argc, char *argv[])
/* create window and renderer */
window = SDL_CreateWindow(NULL, 0, 0, 320, 480, SDL_WINDOW_ALLOW_HIGHDPI);
if (!window) {
if (window == NULL) {
fatalError("Could not initialize Window");
}
renderer = SDL_CreateRenderer(window, -1, 0);
if (!renderer) {
if (renderer == NULL) {
fatalError("Could not create renderer");
}

View file

@ -63,7 +63,7 @@ initializeTexture(SDL_Renderer *renderer)
brush =
SDL_CreateTextureFromSurface(renderer, bmp_surface);
SDL_FreeSurface(bmp_surface);
if (!brush) {
if (brush == NULL) {
fatalError("could not create brush texture");
}
/* additive blending -- laying strokes on top of eachother makes them brighter */

View file

@ -231,7 +231,7 @@ SDL_InitSubSystem(Uint32 flags)
}
/* Initialize the timer subsystem */
if ((flags & SDL_INIT_TIMER)){
if ((flags & SDL_INIT_TIMER)) {
#if !SDL_TIMERS_DISABLED && !SDL_TIMER_DUMMY
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_TIMER)) {
if (SDL_TimerInit() < 0) {
@ -247,7 +247,7 @@ SDL_InitSubSystem(Uint32 flags)
}
/* Initialize the video subsystem */
if ((flags & SDL_INIT_VIDEO)){
if ((flags & SDL_INIT_VIDEO)) {
#if !SDL_VIDEO_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_VIDEO)) {
if (SDL_VideoInit(NULL) < 0) {
@ -263,7 +263,7 @@ SDL_InitSubSystem(Uint32 flags)
}
/* Initialize the audio subsystem */
if ((flags & SDL_INIT_AUDIO)){
if ((flags & SDL_INIT_AUDIO)) {
#if !SDL_AUDIO_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_AUDIO)) {
if (SDL_AudioInit(NULL) < 0) {
@ -279,7 +279,7 @@ SDL_InitSubSystem(Uint32 flags)
}
/* Initialize the joystick subsystem */
if ((flags & SDL_INIT_JOYSTICK)){
if ((flags & SDL_INIT_JOYSTICK)) {
#if !SDL_JOYSTICK_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_JOYSTICK)) {
if (SDL_JoystickInit() < 0) {
@ -294,7 +294,7 @@ SDL_InitSubSystem(Uint32 flags)
#endif
}
if ((flags & SDL_INIT_GAMECONTROLLER)){
if ((flags & SDL_INIT_GAMECONTROLLER)) {
#if !SDL_JOYSTICK_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_GAMECONTROLLER)) {
if (SDL_GameControllerInit() < 0) {
@ -310,7 +310,7 @@ SDL_InitSubSystem(Uint32 flags)
}
/* Initialize the haptic subsystem */
if ((flags & SDL_INIT_HAPTIC)){
if ((flags & SDL_INIT_HAPTIC)) {
#if !SDL_HAPTIC_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_HAPTIC)) {
if (SDL_HapticInit() < 0) {
@ -326,7 +326,7 @@ SDL_InitSubSystem(Uint32 flags)
}
/* Initialize the sensor subsystem */
if ((flags & SDL_INIT_SENSOR)){
if ((flags & SDL_INIT_SENSOR)) {
#if !SDL_SENSOR_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_SENSOR)) {
if (SDL_SensorInit() < 0) {
@ -343,11 +343,11 @@ SDL_InitSubSystem(Uint32 flags)
(void) flags_initialized; /* make static analysis happy, since this only gets used in error cases. */
return (0);
return 0;
quit_and_error:
SDL_QuitSubSystem(flags_initialized);
return (-1);
return -1;
}
int
@ -522,8 +522,7 @@ SDL_GetVersion(SDL_version * ver)
static SDL_bool check_hint = SDL_TRUE;
static SDL_bool legacy_version = SDL_FALSE;
if (!ver) {
return;
if (ver == NULL) { return;
}
SDL_VERSION(ver);

View file

@ -252,10 +252,7 @@ SDL_PromptAssertion(const SDL_assert_data *data, void *userdata)
} else {
state = (SDL_assert_state)selected;
}
}
else
{
} else {
#if defined(__EMSCRIPTEN__)
/* This is nasty, but we can't block on a custom UI. */
for ( ; ; ) {

View file

@ -58,7 +58,7 @@ SDL_NewDataQueue(const size_t _packetlen, const size_t initialslack)
{
SDL_DataQueue *queue = (SDL_DataQueue *) SDL_malloc(sizeof (SDL_DataQueue));
if (!queue) {
if (queue == NULL) {
SDL_OutOfMemory();
return NULL;
} else {
@ -102,7 +102,7 @@ SDL_ClearDataQueue(SDL_DataQueue *queue, const size_t slack)
SDL_DataQueuePacket *prev = NULL;
size_t i;
if (!queue) {
if (queue == NULL) {
return;
}
@ -181,7 +181,7 @@ SDL_WriteToDataQueue(SDL_DataQueue *queue, const void *_data, const size_t _len)
size_t origlen;
size_t datalen;
if (!queue) {
if (queue == NULL) {
return SDL_InvalidParamError("queue");
}
@ -191,13 +191,13 @@ SDL_WriteToDataQueue(SDL_DataQueue *queue, const void *_data, const size_t _len)
while (len > 0) {
SDL_DataQueuePacket *packet = queue->tail;
SDL_assert(!packet || (packet->datalen <= packet_size));
if (!packet || (packet->datalen >= packet_size)) {
SDL_assert(packet == NULL || (packet->datalen <= packet_size));
if (packet == NULL || (packet->datalen >= packet_size)) {
/* tail packet missing or completely full; we need a new packet. */
packet = AllocateDataQueuePacket(queue);
if (!packet) {
if (packet == NULL) {
/* uhoh, reset so we've queued nothing new, free what we can. */
if (!origtail) {
if (origtail == NULL) {
packet = queue->head; /* whole queue. */
} else {
packet = origtail->next; /* what we added to existing queue. */
@ -232,7 +232,7 @@ SDL_PeekIntoDataQueue(SDL_DataQueue *queue, void *_buf, const size_t _len)
Uint8 *ptr = buf;
SDL_DataQueuePacket *packet;
if (!queue) {
if (queue == NULL) {
return 0;
}
@ -257,7 +257,7 @@ SDL_ReadFromDataQueue(SDL_DataQueue *queue, void *_buf, const size_t _len)
Uint8 *ptr = buf;
SDL_DataQueuePacket *packet;
if (!queue) {
if (queue == NULL) {
return 0;
}
@ -300,7 +300,7 @@ SDL_ReserveSpaceInDataQueue(SDL_DataQueue *queue, const size_t len)
{
SDL_DataQueuePacket *packet;
if (!queue) {
if (queue == NULL) {
SDL_InvalidParamError("queue");
return NULL;
} else if (len == 0) {
@ -324,7 +324,7 @@ SDL_ReserveSpaceInDataQueue(SDL_DataQueue *queue, const size_t len)
/* Need a fresh packet. */
packet = AllocateDataQueuePacket(queue);
if (!packet) {
if (packet == NULL) {
SDL_OutOfMemory();
return NULL;
}

View file

@ -52,15 +52,15 @@ void SDL_GUIDToString(SDL_GUID guid, char *pszGUID, int cbGUID)
static unsigned char nibble(unsigned char c)
{
if ((c >= '0') && (c <= '9')) {
return (c - '0');
return c - '0';
}
if ((c >= 'A') && (c <= 'F')) {
return (c - 'A' + 0x0a);
return c - 'A' + 0x0a;
}
if ((c >= 'a') && (c <= 'f')) {
return (c - 'a' + 0x0a);
return c - 'a' + 0x0a;
}
/* received an invalid character, and no real way to return an error */

View file

@ -52,7 +52,7 @@ SDL_SetHintWithPriority(const char *name, const char *value,
SDL_Hint *hint;
SDL_HintWatch *entry;
if (!name) {
if (name == NULL) {
return SDL_FALSE;
}
@ -67,7 +67,7 @@ SDL_SetHintWithPriority(const char *name, const char *value,
return SDL_FALSE;
}
if (hint->value != value &&
(!value || !hint->value || SDL_strcmp(hint->value, value) != 0)) {
(value == NULL || !hint->value || SDL_strcmp(hint->value, value) != 0)) {
for (entry = hint->callbacks; entry; ) {
/* Save the next entry in case this one is deleted */
SDL_HintWatch *next = entry->next;
@ -84,7 +84,7 @@ SDL_SetHintWithPriority(const char *name, const char *value,
/* Couldn't find the hint, add a new one */
hint = (SDL_Hint *)SDL_malloc(sizeof(*hint));
if (!hint) {
if (hint == NULL) {
return SDL_FALSE;
}
hint->name = SDL_strdup(name);
@ -103,7 +103,7 @@ SDL_ResetHint(const char *name)
SDL_Hint *hint;
SDL_HintWatch *entry;
if (!name) {
if (name == NULL) {
return SDL_FALSE;
}
@ -181,7 +181,7 @@ SDL_GetHint(const char *name)
SDL_bool
SDL_GetStringBoolean(const char *value, SDL_bool default_value)
{
if (!value || !*value) {
if (value == NULL || !*value) {
return default_value;
}
if (*value == '0' || SDL_strcasecmp(value, "false") == 0) {
@ -204,7 +204,7 @@ SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userdata)
SDL_HintWatch *entry;
const char *value;
if (!name || !*name) {
if (name == NULL || !*name) {
SDL_InvalidParamError("name");
return;
}
@ -216,7 +216,7 @@ SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userdata)
SDL_DelHintCallback(name, callback, userdata);
entry = (SDL_HintWatch *)SDL_malloc(sizeof(*entry));
if (!entry) {
if (entry == NULL) {
SDL_OutOfMemory();
return;
}
@ -228,10 +228,10 @@ SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userdata)
break;
}
}
if (!hint) {
if (hint == NULL) {
/* Need to add a hint entry for this watcher */
hint = (SDL_Hint *)SDL_malloc(sizeof(*hint));
if (!hint) {
if (hint == NULL) {
SDL_OutOfMemory();
SDL_free(entry);
return;

View file

@ -108,7 +108,7 @@ static int SDL_android_priority[SDL_NUM_LOG_PRIORITIES] = {
void
SDL_LogInit(void)
{
if (!log_function_mutex) {
if (log_function_mutex == NULL) {
/* if this fails we'll try to continue without it. */
log_function_mutex = SDL_CreateMutex();
}
@ -316,7 +316,7 @@ SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va_list
return;
}
if (!log_function_mutex) {
if (log_function_mutex == NULL) {
/* this mutex creation can race if you log from two threads at startup. You should have called SDL_Init first! */
log_function_mutex = SDL_CreateMutex();
}
@ -326,15 +326,17 @@ SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va_list
len = SDL_vsnprintf(stack_buf, sizeof(stack_buf), fmt, aq);
va_end(aq);
if (len < 0)
if (len < 0) {
return;
}
/* If message truncated, allocate and re-render */
if (len >= sizeof(stack_buf) && SDL_size_add_overflow(len, 1, &len_plus_term) == 0) {
/* Allocate exactly what we need, including the zero-terminator */
message = (char *)SDL_malloc(len_plus_term);
if (!message)
if (message == NULL) {
return;
}
va_copy(aq, ap);
len = SDL_vsnprintf(message, len_plus_term, fmt, aq);
va_end(aq);

View file

@ -129,15 +129,15 @@ SDL_AtomicCAS(SDL_atomic_t *a, int oldval, int newval)
{
#ifdef HAVE_MSC_ATOMICS
SDL_COMPILE_TIME_ASSERT(atomic_cas, sizeof(long) == sizeof(a->value));
return (_InterlockedCompareExchange((long*)&a->value, (long)newval, (long)oldval) == (long)oldval);
return _InterlockedCompareExchange((long *)&a->value, (long)newval, (long)oldval) == (long)oldval;
#elif defined(HAVE_WATCOM_ATOMICS)
return (SDL_bool) _SDL_cmpxchg_watcom(&a->value, newval, oldval);
return (SDL_bool)_SDL_cmpxchg_watcom(&a->value, newval, oldval);
#elif defined(HAVE_GCC_ATOMICS)
return (SDL_bool) __sync_bool_compare_and_swap(&a->value, oldval, newval);
#elif defined(__MACOSX__) /* this is deprecated in 10.12 sdk; favor gcc atomics. */
return (SDL_bool) OSAtomicCompareAndSwap32Barrier(oldval, newval, &a->value);
#elif defined(__SOLARIS__)
return (SDL_bool) ((int) atomic_cas_uint((volatile uint_t*)&a->value, (uint_t)oldval, (uint_t)newval) == oldval);
return (SDL_bool)((int)atomic_cas_uint((volatile uint_t *)&a->value, (uint_t)oldval, (uint_t)newval) == oldval);
#elif EMULATE_CAS
SDL_bool retval = SDL_FALSE;
@ -158,9 +158,9 @@ SDL_bool
SDL_AtomicCASPtr(void **a, void *oldval, void *newval)
{
#if defined(HAVE_MSC_ATOMICS)
return (_InterlockedCompareExchangePointer(a, newval, oldval) == oldval);
return _InterlockedCompareExchangePointer(a, newval, oldval) == oldval;
#elif defined(HAVE_WATCOM_ATOMICS)
return (SDL_bool) _SDL_cmpxchg_watcom((int *)a, (long)newval, (long)oldval);
return (SDL_bool)_SDL_cmpxchg_watcom((int *)a, (long)newval, (long)oldval);
#elif defined(HAVE_GCC_ATOMICS)
return __sync_bool_compare_and_swap(a, oldval, newval);
#elif defined(__MACOSX__) && defined(__LP64__) /* this is deprecated in 10.12 sdk; favor gcc atomics. */
@ -168,7 +168,7 @@ SDL_AtomicCASPtr(void **a, void *oldval, void *newval)
#elif defined(__MACOSX__) && !defined(__LP64__) /* this is deprecated in 10.12 sdk; favor gcc atomics. */
return (SDL_bool) OSAtomicCompareAndSwap32Barrier((int32_t)oldval, (int32_t)newval, (int32_t*) a);
#elif defined(__SOLARIS__)
return (SDL_bool) (atomic_cas_ptr(a, oldval, newval) == oldval);
return (SDL_bool)(atomic_cas_ptr(a, oldval, newval) == oldval);
#elif EMULATE_CAS
SDL_bool retval = SDL_FALSE;
@ -190,13 +190,13 @@ SDL_AtomicSet(SDL_atomic_t *a, int v)
{
#ifdef HAVE_MSC_ATOMICS
SDL_COMPILE_TIME_ASSERT(atomic_set, sizeof(long) == sizeof(a->value));
return _InterlockedExchange((long*)&a->value, v);
return _InterlockedExchange((long *)&a->value, v);
#elif defined(HAVE_WATCOM_ATOMICS)
return _SDL_xchg_watcom(&a->value, v);
#elif defined(HAVE_GCC_ATOMICS)
return __sync_lock_test_and_set(&a->value, v);
#elif defined(__SOLARIS__)
return (int) atomic_swap_uint((volatile uint_t*)&a->value, v);
return (int)atomic_swap_uint((volatile uint_t *)&a->value, v);
#else
int value;
do {
@ -212,7 +212,7 @@ SDL_AtomicSetPtr(void **a, void *v)
#if defined(HAVE_MSC_ATOMICS)
return _InterlockedExchangePointer(a, v);
#elif defined(HAVE_WATCOM_ATOMICS)
return (void *) _SDL_xchg_watcom((int *)a, (long)v);
return (void *)_SDL_xchg_watcom((int *)a, (long)v);
#elif defined(HAVE_GCC_ATOMICS)
return __sync_lock_test_and_set(a, v);
#elif defined(__SOLARIS__)
@ -231,7 +231,7 @@ SDL_AtomicAdd(SDL_atomic_t *a, int v)
{
#ifdef HAVE_MSC_ATOMICS
SDL_COMPILE_TIME_ASSERT(atomic_add, sizeof(long) == sizeof(a->value));
return _InterlockedExchangeAdd((long*)&a->value, v);
return _InterlockedExchangeAdd((long *)&a->value, v);
#elif defined(HAVE_WATCOM_ATOMICS)
return _SDL_xadd_watcom(&a->value, v);
#elif defined(HAVE_GCC_ATOMICS)

View file

@ -66,7 +66,7 @@ SDL_AtomicTryLock(SDL_SpinLock *lock)
/* Terrible terrible damage */
static SDL_mutex *_spinlock_mutex;
if (!_spinlock_mutex) {
if (_spinlock_mutex == NULL) {
/* Race condition on first lock... */
_spinlock_mutex = SDL_CreateMutex();
}
@ -81,14 +81,14 @@ SDL_AtomicTryLock(SDL_SpinLock *lock)
}
#elif HAVE_GCC_ATOMICS || HAVE_GCC_SYNC_LOCK_TEST_AND_SET
return (__sync_lock_test_and_set(lock, 1) == 0);
return __sync_lock_test_and_set(lock, 1) == 0;
#elif defined(_MSC_VER) && (defined(_M_ARM) || defined(_M_ARM64))
return (_InterlockedExchange_acq(lock, 1) == 0);
return _InterlockedExchange_acq(lock, 1) == 0;
#elif defined(_MSC_VER)
SDL_COMPILE_TIME_ASSERT(locksize, sizeof(*lock) == sizeof(long));
return (InterlockedExchange((long*)lock, 1) == 0);
return InterlockedExchange((long *)lock, 1) == 0;
#elif defined(__WATCOMC__) && defined(__386__)
return _SDL_xchg_watcom(lock, 1) == 0;
@ -105,28 +105,28 @@ SDL_AtomicTryLock(SDL_SpinLock *lock)
__asm__ __volatile__ (
"ldrex %0, [%2]\nteq %0, #0\nstrexeq %0, %1, [%2]"
: "=&r" (result) : "r" (1), "r" (lock) : "cc", "memory");
return (result == 0);
return result == 0;
}
#endif
__asm__ __volatile__ (
"swp %0, %1, [%2]\n"
: "=&r,&r" (result) : "r,0" (1), "r,r" (lock) : "memory");
return (result == 0);
return result == 0;
#elif defined(__GNUC__) && defined(__arm__)
int result;
__asm__ __volatile__ (
"ldrex %0, [%2]\nteq %0, #0\nstrexeq %0, %1, [%2]"
: "=&r" (result) : "r" (1), "r" (lock) : "cc", "memory");
return (result == 0);
return result == 0;
#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
int result;
__asm__ __volatile__(
"lock ; xchgl %0, (%1)\n"
: "=r" (result) : "r" (lock), "0" (1) : "cc", "memory");
return (result == 0);
return result == 0;
#elif defined(__MACOSX__) || defined(__IPHONEOS__)
/* Maybe used for PowerPC, but the Intel asm or gcc atomics are favored. */
@ -134,11 +134,11 @@ SDL_AtomicTryLock(SDL_SpinLock *lock)
#elif defined(__SOLARIS__) && defined(_LP64)
/* Used for Solaris with non-gcc compilers. */
return (SDL_bool) ((int) atomic_cas_64((volatile uint64_t*)lock, 0, 1) == 0);
return (SDL_bool)((int)atomic_cas_64((volatile uint64_t *)lock, 0, 1) == 0);
#elif defined(__SOLARIS__) && !defined(_LP64)
/* Used for Solaris with non-gcc compilers. */
return (SDL_bool) ((int) atomic_cas_32((volatile uint32_t*)lock, 0, 1) == 0);
return (SDL_bool)((int)atomic_cas_32((volatile uint32_t *)lock, 0, 1) == 0);
#elif defined(PS2)
uint32_t oldintr;
SDL_bool res = SDL_FALSE;
@ -150,7 +150,7 @@ SDL_AtomicTryLock(SDL_SpinLock *lock)
res = SDL_TRUE;
}
// enable interuption
if(oldintr) { EIntr(); }
if (oldintr) { EIntr(); }
return res;
#else
#error Please implement for your platform.

View file

@ -541,11 +541,9 @@ SDL_RemoveAudioDevice(const SDL_bool iscapture, void *handle)
} else {
mark_device_removed(handle, current_audio.outputDevices, &current_audio.outputDevicesRemoved);
}
for (device_index = 0; device_index < SDL_arraysize(open_devices); device_index++)
{
for (device_index = 0; device_index < SDL_arraysize(open_devices); device_index++) {
device = open_devices[device_index];
if (device != NULL && device->handle == handle)
{
if (device != NULL && device->handle == handle) {
device_was_opened = SDL_TRUE;
SDL_OpenedAudioDeviceDisconnected(device);
break;
@ -1009,7 +1007,7 @@ SDL_AudioInit(const char *driver_name)
}
} else {
for (i = 0; (!initialized) && (bootstrap[i]); ++i) {
if(bootstrap[i]->demand_only) {
if (bootstrap[i]->demand_only) {
continue;
}

View file

@ -184,7 +184,7 @@ ResamplerPadding(const int inrate, const int outrate)
return 0;
}
if (inrate > outrate) {
return (int) SDL_ceilf(((float) (RESAMPLER_SAMPLES_PER_ZERO_CROSSING * inrate) / ((float) outrate)));
return (int)SDL_ceilf(((float)(RESAMPLER_SAMPLES_PER_ZERO_CROSSING * inrate) / ((float)outrate)));
}
return RESAMPLER_SAMPLES_PER_ZERO_CROSSING;
}
@ -249,7 +249,7 @@ SDL_ResampleAudio(const int chans, const int inrate, const int outrate,
outtime = ((ResampleFloatType) i) / ((ResampleFloatType) outrate);
}
return outframes * chans * sizeof (float);
return outframes * chans * sizeof(float);
}
int
@ -488,7 +488,7 @@ SDL_ResampleCVT(SDL_AudioCVT *cvt, const int chans, const SDL_AudioFormat format
/* we keep no streaming state here, so pad with silence on both ends. */
padding = (float *) SDL_calloc(paddingsamples ? paddingsamples : 1, sizeof (float));
if (!padding) {
if (padding == NULL) {
SDL_OutOfMemory();
return;
}
@ -586,7 +586,7 @@ SDL_BuildAudioResampleCVT(SDL_AudioCVT * cvt, const int dst_channels,
!!! FIXME in 2.1: We need to store data for this resampler, because the cvt structure doesn't store the original sample rates,
!!! FIXME in 2.1: so we steal the ninth and tenth slot. :( */
if (cvt->filter_index >= (SDL_AUDIOCVT_MAX_FILTERS-2)) {
return SDL_SetError("Too many filters needed for conversion, exceeded maximum of %d", SDL_AUDIOCVT_MAX_FILTERS-2);
return SDL_SetError("Too many filters needed for conversion, exceeded maximum of %d", SDL_AUDIOCVT_MAX_FILTERS - 2);
}
cvt->filters[SDL_AUDIOCVT_MAX_FILTERS-1] = (SDL_AudioFilter) (uintptr_t) src_rate;
cvt->filters[SDL_AUDIOCVT_MAX_FILTERS] = (SDL_AudioFilter) (uintptr_t) dst_rate;
@ -788,7 +788,7 @@ SDL_BuildAudioCVT(SDL_AudioCVT * cvt,
}
cvt->needed = (cvt->filter_index != 0);
return (cvt->needed);
return cvt->needed;
}
typedef int (*SDL_ResampleAudioStreamFunc)(SDL_AudioStream *stream, const void *inbuf, const int inbuflen, void *outbuf, const int outbuflen);
@ -835,7 +835,7 @@ EnsureStreamBufferSize(SDL_AudioStream *stream, const int newlen)
ptr = stream->work_buffer_base;
} else {
ptr = (Uint8 *) SDL_realloc(stream->work_buffer_base, newlen + 32);
if (!ptr) {
if (ptr == NULL) {
SDL_OutOfMemory();
return NULL;
}
@ -911,12 +911,12 @@ SetupLibSampleRateResampling(SDL_AudioStream *stream)
if (SRC_available) {
state = SRC_src_new(SRC_converter, stream->pre_resample_channels, &result);
if (!state) {
if (state == NULL) {
SDL_SetError("src_new() failed: %s", SRC_src_strerror(result));
}
}
if (!state) {
if (state == NULL) {
SDL_CleanupAudioStreamResampler_SRC(stream);
return SDL_FALSE;
}
@ -983,7 +983,7 @@ SDL_NewAudioStream(const SDL_AudioFormat src_format,
SDL_AudioStream *retval;
retval = (SDL_AudioStream *) SDL_calloc(1, sizeof (SDL_AudioStream));
if (!retval) {
if (retval == NULL) {
SDL_OutOfMemory();
return NULL;
}
@ -1126,7 +1126,7 @@ SDL_AudioStreamPutInternal(SDL_AudioStream *stream, const void *buf, int len, in
#endif
workbuf = EnsureStreamBufferSize(stream, workbuflen);
if (!workbuf) {
if (workbuf == NULL) {
return -1; /* probably out of memory. */
}
@ -1193,8 +1193,9 @@ SDL_AudioStreamPutInternal(SDL_AudioStream *stream, const void *buf, int len, in
if (maxputbytes) {
const int maxbytes = *maxputbytes;
if (buflen > maxbytes)
if (buflen > maxbytes) {
buflen = maxbytes;
}
*maxputbytes -= buflen;
}
@ -1217,10 +1218,10 @@ SDL_AudioStreamPut(SDL_AudioStream *stream, const void *buf, int len)
SDL_Log("AUDIOSTREAM: wants to put %d preconverted bytes\n", buflen);
#endif
if (!stream) {
if (stream == NULL) {
return SDL_InvalidParamError("stream");
}
if (!buf) {
if (buf == NULL) {
return SDL_InvalidParamError("buf");
}
if (len == 0) {
@ -1272,7 +1273,7 @@ SDL_AudioStreamPut(SDL_AudioStream *stream, const void *buf, int len)
int SDL_AudioStreamFlush(SDL_AudioStream *stream)
{
if (!stream) {
if (stream == NULL) {
return SDL_InvalidParamError("stream");
}
@ -1290,8 +1291,9 @@ int SDL_AudioStreamFlush(SDL_AudioStream *stream)
const SDL_bool first_run = stream->first_run;
const int filled = stream->staging_buffer_filled;
int actual_input_frames = filled / stream->src_sample_frame_size;
if (!first_run)
if (!first_run) {
actual_input_frames += stream->resampler_padding_samples / stream->pre_resample_channels;
}
if (actual_input_frames > 0) { /* don't bother if nothing to flush. */
/* This is how many bytes we're expecting without silence appended. */
@ -1330,10 +1332,10 @@ SDL_AudioStreamGet(SDL_AudioStream *stream, void *buf, int len)
SDL_Log("AUDIOSTREAM: want to get %d converted bytes\n", len);
#endif
if (!stream) {
if (stream == NULL) {
return SDL_InvalidParamError("stream");
}
if (!buf) {
if (buf == NULL) {
return SDL_InvalidParamError("buf");
}
if (len <= 0) {
@ -1343,20 +1345,20 @@ SDL_AudioStreamGet(SDL_AudioStream *stream, void *buf, int len)
return SDL_SetError("Can't request partial sample frames");
}
return (int) SDL_ReadFromDataQueue(stream->queue, buf, len);
return (int)SDL_ReadFromDataQueue(stream->queue, buf, len);
}
/* number of converted/resampled bytes available */
int
SDL_AudioStreamAvailable(SDL_AudioStream *stream)
{
return stream ? (int) SDL_CountDataQueue(stream->queue) : 0;
return stream ? (int)SDL_CountDataQueue(stream->queue) : 0;
}
void
SDL_AudioStreamClear(SDL_AudioStream *stream)
{
if (!stream) {
if (stream == NULL) {
SDL_InvalidParamError("stream");
} else {
SDL_ClearDataQueue(stream->queue, stream->packetlen * 2);

View file

@ -84,8 +84,9 @@ SDL_EnumUnixAudioDevices_Internal(const int iscapture, const int classic, int (*
const char *audiodev;
char audiopath[1024];
if (test == NULL)
if (test == NULL) {
test = test_stub;
}
/* Figure out what our audio device is */
if (((audiodev = SDL_getenv("SDL_PATH_DSP")) == NULL) &&

View file

@ -820,7 +820,7 @@ IMA_ADPCM_Init(WaveFile *file, size_t datalength)
/* There's no specification for this, but it's basically the same
* format because the extensible header has wSampePerBlocks too.
*/
} else {
} else {
/* The Standards Update says there 'should' be 2 bytes for wSamplesPerBlock. */
if (chunk->size >= 20 && format->extsize >= 2) {
format->samplesperblock = chunk->data[18] | ((Uint16)chunk->data[19] << 8);
@ -901,14 +901,18 @@ IMA_ADPCM_ProcessNibble(Sint8 *cindex, Sint16 lastsample, Uint8 nybble)
* (nybble & 0x8 ? -1 : 1) * ((nybble & 0x7) * step / 4 + step / 8)
*/
delta = step >> 3;
if (nybble & 0x04)
if (nybble & 0x04) {
delta += step;
if (nybble & 0x02)
}
if (nybble & 0x02) {
delta += step >> 1;
if (nybble & 0x01)
}
if (nybble & 0x01) {
delta += step >> 2;
if (nybble & 0x08)
}
if (nybble & 0x08) {
delta = -delta;
}
sample = lastsample + delta;

View file

@ -441,7 +441,7 @@ SDL_bool aaudio_DetectBrokenPlayState( void )
int64_t framePosition, timeNanoseconds;
aaudio_result_t res;
if ( !audioDevice || !audioDevice->hidden ) {
if (audioDevice == NULL || !audioDevice->hidden ) {
return SDL_FALSE;
}

View file

@ -233,7 +233,7 @@ get_audio_device(void *handle, const int channels)
const char *device;
if (handle != NULL) {
return (const char *) handle;
return (const char *)handle;
}
/* !!! FIXME: we also check "SDL_AUDIO_DEVICE_NAME" at the higher level. */
@ -401,8 +401,7 @@ ALSA_PlayDevice(_THIS)
return;
}
continue;
}
else if (status == 0) {
} else if (status == 0) {
/* No frames were written (no available space in pcm device).
Allow other threads to catch up. */
Uint32 delay = (frames_left / 2 * 1000) / this->spec.freq;
@ -417,7 +416,7 @@ ALSA_PlayDevice(_THIS)
static Uint8 *
ALSA_GetDeviceBuf(_THIS)
{
return (this->hidden->mixbuf);
return this->hidden->mixbuf;
}
static int
@ -441,8 +440,7 @@ ALSA_CaptureFromDevice(_THIS, void *buffer, int buflen)
if (status == -EAGAIN) {
ALSA_snd_pcm_wait(this->hidden->pcm_handle, wait_time);
status = 0;
}
else if (status < 0) {
} else if (status < 0) {
/*printf("ALSA: capture error %d\n", status);*/
status = ALSA_snd_pcm_recover(this->hidden->pcm_handle, status, 0);
if (status < 0) {
@ -503,7 +501,7 @@ ALSA_set_buffer_size(_THIS, snd_pcm_hw_params_t *params)
status = ALSA_snd_pcm_hw_params_set_period_size_near(
this->hidden->pcm_handle, hwparams, &persize, NULL);
if ( status < 0 ) {
return(-1);
return -1;
}
/* Need to at least double buffer */
@ -511,19 +509,19 @@ ALSA_set_buffer_size(_THIS, snd_pcm_hw_params_t *params)
status = ALSA_snd_pcm_hw_params_set_periods_min(
this->hidden->pcm_handle, hwparams, &periods, NULL);
if ( status < 0 ) {
return(-1);
return -1;
}
status = ALSA_snd_pcm_hw_params_set_periods_first(
this->hidden->pcm_handle, hwparams, &periods, NULL);
if ( status < 0 ) {
return(-1);
return -1;
}
/* "set" the hardware with the desired parameters */
status = ALSA_snd_pcm_hw_params(this->hidden->pcm_handle, hwparams);
if ( status < 0 ) {
return(-1);
return -1;
}
this->spec.samples = persize;
@ -539,7 +537,7 @@ ALSA_set_buffer_size(_THIS, snd_pcm_hw_params_t *params)
persize, periods, bufsize);
}
return(0);
return 0;
}
static int
@ -575,8 +573,7 @@ ALSA_OpenDevice(_THIS, const char *devname)
SND_PCM_NONBLOCK);
if (status < 0) {
return SDL_SetError("ALSA: Couldn't open audio device: %s",
ALSA_snd_strerror(status));
return SDL_SetError("ALSA: Couldn't open audio device: %s", ALSA_snd_strerror(status));
}
this->hidden->pcm_handle = pcm_handle;
@ -585,16 +582,14 @@ ALSA_OpenDevice(_THIS, const char *devname)
snd_pcm_hw_params_alloca(&hwparams);
status = ALSA_snd_pcm_hw_params_any(pcm_handle, hwparams);
if (status < 0) {
return SDL_SetError("ALSA: Couldn't get hardware config: %s",
ALSA_snd_strerror(status));
return SDL_SetError("ALSA: Couldn't get hardware config: %s", ALSA_snd_strerror(status));
}
/* SDL only uses interleaved sample output */
status = ALSA_snd_pcm_hw_params_set_access(pcm_handle, hwparams,
SND_PCM_ACCESS_RW_INTERLEAVED);
if (status < 0) {
return SDL_SetError("ALSA: Couldn't set interleaved access: %s",
ALSA_snd_strerror(status));
return SDL_SetError("ALSA: Couldn't set interleaved access: %s", ALSA_snd_strerror(status));
}
/* Try for a closest match on audio format */
@ -676,8 +671,7 @@ ALSA_OpenDevice(_THIS, const char *devname)
status = ALSA_snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams,
&rate, NULL);
if (status < 0) {
return SDL_SetError("ALSA: Couldn't set audio frequency: %s",
ALSA_snd_strerror(status));
return SDL_SetError("ALSA: Couldn't set audio frequency: %s", ALSA_snd_strerror(status));
}
this->spec.freq = rate;
@ -691,24 +685,20 @@ ALSA_OpenDevice(_THIS, const char *devname)
snd_pcm_sw_params_alloca(&swparams);
status = ALSA_snd_pcm_sw_params_current(pcm_handle, swparams);
if (status < 0) {
return SDL_SetError("ALSA: Couldn't get software config: %s",
ALSA_snd_strerror(status));
return SDL_SetError("ALSA: Couldn't get software config: %s", ALSA_snd_strerror(status));
}
status = ALSA_snd_pcm_sw_params_set_avail_min(pcm_handle, swparams, this->spec.samples);
if (status < 0) {
return SDL_SetError("Couldn't set minimum available samples: %s",
ALSA_snd_strerror(status));
return SDL_SetError("Couldn't set minimum available samples: %s", ALSA_snd_strerror(status));
}
status =
ALSA_snd_pcm_sw_params_set_start_threshold(pcm_handle, swparams, 1);
if (status < 0) {
return SDL_SetError("ALSA: Couldn't set start threshold: %s",
ALSA_snd_strerror(status));
return SDL_SetError("ALSA: Couldn't set start threshold: %s", ALSA_snd_strerror(status));
}
status = ALSA_snd_pcm_sw_params(pcm_handle, swparams);
if (status < 0) {
return SDL_SetError("Couldn't set software audio parameters: %s",
ALSA_snd_strerror(status));
return SDL_SetError("Couldn't set software audio parameters: %s", ALSA_snd_strerror(status));
}
/* Calculate the final parameters for this audio specification */
@ -749,7 +739,7 @@ add_device(const int iscapture, const char *name, void *hint, ALSA_Device **pSee
char *handle = NULL;
char *ptr;
if (!dev) {
if (dev == NULL) {
return;
}
@ -759,7 +749,7 @@ add_device(const int iscapture, const char *name, void *hint, ALSA_Device **pSee
Make sure not to free the storage associated with desc in this case */
if (hint) {
desc = ALSA_snd_device_name_get_hint(hint, "DESC");
if (!desc) {
if (desc == NULL) {
SDL_free(dev);
return;
}
@ -779,7 +769,7 @@ add_device(const int iscapture, const char *name, void *hint, ALSA_Device **pSee
/*printf("ALSA: adding %s device '%s' (%s)\n", iscapture ? "capture" : "output", name, desc);*/
handle = SDL_strdup(name);
if (!handle) {
if (handle == NULL) {
if (hint) {
free(desc);
}
@ -792,8 +782,9 @@ add_device(const int iscapture, const char *name, void *hint, ALSA_Device **pSee
* enumeration time
*/
SDL_AddAudioDevice(iscapture, desc, NULL, handle);
if (hint)
if (hint) {
free(desc);
}
dev->name = handle;
dev->iscapture = iscapture;
dev->next = *pSeen;
@ -832,7 +823,7 @@ ALSA_HotplugIteration(void)
if we can find a preferred prefix for the system. */
for (i = 0; hints[i]; i++) {
char *name = ALSA_snd_device_name_get_hint(hints[i], "NAME");
if (!name) {
if (name == NULL) {
continue;
}
@ -861,17 +852,17 @@ ALSA_HotplugIteration(void)
char *name;
/* if we didn't find a device name prefix we like at all... */
if ((!match) && (defaultdev != i)) {
if ((match == NULL) && (defaultdev != i)) {
continue; /* ...skip anything that isn't the default device. */
}
name = ALSA_snd_device_name_get_hint(hints[i], "NAME");
if (!name) {
if (name == NULL) {
continue;
}
/* only want physical hardware interfaces */
if (!match || (SDL_strncmp(name, match, match_len) == 0)) {
if (match == NULL || (SDL_strncmp(name, match, match_len) == 0)) {
char *ioid = ALSA_snd_device_name_get_hint(hints[i], "IOID");
const SDL_bool isoutput = (ioid == NULL) || (SDL_strcmp(ioid, "Output") == 0);
const SDL_bool isinput = (ioid == NULL) || (SDL_strcmp(ioid, "Input") == 0);
@ -896,8 +887,12 @@ ALSA_HotplugIteration(void)
}
dev->next = seen;
seen = dev;
if (isinput) have_input = SDL_TRUE;
if (isoutput) have_output = SDL_TRUE;
if (isinput) {
have_input = SDL_TRUE;
}
if (isoutput) {
have_output = SDL_TRUE;
}
} else {
prev = dev;
}

View file

@ -147,26 +147,24 @@ void ANDROIDAUDIO_PauseDevices(void)
{
/* TODO: Handle multiple devices? */
struct SDL_PrivateAudioData *private;
if(audioDevice != NULL && audioDevice->hidden != NULL) {
if (audioDevice != NULL && audioDevice->hidden != NULL) {
private = (struct SDL_PrivateAudioData *) audioDevice->hidden;
if (SDL_AtomicGet(&audioDevice->paused)) {
/* The device is already paused, leave it alone */
private->resume = SDL_FALSE;
}
else {
} else {
SDL_LockMutex(audioDevice->mixer_lock);
SDL_AtomicSet(&audioDevice->paused, 1);
private->resume = SDL_TRUE;
}
}
if(captureDevice != NULL && captureDevice->hidden != NULL) {
if (captureDevice != NULL && captureDevice->hidden != NULL) {
private = (struct SDL_PrivateAudioData *) captureDevice->hidden;
if (SDL_AtomicGet(&captureDevice->paused)) {
/* The device is already paused, leave it alone */
private->resume = SDL_FALSE;
}
else {
} else {
SDL_LockMutex(captureDevice->mixer_lock);
SDL_AtomicSet(&captureDevice->paused, 1);
private->resume = SDL_TRUE;
@ -179,7 +177,7 @@ void ANDROIDAUDIO_ResumeDevices(void)
{
/* TODO: Handle multiple devices? */
struct SDL_PrivateAudioData *private;
if(audioDevice != NULL && audioDevice->hidden != NULL) {
if (audioDevice != NULL && audioDevice->hidden != NULL) {
private = (struct SDL_PrivateAudioData *) audioDevice->hidden;
if (private->resume) {
SDL_AtomicSet(&audioDevice->paused, 0);
@ -188,7 +186,7 @@ void ANDROIDAUDIO_ResumeDevices(void)
}
}
if(captureDevice != NULL && captureDevice->hidden != NULL) {
if (captureDevice != NULL && captureDevice->hidden != NULL) {
private = (struct SDL_PrivateAudioData *) captureDevice->hidden;
if (private->resume) {
SDL_AtomicSet(&captureDevice->paused, 0);

View file

@ -296,7 +296,7 @@ DSOUND_GetDeviceBuf(_THIS)
}
if (result != DS_OK) {
SetDSerror("DirectSound GetCurrentPosition", result);
return (NULL);
return NULL;
}
cursor /= this->spec.size;
#ifdef DEBUG_SOUND
@ -331,9 +331,9 @@ DSOUND_GetDeviceBuf(_THIS)
}
if (result != DS_OK) {
SetDSerror("DirectSound Lock", result);
return (NULL);
return NULL;
}
return (this->hidden->locked_buf);
return this->hidden->locked_buf;
}
static int

View file

@ -68,7 +68,7 @@ DISKAUDIO_PlayDevice(_THIS)
static Uint8 *
DISKAUDIO_GetDeviceBuf(_THIS)
{
return (_this->hidden->mixbuf);
return _this->hidden->mixbuf;
}
static int

View file

@ -82,12 +82,13 @@ DSP_OpenDevice(_THIS, const char *devname)
/* Make sure fragment size stays a power of 2, or OSS fails. */
/* I don't know which of these are actually legal values, though... */
if (this->spec.channels > 8)
if (this->spec.channels > 8) {
this->spec.channels = 8;
else if (this->spec.channels > 4)
} else if (this->spec.channels > 4) {
this->spec.channels = 4;
else if (this->spec.channels > 2)
} else if (this->spec.channels > 2) {
this->spec.channels = 2;
}
/* Initialize all variables that we clean on shutdown */
this->hidden = (struct SDL_PrivateAudioData *)
@ -260,13 +261,13 @@ DSP_PlayDevice(_THIS)
static Uint8 *
DSP_GetDeviceBuf(_THIS)
{
return (this->hidden->mixbuf);
return this->hidden->mixbuf;
}
static int
DSP_CaptureFromDevice(_THIS, void *buffer, int buflen)
{
return (int) read(this->hidden->audio_fd, buffer, buflen);
return (int)read(this->hidden->audio_fd, buffer, buflen);
}
static void

View file

@ -313,7 +313,7 @@ JACK_OpenDevice(_THIS, const char *devname)
}
devports = JACK_jack_get_ports(client, NULL, NULL, JackPortIsPhysical | sysportflags);
if (!devports || !devports[0]) {
if (devports == NULL || !devports[0]) {
return SDL_SetError("No physical JACK ports available");
}

View file

@ -146,7 +146,7 @@ NETBSDAUDIO_PlayDevice(_THIS)
static Uint8 *
NETBSDAUDIO_GetDeviceBuf(_THIS)
{
return (this->hidden->mixbuf);
return this->hidden->mixbuf;
}

View file

@ -424,7 +424,7 @@ openslES_CreatePCMPlayer(_THIS)
it can be done as described here:
https://developer.android.com/ndk/guides/audio/opensl/android-extensions.html#floating-point
*/
if(SDL_GetAndroidSDKVersion() >= 21) {
if (SDL_GetAndroidSDKVersion() >= 21) {
SDL_AudioFormat test_format;
for (test_format = SDL_FirstAudioFormat(this->spec.format); test_format; test_format = SDL_NextAudioFormat()) {
if (SDL_AUDIO_ISSIGNED(test_format)) {
@ -499,7 +499,7 @@ openslES_CreatePCMPlayer(_THIS)
break;
}
if(SDL_AUDIO_ISFLOAT(this->spec.format)) {
if (SDL_AUDIO_ISFLOAT(this->spec.format)) {
/* Copy all setup into PCM EX structure */
format_pcm_ex.formatType = SL_ANDROID_DATAFORMAT_PCM_EX;
format_pcm_ex.endianness = format_pcm.endianness;

View file

@ -1065,7 +1065,7 @@ input_callback(void *data)
}
pw_buf = PIPEWIRE_pw_stream_dequeue_buffer(stream);
if (!pw_buf) {
if (pw_buf == NULL) {
return;
}
@ -1189,15 +1189,15 @@ PIPEWIRE_OpenDevice(_THIS, const char *devname)
/* Get the hints for the application name, stream name and role */
app_name = SDL_GetHint(SDL_HINT_AUDIO_DEVICE_APP_NAME);
if (!app_name || *app_name == '\0') {
if (app_name == NULL || *app_name == '\0') {
app_name = SDL_GetHint(SDL_HINT_APP_NAME);
if (!app_name || *app_name == '\0') {
if (app_name == NULL || *app_name == '\0') {
app_name = "SDL Application";
}
}
stream_name = SDL_GetHint(SDL_HINT_AUDIO_DEVICE_STREAM_NAME);
if (!stream_name || *stream_name == '\0') {
if (stream_name == NULL || *stream_name == '\0') {
stream_name = "Audio Stream";
}
@ -1206,7 +1206,7 @@ PIPEWIRE_OpenDevice(_THIS, const char *devname)
* but 'Game' seems more appropriate for the majority of SDL applications.
*/
stream_role = SDL_GetHint(SDL_HINT_AUDIO_DEVICE_STREAM_ROLE);
if (!stream_role || *stream_role == '\0') {
if (stream_role == NULL || *stream_role == '\0') {
stream_role = "Game";
}

View file

@ -156,8 +156,9 @@ static void PS2AUDIO_Deinitialize(void)
static SDL_bool PS2AUDIO_Init(SDL_AudioDriverImpl * impl)
{
if(init_audio_driver() < 0)
if (init_audio_driver() < 0) {
return SDL_FALSE;
}
/* Set the function pointers */
impl->OpenDevice = PS2AUDIO_OpenDevice;

View file

@ -105,7 +105,7 @@ PSPAUDIO_OpenDevice(_THIS, const char *devname)
static void PSPAUDIO_PlayDevice(_THIS)
{
if (this->spec.freq != 44100){
if (this->spec.freq != 44100) {
Uint8 *mixbuf = this->hidden->mixbufs[this->hidden->next_buffer];
SDL_assert(this->spec.channels == 2);
sceAudioSRCOutputBlocking(PSP_AUDIO_VOLUME_MAX, mixbuf);
@ -131,7 +131,7 @@ static Uint8 *PSPAUDIO_GetDeviceBuf(_THIS)
static void PSPAUDIO_CloseDevice(_THIS)
{
if (this->hidden->channel >= 0) {
if (this->spec.freq != 44100){
if (this->spec.freq != 44100) {
sceAudioSRCChRelease();
} else {
sceAudioChRelease(this->hidden->channel);

View file

@ -53,17 +53,11 @@ static SDL_bool include_monitors = SDL_FALSE;
#if (PA_API_VERSION < 12)
/** Return non-zero if the passed state is one of the connected states */
static SDL_INLINE int PA_CONTEXT_IS_GOOD(pa_context_state_t x) {
return
x == PA_CONTEXT_CONNECTING ||
x == PA_CONTEXT_AUTHORIZING ||
x == PA_CONTEXT_SETTING_NAME ||
x == PA_CONTEXT_READY;
return x == PA_CONTEXT_CONNECTING || x == PA_CONTEXT_AUTHORIZING || x == PA_CONTEXT_SETTING_NAME || x == PA_CONTEXT_READY;
}
/** Return non-zero if the passed state is one of the connected states */
static SDL_INLINE int PA_STREAM_IS_GOOD(pa_stream_state_t x) {
return
x == PA_STREAM_CREATING ||
x == PA_STREAM_READY;
return x == PA_STREAM_CREATING || x == PA_STREAM_READY;
}
#endif /* pulseaudio <= 0.9.10 */
@ -312,7 +306,7 @@ ConnectToPulseServer_Internal(pa_mainloop **_mainloop, pa_context **_context)
SDL_assert(mainloop_api); /* this never fails, right? */
context = PULSEAUDIO_pa_context_new(mainloop_api, getAppName());
if (!context) {
if (context == NULL) {
PULSEAUDIO_pa_mainloop_free(mainloop);
return SDL_SetError("pa_context_new() failed");
}
@ -545,7 +539,7 @@ FindDeviceName(struct SDL_PrivateAudioData *h, const SDL_bool iscapture, void *h
SinkDeviceNameCallback, &h->device_name));
}
return (h->device_name != NULL);
return h->device_name != NULL;
}
static int

View file

@ -81,7 +81,7 @@ VITAAUD_OpenDevice(_THIS, const char *devname)
}
}
if(!test_format) {
if (!test_format) {
return SDL_SetError("Unsupported audio format");
}
@ -111,7 +111,7 @@ VITAAUD_OpenDevice(_THIS, const char *devname)
format = SCE_AUDIO_OUT_MODE_STEREO;
}
if(this->spec.freq < 48000) {
if (this->spec.freq < 48000) {
port = SCE_AUDIO_OUT_PORT_TYPE_BGM;
}

View file

@ -389,8 +389,7 @@ WASAPI_RemoveDevice(const SDL_bool iscapture, LPCWSTR devid)
if (SDL_wcscmp(i->str, devid) == 0) {
if (prev) {
prev->next = next;
}
else {
} else {
deviceid_list = next;
}
SDL_RemoveAudioDevice(iscapture, i->str);
@ -421,7 +420,7 @@ WASAPI_AddDevice(const SDL_bool iscapture, const char *devname, WAVEFORMATEXTENS
}
devidlist = (DevIdList *)SDL_malloc(sizeof(*devidlist));
if (!devidlist) {
if (devidlist == NULL) {
return; /* oh well. */
}

View file

@ -734,7 +734,7 @@ JNIEXPORT int JNICALL SDL_JAVA_INTERFACE(nativeRunMain)(JNIEnv *env, jclass cls,
library_file = (*env)->GetStringUTFChars(env, library, NULL);
library_handle = dlopen(library_file, RTLD_GLOBAL);
if (!library_handle) {
if (library_handle == NULL) {
/* When deploying android app bundle format uncompressed native libs may not extract from apk to filesystem.
In this case we should use lib name without path. https://bugzilla.libsdl.org/show_bug.cgi?id=4739 */
const char *library_name = SDL_strrchr(library_file, '/');
@ -777,7 +777,7 @@ JNIEXPORT int JNICALL SDL_JAVA_INTERFACE(nativeRunMain)(JNIEnv *env, jclass cls,
}
(*env)->DeleteLocalRef(env, string);
}
if (!arg) {
if (arg == NULL) {
arg = SDL_strdup("");
}
argv[argc++] = arg;
@ -874,8 +874,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeResize)(
{
SDL_LockMutex(Android_ActivityMutex);
if (Android_Window)
{
if (Android_Window) {
Android_SendResize(Android_Window);
}
@ -890,8 +889,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeOrientationChanged)(
displayOrientation = (SDL_DisplayOrientation)orientation;
if (Android_Window)
{
if (Android_Window) {
SDL_VideoDisplay *display = SDL_GetDisplay(0);
SDL_SendDisplayEvent(display, SDL_DISPLAYEVENT_ORIENTATION, orientation);
}
@ -1000,8 +998,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceCreated)(JNIEnv *env, j
{
SDL_LockMutex(Android_ActivityMutex);
if (Android_Window)
{
if (Android_Window) {
SDL_WindowData *data = (SDL_WindowData *) Android_Window->driverdata;
data->native_window = Android_JNI_GetNativeWindow();
@ -1019,8 +1016,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceChanged)(JNIEnv *env, j
SDL_LockMutex(Android_ActivityMutex);
#if SDL_VIDEO_OPENGL_EGL
if (Android_Window)
{
if (Android_Window) {
SDL_VideoDevice *_this = SDL_GetVideoDevice();
SDL_WindowData *data = (SDL_WindowData *) Android_Window->driverdata;
@ -1045,8 +1041,7 @@ retry:
SDL_LockMutex(Android_ActivityMutex);
if (Android_Window)
{
if (Android_Window) {
SDL_VideoDevice *_this = SDL_GetVideoDevice();
SDL_WindowData *data = (SDL_WindowData *) Android_Window->driverdata;
@ -1880,7 +1875,7 @@ size_t Android_JNI_FileRead(SDL_RWops* ctx, void* buffer,
if (result > 0) {
/* Number of chuncks */
return (result / size);
return result / size;
} else {
/* Error or EOF */
return result;
@ -2265,7 +2260,7 @@ void *SDL_AndroidGetActivity(void)
/* See SDL_system.h for caveats on using this function. */
JNIEnv *env = Android_JNI_GetEnv();
if (!env) {
if (env == NULL) {
return NULL;
}
@ -2319,7 +2314,7 @@ const char * SDL_AndroidGetInternalStoragePath(void)
{
static char *s_AndroidInternalFilesPath = NULL;
if (!s_AndroidInternalFilesPath) {
if (s_AndroidInternalFilesPath == NULL) {
struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
jmethodID mid;
jobject context;
@ -2412,7 +2407,7 @@ const char * SDL_AndroidGetExternalStoragePath(void)
{
static char *s_AndroidExternalFilesPath = NULL;
if (!s_AndroidExternalFilesPath) {
if (s_AndroidExternalFilesPath == NULL) {
struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
jmethodID mid;
jobject context;

View file

@ -68,7 +68,7 @@ struct SDL_EVDEV_keyboard_state
static int SDL_EVDEV_kbd_load_keymaps(SDL_EVDEV_keyboard_state *kbd)
{
return (ioctl(kbd->keyboard_fd, GIO_KEYMAP, kbd->key_map) >= 0);
return ioctl(kbd->keyboard_fd, GIO_KEYMAP, kbd->key_map) >= 0;
}
static SDL_EVDEV_keyboard_state * kbd_cleanup_state = NULL;
@ -96,7 +96,9 @@ static void kbd_cleanup(void)
SDL_zero(mData);
mData.operation = MOUSE_SHOW;
ioctl(kbd->keyboard_fd, KDSKBMODE, kbd->old_kbd_mode);
if (kbd->keyboard_fd != kbd->console_fd) close(kbd->keyboard_fd);
if (kbd->keyboard_fd != kbd->console_fd) {
close(kbd->keyboard_fd);
}
ioctl(kbd->console_fd, CONS_SETKBD, (unsigned long)(kbd->kbInfo->kb_index));
ioctl(kbd->console_fd, CONS_MOUSECTL, &mData);
}
@ -152,13 +154,14 @@ static void kbd_unregister_emerg_cleanup()
old_action_p = &(old_sigaction[signum]);
/* Examine current signal action */
if (sigaction(signum, NULL, &cur_action))
if (sigaction(signum, NULL, &cur_action)) {
continue;
}
/* Check if action installed and not modifed */
if (!(cur_action.sa_flags & SA_SIGINFO)
|| cur_action.sa_sigaction != &kbd_cleanup_signal_action)
if (!(cur_action.sa_flags & SA_SIGINFO) || cur_action.sa_sigaction != &kbd_cleanup_signal_action) {
continue;
}
/* Restore original action */
sigaction(signum, old_action_p, NULL);
@ -202,16 +205,16 @@ static void kbd_register_emerg_cleanup(SDL_EVDEV_keyboard_state * kbd)
struct sigaction new_action;
signum = fatal_signals[tabidx];
old_action_p = &(old_sigaction[signum]);
if (sigaction(signum, NULL, old_action_p))
if (sigaction(signum, NULL, old_action_p)) {
continue;
}
/* Skip SIGHUP and SIGPIPE if handler is already installed
* - assume the handler will do the cleanup
*/
if ((signum == SIGHUP || signum == SIGPIPE)
&& (old_action_p->sa_handler != SIG_DFL
|| (void (*)(int))old_action_p->sa_sigaction != SIG_DFL))
if ((signum == SIGHUP || signum == SIGPIPE) && (old_action_p->sa_handler != SIG_DFL || (void(*)(int))old_action_p->sa_sigaction != SIG_DFL)) {
continue;
}
new_action = *old_action_p;
new_action.sa_flags |= SA_SIGINFO;
@ -231,7 +234,7 @@ SDL_EVDEV_kbd_init(void)
SDL_zero(mData);
mData.operation = MOUSE_HIDE;
kbd = (SDL_EVDEV_keyboard_state *)SDL_calloc(1, sizeof(SDL_EVDEV_keyboard_state));
if (!kbd) {
if (kbd == NULL) {
return NULL;
}
@ -253,8 +256,7 @@ SDL_EVDEV_kbd_init(void)
kbd->ledflagstate = flag_state;
}
if (ioctl(kbd->console_fd, GIO_DEADKEYMAP, kbd->accents) < 0)
{
if (ioctl(kbd->console_fd, GIO_DEADKEYMAP, kbd->accents) < 0) {
SDL_free(kbd->accents);
kbd->accents = &accentmap_default_us_acc;
}
@ -262,8 +264,7 @@ SDL_EVDEV_kbd_init(void)
if (ioctl(kbd->console_fd, KDGKBMODE, &kbd->old_kbd_mode) == 0) {
/* Set the keyboard in XLATE mode and load the keymaps */
ioctl(kbd->console_fd, KDSKBMODE, (unsigned long)(K_XLATE));
if(!SDL_EVDEV_kbd_load_keymaps(kbd))
{
if (!SDL_EVDEV_kbd_load_keymaps(kbd)) {
SDL_free(kbd->key_map);
kbd->key_map = &keymap_default_us_acc;
}
@ -275,8 +276,7 @@ SDL_EVDEV_kbd_init(void)
ioctl(kbd->console_fd, CONS_RELKBD, 1ul);
SDL_asprintf(&devicePath, "/dev/kbd%d", kbd->kbInfo->kb_index);
kbd->keyboard_fd = open(devicePath, O_WRONLY | O_CLOEXEC);
if (kbd->keyboard_fd == -1)
{
if (kbd->keyboard_fd == -1) {
// Give keyboard back.
ioctl(kbd->console_fd, CONS_SETKBD, (unsigned long)(kbd->kbInfo->kb_index));
kbd->keyboard_fd = kbd->console_fd;
@ -289,8 +289,7 @@ SDL_EVDEV_kbd_init(void)
kbd_register_emerg_cleanup(kbd);
}
SDL_free(devicePath);
}
else kbd->keyboard_fd = kbd->console_fd;
} else kbd->keyboard_fd = kbd->console_fd;
}
return kbd;
@ -301,7 +300,7 @@ SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *kbd)
{
struct mouse_info mData;
if (!kbd) {
if (kbd == NULL) {
return;
}
SDL_zero(mData);
@ -315,8 +314,7 @@ SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *kbd)
ioctl(kbd->keyboard_fd, KDSKBMODE, kbd->old_kbd_mode);
close(kbd->keyboard_fd);
if (kbd->console_fd != kbd->keyboard_fd && kbd->console_fd >= 0)
{
if (kbd->console_fd != kbd->keyboard_fd && kbd->console_fd >= 0) {
// Give back keyboard.
ioctl(kbd->console_fd, CONS_SETKBD, (unsigned long)(kbd->kbInfo->kb_index));
}
@ -347,10 +345,12 @@ static void put_utf8(SDL_EVDEV_keyboard_state *kbd, uint c)
put_queue(kbd, 0xc0 | (c >> 6));
put_queue(kbd, 0x80 | (c & 0x3f));
} else if (c < 0x10000) {
if (c >= 0xD800 && c < 0xE000)
if (c >= 0xD800 && c < 0xE000) {
return;
if (c == 0xFFFF)
}
if (c == 0xFFFF) {
return;
}
/* 1110**** 10****** 10****** */
put_queue(kbd, 0xe0 | (c >> 12));
put_queue(kbd, 0x80 | ((c >> 6) & 0x3f));
@ -379,13 +379,14 @@ static unsigned int handle_diacr(SDL_EVDEV_keyboard_state *kbd, unsigned int ch)
kbd->diacr = 0;
for (i = 0; i < kbd->accents->n_accs; i++) {
if (kbd->accents->acc[i].accchar == d)
{
if (kbd->accents->acc[i].accchar == d) {
for (j = 0; j < NUM_ACCENTCHARS; ++j) {
if (kbd->accents->acc[i].map[j][0] == 0) /* end of table */
if (kbd->accents->acc[i].map[j][0] == 0) { /* end of table */
break;
if (kbd->accents->acc[i].map[j][0] == ch)
}
if (kbd->accents->acc[i].map[j][0] == ch) {
return kbd->accents->acc[i].map[j][1];
}
}
}
}
@ -416,11 +417,13 @@ static void chg_vc_kbd_led(SDL_EVDEV_keyboard_state *kbd, int flag)
static void k_self(SDL_EVDEV_keyboard_state *kbd, unsigned int value, char up_flag)
{
if (up_flag)
return; /* no action, if this is a key release */
if (up_flag) {
return; /* no action, if this is a key release */
}
if (kbd->diacr)
if (kbd->diacr) {
value = handle_diacr(kbd, value);
}
if (kbd->dead_key_next) {
kbd->dead_key_next = SDL_FALSE;
@ -450,8 +453,9 @@ static void k_shift(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_
* handle the case that two shift or control
* keys are depressed simultaneously
*/
if (kbd->shift_down[value])
if (kbd->shift_down[value]) {
kbd->shift_down[value]--;
}
} else
kbd->shift_down[value]++;
@ -477,7 +481,7 @@ SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int d
key_map = *kbd->key_map;
if (!kbd) {
if (kbd == NULL) {
return;
}
@ -488,10 +492,10 @@ SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int d
/* These constitute unprintable language-related keys, so ignore them. */
return;
}
if (keycode > 95)
if (keycode > 95) {
keycode -= 7;
if (vc_kbd_led(kbd, ALKED) || (kbd->shift_state & 0x8))
{
}
if (vc_kbd_led(kbd, ALKED) || (kbd->shift_state & 0x8)) {
keycode += ALTGR_OFFSET;
}
keysym = key_map.key[keycode];
@ -500,18 +504,21 @@ SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int d
}
final_key_state = kbd->shift_state & 0x7;
if ((keysym.flgs & FLAG_LOCK_C) && vc_kbd_led(kbd, LED_CAP))
if ((keysym.flgs & FLAG_LOCK_C) && vc_kbd_led(kbd, LED_CAP)) {
final_key_state ^= 0x1;
if ((keysym.flgs & FLAG_LOCK_N) && vc_kbd_led(kbd, LED_NUM))
}
if ((keysym.flgs & FLAG_LOCK_N) && vc_kbd_led(kbd, LED_NUM)) {
final_key_state ^= 0x1;
}
map_from_key_sym = keysym.map[final_key_state];
if ((keysym.spcl & (0x80 >> final_key_state)) || (map_from_key_sym & SPCLKEY)) {
/* Special function.*/
if (map_from_key_sym == 0)
return; /* Nothing to do. */
if (map_from_key_sym & SPCLKEY)
if (map_from_key_sym & SPCLKEY) {
map_from_key_sym &= ~SPCLKEY;
}
if (map_from_key_sym >= F_ACC && map_from_key_sym <= L_ACC) {
/* Accent function.*/
unsigned int accent_index = map_from_key_sym - F_ACC;
@ -525,36 +532,50 @@ SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int d
break;
case LSHA: /* left shift + alt lock */
case RSHA: /* right shift + alt lock */
if (down == 0) chg_vc_kbd_led(kbd, ALKED);
if (down == 0) {
chg_vc_kbd_led(kbd, ALKED);
}
case LSH: /* left shift */
case RSH: /* right shift */
k_shift(kbd, 0, down == 0);
break;
case LCTRA: /* left ctrl + alt lock */
case RCTRA: /* right ctrl + alt lock */
if (down == 0) chg_vc_kbd_led(kbd, ALKED);
if (down == 0) {
chg_vc_kbd_led(kbd, ALKED);
}
case LCTR: /* left ctrl */
case RCTR: /* right ctrl */
k_shift(kbd, 1, down == 0);
break;
case LALTA: /* left alt + alt lock */
case RALTA: /* right alt + alt lock */
if (down == 0) chg_vc_kbd_led(kbd, ALKED);
if (down == 0) {
chg_vc_kbd_led(kbd, ALKED);
}
case LALT: /* left alt */
case RALT: /* right alt */
k_shift(kbd, 2, down == 0);
break;
case ALK: /* alt lock */
if (down == 1) chg_vc_kbd_led(kbd, ALKED);
if (down == 1) {
chg_vc_kbd_led(kbd, ALKED);
}
break;
case CLK: /* caps lock*/
if (down == 1) chg_vc_kbd_led(kbd, CLKED);
if (down == 1) {
chg_vc_kbd_led(kbd, CLKED);
}
break;
case NLK: /* num lock */
if (down == 1) chg_vc_kbd_led(kbd, NLKED);
if (down == 1) {
chg_vc_kbd_led(kbd, NLKED);
}
break;
case SLK: /* scroll lock */
if (down == 1) chg_vc_kbd_led(kbd, SLKED);
if (down == 1) {
chg_vc_kbd_led(kbd, SLKED);
}
break;
default:
return;

View file

@ -109,13 +109,13 @@ SDL_GDKRunApp(SDL_main_func mainFunction, void *reserved)
/* Parse it into argv and argc */
argv = (char **) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (argc + 1) * sizeof(*argv));
if (!argv) {
if (argv == NULL) {
return OutOfMemory();
}
for (i = 0; i < argc; ++i) {
DWORD len;
char *arg = WIN_StringToUTF8W(argvw[i]);
if (!arg) {
if (arg == NULL) {
return OutOfMemory();
}
len = (DWORD) SDL_strlen(arg);

View file

@ -201,7 +201,7 @@ SDL_DBus_Quit(void)
SDL_DBusContext *
SDL_DBus_GetContext(void)
{
if (!dbus_handle || !dbus.session_conn) {
if (dbus_handle == NULL || !dbus.session_conn) {
SDL_DBus_Init();
}
@ -379,20 +379,25 @@ SDL_DBus_AppendDictWithKeyValue(DBusMessageIter *iterInit, const char *key, cons
{
DBusMessageIter iterDict, iterEntry, iterValue;
if (!dbus.message_iter_open_container(iterInit, DBUS_TYPE_ARRAY, "{sv}", &iterDict))
if (!dbus.message_iter_open_container(iterInit, DBUS_TYPE_ARRAY, "{sv}", &iterDict)) {
goto failed;
}
if (!dbus.message_iter_open_container(&iterDict, DBUS_TYPE_DICT_ENTRY, NULL, &iterEntry))
if (!dbus.message_iter_open_container(&iterDict, DBUS_TYPE_DICT_ENTRY, NULL, &iterEntry)) {
goto failed;
}
if (!dbus.message_iter_append_basic(&iterEntry, DBUS_TYPE_STRING, &key))
if (!dbus.message_iter_append_basic(&iterEntry, DBUS_TYPE_STRING, &key)) {
goto failed;
}
if (!dbus.message_iter_open_container(&iterEntry, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &iterValue))
if (!dbus.message_iter_open_container(&iterEntry, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &iterValue)) {
goto failed;
}
if (!dbus.message_iter_append_basic(&iterValue, DBUS_TYPE_STRING, &value))
if (!dbus.message_iter_append_basic(&iterValue, DBUS_TYPE_STRING, &value)) {
goto failed;
}
if (!dbus.message_iter_close_container(&iterEntry, &iterValue)
|| !dbus.message_iter_close_container(&iterDict, &iterEntry)
@ -439,12 +444,12 @@ SDL_DBus_ScreensaverInhibit(SDL_bool inhibit)
const char *key = "reason";
const char *reply = NULL;
const char *reason = SDL_GetHint(SDL_HINT_SCREENSAVER_INHIBIT_ACTIVITY_NAME);
if (!reason || !reason[0]) {
if (reason == NULL || !reason[0]) {
reason = default_inhibit_reason;
}
msg = dbus.message_new_method_call(bus_name, path, interface, "Inhibit");
if (!msg) {
if (msg == NULL) {
return SDL_FALSE;
}
@ -481,10 +486,10 @@ SDL_DBus_ScreensaverInhibit(SDL_bool inhibit)
if (inhibit) {
const char *app = SDL_GetHint(SDL_HINT_APP_NAME);
const char *reason = SDL_GetHint(SDL_HINT_SCREENSAVER_INHIBIT_ACTIVITY_NAME);
if (!app || !app[0]) {
if (app == NULL || !app[0]) {
app = "My SDL application";
}
if (!reason || !reason[0]) {
if (reason == NULL || !reason[0]) {
reason = default_inhibit_reason;
}

View file

@ -188,14 +188,14 @@ SDL_EVDEV_Init(void)
ROM. */
char* rest = (char*) devices;
char* spec;
while ((spec = strtok_r(rest, ",", &rest))) {
while ((spec = SDL_strtokr(rest, ",", &rest))) {
char* endofcls = 0;
long cls = strtol(spec, &endofcls, 0);
if (endofcls)
long cls = SDL_strtol(spec, &endofcls, 0);
if (endofcls) {
SDL_EVDEV_device_added(endofcls + 1, cls);
}
}
}
else {
} else {
/* TODO: Scan the devices manually, like a caveman */
}
}
@ -229,7 +229,7 @@ SDL_EVDEV_Quit(void)
SDL_EVDEV_kbd_quit(_this->kbd);
/* Remove existing devices */
while(_this->first != NULL) {
while (_this->first != NULL) {
SDL_EVDEV_device_removed(_this->first->path);
}
@ -252,11 +252,13 @@ static void SDL_EVDEV_udev_callback(SDL_UDEV_deviceevent udev_event, int udev_cl
switch(udev_event) {
case SDL_UDEV_DEVICEADDED:
if (!(udev_class & (SDL_UDEV_DEVICE_MOUSE | SDL_UDEV_DEVICE_KEYBOARD | SDL_UDEV_DEVICE_TOUCHSCREEN | SDL_UDEV_DEVICE_TOUCHPAD)))
if (!(udev_class & (SDL_UDEV_DEVICE_MOUSE | SDL_UDEV_DEVICE_KEYBOARD | SDL_UDEV_DEVICE_TOUCHSCREEN | SDL_UDEV_DEVICE_TOUCHPAD))) {
return;
}
if ((udev_class & SDL_UDEV_DEVICE_JOYSTICK))
if ((udev_class & SDL_UDEV_DEVICE_JOYSTICK)) {
return;
}
SDL_EVDEV_device_added(dev_path, udev_class);
break;
@ -341,13 +343,15 @@ SDL_EVDEV_Poll(void)
case EV_ABS:
switch(events[i].code) {
case ABS_MT_SLOT:
if (!item->is_touchscreen) /* FIXME: temp hack */
if (!item->is_touchscreen) { /* FIXME: temp hack */
break;
}
item->touchscreen_data->current_slot = events[i].value;
break;
case ABS_MT_TRACKING_ID:
if (!item->is_touchscreen) /* FIXME: temp hack */
if (!item->is_touchscreen) { /* FIXME: temp hack */
break;
}
if (events[i].value >= 0) {
item->touchscreen_data->slots[item->touchscreen_data->current_slot].tracking_id = events[i].value;
item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta = EVDEV_TOUCH_SLOTDELTA_DOWN;
@ -356,24 +360,27 @@ SDL_EVDEV_Poll(void)
}
break;
case ABS_MT_POSITION_X:
if (!item->is_touchscreen) /* FIXME: temp hack */
if (!item->is_touchscreen) { /* FIXME: temp hack */
break;
}
item->touchscreen_data->slots[item->touchscreen_data->current_slot].x = events[i].value;
if (item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta == EVDEV_TOUCH_SLOTDELTA_NONE) {
item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta = EVDEV_TOUCH_SLOTDELTA_MOVE;
}
break;
case ABS_MT_POSITION_Y:
if (!item->is_touchscreen) /* FIXME: temp hack */
if (!item->is_touchscreen) { /* FIXME: temp hack */
break;
}
item->touchscreen_data->slots[item->touchscreen_data->current_slot].y = events[i].value;
if (item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta == EVDEV_TOUCH_SLOTDELTA_NONE) {
item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta = EVDEV_TOUCH_SLOTDELTA_MOVE;
}
break;
case ABS_MT_PRESSURE:
if (!item->is_touchscreen) /* FIXME: temp hack */
if (!item->is_touchscreen) { /* FIXME: temp hack */
break;
}
item->touchscreen_data->slots[item->touchscreen_data->current_slot].pressure = events[i].value;
if (item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta == EVDEV_TOUCH_SLOTDELTA_NONE) {
item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta = EVDEV_TOUCH_SLOTDELTA_MOVE;
@ -381,8 +388,9 @@ SDL_EVDEV_Poll(void)
break;
case ABS_X:
if (item->is_touchscreen) {
if (item->touchscreen_data->max_slots != 1)
if (item->touchscreen_data->max_slots != 1) {
break;
}
item->touchscreen_data->slots[0].x = events[i].value;
} else if (!item->relative_mouse) {
/* FIXME: Normalize to input device's reported input range (EVIOCGABS) */
@ -391,8 +399,9 @@ SDL_EVDEV_Poll(void)
break;
case ABS_Y:
if (item->is_touchscreen) {
if (item->touchscreen_data->max_slots != 1)
if (item->touchscreen_data->max_slots != 1) {
break;
}
item->touchscreen_data->slots[0].y = events[i].value;
} else if (!item->relative_mouse) {
/* FIXME: Normalize to input device's reported input range (EVIOCGABS) */
@ -406,24 +415,28 @@ SDL_EVDEV_Poll(void)
case EV_REL:
switch(events[i].code) {
case REL_X:
if (item->relative_mouse)
if (item->relative_mouse) {
item->mouse_x += events[i].value;
}
break;
case REL_Y:
if (item->relative_mouse)
if (item->relative_mouse) {
item->mouse_y += events[i].value;
}
break;
case REL_WHEEL:
if (!item->high_res_wheel)
if (!item->high_res_wheel) {
item->mouse_wheel += events[i].value;
}
break;
case REL_WHEEL_HI_RES:
SDL_assert(item->high_res_wheel);
item->mouse_wheel += events[i].value;
break;
case REL_HWHEEL:
if (!item->high_res_hwheel)
if (!item->high_res_hwheel) {
item->mouse_hwheel += events[i].value;
}
break;
case REL_HWHEEL_HI_RES:
SDL_assert(item->high_res_hwheel);
@ -449,10 +462,11 @@ SDL_EVDEV_Poll(void)
item->mouse_wheel = item->mouse_hwheel = 0;
}
if (!item->is_touchscreen) /* FIXME: temp hack */
if (!item->is_touchscreen) { /* FIXME: temp hack */
break;
}
for(j = 0; j < item->touchscreen_data->max_slots; j++) {
for (j = 0; j < item->touchscreen_data->max_slots; j++) {
norm_x = (float)(item->touchscreen_data->slots[j].x - item->touchscreen_data->min_x) /
(float)item->touchscreen_data->range_x;
norm_y = (float)(item->touchscreen_data->slots[j].y - item->touchscreen_data->min_y) /
@ -488,12 +502,14 @@ SDL_EVDEV_Poll(void)
}
}
if (item->out_of_sync)
if (item->out_of_sync) {
item->out_of_sync = SDL_FALSE;
}
break;
case SYN_DROPPED:
if (item->is_touchscreen)
if (item->is_touchscreen) {
item->out_of_sync = SDL_TRUE;
}
SDL_EVDEV_sync_device(item);
break;
default:
@ -536,12 +552,14 @@ SDL_EVDEV_init_touchscreen(SDL_evdevlist_item* item, int udev_class)
char name[64];
struct input_absinfo abs_info;
if (!item->is_touchscreen)
if (!item->is_touchscreen) {
return 0;
}
item->touchscreen_data = SDL_calloc(1, sizeof(*item->touchscreen_data));
if (item->touchscreen_data == NULL)
if (item->touchscreen_data == NULL) {
return SDL_OutOfMemory();
}
ret = ioctl(item->fd, EVIOCGNAME(sizeof(name)), name);
if (ret < 0) {
@ -611,7 +629,7 @@ SDL_EVDEV_init_touchscreen(SDL_evdevlist_item* item, int udev_class)
return SDL_OutOfMemory();
}
for(i = 0; i < item->touchscreen_data->max_slots; i++) {
for (i = 0; i < item->touchscreen_data->max_slots; i++) {
item->touchscreen_data->slots[i].tracking_id = -1;
}
@ -630,8 +648,9 @@ SDL_EVDEV_init_touchscreen(SDL_evdevlist_item* item, int udev_class)
static void
SDL_EVDEV_destroy_touchscreen(SDL_evdevlist_item* item) {
if (!item->is_touchscreen)
if (!item->is_touchscreen) {
return;
}
SDL_DelTouch(item->fd);
SDL_free(item->touchscreen_data->slots);
@ -658,8 +677,9 @@ SDL_EVDEV_sync_device(SDL_evdevlist_item *item)
size_t mt_req_size;
/* TODO: sync devices other than touchscreen */
if (!item->is_touchscreen)
if (!item->is_touchscreen) {
return;
}
mt_req_size = sizeof(*mt_req_code) +
sizeof(*mt_req_values) * item->touchscreen_data->max_slots;
@ -677,7 +697,7 @@ SDL_EVDEV_sync_device(SDL_evdevlist_item *item)
SDL_free(mt_req_code);
return;
}
for(i = 0; i < item->touchscreen_data->max_slots; i++) {
for (i = 0; i < item->touchscreen_data->max_slots; i++) {
/*
* This doesn't account for the very edge case of the user removing their
* finger and replacing it on the screen during the time we're out of sync,
@ -704,7 +724,7 @@ SDL_EVDEV_sync_device(SDL_evdevlist_item *item)
SDL_free(mt_req_code);
return;
}
for(i = 0; i < item->touchscreen_data->max_slots; i++) {
for (i = 0; i < item->touchscreen_data->max_slots; i++) {
if (item->touchscreen_data->slots[i].tracking_id >= 0 &&
item->touchscreen_data->slots[i].x != mt_req_values[i]) {
item->touchscreen_data->slots[i].x = mt_req_values[i];
@ -722,7 +742,7 @@ SDL_EVDEV_sync_device(SDL_evdevlist_item *item)
SDL_free(mt_req_code);
return;
}
for(i = 0; i < item->touchscreen_data->max_slots; i++) {
for (i = 0; i < item->touchscreen_data->max_slots; i++) {
if (item->touchscreen_data->slots[i].tracking_id >= 0 &&
item->touchscreen_data->slots[i].y != mt_req_values[i]) {
item->touchscreen_data->slots[i].y = mt_req_values[i];
@ -740,7 +760,7 @@ SDL_EVDEV_sync_device(SDL_evdevlist_item *item)
SDL_free(mt_req_code);
return;
}
for(i = 0; i < item->touchscreen_data->max_slots; i++) {
for (i = 0; i < item->touchscreen_data->max_slots; i++) {
if (item->touchscreen_data->slots[i].tracking_id >= 0 &&
item->touchscreen_data->slots[i].pressure != mt_req_values[i]) {
item->touchscreen_data->slots[i].pressure = mt_req_values[i];

View file

@ -138,8 +138,9 @@ SDL_EVDEV_GuessDeviceClass(unsigned long bitmask_ev[NBITS(EV_MAX)],
/* the first 32 bits are ESC, numbers, and Q to D; if we have any of
* those, consider it a keyboard device; do not test KEY_RESERVED, though */
keyboard_mask = 0xFFFFFFFE;
if ((bitmask_key[0] & keyboard_mask) != 0)
if ((bitmask_key[0] & keyboard_mask) != 0) {
devclass |= SDL_UDEV_DEVICE_KEYBOARD; /* ID_INPUT_KEYBOARD */
}
return devclass;
}

View file

@ -270,13 +270,14 @@ static void kbd_unregister_emerg_cleanup()
old_action_p = &(old_sigaction[signum]);
/* Examine current signal action */
if (sigaction(signum, NULL, &cur_action))
if (sigaction(signum, NULL, &cur_action)) {
continue;
}
/* Check if action installed and not modifed */
if (!(cur_action.sa_flags & SA_SIGINFO)
|| cur_action.sa_sigaction != &kbd_cleanup_signal_action)
if (!(cur_action.sa_flags & SA_SIGINFO) || cur_action.sa_sigaction != &kbd_cleanup_signal_action) {
continue;
}
/* Restore original action */
sigaction(signum, old_action_p, NULL);
@ -320,16 +321,16 @@ static void kbd_register_emerg_cleanup(SDL_EVDEV_keyboard_state * kbd)
struct sigaction new_action;
signum = fatal_signals[tabidx];
old_action_p = &(old_sigaction[signum]);
if (sigaction(signum, NULL, old_action_p))
if (sigaction(signum, NULL, old_action_p)) {
continue;
}
/* Skip SIGHUP and SIGPIPE if handler is already installed
* - assume the handler will do the cleanup
*/
if ((signum == SIGHUP || signum == SIGPIPE)
&& (old_action_p->sa_handler != SIG_DFL
|| (void (*)(int))old_action_p->sa_sigaction != SIG_DFL))
if ((signum == SIGHUP || signum == SIGPIPE) && (old_action_p->sa_handler != SIG_DFL || (void(*)(int))old_action_p->sa_sigaction != SIG_DFL)) {
continue;
}
new_action = *old_action_p;
new_action.sa_flags |= SA_SIGINFO;
@ -347,7 +348,7 @@ SDL_EVDEV_kbd_init(void)
char shift_state[ sizeof (long) ] = {TIOCL_GETSHIFTSTATE, 0};
kbd = (SDL_EVDEV_keyboard_state *)SDL_calloc(1, sizeof(*kbd));
if (!kbd) {
if (kbd == NULL) {
return NULL;
}
@ -413,7 +414,7 @@ SDL_EVDEV_kbd_init(void)
void
SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *kbd)
{
if (!kbd) {
if (kbd == NULL) {
return;
}
@ -461,10 +462,12 @@ static void put_utf8(SDL_EVDEV_keyboard_state *kbd, uint c)
put_queue(kbd, 0xc0 | (c >> 6));
put_queue(kbd, 0x80 | (c & 0x3f));
} else if (c < 0x10000) {
if (c >= 0xD800 && c < 0xE000)
if (c >= 0xD800 && c < 0xE000) {
return;
if (c == 0xFFFF)
}
if (c == 0xFFFF) {
return;
}
/* 1110**** 10****** 10****** */
put_queue(kbd, 0xe0 | (c >> 12));
put_queue(kbd, 0x80 | ((c >> 6) & 0x3f));
@ -499,8 +502,9 @@ static unsigned int handle_diacr(SDL_EVDEV_keyboard_state *kbd, unsigned int ch)
}
}
if (ch == ' ' || ch == d)
if (ch == ' ' || ch == d) {
return d;
}
put_utf8(kbd, d);
@ -554,24 +558,27 @@ static void fn_enter(SDL_EVDEV_keyboard_state *kbd)
static void fn_caps_toggle(SDL_EVDEV_keyboard_state *kbd)
{
if (kbd->rep)
if (kbd->rep) {
return;
}
chg_vc_kbd_led(kbd, K_CAPSLOCK);
}
static void fn_caps_on(SDL_EVDEV_keyboard_state *kbd)
{
if (kbd->rep)
if (kbd->rep) {
return;
}
set_vc_kbd_led(kbd, K_CAPSLOCK);
}
static void fn_num(SDL_EVDEV_keyboard_state *kbd)
{
if (!kbd->rep)
if (!kbd->rep) {
chg_vc_kbd_led(kbd, K_NUMLOCK);
}
}
static void fn_compose(SDL_EVDEV_keyboard_state *kbd)
@ -589,12 +596,15 @@ static void k_ignore(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up
static void k_spec(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag)
{
if (up_flag)
if (up_flag) {
return;
if (value >= SDL_arraysize(fn_handler))
}
if (value >= SDL_arraysize(fn_handler)) {
return;
if (fn_handler[value])
}
if (fn_handler[value]) {
fn_handler[value](kbd);
}
}
static void k_lowercase(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag)
@ -603,11 +613,13 @@ static void k_lowercase(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char
static void k_self(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag)
{
if (up_flag)
return; /* no action, if this is a key release */
if (up_flag) {
return; /* no action, if this is a key release */
}
if (kbd->diacr)
if (kbd->diacr) {
value = handle_diacr(kbd, value);
}
if (kbd->dead_key_next) {
kbd->dead_key_next = SDL_FALSE;
@ -676,8 +688,9 @@ static void k_shift(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_
*/
if (value == KVAL(K_CAPSSHIFT)) {
value = KVAL(K_SHIFT);
if (!up_flag)
if (!up_flag) {
clr_vc_kbd_led(kbd, K_CAPSLOCK);
}
}
if (up_flag) {
@ -685,8 +698,9 @@ static void k_shift(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_
* handle the case that two shift or control
* keys are depressed simultaneously
*/
if (kbd->shift_down[value])
if (kbd->shift_down[value]) {
kbd->shift_down[value]--;
}
} else
kbd->shift_down[value]++;
@ -762,7 +776,7 @@ SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int d
unsigned short *key_map;
unsigned short keysym;
if (!kbd) {
if (kbd == NULL) {
return;
}
@ -770,7 +784,7 @@ SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int d
shift_final = (kbd->shift_state | kbd->slockstate) ^ kbd->lockstate;
key_map = kbd->key_maps[shift_final];
if (!key_map) {
if (key_map == NULL) {
/* Unsupported shift state (e.g. ctrl = 4, alt = 8), just reset to the default state */
kbd->shift_state = 0;
kbd->slockstate = 0;

View file

@ -347,14 +347,30 @@ Fcitx_ModState(void)
Uint32 fcitx_mods = 0;
SDL_Keymod sdl_mods = SDL_GetModState();
if (sdl_mods & KMOD_SHIFT) fcitx_mods |= (1 << 0);
if (sdl_mods & KMOD_CAPS) fcitx_mods |= (1 << 1);
if (sdl_mods & KMOD_CTRL) fcitx_mods |= (1 << 2);
if (sdl_mods & KMOD_ALT) fcitx_mods |= (1 << 3);
if (sdl_mods & KMOD_NUM) fcitx_mods |= (1 << 4);
if (sdl_mods & KMOD_MODE) fcitx_mods |= (1 << 7);
if (sdl_mods & KMOD_LGUI) fcitx_mods |= (1 << 6);
if (sdl_mods & KMOD_RGUI) fcitx_mods |= (1 << 28);
if (sdl_mods & KMOD_SHIFT) {
fcitx_mods |= (1 << 0);
}
if (sdl_mods & KMOD_CAPS) {
fcitx_mods |= (1 << 1);
}
if (sdl_mods & KMOD_CTRL) {
fcitx_mods |= (1 << 2);
}
if (sdl_mods & KMOD_ALT) {
fcitx_mods |= (1 << 3);
}
if (sdl_mods & KMOD_NUM) {
fcitx_mods |= (1 << 4);
}
if (sdl_mods & KMOD_MODE) {
fcitx_mods |= (1 << 7);
}
if (sdl_mods & KMOD_LGUI) {
fcitx_mods |= (1 << 6);
}
if (sdl_mods & KMOD_RGUI) {
fcitx_mods |= (1 << 28);
}
return fcitx_mods;
}
@ -436,7 +452,7 @@ SDL_Fcitx_UpdateTextRect(const SDL_Rect *rect)
}
focused_win = SDL_GetKeyboardFocus();
if (!focused_win) {
if (focused_win == NULL) {
return ;
}

View file

@ -65,14 +65,30 @@ IBus_ModState(void)
SDL_Keymod sdl_mods = SDL_GetModState();
/* Not sure about MOD3, MOD4 and HYPER mappings */
if (sdl_mods & KMOD_LSHIFT) ibus_mods |= IBUS_SHIFT_MASK;
if (sdl_mods & KMOD_CAPS) ibus_mods |= IBUS_LOCK_MASK;
if (sdl_mods & KMOD_LCTRL) ibus_mods |= IBUS_CONTROL_MASK;
if (sdl_mods & KMOD_LALT) ibus_mods |= IBUS_MOD1_MASK;
if (sdl_mods & KMOD_NUM) ibus_mods |= IBUS_MOD2_MASK;
if (sdl_mods & KMOD_MODE) ibus_mods |= IBUS_MOD5_MASK;
if (sdl_mods & KMOD_LGUI) ibus_mods |= IBUS_SUPER_MASK;
if (sdl_mods & KMOD_RGUI) ibus_mods |= IBUS_META_MASK;
if (sdl_mods & KMOD_LSHIFT) {
ibus_mods |= IBUS_SHIFT_MASK;
}
if (sdl_mods & KMOD_CAPS) {
ibus_mods |= IBUS_LOCK_MASK;
}
if (sdl_mods & KMOD_LCTRL) {
ibus_mods |= IBUS_CONTROL_MASK;
}
if (sdl_mods & KMOD_LALT) {
ibus_mods |= IBUS_MOD1_MASK;
}
if (sdl_mods & KMOD_NUM) {
ibus_mods |= IBUS_MOD2_MASK;
}
if (sdl_mods & KMOD_MODE) {
ibus_mods |= IBUS_MOD5_MASK;
}
if (sdl_mods & KMOD_LGUI) {
ibus_mods |= IBUS_SUPER_MASK;
}
if (sdl_mods & KMOD_RGUI) {
ibus_mods |= IBUS_META_MASK;
}
return ibus_mods;
}
@ -99,7 +115,7 @@ IBus_EnterVariant(DBusConnection *conn, DBusMessageIter *iter, SDL_DBusContext *
}
dbus->message_iter_get_basic(inside, &struct_id);
if (!struct_id || SDL_strncmp(struct_id, struct_id, id_size) != 0) {
if (struct_id == NULL || SDL_strncmp(struct_id, struct_id, id_size) != 0) {
return SDL_FALSE;
}
return SDL_TRUE;
@ -249,13 +265,12 @@ IBus_MessageHandler(DBusConnection *conn, DBusMessage *msg, void *user_data)
dbus->message_iter_init(msg, &iter);
has_dec_pos = IBus_GetDecorationPosition(conn, &iter, dbus, &start_pos, &end_pos);
if (!has_dec_pos)
{
if (!has_dec_pos) {
dbus->message_iter_init(msg, &iter);
has_pos = IBus_GetVariantCursorPos(conn, &iter, dbus, &pos);
}
if(has_dec_pos) {
if (has_dec_pos) {
SDL_SendEditingText(text, start_pos, end_pos - start_pos);
} else if (has_pos) {
SDL_SendEditingText(text, pos, -1);
@ -299,15 +314,19 @@ IBus_ReadAddressFromFile(const char *file_path)
FILE *addr_file;
addr_file = fopen(file_path, "r");
if (!addr_file) {
if (addr_file == NULL) {
return NULL;
}
while (fgets(addr_buf, sizeof(addr_buf), addr_file)) {
if (SDL_strncmp(addr_buf, "IBUS_ADDRESS=", sizeof("IBUS_ADDRESS=")-1) == 0) {
size_t sz = SDL_strlen(addr_buf);
if (addr_buf[sz-1] == '\n') addr_buf[sz-1] = 0;
if (addr_buf[sz-2] == '\r') addr_buf[sz-2] = 0;
if (addr_buf[sz - 1] == '\n') {
addr_buf[sz - 1] = 0;
}
if (addr_buf[sz - 2] == '\r') {
addr_buf[sz - 2] = 0;
}
success = SDL_TRUE;
break;
}
@ -341,7 +360,7 @@ IBus_GetDBusAddressFilename(void)
}
dbus = SDL_DBus_GetContext();
if (!dbus) {
if (dbus == NULL) {
return NULL;
}
@ -355,7 +374,7 @@ IBus_GetDBusAddressFilename(void)
and look up the address from a filepath using all those bits, eek. */
disp_env = SDL_getenv("DISPLAY");
if (!disp_env || !*disp_env) {
if (disp_env == NULL || !*disp_env) {
display = SDL_strdup(":0.0");
} else {
display = SDL_strdup(disp_env);
@ -365,7 +384,7 @@ IBus_GetDBusAddressFilename(void)
disp_num = SDL_strrchr(display, ':');
screen_num = SDL_strrchr(display, '.');
if (!disp_num) {
if (disp_num == NULL) {
SDL_free(display);
return NULL;
}
@ -393,7 +412,7 @@ IBus_GetDBusAddressFilename(void)
SDL_strlcpy(config_dir, conf_env, sizeof(config_dir));
} else {
const char *home_env = SDL_getenv("HOME");
if (!home_env || !*home_env) {
if (home_env == NULL || !*home_env) {
SDL_free(display);
return NULL;
}
@ -461,7 +480,7 @@ IBus_SetupConnection(SDL_DBusContext *dbus, const char* addr)
ibus_input_interface = IBUS_INPUT_INTERFACE;
ibus_conn = dbus->connection_open_private(addr, NULL);
if (!ibus_conn) {
if (ibus_conn == NULL) {
return SDL_FALSE; /* oh well. */
}
@ -499,7 +518,9 @@ IBus_SetupConnection(SDL_DBusContext *dbus, const char* addr)
static SDL_bool
IBus_CheckConnection(SDL_DBusContext *dbus)
{
if (!dbus) return SDL_FALSE;
if (dbus == NULL) {
return SDL_FALSE;
}
if (ibus_conn && dbus->connection_get_is_connected(ibus_conn)) {
return SDL_TRUE;
@ -517,7 +538,9 @@ IBus_CheckConnection(SDL_DBusContext *dbus)
struct inotify_event *event = (struct inotify_event*) p;
if (event->len > 0) {
char *addr_file_no_path = SDL_strrchr(ibus_addr_file, '/');
if (!addr_file_no_path) return SDL_FALSE;
if (addr_file_no_path == NULL) {
return SDL_FALSE;
}
if (SDL_strcmp(addr_file_no_path + 1, event->name) == 0) {
file_updated = SDL_TRUE;
@ -553,7 +576,7 @@ SDL_IBus_Init(void)
char *addr;
char *addr_file_dir;
if (!addr_file) {
if (addr_file == NULL) {
return SDL_FALSE;
}
@ -561,7 +584,7 @@ SDL_IBus_Init(void)
ibus_addr_file = SDL_strdup(addr_file);
addr = IBus_ReadAddressFromFile(addr_file);
if (!addr) {
if (addr == NULL) {
SDL_free(addr_file);
return SDL_FALSE;
}
@ -700,7 +723,7 @@ SDL_IBus_UpdateTextRect(const SDL_Rect *rect)
}
focused_win = SDL_GetKeyboardFocus();
if (!focused_win) {
if (focused_win == NULL) {
return;
}

View file

@ -49,16 +49,17 @@ InitIME()
const char *xmodifiers = SDL_getenv("XMODIFIERS");
#endif
if (inited == SDL_TRUE)
if (inited == SDL_TRUE) {
return;
}
inited = SDL_TRUE;
/* See if fcitx IME support is being requested */
#ifdef HAVE_FCITX
if (!SDL_IME_Init_Real &&
if (SDL_IME_Init_Real == NULL &&
((im_module && SDL_strcmp(im_module, "fcitx") == 0) ||
(!im_module && xmodifiers && SDL_strstr(xmodifiers, "@im=fcitx") != NULL))) {
(im_module == NULL && xmodifiers && SDL_strstr(xmodifiers, "@im=fcitx") != NULL))) {
SDL_IME_Init_Real = SDL_Fcitx_Init;
SDL_IME_Quit_Real = SDL_Fcitx_Quit;
SDL_IME_SetFocus_Real = SDL_Fcitx_SetFocus;
@ -71,7 +72,7 @@ InitIME()
/* default to IBus */
#ifdef HAVE_IBUS_IBUS_H
if (!SDL_IME_Init_Real) {
if (SDL_IME_Init_Real == NULL) {
SDL_IME_Init_Real = SDL_IBus_Init;
SDL_IME_Quit_Real = SDL_IBus_Quit;
SDL_IME_SetFocus_Real = SDL_IBus_SetFocus;
@ -109,29 +110,33 @@ SDL_IME_Init(void)
void
SDL_IME_Quit(void)
{
if (SDL_IME_Quit_Real)
if (SDL_IME_Quit_Real) {
SDL_IME_Quit_Real();
}
}
void
SDL_IME_SetFocus(SDL_bool focused)
{
if (SDL_IME_SetFocus_Real)
if (SDL_IME_SetFocus_Real) {
SDL_IME_SetFocus_Real(focused);
}
}
void
SDL_IME_Reset(void)
{
if (SDL_IME_Reset_Real)
if (SDL_IME_Reset_Real) {
SDL_IME_Reset_Real();
}
}
SDL_bool
SDL_IME_ProcessKeyEvent(Uint32 keysym, Uint32 keycode, Uint8 state)
{
if (SDL_IME_ProcessKeyEvent_Real)
if (SDL_IME_ProcessKeyEvent_Real) {
return SDL_IME_ProcessKeyEvent_Real(keysym, keycode, state);
}
return SDL_FALSE;
}
@ -139,15 +144,17 @@ SDL_IME_ProcessKeyEvent(Uint32 keysym, Uint32 keycode, Uint8 state)
void
SDL_IME_UpdateTextRect(const SDL_Rect *rect)
{
if (SDL_IME_UpdateTextRect_Real)
if (SDL_IME_UpdateTextRect_Real) {
SDL_IME_UpdateTextRect_Real(rect);
}
}
void
SDL_IME_PumpEvents()
{
if (SDL_IME_PumpEvents_Real)
if (SDL_IME_PumpEvents_Real) {
SDL_IME_PumpEvents_Real();
}
}
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -120,20 +120,20 @@ rtkit_initialize()
dbus_conn = get_rtkit_dbus_connection();
/* Try getting minimum nice level: this is often greater than PRIO_MIN (-20). */
if (!dbus_conn || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MinNiceLevel",
DBUS_TYPE_INT32, &rtkit_min_nice_level)) {
if (dbus_conn == NULL || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MinNiceLevel",
DBUS_TYPE_INT32, &rtkit_min_nice_level)) {
rtkit_min_nice_level = -20;
}
/* Try getting maximum realtime priority: this can be less than the POSIX default (99). */
if (!dbus_conn || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MaxRealtimePriority",
DBUS_TYPE_INT32, &rtkit_max_realtime_priority)) {
if (dbus_conn == NULL || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MaxRealtimePriority",
DBUS_TYPE_INT32, &rtkit_max_realtime_priority)) {
rtkit_max_realtime_priority = 99;
}
/* Try getting maximum rttime allowed by rtkit: exceeding this value will result in SIGKILL */
if (!dbus_conn || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "RTTimeUSecMax",
DBUS_TYPE_INT64, &rtkit_max_rttime_usec)) {
if (dbus_conn == NULL || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "RTTimeUSecMax",
DBUS_TYPE_INT64, &rtkit_max_rttime_usec)) {
rtkit_max_rttime_usec = 200000;
}
}
@ -172,8 +172,7 @@ rtkit_initialize_realtime_thread()
// Requirement #1: Set RLIMIT_RTTIME
err = getrlimit(nLimit, &rlimit);
if (err)
{
if (err) {
return SDL_FALSE;
}
@ -181,21 +180,18 @@ rtkit_initialize_realtime_thread()
rlimit.rlim_max = rtkit_max_rttime_usec;
rlimit.rlim_cur = rlimit.rlim_max / 2;
err = setrlimit(nLimit, &rlimit);
if (err)
{
if (err) {
return SDL_FALSE;
}
// Requirement #2: Add SCHED_RESET_ON_FORK to the scheduler policy
err = sched_getparam(nPid, &schedParam);
if (err)
{
if (err) {
return SDL_FALSE;
}
err = sched_setscheduler(nPid, nSchedPolicy, &schedParam);
if (err)
{
if (err) {
return SDL_FALSE;
}
@ -213,13 +209,14 @@ rtkit_setpriority_nice(pid_t thread, int nice_level)
pthread_once(&rtkit_initialize_once, rtkit_initialize);
dbus_conn = get_rtkit_dbus_connection();
if (nice < rtkit_min_nice_level)
if (nice < rtkit_min_nice_level) {
nice = rtkit_min_nice_level;
}
if (!dbus_conn || !SDL_DBus_CallMethodOnConnection(dbus_conn,
rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MakeThreadHighPriorityWithPID",
DBUS_TYPE_UINT64, &pid, DBUS_TYPE_UINT64, &tid, DBUS_TYPE_INT32, &nice, DBUS_TYPE_INVALID,
DBUS_TYPE_INVALID)) {
if (dbus_conn == NULL || !SDL_DBus_CallMethodOnConnection(dbus_conn,
rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MakeThreadHighPriorityWithPID",
DBUS_TYPE_UINT64, &pid, DBUS_TYPE_UINT64, &tid, DBUS_TYPE_INT32, &nice, DBUS_TYPE_INVALID,
DBUS_TYPE_INVALID)) {
return SDL_FALSE;
}
return SDL_TRUE;
@ -236,8 +233,9 @@ rtkit_setpriority_realtime(pid_t thread, int rt_priority)
pthread_once(&rtkit_initialize_once, rtkit_initialize);
dbus_conn = get_rtkit_dbus_connection();
if (priority > rtkit_max_realtime_priority)
if (priority > rtkit_max_realtime_priority) {
priority = rtkit_max_realtime_priority;
}
// We always perform the thread state changes necessary for rtkit.
// This wastes some system calls if the state is already set but
@ -247,10 +245,10 @@ rtkit_setpriority_realtime(pid_t thread, int rt_priority)
// go through to determine whether it really needs to fail or not.
rtkit_initialize_realtime_thread();
if (!dbus_conn || !SDL_DBus_CallMethodOnConnection(dbus_conn,
rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MakeThreadRealtimeWithPID",
DBUS_TYPE_UINT64, &pid, DBUS_TYPE_UINT64, &tid, DBUS_TYPE_UINT32, &priority, DBUS_TYPE_INVALID,
DBUS_TYPE_INVALID)) {
if (dbus_conn == NULL || !SDL_DBus_CallMethodOnConnection(dbus_conn,
rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MakeThreadRealtimeWithPID",
DBUS_TYPE_UINT64, &pid, DBUS_TYPE_UINT64, &tid, DBUS_TYPE_UINT32, &priority, DBUS_TYPE_INVALID,
DBUS_TYPE_INVALID)) {
return SDL_FALSE;
}
return SDL_TRUE;

View file

@ -119,7 +119,7 @@ SDL_UDEV_Init(void)
if (_this == NULL) {
_this = (SDL_UDEV_PrivateData *) SDL_calloc(1, sizeof(*_this));
if(_this == NULL) {
if (_this == NULL) {
return SDL_OutOfMemory();
}
@ -327,14 +327,13 @@ SDL_UDEV_LoadLibrary(void)
#endif
if (_this->udev_handle == NULL) {
for( i = 0 ; i < SDL_arraysize(SDL_UDEV_LIBS); i++) {
for ( i = 0 ; i < SDL_arraysize(SDL_UDEV_LIBS); i++) {
_this->udev_handle = SDL_LoadObject(SDL_UDEV_LIBS[i]);
if (_this->udev_handle != NULL) {
retval = SDL_UDEV_load_syms();
if (retval < 0) {
SDL_UDEV_UnloadLibrary();
}
else {
} else {
break;
}
}
@ -359,7 +358,7 @@ static void get_caps(struct udev_device *dev, struct udev_device *pdev, const ch
SDL_memset(bitmask, 0, bitmask_len*sizeof(*bitmask));
value = _this->syms.udev_device_get_sysattr_value(pdev, attr);
if (!value) {
if (value == NULL) {
return;
}
@ -394,7 +393,7 @@ guess_device_class(struct udev_device *dev)
while (pdev && !_this->syms.udev_device_get_sysattr_value(pdev, "capabilities/ev")) {
pdev = _this->syms.udev_device_get_parent_with_subsystem_devtype(pdev, "input", NULL);
}
if (!pdev) {
if (pdev == NULL) {
return 0;
}

View file

@ -233,14 +233,15 @@ static struct SDL_wscons_compose_tab_s {
static keysym_t ksym_upcase(keysym_t ksym)
{
if (ksym >= KS_f1 && ksym <= KS_f20)
return(KS_F1 - KS_f1 + ksym);
if (ksym >= KS_f1 && ksym <= KS_f20) {
return KS_F1 - KS_f1 + ksym;
}
if (KS_GROUP(ksym) == KS_GROUP_Ascii && ksym <= 0xff &&
latin1_to_upper[ksym] != 0x00)
return(latin1_to_upper[ksym]);
if (KS_GROUP(ksym) == KS_GROUP_Ascii && ksym <= 0xff && latin1_to_upper[ksym] != 0x00) {
return latin1_to_upper[ksym];
}
return(ksym);
return ksym;
}
static struct wscons_keycode_to_SDL {
keysym_t sourcekey;
@ -414,7 +415,7 @@ static SDL_WSCONS_input_data* SDL_WSCONS_Init_Keyboard(const char* dev)
#endif
SDL_WSCONS_input_data* input = (SDL_WSCONS_input_data*)SDL_calloc(1, sizeof(SDL_WSCONS_input_data));
if (!input) {
if (input == NULL) {
return input;
}
input->fd = open(dev,O_RDWR | O_NONBLOCK | O_CLOEXEC);
@ -491,10 +492,12 @@ static void put_utf8(SDL_WSCONS_input_data* input, uint c)
put_queue(input, 0xc0 | (c >> 6));
put_queue(input, 0x80 | (c & 0x3f));
} else if (c < 0x10000) {
if (c >= 0xD800 && c <= 0xF500)
if (c >= 0xD800 && c <= 0xF500) {
return;
if (c == 0xFFFF)
}
if (c == 0xFFFF) {
return;
}
/* 1110**** 10****** 10****** */
put_queue(input, 0xe0 | (c >> 12));
put_queue(input, 0x80 | ((c >> 6) & 0x3f));
@ -511,7 +514,9 @@ static void put_utf8(SDL_WSCONS_input_data* input, uint c)
static void Translate_to_text(SDL_WSCONS_input_data* input, keysym_t ksym)
{
if (KS_GROUP(ksym) == KS_GROUP_Keypad) {
if (SDL_isprint(ksym & 0xFF)) ksym &= 0xFF;
if (SDL_isprint(ksym & 0xFF)) {
ksym &= 0xFF;
}
}
switch(ksym) {
case KS_Escape:
@ -569,7 +574,9 @@ static void updateKeyboard(SDL_WSCONS_input_data* input)
keysym_t *group;
keysym_t ksym, result;
if (!input) return;
if (input == NULL) {
return;
}
if ((n = read(input->fd, events, sizeof(events))) > 0) {
n /= sizeof(struct wscons_event);
for (i = 0; i < n; i++) {
@ -578,21 +585,27 @@ static void updateKeyboard(SDL_WSCONS_input_data* input)
case WSCONS_EVENT_KEY_DOWN: {
switch (input->keymap.map[events[i].value].group1[0]) {
case KS_Hold_Screen: {
if (input->lockheldstate[0] >= 1) break;
if (input->lockheldstate[0] >= 1) {
break;
}
input->ledstate ^= LED_SCR;
ioctl(input->fd, WSKBDIO_SETLEDS, &input->ledstate);
input->lockheldstate[0] = 1;
break;
}
case KS_Num_Lock: {
if (input->lockheldstate[1] >= 1) break;
if (input->lockheldstate[1] >= 1) {
break;
}
input->ledstate ^= LED_NUM;
ioctl(input->fd, WSKBDIO_SETLEDS, &input->ledstate);
input->lockheldstate[1] = 1;
break;
}
case KS_Caps_Lock: {
if (input->lockheldstate[2] >= 1) break;
if (input->lockheldstate[2] >= 1) {
break;
}
input->ledstate ^= LED_CAP;
ioctl(input->fd, WSKBDIO_SETLEDS, &input->ledstate);
input->lockheldstate[2] = 1;
@ -600,7 +613,9 @@ static void updateKeyboard(SDL_WSCONS_input_data* input)
}
#ifndef __NetBSD__
case KS_Mode_Lock: {
if (input->lockheldstate[3] >= 1) break;
if (input->lockheldstate[3] >= 1) {
break;
}
input->ledstate ^= 1 << 4;
ioctl(input->fd, WSKBDIO_SETLEDS, &input->ledstate);
input->lockheldstate[3] = 1;
@ -608,50 +623,66 @@ static void updateKeyboard(SDL_WSCONS_input_data* input)
}
#endif
case KS_Shift_Lock: {
if (input->lockheldstate[4] >= 1) break;
if (input->lockheldstate[4] >= 1) {
break;
}
input->ledstate ^= 1 << 5;
ioctl(input->fd, WSKBDIO_SETLEDS, &input->ledstate);
input->lockheldstate[4] = 1;
break;
}
case KS_Shift_L: {
if (input->shiftheldstate[0]) break;
if (input->shiftheldstate[0]) {
break;
}
input->shiftstate[0]++;
input->shiftheldstate[0] = 1;
break;
}
case KS_Shift_R: {
if (input->shiftheldstate[1]) break;
if (input->shiftheldstate[1]) {
break;
}
input->shiftstate[0]++;
input->shiftheldstate[1] = 1;
break;
}
case KS_Alt_L: {
if (input->shiftheldstate[2]) break;
if (input->shiftheldstate[2]) {
break;
}
input->shiftstate[1]++;
input->shiftheldstate[2] = 1;
break;
}
case KS_Alt_R: {
if (input->shiftheldstate[3]) break;
if (input->shiftheldstate[3]) {
break;
}
input->shiftstate[1]++;
input->shiftheldstate[3] = 1;
break;
}
case KS_Control_L: {
if (input->shiftheldstate[4]) break;
if (input->shiftheldstate[4]) {
break;
}
input->shiftstate[2]++;
input->shiftheldstate[4] = 1;
break;
}
case KS_Control_R: {
if (input->shiftheldstate[5]) break;
if (input->shiftheldstate[5]) {
break;
}
input->shiftstate[2]++;
input->shiftheldstate[5] = 1;
break;
}
case KS_Mode_switch: {
if (input->shiftheldstate[6]) break;
if (input->shiftheldstate[6]) {
break;
}
input->shiftstate[3]++;
input->shiftheldstate[6] = 1;
break;
@ -662,60 +693,84 @@ static void updateKeyboard(SDL_WSCONS_input_data* input)
case WSCONS_EVENT_KEY_UP: {
switch(input->keymap.map[events[i].value].group1[0]) {
case KS_Hold_Screen: {
if (input->lockheldstate[0]) input->lockheldstate[0] = 0;
if (input->lockheldstate[0]) {
input->lockheldstate[0] = 0;
}
}
break;
case KS_Num_Lock: {
if (input->lockheldstate[1]) input->lockheldstate[1] = 0;
if (input->lockheldstate[1]) {
input->lockheldstate[1] = 0;
}
}
break;
case KS_Caps_Lock: {
if (input->lockheldstate[2]) input->lockheldstate[2] = 0;
if (input->lockheldstate[2]) {
input->lockheldstate[2] = 0;
}
}
break;
#ifndef __NetBSD__
case KS_Mode_Lock: {
if (input->lockheldstate[3]) input->lockheldstate[3] = 0;
if (input->lockheldstate[3]) {
input->lockheldstate[3] = 0;
}
}
break;
#endif
case KS_Shift_Lock: {
if (input->lockheldstate[4]) input->lockheldstate[4] = 0;
if (input->lockheldstate[4]) {
input->lockheldstate[4] = 0;
}
}
break;
case KS_Shift_L: {
input->shiftheldstate[0] = 0;
if (input->shiftstate[0]) input->shiftstate[0]--;
if (input->shiftstate[0]) {
input->shiftstate[0]--;
}
break;
}
case KS_Shift_R: {
input->shiftheldstate[1] = 0;
if (input->shiftstate[0]) input->shiftstate[0]--;
if (input->shiftstate[0]) {
input->shiftstate[0]--;
}
break;
}
case KS_Alt_L: {
input->shiftheldstate[2] = 0;
if (input->shiftstate[1]) input->shiftstate[1]--;
if (input->shiftstate[1]) {
input->shiftstate[1]--;
}
break;
}
case KS_Alt_R: {
input->shiftheldstate[3] = 0;
if (input->shiftstate[1]) input->shiftstate[1]--;
if (input->shiftstate[1]) {
input->shiftstate[1]--;
}
break;
}
case KS_Control_L: {
input->shiftheldstate[4] = 0;
if (input->shiftstate[2]) input->shiftstate[2]--;
if (input->shiftstate[2]) {
input->shiftstate[2]--;
}
break;
}
case KS_Control_R: {
input->shiftheldstate[5] = 0;
if (input->shiftstate[2]) input->shiftstate[2]--;
if (input->shiftstate[2]) {
input->shiftstate[2]--;
}
break;
}
case KS_Mode_switch: {
input->shiftheldstate[6] = 0;
if (input->shiftstate[3]) input->shiftstate[3]--;
if (input->shiftstate[3]) {
input->shiftstate[3]--;
}
break;
}
}
@ -733,7 +788,9 @@ static void updateKeyboard(SDL_WSCONS_input_data* input)
else
Translate_to_keycode(input, type, events[i].value);
if (type == WSCONS_EVENT_KEY_UP) continue;
if (type == WSCONS_EVENT_KEY_UP) {
continue;
}
if (IS_ALTGR_MODE && !IS_CONTROL_HELD)
group = &input->keymap.map[events[i].value].group2[0];
@ -778,7 +835,9 @@ static void updateKeyboard(SDL_WSCONS_input_data* input)
} else result = ksym;
break;
}
if (result == KS_voidSymbol) continue;
if (result == KS_voidSymbol) {
continue;
}
if (input->composelen > 0) {
if (input->composelen == 2 && group == &input->keymap.map[events[i].value].group2[0]) {
@ -809,21 +868,24 @@ static void updateKeyboard(SDL_WSCONS_input_data* input)
if (KS_GROUP(result) == KS_GROUP_Ascii) {
if (IS_CONTROL_HELD) {
if ((result >= KS_at && result <= KS_z) || result == KS_space)
if ((result >= KS_at && result <= KS_z) || result == KS_space) {
result = result & 0x1f;
else if (result == KS_2)
} else if (result == KS_2) {
result = 0x00;
else if (result >= KS_3 && result <= KS_7)
} else if (result >= KS_3 && result <= KS_7) {
result = KS_Escape + (result - KS_3);
else if (result == KS_8)
result = KS_Delete;
} else if (result == KS_8) {
result = KS_Delete;
}
}
if (IS_ALT_HELD) {
if (input->encoding & KB_METAESC) {
Translate_to_keycode(input, WSCONS_EVENT_KEY_DOWN, KS_Escape);
Translate_to_text(input, result);
continue;
} else result |= 0x80;
} else {
result |= 0x80;
}
}
}
Translate_to_text(input,result);
@ -835,7 +897,10 @@ static void updateKeyboard(SDL_WSCONS_input_data* input)
void SDL_WSCONS_PumpEvents()
{
int i = 0;
for (i = 0; i < 4; i++)
for (i = 0; i < 4; i++) {
updateKeyboard(inputs[i]);
if (mouseInputData != NULL) updateMouse(mouseInputData);
}
if (mouseInputData != NULL) {
updateMouse(mouseInputData);
}
}

View file

@ -42,7 +42,9 @@ SDL_WSCONS_mouse_input_data* SDL_WSCONS_Init_Mouse()
#endif
SDL_WSCONS_mouse_input_data* mouseInputData = SDL_calloc(1, sizeof(SDL_WSCONS_mouse_input_data));
if (!mouseInputData) return NULL;
if (mouseInputData == NULL) {
return NULL;
}
mouseInputData->fd = open("/dev/wsmouse",O_RDWR | O_NONBLOCK | O_CLOEXEC);
if (mouseInputData->fd == -1) {free(mouseInputData); return NULL; }
#ifdef WSMOUSEIO_SETMODE
@ -61,11 +63,9 @@ void updateMouse(SDL_WSCONS_mouse_input_data* inputData)
int n,i;
SDL_Mouse* mouse = SDL_GetMouse();
if ((n = read(inputData->fd, events, sizeof(events))) > 0)
{
if ((n = read(inputData->fd, events, sizeof(events))) > 0) {
n /= sizeof(struct wscons_event);
for (i = 0; i < n; i++)
{
for (i = 0; i < n; i++) {
type = events[i].type;
switch(type)
{
@ -128,7 +128,9 @@ void updateMouse(SDL_WSCONS_mouse_input_data* inputData)
void SDL_WSCONS_Quit_Mouse(SDL_WSCONS_mouse_input_data* inputData)
{
if (!inputData) return;
if (inputData == NULL) {
return;
}
close(inputData->fd);
free(inputData);
}

View file

@ -61,9 +61,9 @@ WIN_LoadHIDDLL(void)
SDL_HidP_GetValueCaps = (HidP_GetValueCaps_t)GetProcAddress(s_pHIDDLL, "HidP_GetValueCaps");
SDL_HidP_MaxDataListLength = (HidP_MaxDataListLength_t)GetProcAddress(s_pHIDDLL, "HidP_MaxDataListLength");
SDL_HidP_GetData = (HidP_GetData_t)GetProcAddress(s_pHIDDLL, "HidP_GetData");
if (!SDL_HidD_GetManufacturerString || !SDL_HidD_GetProductString ||
!SDL_HidP_GetCaps || !SDL_HidP_GetButtonCaps ||
!SDL_HidP_GetValueCaps || !SDL_HidP_MaxDataListLength || !SDL_HidP_GetData) {
if (SDL_HidD_GetManufacturerString == NULL || SDL_HidD_GetProductString == NULL ||
SDL_HidP_GetCaps == NULL || SDL_HidP_GetButtonCaps == NULL ||
SDL_HidP_GetValueCaps == NULL || SDL_HidP_MaxDataListLength == NULL || SDL_HidP_GetData == NULL) {
WIN_UnloadHIDDLL();
return -1;
}

View file

@ -136,7 +136,7 @@ SDL_IMMDevice_Add(const SDL_bool iscapture, const char *devname, WAVEFORMATEXTEN
}
devidlist = (DevIdList *)SDL_malloc(sizeof(*devidlist));
if (!devidlist) {
if (devidlist == NULL) {
return; /* oh well. */
}
@ -442,7 +442,7 @@ EnumerateEndpointsForFlow(const SDL_bool iscapture)
}
items = (EndpointItem *)SDL_calloc(total, sizeof(EndpointItem));
if (!items) {
if (items == NULL) {
return; /* oh well. */
}

View file

@ -291,7 +291,7 @@ WIN_LookupAudioDeviceName(const WCHAR *name, const GUID *guid)
}
strw = (WCHAR *) SDL_malloc(len + sizeof (WCHAR));
if (!strw) {
if (strw == NULL) {
RegCloseKey(hkey);
return WIN_StringToUTF8(name); /* oh well. */
}
@ -314,13 +314,13 @@ WIN_LookupAudioDeviceName(const WCHAR *name, const GUID *guid)
BOOL
WIN_IsEqualGUID(const GUID * a, const GUID * b)
{
return (SDL_memcmp(a, b, sizeof (*a)) == 0);
return SDL_memcmp(a, b, sizeof(*a)) == 0;
}
BOOL
WIN_IsEqualIID(REFIID a, REFIID b)
{
return (SDL_memcmp(a, b, sizeof (*a)) == 0);
return SDL_memcmp(a, b, sizeof(*a)) == 0;
}
void

View file

@ -110,13 +110,13 @@ WIN_LoadXInputDLL(void)
/* 100 is the ordinal for _XInputGetStateEx, which returns the same struct as XinputGetState, but with extra data in wButtons for the guide button, we think... */
SDL_XInputGetState = (XInputGetState_t)GetProcAddress((HMODULE)s_pXInputDLL, (LPCSTR)100);
if (!SDL_XInputGetState) {
if (SDL_XInputGetState == NULL) {
SDL_XInputGetState = (XInputGetState_t)GetProcAddress((HMODULE)s_pXInputDLL, "XInputGetState");
}
SDL_XInputSetState = (XInputSetState_t)GetProcAddress((HMODULE)s_pXInputDLL, "XInputSetState");
SDL_XInputGetCapabilities = (XInputGetCapabilities_t)GetProcAddress((HMODULE)s_pXInputDLL, "XInputGetCapabilities");
SDL_XInputGetBatteryInformation = (XInputGetBatteryInformation_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputGetBatteryInformation" );
if (!SDL_XInputGetState || !SDL_XInputSetState || !SDL_XInputGetCapabilities) {
if (SDL_XInputGetState == NULL || SDL_XInputSetState == NULL || SDL_XInputGetCapabilities == NULL) {
WIN_UnloadXInputDLL();
return -1;
}

View file

@ -49,16 +49,11 @@ SDL_WinRTGetDeviceFamily()
#if NTDDI_VERSION >= NTDDI_WIN10 /* !!! FIXME: I have no idea if this is the right test. This is a UWP API, I think. Older windows should...just return "mobile"? I don't know. --ryan. */
Platform::String^ deviceFamily = Windows::System::Profile::AnalyticsInfo::VersionInfo->DeviceFamily;
if (deviceFamily->Equals("Windows.Desktop"))
{
if (deviceFamily->Equals("Windows.Desktop")) {
return SDL_WINRT_DEVICEFAMILY_DESKTOP;
}
else if (deviceFamily->Equals("Windows.Mobile"))
{
} else if (deviceFamily->Equals("Windows.Mobile")) {
return SDL_WINRT_DEVICEFAMILY_MOBILE;
}
else if (deviceFamily->Equals("Windows.Xbox"))
{
} else if (deviceFamily->Equals("Windows.Xbox")) {
return SDL_WINRT_DEVICEFAMILY_XBOX;
}
#endif

View file

@ -104,8 +104,7 @@ IFrameworkView^ SDLApplicationSource::CreateView()
// SDL_WinRTGlobalApp more than once.
SDL_assert(!SDL_WinRTGlobalApp);
SDL_WinRTApp ^ app = ref new SDL_WinRTApp();
if (!SDL_WinRTGlobalApp)
{
if (!SDL_WinRTGlobalApp) {
SDL_WinRTGlobalApp = app;
}
return app;
@ -353,13 +352,12 @@ void SDL_WinRTApp::Load(Platform::String^ entryPoint)
void SDL_WinRTApp::Run()
{
SDL_SetMainReady();
if (WINRT_SDLAppEntryPoint)
{
if (WINRT_SDLAppEntryPoint) {
// TODO, WinRT: pass the C-style main() a reasonably realistic
// representation of command line arguments.
int argc = 1;
char **argv = (char **)SDL_malloc(2 * sizeof(*argv));
if (!argv) {
if (argv == NULL) {
return;
}
argv[0] = SDL_strdup("WinRTApp");

View file

@ -336,8 +336,9 @@ CPU_haveAltiVec(void)
int hasVectorUnit = 0;
size_t length = sizeof(hasVectorUnit);
int error = sysctl(selectors, 2, &hasVectorUnit, &length, NULL, 0);
if (0 == error)
if (0 == error) {
altivec = (hasVectorUnit != 0);
}
#elif defined(__FreeBSD__) && defined(__powerpc__)
unsigned long cpufeatures = 0;
elf_aux_info(AT_HWCAP, &cpufeatures, sizeof(cpufeatures));
@ -378,13 +379,10 @@ CPU_haveARMSIMD(void)
int fd;
fd = open("/proc/self/auxv", O_RDONLY | O_CLOEXEC);
if (fd >= 0)
{
if (fd >= 0) {
Elf32_auxv_t aux;
while (read(fd, &aux, sizeof aux) == sizeof aux)
{
if (aux.a_type == AT_PLATFORM)
{
while (read(fd, &aux, sizeof aux) == sizeof aux) {
if (aux.a_type == AT_PLATFORM) {
const char *plat = (const char *) aux.a_un.a_val;
if (plat) {
arm_simd = SDL_strncmp(plat, "v6l", 3) == 0 ||
@ -403,16 +401,19 @@ CPU_haveARMSIMD(void)
{
_kernel_swi_regs regs;
regs.r[0] = 0;
if (_kernel_swi(OS_PlatformFeatures, &regs, &regs) != NULL)
if (_kernel_swi(OS_PlatformFeatures, &regs, &regs) != NULL) {
return 0;
}
if (!(regs.r[0] & (1<<31)))
if (!(regs.r[0] & (1 << 31))) {
return 0;
}
regs.r[0] = 34;
regs.r[1] = 29;
if (_kernel_swi(OS_PlatformFeatures, &regs, &regs) != NULL)
if (_kernel_swi(OS_PlatformFeatures, &regs, &regs) != NULL) {
return 0;
}
return regs.r[0];
}
@ -434,8 +435,7 @@ readProcAuxvForNeon(void)
int fd;
fd = open("/proc/self/auxv", O_RDONLY | O_CLOEXEC);
if (fd >= 0)
{
if (fd >= 0) {
Elf32_auxv_t aux;
while (read(fd, &aux, sizeof (aux)) == sizeof (aux)) {
if (aux.a_type == AT_HWCAP) {
@ -481,13 +481,14 @@ CPU_haveNEON(void)
return 1; /* OpenBSD only supports ARMv7 CPUs that have NEON. */
#elif defined(HAVE_ELF_AUX_INFO)
unsigned long hasneon = 0;
if (elf_aux_info(AT_HWCAP, (void *)&hasneon, (int)sizeof(hasneon)) != 0)
if (elf_aux_info(AT_HWCAP, (void *)&hasneon, (int)sizeof(hasneon)) != 0) {
return 0;
}
return ((hasneon & HWCAP_NEON) == HWCAP_NEON);
#elif defined(__QNXNTO__)
return SYSPAGE_ENTRY(cpuinfo)->flags & ARM_CPU_FLAG_NEON;
#elif (defined(__LINUX__) || defined(__ANDROID__)) && defined(HAVE_GETAUXVAL)
return ((getauxval(AT_HWCAP) & HWCAP_NEON) == HWCAP_NEON);
return (getauxval(AT_HWCAP) & HWCAP_NEON) == HWCAP_NEON;
#elif defined(__LINUX__)
return readProcAuxvForNeon();
#elif defined(__ANDROID__)
@ -556,7 +557,7 @@ CPU_have3DNow(void)
cpuid(0x80000000, a, b, c, d);
if (a >= 0x80000001) {
cpuid(0x80000001, a, b, c, d);
return (d & 0x80000000);
return d & 0x80000000;
}
}
return 0;
@ -629,7 +630,7 @@ CPU_haveAVX2(void)
int a, b, c, d;
(void) a; (void) b; (void) c; (void) d; /* compiler warnings... */
cpuid(7, a, b, c, d);
return (b & 0x00000020);
return b & 0x00000020;
}
return 0;
}
@ -649,7 +650,7 @@ CPU_haveAVX512F(void)
int a, b, c, d;
(void) a; (void) b; (void) c; (void) d; /* compiler warnings... */
cpuid(7, a, b, c, d);
return (b & 0x00010000);
return b & 0x00010000;
}
return 0;
}
@ -839,10 +840,10 @@ SDL_GetCPUCacheLineSize(void)
(void) a; (void) b; (void) c; (void) d;
if (SDL_strcmp(cpuType, "GenuineIntel") == 0 || SDL_strcmp(cpuType, "CentaurHauls") == 0 || SDL_strcmp(cpuType, " Shanghai ") == 0) {
cpuid(0x00000001, a, b, c, d);
return (((b >> 8) & 0xff) * 8);
return ((b >> 8) & 0xff) * 8;
} else if (SDL_strcmp(cpuType, "AuthenticAMD") == 0 || SDL_strcmp(cpuType, "HygonGenuine") == 0) {
cpuid(0x80000005, a, b, c, d);
return (c & 0xff);
return c & 0xff;
} else {
/* Just make a guess here... */
return SDL_CACHELINE_SIZE;

View file

@ -40,7 +40,7 @@ SDL_SendClipboardUpdate(void)
posted = (SDL_PushEvent(&event) > 0);
}
return (posted);
return posted;
}
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -31,7 +31,7 @@ SDL_SendDisplayEvent(SDL_VideoDisplay *display, Uint8 displayevent, int data1)
{
int posted;
if (!display) {
if (display == NULL) {
return 0;
}
switch (displayevent) {
@ -54,7 +54,7 @@ SDL_SendDisplayEvent(SDL_VideoDisplay *display, Uint8 displayevent, int data1)
posted = (SDL_PushEvent(&event) > 0);
}
return (posted);
return posted;
}
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -556,7 +556,7 @@ SDL_StartEventLoop(void)
}
SDL_LockMutex(SDL_EventQ.lock);
if (!SDL_event_watchers_lock) {
if (SDL_event_watchers_lock == NULL) {
SDL_event_watchers_lock = SDL_CreateMutex();
if (SDL_event_watchers_lock == NULL) {
SDL_UnlockMutex(SDL_EventQ.lock);
@ -597,7 +597,7 @@ SDL_AddEvent(SDL_Event * event)
if (SDL_EventQ.free == NULL) {
entry = (SDL_EventEntry *)SDL_malloc(sizeof(*entry));
if (!entry) {
if (entry == NULL) {
return 0;
}
} else {
@ -672,7 +672,7 @@ static int
SDL_SendWakeupEvent()
{
SDL_VideoDevice *_this = SDL_GetVideoDevice();
if (!_this || !_this->SendWakeupEvent) {
if (_this == NULL || !_this->SendWakeupEvent) {
return 0;
}
if (!_this->wakeup_lock || SDL_LockMutex(_this->wakeup_lock) == 0) {
@ -708,7 +708,7 @@ SDL_PeepEventsInternal(SDL_Event * events, int numevents, SDL_eventaction action
if (action == SDL_GETEVENT) {
SDL_SetError("The event system has been shut down");
}
return (-1);
return -1;
}
if (action == SDL_ADDEVENT) {
for (i = 0; i < numevents; ++i) {
@ -731,7 +731,7 @@ SDL_PeepEventsInternal(SDL_Event * events, int numevents, SDL_eventaction action
SDL_EventQ.wmmsg_used = NULL;
}
for (entry = SDL_EventQ.head; entry && (!events || used < numevents); entry = next) {
for (entry = SDL_EventQ.head; entry && (events == NULL || used < numevents); entry = next) {
next = entry->next;
type = entry->event.type;
if (minType <= type && type <= maxType) {
@ -764,7 +764,7 @@ SDL_PeepEventsInternal(SDL_Event * events, int numevents, SDL_eventaction action
/* Skip it, we don't want to include it */
continue;
}
if (!events || action != SDL_GETEVENT) {
if (events == NULL || action != SDL_GETEVENT) {
++sentinels_expected;
}
if (SDL_AtomicGet(&SDL_sentinel_pending) > sentinels_expected) {
@ -787,7 +787,7 @@ SDL_PeepEventsInternal(SDL_Event * events, int numevents, SDL_eventaction action
SDL_SendWakeupEvent();
}
return (used);
return used;
}
int
SDL_PeepEvents(SDL_Event * events, int numevents, SDL_eventaction action,
@ -799,13 +799,13 @@ SDL_PeepEvents(SDL_Event * events, int numevents, SDL_eventaction action,
SDL_bool
SDL_HasEvent(Uint32 type)
{
return (SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, type, type) > 0);
return SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, type, type) > 0;
}
SDL_bool
SDL_HasEvents(Uint32 minType, Uint32 maxType)
{
return (SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, minType, maxType) > 0);
return SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, minType, maxType) > 0;
}
void
@ -1128,7 +1128,7 @@ SDL_PushEvent(SDL_Event * event)
event->common.timestamp = SDL_GetTicks();
if (SDL_EventOK.callback || SDL_event_watchers_count > 0) {
if (!SDL_event_watchers_lock || SDL_LockMutex(SDL_event_watchers_lock) == 0) {
if (SDL_event_watchers_lock == NULL || SDL_LockMutex(SDL_event_watchers_lock) == 0) {
if (SDL_EventOK.callback && !SDL_EventOK.callback(SDL_EventOK.userdata, event)) {
if (SDL_event_watchers_lock) {
SDL_UnlockMutex(SDL_event_watchers_lock);
@ -1179,7 +1179,7 @@ SDL_PushEvent(SDL_Event * event)
void
SDL_SetEventFilter(SDL_EventFilter filter, void *userdata)
{
if (!SDL_event_watchers_lock || SDL_LockMutex(SDL_event_watchers_lock) == 0) {
if (SDL_event_watchers_lock == NULL || SDL_LockMutex(SDL_event_watchers_lock) == 0) {
/* Set filter and discard pending events */
SDL_EventOK.callback = filter;
SDL_EventOK.userdata = userdata;
@ -1196,7 +1196,7 @@ SDL_GetEventFilter(SDL_EventFilter * filter, void **userdata)
{
SDL_EventWatcher event_ok;
if (!SDL_event_watchers_lock || SDL_LockMutex(SDL_event_watchers_lock) == 0) {
if (SDL_event_watchers_lock == NULL || SDL_LockMutex(SDL_event_watchers_lock) == 0) {
event_ok = SDL_EventOK;
if (SDL_event_watchers_lock) {
@ -1218,7 +1218,7 @@ SDL_GetEventFilter(SDL_EventFilter * filter, void **userdata)
void
SDL_AddEventWatch(SDL_EventFilter filter, void *userdata)
{
if (!SDL_event_watchers_lock || SDL_LockMutex(SDL_event_watchers_lock) == 0) {
if (SDL_event_watchers_lock == NULL || SDL_LockMutex(SDL_event_watchers_lock) == 0) {
SDL_EventWatcher *event_watchers;
event_watchers = SDL_realloc(SDL_event_watchers, (SDL_event_watchers_count + 1) * sizeof(*event_watchers));
@ -1242,7 +1242,7 @@ SDL_AddEventWatch(SDL_EventFilter filter, void *userdata)
void
SDL_DelEventWatch(SDL_EventFilter filter, void *userdata)
{
if (!SDL_event_watchers_lock || SDL_LockMutex(SDL_event_watchers_lock) == 0) {
if (SDL_event_watchers_lock == NULL || SDL_LockMutex(SDL_event_watchers_lock) == 0) {
int i;
for (i = 0; i < SDL_event_watchers_count; ++i) {
@ -1355,7 +1355,7 @@ SDL_SendAppEvent(SDL_EventType eventType)
event.type = eventType;
posted = (SDL_PushEvent(&event) > 0);
}
return (posted);
return posted;
}
int
@ -1372,7 +1372,7 @@ SDL_SendSysWMEvent(SDL_SysWMmsg * message)
posted = (SDL_PushEvent(&event) > 0);
}
/* Update internal event state */
return (posted);
return posted;
}
int

View file

@ -92,15 +92,18 @@ static void PrintPath(SDL_FloatPoint *path)
int SDL_RecordGesture(SDL_TouchID touchId)
{
int i;
if (touchId < 0) recordAll = SDL_TRUE;
if (touchId < 0) {
recordAll = SDL_TRUE;
}
for (i = 0; i < SDL_numGestureTouches; i++) {
if ((touchId < 0) || (SDL_gestureTouch[i].id == touchId)) {
SDL_gestureTouch[i].recording = SDL_TRUE;
if (touchId >= 0)
if (touchId >= 0) {
return 1;
}
}
}
return (touchId < 0);
return touchId < 0;
}
void SDL_GestureQuit()
@ -195,7 +198,7 @@ static int SDL_AddDollarGesture_one(SDL_GestureTouch* inTouch, SDL_FloatPoint* p
(SDL_DollarTemplate *)SDL_realloc(inTouch->dollarTemplate,
(index + 1) *
sizeof(SDL_DollarTemplate));
if (!dollarTemplate) {
if (dollarTemplate == NULL) {
return SDL_OutOfMemory();
}
inTouch->dollarTemplate = dollarTemplate;
@ -213,12 +216,15 @@ static int SDL_AddDollarGesture(SDL_GestureTouch* inTouch, SDL_FloatPoint* path)
int index = -1;
int i = 0;
if (inTouch == NULL) {
if (SDL_numGestureTouches == 0) return SDL_SetError("no gesture touch devices registered");
if (SDL_numGestureTouches == 0) {
return SDL_SetError("no gesture touch devices registered");
}
for (i = 0; i < SDL_numGestureTouches; i++) {
inTouch = &SDL_gestureTouch[i];
index = SDL_AddDollarGesture_one(inTouch, path);
if (index < 0)
if (index < 0) {
return -1;
}
}
/* Use the index of the last one added. */
return index;
@ -230,7 +236,9 @@ int SDL_LoadDollarTemplates(SDL_TouchID touchId, SDL_RWops *src)
{
int i,loaded = 0;
SDL_GestureTouch *touch = NULL;
if (src == NULL) return 0;
if (src == NULL) {
return 0;
}
if (touchId >= 0) {
for (i = 0; i < SDL_numGestureTouches; i++) {
if (SDL_gestureTouch[i].id == touchId) {
@ -262,10 +270,10 @@ int SDL_LoadDollarTemplates(SDL_TouchID touchId, SDL_RWops *src)
if (touchId >= 0) {
/* printf("Adding loaded gesture to 1 touch\n"); */
if (SDL_AddDollarGesture(touch, templ.path) >= 0)
if (SDL_AddDollarGesture(touch, templ.path) >= 0) {
loaded++;
}
else {
}
} else {
/* printf("Adding to: %i touches\n",SDL_numGestureTouches); */
for (i = 0; i < SDL_numGestureTouches; i++) {
touch = &SDL_gestureTouch[i];
@ -294,7 +302,7 @@ static float dollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ,float
dist += (float)(SDL_sqrt((p.x-templ[i].x)*(p.x-templ[i].x)+
(p.y-templ[i].y)*(p.y-templ[i].y)));
}
return dist/DOLLARNPOINTS;
return dist / DOLLARNPOINTS;
}
@ -318,8 +326,7 @@ static float bestDollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ)
f2 = f1;
x1 = (float)(PHI*ta + (1-PHI)*tb);
f1 = dollarDifference(points,templ,x1);
}
else {
} else {
ta = x1;
x1 = x2;
f1 = f2;
@ -333,7 +340,7 @@ static float bestDollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ)
else if (f1 > f2)
printf("Min angle (x2): %f\n",x2);
*/
return SDL_min(f1,f2);
return SDL_min(f1, f2);
}
/* DollarPath contains raw points, plus (possibly) the calculated length */
@ -414,10 +421,18 @@ static int dollarNormalize(const SDL_DollarPath *path,SDL_FloatPoint *points, SD
(py - centroid.y)*SDL_cos(ang) + centroid.y);
if (points[i].x < xmin) xmin = points[i].x;
if (points[i].x > xmax) xmax = points[i].x;
if (points[i].y < ymin) ymin = points[i].y;
if (points[i].y > ymax) ymax = points[i].y;
if (points[i].x < xmin) {
xmin = points[i].x;
}
if (points[i].x > xmax) {
xmax = points[i].x;
}
if (points[i].y < ymin) {
ymin = points[i].y;
}
if (points[i].y > ymax) {
ymax = points[i].y;
}
}
/* Scale points to DOLLARSIZE, and translate to the origin */
@ -457,7 +472,7 @@ int SDL_GestureAddTouch(SDL_TouchID touchId)
(SDL_numGestureTouches + 1) *
sizeof(SDL_GestureTouch));
if (!gestureTouch) {
if (gestureTouch == NULL) {
return SDL_OutOfMemory();
}
@ -498,8 +513,9 @@ static SDL_GestureTouch * SDL_GetGestureTouch(SDL_TouchID id)
int i;
for (i = 0; i < SDL_numGestureTouches; i++) {
/* printf("%i ?= %i\n",SDL_gestureTouch[i].id,id); */
if (SDL_gestureTouch[i].id == id)
if (SDL_gestureTouch[i].id == id) {
return &SDL_gestureTouch[i];
}
}
return NULL;
}
@ -571,7 +587,9 @@ void SDL_GestureProcessEvent(SDL_Event* event)
SDL_GestureTouch* inTouch = SDL_GetGestureTouch(event->tfinger.touchId);
/* Shouldn't be possible */
if (inTouch == NULL) return;
if (inTouch == NULL) {
return;
}
x = event->tfinger.x;
y = event->tfinger.y;
@ -591,26 +609,24 @@ void SDL_GestureProcessEvent(SDL_Event* event)
/* PrintPath(path); */
if (recordAll) {
index = SDL_AddDollarGesture(NULL,path);
for (i = 0; i < SDL_numGestureTouches; i++)
for (i = 0; i < SDL_numGestureTouches; i++) {
SDL_gestureTouch[i].recording = SDL_FALSE;
}
else {
}
} else {
index = SDL_AddDollarGesture(inTouch,path);
}
if (index >= 0) {
SDL_SendDollarRecord(inTouch,inTouch->dollarTemplate[index].hash);
}
else {
} else {
SDL_SendDollarRecord(inTouch,-1);
}
}
else {
} else {
int bestTempl;
float error;
error = dollarRecognize(&inTouch->dollarPath,
&bestTempl,inTouch);
if (bestTempl >= 0){
if (bestTempl >= 0) {
/* Send Event */
unsigned long gestureId = inTouch->dollarTemplate[bestTempl].hash;
SDL_SendGestureDollar(inTouch,gestureId,error);
@ -625,8 +641,7 @@ void SDL_GestureProcessEvent(SDL_Event* event)
inTouch->centroid.y = (inTouch->centroid.y*(inTouch->numDownFingers+1)-
y)/inTouch->numDownFingers;
}
}
else if (event->type == SDL_FINGERMOTION) {
} else if (event->type == SDL_FINGERMOTION) {
float dx = event->tfinger.dx;
float dy = event->tfinger.dy;
#if defined(ENABLE_DOLLAR)
@ -671,7 +686,12 @@ void SDL_GestureProcessEvent(SDL_Event* event)
dtheta = (float)SDL_atan2(lv.x*v.y - lv.y*v.x,lv.x*v.x + lv.y*v.y);
dDist = (Dist - lDist);
if (lDist == 0) {dDist = 0;dtheta = 0;} /* To avoid impossible values */
if (lDist == 0) {
/* To avoid impossible values */
dDist = 0;
dtheta = 0;
}
/* inTouch->gestureLast[j].dDist = dDist;
inTouch->gestureLast[j].dtheta = dtheta;
@ -684,8 +704,7 @@ void SDL_GestureProcessEvent(SDL_Event* event)
printf("thetaSum = %f, distSum = %f\n",gdtheta,gdDist);
printf("id: %i dTheta = %f, dDist = %f\n",j,dtheta,dDist); */
SDL_SendGestureMulti(inTouch,dtheta,dDist);
}
else {
} else {
/* inTouch->gestureLast[j].dDist = 0;
inTouch->gestureLast[j].dtheta = 0;
inTouch->gestureLast[j].cv.x = 0;
@ -695,8 +714,7 @@ void SDL_GestureProcessEvent(SDL_Event* event)
inTouch->gestureLast[j].f.p.y = y;
break;
pressure? */
}
else if (event->type == SDL_FINGERDOWN) {
} else if (event->type == SDL_FINGERDOWN) {
inTouch->numDownFingers++;
inTouch->centroid.x = (inTouch->centroid.x*(inTouch->numDownFingers - 1)+

View file

@ -754,7 +754,7 @@ SDL_SetKeyboardFocus(SDL_Window * window)
{
SDL_Keyboard *keyboard = &SDL_keyboard;
if (keyboard->focus && !window) {
if (keyboard->focus && window == NULL) {
/* We won't get anymore keyboard messages, so reset keyboard state */
SDL_ResetKeyboard();
}
@ -763,7 +763,7 @@ SDL_SetKeyboardFocus(SDL_Window * window)
if (keyboard->focus && keyboard->focus != window) {
/* new window shouldn't think it has mouse captured. */
SDL_assert(!window || !(window->flags & SDL_WINDOW_MOUSE_CAPTURE));
SDL_assert(window == NULL || !(window->flags & SDL_WINDOW_MOUSE_CAPTURE));
/* old window must lose an existing mouse capture. */
if (keyboard->focus->flags & SDL_WINDOW_MOUSE_CAPTURE) {
@ -939,7 +939,7 @@ SDL_SendKeyboardKeyInternal(Uint8 source, Uint8 state, SDL_Scancode scancode, SD
SDL_MinimizeWindow(keyboard->focus);
}
return (posted);
return posted;
}
int
@ -1045,7 +1045,7 @@ SDL_SendKeyboardText(const char *text)
posted |= (SDL_PushEvent(&event) > 0);
}
}
return (posted);
return posted;
}
int
@ -1076,7 +1076,7 @@ SDL_SendEditingText(const char *text, int start, int length)
posted = (SDL_PushEvent(&event) > 0);
}
return (posted);
return posted;
}
void
@ -1100,7 +1100,7 @@ SDL_GetModState(void)
{
SDL_Keyboard *keyboard = &SDL_keyboard;
return (SDL_Keymod) keyboard->modstate;
return (SDL_Keymod)keyboard->modstate;
}
void
@ -1183,7 +1183,7 @@ SDL_Scancode SDL_GetScancodeFromName(const char *name)
{
int i;
if (!name || !*name) {
if (name == NULL || !*name) {
SDL_InvalidParamError("name");
return SDL_SCANCODE_UNKNOWN;
}
@ -1208,8 +1208,7 @@ SDL_GetKeyName(SDL_Keycode key)
char *end;
if (key & SDLK_SCANCODE_MASK) {
return
SDL_GetScancodeName((SDL_Scancode) (key & ~SDLK_SCANCODE_MASK));
return SDL_GetScancodeName((SDL_Scancode)(key & ~SDLK_SCANCODE_MASK));
}
switch (key) {

View file

@ -225,7 +225,7 @@ SDL_MouseInit(void)
mouse->cursor_shown = SDL_TRUE;
return (0);
return 0;
}
void
@ -462,7 +462,7 @@ SDL_SetMouseSystemScale(int num_values, const float *values)
}
v = (float *)SDL_realloc(mouse->system_scale_values, num_values * sizeof(*values));
if (!v) {
if (v == NULL) {
return SDL_OutOfMemory();
}
SDL_memcpy(v, values, num_values * sizeof(*values));
@ -685,7 +685,7 @@ static SDL_MouseClickState *GetMouseClickState(SDL_Mouse *mouse, Uint8 button)
if (button >= mouse->num_clickstates) {
int i, count = button + 1;
SDL_MouseClickState *clickstate = (SDL_MouseClickState *)SDL_realloc(mouse->clickstate, count * sizeof(*mouse->clickstate));
if (!clickstate) {
if (clickstate == NULL) {
return NULL;
}
mouse->clickstate = clickstate;
@ -708,7 +708,7 @@ SDL_PrivateSendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state
SDL_MouseInputSource *source;
source = GetMouseInputSource(mouse, mouseID);
if (!source) {
if (source == NULL) {
return 0;
}
buttonstate = source->buttonstate;
@ -1005,10 +1005,10 @@ SDL_GetGlobalMouseState(int *x, int *y)
int tmpx, tmpy;
/* make sure these are never NULL for the backend implementations... */
if (!x) {
if (x == NULL) {
x = &tmpx;
}
if (!y) {
if (y == NULL) {
y = &tmpy;
}
@ -1268,7 +1268,7 @@ SDL_CreateCursor(const Uint8 * data, const Uint8 * mask,
0x0000FF00,
0x000000FF,
0xFF000000);
if (!surface) {
if (surface == NULL) {
return NULL;
}
for (y = 0; y < h; ++y) {
@ -1302,7 +1302,7 @@ SDL_CreateColorCursor(SDL_Surface *surface, int hot_x, int hot_y)
SDL_Surface *temp = NULL;
SDL_Cursor *cursor;
if (!surface) {
if (surface == NULL) {
SDL_InvalidParamError("surface");
return NULL;
}
@ -1321,7 +1321,7 @@ SDL_CreateColorCursor(SDL_Surface *surface, int hot_x, int hot_y)
if (surface->format->format != SDL_PIXELFORMAT_ARGB8888) {
temp = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_ARGB8888, 0);
if (!temp) {
if (temp == NULL) {
return NULL;
}
surface = temp;
@ -1377,7 +1377,7 @@ SDL_SetCursor(SDL_Cursor * cursor)
break;
}
}
if (!found) {
if (found == NULL) {
SDL_SetError("Cursor not associated with the current mouse");
return;
}
@ -1407,7 +1407,7 @@ SDL_GetCursor(void)
{
SDL_Mouse *mouse = SDL_GetMouse();
if (!mouse) {
if (mouse == NULL) {
return NULL;
}
return mouse->cur_cursor;
@ -1418,7 +1418,7 @@ SDL_GetDefaultCursor(void)
{
SDL_Mouse *mouse = SDL_GetMouse();
if (!mouse) {
if (mouse == NULL) {
return NULL;
}
return mouse->def_cursor;
@ -1430,7 +1430,7 @@ SDL_FreeCursor(SDL_Cursor * cursor)
SDL_Mouse *mouse = SDL_GetMouse();
SDL_Cursor *curr, *prev;
if (!cursor) {
if (cursor == NULL) {
return;
}
@ -1464,7 +1464,7 @@ SDL_ShowCursor(int toggle)
SDL_Mouse *mouse = SDL_GetMouse();
SDL_bool shown;
if (!mouse) {
if (mouse == NULL) {
return 0;
}

View file

@ -44,7 +44,7 @@ static SDL_TouchID track_touchid;
int
SDL_TouchInit(void)
{
return (0);
return 0;
}
int
@ -150,7 +150,7 @@ SDL_Finger *
SDL_GetTouchFinger(SDL_TouchID touchID, int index)
{
SDL_Touch *touch = SDL_GetTouch(touchID);
if (!touch) {
if (touch == NULL) {
return NULL;
}
if (index < 0 || index >= touch->num_fingers) {
@ -174,7 +174,7 @@ SDL_AddTouch(SDL_TouchID touchID, SDL_TouchDeviceType type, const char *name)
/* Add the touch to the list of touch */
touchDevices = (SDL_Touch **) SDL_realloc(SDL_touchDevices,
(SDL_num_touch + 1) * sizeof(*touchDevices));
if (!touchDevices) {
if (touchDevices == NULL) {
return SDL_OutOfMemory();
}
@ -212,7 +212,7 @@ SDL_AddFinger(SDL_Touch *touch, SDL_FingerID fingerid, float x, float y, float p
if (touch->num_fingers == touch->max_fingers) {
SDL_Finger **new_fingers;
new_fingers = (SDL_Finger **)SDL_realloc(touch->fingers, (touch->max_fingers+1)*sizeof(*touch->fingers));
if (!new_fingers) {
if (new_fingers == NULL) {
return SDL_OutOfMemory();
}
touch->fingers = new_fingers;
@ -257,7 +257,7 @@ SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, SDL_Window * window,
SDL_Mouse *mouse;
SDL_Touch* touch = SDL_GetTouch(id);
if (!touch) {
if (touch == NULL) {
return -1;
}
@ -279,10 +279,18 @@ SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, SDL_Window * window,
if (finger_touching == SDL_FALSE) {
int pos_x = (int)(x * (float)window->w);
int pos_y = (int)(y * (float)window->h);
if (pos_x < 0) pos_x = 0;
if (pos_x > window->w - 1) pos_x = window->w - 1;
if (pos_y < 0) pos_y = 0;
if (pos_y > window->h - 1) pos_y = window->h - 1;
if (pos_x < 0) {
pos_x = 0;
}
if (pos_x > window->w - 1) {
pos_x = window->w - 1;
}
if (pos_y < 0) {
pos_y = 0;
}
if (pos_y > window->h - 1) {
pos_y = window->h - 1;
}
SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y);
SDL_SendMouseButton(window, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
}
@ -342,7 +350,7 @@ SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, SDL_Window * window,
posted = (SDL_PushEvent(&event) > 0);
}
} else {
if (!finger) {
if (finger == NULL) {
/* This finger is already up */
return 0;
}
@ -379,7 +387,7 @@ SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, SDL_Window * window,
float xrel, yrel, prel;
touch = SDL_GetTouch(id);
if (!touch) {
if (touch == NULL) {
return -1;
}
@ -394,10 +402,18 @@ SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, SDL_Window * window,
if (finger_touching == SDL_TRUE && track_touchid == id && track_fingerid == fingerid) {
int pos_x = (int)(x * (float)window->w);
int pos_y = (int)(y * (float)window->h);
if (pos_x < 0) pos_x = 0;
if (pos_x > window->w - 1) pos_x = window->w - 1;
if (pos_y < 0) pos_y = 0;
if (pos_y > window->h - 1) pos_y = window->h - 1;
if (pos_x < 0) {
pos_x = 0;
}
if (pos_x > window->w - 1) {
pos_x = window->w - 1;
}
if (pos_y < 0) {
pos_y = 0;
}
if (pos_y > window->h - 1) {
pos_y = window->h - 1;
}
SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y);
}
}
@ -414,7 +430,7 @@ SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, SDL_Window * window,
}
finger = SDL_GetFinger(touch,fingerid);
if (!finger) {
if (finger == NULL) {
return SDL_SendTouch(id, fingerid, window, SDL_TRUE, x, y, pressure);
}
@ -466,7 +482,7 @@ SDL_DelTouch(SDL_TouchID id)
index = SDL_GetTouchIndex(id);
touch = SDL_GetTouch(id);
if (!touch) {
if (touch == NULL) {
return;
}

View file

@ -88,7 +88,7 @@ SDL_SendWindowEvent(SDL_Window * window, Uint8 windowevent, int data1,
{
int posted;
if (!window) {
if (window == NULL) {
return 0;
}
switch (windowevent) {

View file

@ -87,8 +87,9 @@ windows_file_open(SDL_RWops * context, const char *filename, const char *mode)
DWORD must_exist, truncate;
int a_mode;
if (!context)
return -1; /* failed (invalid call) */
if (context == NULL) {
return -1; /* failed (invalid call) */
}
context->hidden.windowsio.h = INVALID_HANDLE_VALUE; /* mark this as unusable */
context->hidden.windowsio.buffer.data = NULL;
@ -110,8 +111,10 @@ windows_file_open(SDL_RWops * context, const char *filename, const char *mode)
w_right = (a_mode || SDL_strchr(mode, '+')
|| truncate) ? GENERIC_WRITE : 0;
if (!r_right && !w_right) /* inconsistent mode */
return -1; /* failed (invalid call) */
if (!r_right && !w_right) {
return -1; /* inconsistent mode */
}
/* failed (invalid call) */
context->hidden.windowsio.buffer.data =
(char *) SDL_malloc(READAHEAD_BUFFER_SIZE);
@ -155,7 +158,7 @@ windows_file_size(SDL_RWops * context)
{
LARGE_INTEGER size;
if (!context || context->hidden.windowsio.h == INVALID_HANDLE_VALUE) {
if (context == NULL || context->hidden.windowsio.h == INVALID_HANDLE_VALUE) {
return SDL_SetError("windows_file_size: invalid context/file not opened");
}
@ -172,7 +175,7 @@ windows_file_seek(SDL_RWops * context, Sint64 offset, int whence)
DWORD windowswhence;
LARGE_INTEGER windowsoffset;
if (!context || context->hidden.windowsio.h == INVALID_HANDLE_VALUE) {
if (context == NULL || context->hidden.windowsio.h == INVALID_HANDLE_VALUE) {
return SDL_SetError("windows_file_seek: invalid context/file not opened");
}
@ -213,7 +216,7 @@ windows_file_read(SDL_RWops * context, void *ptr, size_t size, size_t maxnum)
total_need = size * maxnum;
if (!context || context->hidden.windowsio.h == INVALID_HANDLE_VALUE || !total_need) {
if (context == NULL || context->hidden.windowsio.h == INVALID_HANDLE_VALUE || !total_need) {
return 0;
}
@ -254,7 +257,7 @@ windows_file_read(SDL_RWops * context, void *ptr, size_t size, size_t maxnum)
}
total_read += byte_read;
}
return (total_read / size);
return total_read / size;
}
static size_t SDLCALL
@ -268,7 +271,7 @@ windows_file_write(SDL_RWops * context, const void *ptr, size_t size,
total_bytes = size * num;
if (!context || context->hidden.windowsio.h == INVALID_HANDLE_VALUE || !size || !total_bytes) {
if (context == NULL || context->hidden.windowsio.h == INVALID_HANDLE_VALUE || !size || !total_bytes) {
return 0;
}
@ -501,7 +504,7 @@ mem_read(SDL_RWops * context, void *ptr, size_t size, size_t maxnum)
SDL_memcpy(ptr, context->hidden.mem.here, total_bytes);
context->hidden.mem.here += total_bytes;
return (total_bytes / size);
return total_bytes / size;
}
static size_t SDLCALL
@ -538,7 +541,7 @@ SDL_RWops *
SDL_RWFromFile(const char *file, const char *mode)
{
SDL_RWops *rwops = NULL;
if (!file || !*file || !mode || !*mode) {
if (file == NULL || !*file || mode == NULL || !*mode) {
SDL_SetError("SDL_RWFromFile(): No file or no mode specified");
return NULL;
}
@ -571,8 +574,10 @@ SDL_RWFromFile(const char *file, const char *mode)
/* Try to open the file from the asset system */
rwops = SDL_AllocRW();
if (!rwops)
return NULL; /* SDL_SetError already setup by SDL_AllocRW() */
if (rwops == NULL) {
return NULL; /* SDL_SetError already setup by SDL_AllocRW() */
}
if (Android_JNI_FileOpen(rwops, file, mode) < 0) {
SDL_FreeRW(rwops);
return NULL;
@ -586,8 +591,10 @@ SDL_RWFromFile(const char *file, const char *mode)
#elif defined(__WIN32__) || defined(__GDK__)
rwops = SDL_AllocRW();
if (!rwops)
return NULL; /* SDL_SetError already setup by SDL_AllocRW() */
if (rwops == NULL) {
return NULL; /* SDL_SetError already setup by SDL_AllocRW() */
}
if (windows_file_open(rwops, file, mode) < 0) {
SDL_FreeRW(rwops);
return NULL;
@ -655,7 +662,7 @@ SDL_RWops *
SDL_RWFromMem(void *mem, int size)
{
SDL_RWops *rwops = NULL;
if (!mem) {
if (mem == NULL) {
SDL_InvalidParamError("mem");
return rwops;
}
@ -683,7 +690,7 @@ SDL_RWops *
SDL_RWFromConstMem(const void *mem, int size)
{
SDL_RWops *rwops = NULL;
if (!mem) {
if (mem == NULL) {
SDL_InvalidParamError("mem");
return rwops;
}
@ -736,7 +743,7 @@ SDL_LoadFile_RW(SDL_RWops * src, size_t *datasize, int freesrc)
size_t size_read, size_total;
void *data = NULL, *newdata;
if (!src) {
if (src == NULL) {
SDL_InvalidParamError("src");
return NULL;
}
@ -752,7 +759,7 @@ SDL_LoadFile_RW(SDL_RWops * src, size_t *datasize, int freesrc)
if ((((Sint64)size_total) + FILE_CHUNK_SIZE) > size) {
size = (size_total + FILE_CHUNK_SIZE);
newdata = SDL_realloc(data, (size_t)(size + 1));
if (!newdata) {
if (newdata == NULL) {
SDL_free(data);
data = NULL;
SDL_OutOfMemory();
@ -890,49 +897,49 @@ SDL_ReadBE64(SDL_RWops * src)
size_t
SDL_WriteU8(SDL_RWops * dst, Uint8 value)
{
return SDL_RWwrite(dst, &value, sizeof (value), 1);
return SDL_RWwrite(dst, &value, sizeof(value), 1);
}
size_t
SDL_WriteLE16(SDL_RWops * dst, Uint16 value)
{
const Uint16 swapped = SDL_SwapLE16(value);
return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1);
return SDL_RWwrite(dst, &swapped, sizeof(swapped), 1);
}
size_t
SDL_WriteBE16(SDL_RWops * dst, Uint16 value)
{
const Uint16 swapped = SDL_SwapBE16(value);
return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1);
return SDL_RWwrite(dst, &swapped, sizeof(swapped), 1);
}
size_t
SDL_WriteLE32(SDL_RWops * dst, Uint32 value)
{
const Uint32 swapped = SDL_SwapLE32(value);
return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1);
return SDL_RWwrite(dst, &swapped, sizeof(swapped), 1);
}
size_t
SDL_WriteBE32(SDL_RWops * dst, Uint32 value)
{
const Uint32 swapped = SDL_SwapBE32(value);
return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1);
return SDL_RWwrite(dst, &swapped, sizeof(swapped), 1);
}
size_t
SDL_WriteLE64(SDL_RWops * dst, Uint64 value)
{
const Uint64 swapped = SDL_SwapLE64(value);
return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1);
return SDL_RWwrite(dst, &swapped, sizeof(swapped), 1);
}
size_t
SDL_WriteBE64(SDL_RWops * dst, Uint64 value)
{
const Uint64 swapped = SDL_SwapBE64(value);
return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1);
return SDL_RWwrite(dst, &swapped, sizeof(swapped), 1);
}
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -47,7 +47,7 @@ SDL_GetPrefPath(const char *org, const char *app)
if (path) {
size_t pathlen = SDL_strlen(path)+2;
char *fullpath = (char *)SDL_malloc(pathlen);
if (!fullpath) {
if (fullpath == NULL) {
SDL_OutOfMemory();
return NULL;
}

View file

@ -47,17 +47,17 @@ SDL_GetPrefPath(const char *org, const char *app)
char *ptr = NULL;
size_t len = 0;
if (!app) {
if (app == NULL) {
SDL_InvalidParamError("app");
return NULL;
}
if (!org) {
if (org == NULL) {
org = "";
}
len = SDL_strlen(append) + SDL_strlen(org) + SDL_strlen(app) + 3;
retval = (char *) SDL_malloc(len);
if (!retval) {
if (retval == NULL) {
SDL_OutOfMemory();
return NULL;
}
@ -71,8 +71,9 @@ SDL_GetPrefPath(const char *org, const char *app)
for (ptr = retval+1; *ptr; ptr++) {
if (*ptr == '/') {
*ptr = '\0';
if (mkdir(retval, 0700) != 0 && errno != EEXIST)
if (mkdir(retval, 0700) != 0 && errno != EEXIST) {
goto error;
}
*ptr = '/';
}
}

View file

@ -57,7 +57,7 @@ SDL_GetBasePath(void)
const size_t len = SDL_strlen(str);
char *retval = (char *) SDL_malloc(len + 2);
if (!retval) {
if (retval == NULL) {
SDL_OutOfMemory();
return NULL;
}
@ -77,11 +77,11 @@ SDL_GetPrefPath(const char *org, const char *app)
const char *append = "/config/settings/";
size_t len = SDL_strlen(home);
if (!app) {
if (app == NULL) {
SDL_InvalidParamError("app");
return NULL;
}
if (!org) {
if (org == NULL) {
org = "";
}
@ -90,7 +90,7 @@ SDL_GetPrefPath(const char *org, const char *app)
}
len += SDL_strlen(append) + SDL_strlen(org) + SDL_strlen(app) + 3;
char *retval = (char *) SDL_malloc(len);
if (!retval) {
if (retval == NULL) {
SDL_OutOfMemory();
} else {
if (*org) {

View file

@ -41,8 +41,9 @@ SDL_GetBasePath(void)
getcwd(cwd, sizeof(cwd));
len = SDL_strlen(cwd) + 1;
retval = (char *) SDL_malloc(len);
if (retval)
if (retval) {
SDL_memcpy(retval, cwd, len);
}
return retval;
}
@ -56,15 +57,17 @@ static void recursive_mkdir(const char *dir) {
snprintf(tmp, sizeof(tmp),"%s",dir);
len = strlen(tmp);
if (tmp[len - 1] == '/')
if (tmp[len - 1] == '/') {
tmp[len - 1] = 0;
}
for (p = tmp + 1; *p; p++) {
if (*p == '/') {
*p = 0;
// Just creating subfolders from current path
if (strstr(tmp, base) != NULL)
if (strstr(tmp, base) != NULL) {
mkdir(tmp, S_IRWXU);
}
*p = '/';
}
@ -80,11 +83,11 @@ SDL_GetPrefPath(const char *org, const char *app)
char *retval = NULL;
size_t len;
char *base = SDL_GetBasePath();
if (!app) {
if (app == NULL) {
SDL_InvalidParamError("app");
return NULL;
}
if(!org) {
if (org == NULL) {
org = "";
}

View file

@ -52,11 +52,11 @@ SDL_GetPrefPath(const char *org, const char *app)
char *retval = NULL;
size_t len;
char *base = SDL_GetBasePath();
if (!app) {
if (app == NULL) {
SDL_InvalidParamError("app");
return NULL;
}
if(!org) {
if (org == NULL) {
org = "";
}

View file

@ -39,22 +39,23 @@ SDL_unixify_std(const char *ro_path, char *buffer, size_t buf_len, int filetype)
{
const char *const in_buf = buffer; /* = NULL if we allocate the buffer. */
if (!buffer) {
if (buffer == NULL) {
/* This matches the logic in __unixify, with an additional byte for the
* extra path separator.
*/
buf_len = SDL_strlen(ro_path) + 14 + 1;
buffer = SDL_malloc(buf_len);
if (!buffer) {
if (buffer == NULL) {
SDL_OutOfMemory();
return NULL;
}
}
if (!__unixify_std(ro_path, buffer, buf_len, filetype)) {
if (!in_buf)
if (in_buf == NULL) {
SDL_free(buffer);
}
SDL_SetError("Could not convert '%s' to a Unix-style path", ro_path);
return NULL;
@ -93,7 +94,7 @@ canonicalisePath(const char *path, const char *pathVar)
regs.r[5] = 1 - regs.r[5];
buf = SDL_malloc(regs.r[5]);
if (!buf) {
if (buf == NULL) {
SDL_OutOfMemory();
return NULL;
}
@ -123,8 +124,9 @@ createDirectoryRecursive(char *path)
*ptr = '\0';
error = _kernel_swi(OS_File, &regs, &regs);
*ptr = '.';
if (error != NULL)
if (error != NULL) {
return error;
}
}
}
return _kernel_swi(OS_File, &regs, &regs);
@ -143,14 +145,15 @@ SDL_GetBasePath(void)
}
canon = canonicalisePath((const char *)regs.r[0], "Run$Path");
if (!canon) {
if (canon == NULL) {
return NULL;
}
/* chop off filename. */
ptr = SDL_strrchr(canon, '.');
if (ptr != NULL)
if (ptr != NULL) {
*ptr = '\0';
}
retval = SDL_unixify_std(canon, NULL, 0, __RISCOSIFY_FILETYPE_NOTSPECIFIED);
SDL_free(canon);
@ -164,22 +167,22 @@ SDL_GetPrefPath(const char *org, const char *app)
size_t len;
_kernel_oserror *error;
if (!app) {
if (app == NULL) {
SDL_InvalidParamError("app");
return NULL;
}
if (!org) {
if (org == NULL) {
org = "";
}
canon = canonicalisePath("<Choices$Write>", "Run$Path");
if (!canon) {
if (canon == NULL) {
return NULL;
}
len = SDL_strlen(canon) + SDL_strlen(org) + SDL_strlen(app) + 4;
dir = (char *) SDL_malloc(len);
if (!dir) {
if (dir == NULL) {
SDL_OutOfMemory();
SDL_free(canon);
return NULL;

View file

@ -52,8 +52,7 @@ readSymLink(const char *path)
ssize_t len = 64;
ssize_t rc = -1;
while (1)
{
while (1) {
char *ptr = (char *) SDL_realloc(retval, (size_t) len);
if (ptr == NULL) {
SDL_OutOfMemory();
@ -88,13 +87,13 @@ static char *search_path_for_binary(const char *bin)
char *start = envr;
char *ptr;
if (!envr) {
if (envr == NULL) {
SDL_SetError("No $PATH set");
return NULL;
}
envr = SDL_strdup(envr);
if (!envr) {
if (envr == NULL) {
SDL_OutOfMemory();
return NULL;
}
@ -143,7 +142,7 @@ SDL_GetBasePath(void)
const int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
if (sysctl(mib, SDL_arraysize(mib), fullpath, &buflen, NULL, 0) != -1) {
retval = SDL_strdup(fullpath);
if (!retval) {
if (retval == NULL) {
SDL_OutOfMemory();
return NULL;
}
@ -157,13 +156,13 @@ SDL_GetBasePath(void)
if (sysctl(mib, 4, NULL, &len, NULL, 0) != -1) {
char *exe, *pwddst;
char *realpathbuf = (char *) SDL_malloc(PATH_MAX + 1);
if (!realpathbuf) {
if (realpathbuf == NULL) {
SDL_OutOfMemory();
return NULL;
}
cmdline = SDL_malloc(len);
if (!cmdline) {
if (cmdline == NULL) {
SDL_free(realpathbuf);
SDL_OutOfMemory();
return NULL;
@ -201,7 +200,7 @@ SDL_GetBasePath(void)
}
}
if (!retval) {
if (retval == NULL) {
SDL_free(realpathbuf);
}
@ -210,7 +209,7 @@ SDL_GetBasePath(void)
#endif
/* is a Linux-style /proc filesystem available? */
if (!retval && (access("/proc", F_OK) == 0)) {
if (retval == NULL && (access("/proc", F_OK) == 0)) {
/* !!! FIXME: after 2.0.6 ships, let's delete this code and just
use the /proc/%llu version. There's no reason to have
two copies of this plus all the #ifdefs. --ryan. */
@ -265,8 +264,9 @@ SDL_GetBasePath(void)
if (retval != NULL) {
/* try to shrink buffer... */
char *ptr = (char *) SDL_realloc(retval, SDL_strlen(retval) + 1);
if (ptr != NULL)
retval = ptr; /* oh well if it failed. */
if (ptr != NULL) {
retval = ptr; /* oh well if it failed. */
}
}
return retval;
@ -288,18 +288,18 @@ SDL_GetPrefPath(const char *org, const char *app)
char *ptr = NULL;
size_t len = 0;
if (!app) {
if (app == NULL) {
SDL_InvalidParamError("app");
return NULL;
}
if (!org) {
if (org == NULL) {
org = "";
}
if (!envr) {
if (envr == NULL) {
/* You end up with "$HOME/.local/share/Game Name 2" */
envr = SDL_getenv("HOME");
if (!envr) {
if (envr == NULL) {
/* we could take heroic measures with /etc/passwd, but oh well. */
SDL_SetError("neither XDG_DATA_HOME nor HOME environment is set");
return NULL;
@ -310,12 +310,13 @@ SDL_GetPrefPath(const char *org, const char *app)
}
len = SDL_strlen(envr);
if (envr[len - 1] == '/')
if (envr[len - 1] == '/') {
append += 1;
}
len += SDL_strlen(append) + SDL_strlen(org) + SDL_strlen(app) + 3;
retval = (char *) SDL_malloc(len);
if (!retval) {
if (retval == NULL) {
SDL_OutOfMemory();
return NULL;
}
@ -329,8 +330,9 @@ SDL_GetPrefPath(const char *org, const char *app)
for (ptr = retval+1; *ptr; ptr++) {
if (*ptr == '/') {
*ptr = '\0';
if (mkdir(retval, 0700) != 0 && errno != EEXIST)
if (mkdir(retval, 0700) != 0 && errno != EEXIST) {
goto error;
}
*ptr = '/';
}
}

View file

@ -55,11 +55,11 @@ SDL_GetPrefPath(const char *org, const char *app)
char *ptr = NULL;
size_t len = 0;
if (!app) {
if (app == NULL) {
SDL_InvalidParamError("app");
return NULL;
}
if (!org) {
if (org == NULL) {
org = "";
}
@ -67,7 +67,7 @@ SDL_GetPrefPath(const char *org, const char *app)
len += SDL_strlen(org) + SDL_strlen(app) + 3;
retval = (char *) SDL_malloc(len);
if (!retval) {
if (retval == NULL) {
SDL_OutOfMemory();
return NULL;
}

View file

@ -43,7 +43,7 @@ SDL_GetBasePath(void)
while (SDL_TRUE) {
void *ptr = SDL_realloc(path, buflen * sizeof (WCHAR));
if (!ptr) {
if (ptr == NULL) {
SDL_free(path);
SDL_OutOfMemory();
return NULL;
@ -101,11 +101,11 @@ SDL_GetPrefPath(const char *org, const char *app)
size_t new_wpath_len = 0;
BOOL api_result = FALSE;
if (!app) {
if (app == NULL) {
SDL_InvalidParamError("app");
return NULL;
}
if (!org) {
if (org == NULL) {
org = "";
}

View file

@ -111,7 +111,7 @@ SDL_WinRTGetFSPathUTF8(SDL_WinRT_Path pathType)
}
const wchar_t * ucs2Path = SDL_WinRTGetFSPathUNICODE(pathType);
if (!ucs2Path) {
if (ucs2Path == NULL) {
return NULL;
}
@ -128,14 +128,14 @@ SDL_GetBasePath(void)
size_t destPathLen;
char * destPath = NULL;
if (!srcPath) {
if (srcPath == NULL) {
SDL_SetError("Couldn't locate our basepath: %s", SDL_GetError());
return NULL;
}
destPathLen = SDL_strlen(srcPath) + 2;
destPath = (char *) SDL_malloc(destPathLen);
if (!destPath) {
if (destPath == NULL) {
SDL_OutOfMemory();
return NULL;
}
@ -161,16 +161,16 @@ SDL_GetPrefPath(const char *org, const char *app)
size_t new_wpath_len = 0;
BOOL api_result = FALSE;
if (!app) {
if (app == NULL) {
SDL_InvalidParamError("app");
return NULL;
}
if (!org) {
if (org == NULL) {
org = "";
}
srcPath = SDL_WinRTGetFSPathUNICODE(SDL_WINRT_PATH_LOCAL_FOLDER);
if ( ! srcPath) {
if (srcPath == NULL) {
SDL_SetError("Unable to find a source path");
return NULL;
}

View file

@ -60,8 +60,7 @@ ValidHaptic(SDL_Haptic * haptic)
valid = 0;
if (haptic != NULL) {
hapticlist = SDL_haptics;
while ( hapticlist )
{
while ( hapticlist ) {
if (hapticlist == haptic) {
valid = 1;
break;
@ -123,8 +122,7 @@ SDL_HapticOpen(int device_index)
/* If the haptic is already open, return it
* TODO: Should we create haptic instance IDs like the Joystick API?
*/
while ( hapticlist )
{
while ( hapticlist ) {
if (device_index == hapticlist->index) {
haptic = hapticlist;
++haptic->ref_count;
@ -156,10 +154,12 @@ SDL_HapticOpen(int device_index)
SDL_haptics = haptic;
/* Disable autocenter and set gain to max. */
if (haptic->supported & SDL_HAPTIC_GAIN)
if (haptic->supported & SDL_HAPTIC_GAIN) {
SDL_HapticSetGain(haptic, 100);
if (haptic->supported & SDL_HAPTIC_AUTOCENTER)
}
if (haptic->supported & SDL_HAPTIC_AUTOCENTER) {
SDL_HapticSetAutocenter(haptic, 0);
}
return haptic;
}
@ -184,8 +184,7 @@ SDL_HapticOpened(int device_index)
opened = 0;
hapticlist = SDL_haptics;
/* TODO Should this use an instance ID? */
while ( hapticlist )
{
while ( hapticlist ) {
if (hapticlist->index == (Uint8) device_index) {
opened = 1;
break;
@ -216,8 +215,9 @@ SDL_HapticIndex(SDL_Haptic * haptic)
int
SDL_MouseIsHaptic(void)
{
if (SDL_SYS_HapticMouse() < 0)
if (SDL_SYS_HapticMouse() < 0) {
return SDL_FALSE;
}
return SDL_TRUE;
}
@ -295,8 +295,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;
@ -362,17 +361,12 @@ SDL_HapticClose(SDL_Haptic * haptic)
/* Remove from the list */
hapticlist = SDL_haptics;
hapticlistprev = NULL;
while ( hapticlist )
{
if (haptic == hapticlist)
{
if ( hapticlistprev )
{
while ( hapticlist ) {
if (haptic == hapticlist) {
if ( hapticlistprev ) {
/* unlink this entry */
hapticlistprev->next = hapticlist->next;
}
else
{
} else {
SDL_haptics = haptic->next;
}
@ -464,8 +458,9 @@ SDL_HapticEffectSupported(SDL_Haptic * haptic, SDL_HapticEffect * effect)
return -1;
}
if ((haptic->supported & effect->type) != 0)
if ((haptic->supported & effect->type) != 0) {
return SDL_TRUE;
}
return SDL_FALSE;
}
@ -646,10 +641,11 @@ SDL_HapticSetGain(SDL_Haptic * haptic, int gain)
max_gain = SDL_atoi(env);
/* Check for sanity. */
if (max_gain < 0)
if (max_gain < 0) {
max_gain = 0;
else if (max_gain > 100)
} else if (max_gain > 100) {
max_gain = 100;
}
/* We'll scale it linearly with SDL_HAPTIC_GAIN_MAX */
real_gain = (gain * max_gain) / 100;
@ -747,7 +743,7 @@ SDL_HapticRumbleSupported(SDL_Haptic * haptic)
}
/* Most things can use SINE, but XInput only has LEFTRIGHT. */
return ((haptic->supported & (SDL_HAPTIC_SINE|SDL_HAPTIC_LEFTRIGHT)) != 0);
return (haptic->supported & (SDL_HAPTIC_SINE | SDL_HAPTIC_LEFTRIGHT)) != 0;
}
/*

View file

@ -57,13 +57,13 @@ SDL_SYS_HapticInit(void)
timeout = SDL_GetTicks() + 3000;
Android_JNI_PollHapticDevices();
}
return (numhaptics);
return numhaptics;
}
int
SDL_SYS_NumHaptics(void)
{
return (numhaptics);
return numhaptics;
}
static SDL_hapticlist_item *
@ -136,19 +136,19 @@ OpenHaptic(SDL_Haptic *haptic, SDL_hapticlist_item *item)
static SDL_hapticlist_item *
OpenHapticByOrder(SDL_Haptic *haptic, int index)
{
return OpenHaptic (haptic, HapticByOrder(index));
return OpenHaptic(haptic, HapticByOrder(index));
}
static SDL_hapticlist_item *
OpenHapticByDevId(SDL_Haptic *haptic, int device_id)
{
return OpenHaptic (haptic, HapticByDevId(device_id));
return OpenHaptic(haptic, HapticByDevId(device_id));
}
int
SDL_SYS_HapticOpen(SDL_Haptic *haptic)
{
return (OpenHapticByOrder(haptic, haptic->index) == NULL ? -1 : 0);
return OpenHapticByOrder(haptic, haptic->index) == NULL ? -1 : 0;
}
@ -171,14 +171,14 @@ SDL_SYS_JoystickIsHaptic(SDL_Joystick *joystick)
int
SDL_SYS_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick)
{
return (OpenHapticByDevId(haptic, ((joystick_hwdata *)joystick->hwdata)->device_id) == NULL ? -1 : 0);
return OpenHapticByDevId(haptic, ((joystick_hwdata *)joystick->hwdata)->device_id) == NULL ? -1 : 0;
}
int
SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
{
return (((SDL_hapticlist_item *)haptic->hwdata)->device_id == ((joystick_hwdata *)joystick->hwdata)->device_id ? 1 : 0);
return ((SDL_hapticlist_item *)haptic->hwdata)->device_id == ((joystick_hwdata *)joystick->hwdata)->device_id ? 1 : 0;
}

View file

@ -229,8 +229,7 @@ MacHaptic_MaybeAddDevice( io_object_t device )
}
/* Make sure we don't already have it */
for (item = SDL_hapticlist; item ; item = item->next)
{
for (item = SDL_hapticlist; item ; item = item->next) {
if (IOObjectIsEqualTo((io_object_t) item->dev, device)) {
/* Already added */
return -1;

View file

@ -85,8 +85,10 @@ static SDL_hapticlist_item *SDL_hapticlist = NULL;
static SDL_hapticlist_item *SDL_hapticlist_tail = NULL;
static int numhaptics = 0;
#define EV_TEST(ev,f) \
if (test_bit((ev), features)) ret |= (f);
#define EV_TEST(ev,f) \
if (test_bit((ev), features)) { \
ret |= (f); \
}
/*
* Test whether a device has haptic properties.
* Returns available properties or 0 if there are none.
@ -760,8 +762,9 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src)
/* Header */
dest->type = FF_CONSTANT;
if (SDL_SYS_ToDirection(&dest->direction, &constant->direction) == -1)
if (SDL_SYS_ToDirection(&dest->direction, &constant->direction) == -1) {
return -1;
}
/* Replay */
dest->replay.length = (constant->length == SDL_HAPTIC_INFINITY) ?
@ -795,8 +798,9 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src)
/* Header */
dest->type = FF_PERIODIC;
if (SDL_SYS_ToDirection(&dest->direction, &periodic->direction) == -1)
if (SDL_SYS_ToDirection(&dest->direction, &periodic->direction) == -1) {
return -1;
}
/* Replay */
dest->replay.length = (periodic->length == SDL_HAPTIC_INFINITY) ?
@ -808,17 +812,18 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src)
dest->trigger.interval = CLAMP(periodic->interval);
/* Periodic */
if (periodic->type == SDL_HAPTIC_SINE)
if (periodic->type == SDL_HAPTIC_SINE) {
dest->u.periodic.waveform = FF_SINE;
/* !!! FIXME: put this back when we have more bits in 2.1 */
/* else if (periodic->type == SDL_HAPTIC_SQUARE)
dest->u.periodic.waveform = FF_SQUARE; */
else if (periodic->type == SDL_HAPTIC_TRIANGLE)
} else if (periodic->type == SDL_HAPTIC_TRIANGLE) {
dest->u.periodic.waveform = FF_TRIANGLE;
else if (periodic->type == SDL_HAPTIC_SAWTOOTHUP)
} else if (periodic->type == SDL_HAPTIC_SAWTOOTHUP) {
dest->u.periodic.waveform = FF_SAW_UP;
else if (periodic->type == SDL_HAPTIC_SAWTOOTHDOWN)
} else if (periodic->type == SDL_HAPTIC_SAWTOOTHDOWN) {
dest->u.periodic.waveform = FF_SAW_DOWN;
}
dest->u.periodic.period = CLAMP(periodic->period);
dest->u.periodic.magnitude = periodic->magnitude;
dest->u.periodic.offset = periodic->offset;
@ -842,14 +847,16 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src)
condition = &src->condition;
/* Header */
if (condition->type == SDL_HAPTIC_SPRING)
if (condition->type == SDL_HAPTIC_SPRING) {
dest->type = FF_SPRING;
else if (condition->type == SDL_HAPTIC_DAMPER)
} else if (condition->type == SDL_HAPTIC_DAMPER) {
dest->type = FF_DAMPER;
else if (condition->type == SDL_HAPTIC_INERTIA)
} else if (condition->type == SDL_HAPTIC_INERTIA) {
dest->type = FF_INERTIA;
else if (condition->type == SDL_HAPTIC_FRICTION)
} else if (condition->type == SDL_HAPTIC_FRICTION) {
dest->type = FF_FRICTION;
}
dest->direction = 0; /* Handled by the condition-specifics. */
/* Replay */
@ -888,8 +895,9 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src)
/* Header */
dest->type = FF_RAMP;
if (SDL_SYS_ToDirection(&dest->direction, &ramp->direction) == -1)
if (SDL_SYS_ToDirection(&dest->direction, &ramp->direction) == -1) {
return -1;
}
/* Replay */
dest->replay.length = (ramp->length == SDL_HAPTIC_INFINITY) ?

View file

@ -575,18 +575,22 @@ SDL_SYS_SetDirection(DIEFFECT * effect, SDL_HapticDirection * dir, int naxes)
case SDL_HAPTIC_CARTESIAN:
effect->dwFlags |= DIEFF_CARTESIAN;
rglDir[0] = dir->dir[0];
if (naxes > 1)
if (naxes > 1) {
rglDir[1] = dir->dir[1];
if (naxes > 2)
}
if (naxes > 2) {
rglDir[2] = dir->dir[2];
}
return 0;
case SDL_HAPTIC_SPHERICAL:
effect->dwFlags |= DIEFF_SPHERICAL;
rglDir[0] = dir->dir[0];
if (naxes > 1)
if (naxes > 1) {
rglDir[1] = dir->dir[1];
if (naxes > 2)
}
if (naxes > 2) {
rglDir[2] = dir->dir[2];
}
return 0;
case SDL_HAPTIC_STEERING_AXIS:
effect->dwFlags |= DIEFF_CARTESIAN;
@ -1098,8 +1102,9 @@ SDL_DINPUT_HapticGetEffectStatus(SDL_Haptic * haptic, struct haptic_effect *effe
return DI_SetError("Getting effect status", ret);
}
if (status == 0)
if (status == 0) {
return SDL_FALSE;
}
return SDL_TRUE;
}

View file

@ -233,7 +233,7 @@ SDL_XINPUT_HapticOpen(SDL_Haptic * haptic, SDL_hapticlist_item *item)
int
SDL_XINPUT_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
{
return (haptic->hwdata->userid == joystick->hwdata->userid);
return haptic->hwdata->userid == joystick->hwdata->userid;
}
int

View file

@ -185,7 +185,9 @@ static int SDL_inotify_init1(void) {
#else
static int SDL_inotify_init1(void) {
int fd = inotify_init();
if (fd < 0) return -1;
if (fd < 0) {
return -1;
}
fcntl(fd, F_SETFL, O_NONBLOCK);
fcntl(fd, F_SETFD, FD_CLOEXEC);
return fd;
@ -195,7 +197,7 @@ static int SDL_inotify_init1(void) {
static int
StrHasPrefix(const char *string, const char *prefix)
{
return (SDL_strncmp(string, prefix, SDL_strlen(prefix)) == 0);
return SDL_strncmp(string, prefix, SDL_strlen(prefix)) == 0;
}
static int
@ -324,8 +326,7 @@ HIDAPI_InitializeDiscovery()
SDL_HIDAPI_discovery.m_bCanGetNotifications = SDL_TRUE;
}
}
}
else
} else
#endif /* SDL_USE_LIBUDEV */
{
#if defined(HAVE_INOTIFY)
@ -421,15 +422,14 @@ HIDAPI_UpdateDiscovery()
if (pUdevDevice) {
const char *action = NULL;
action = usyms->udev_device_get_action(pUdevDevice);
if (!action || SDL_strcmp(action, "add") == 0 || SDL_strcmp(action, "remove") == 0) {
if (action == NULL || SDL_strcmp(action, "add") == 0 || SDL_strcmp(action, "remove") == 0) {
++SDL_HIDAPI_discovery.m_unDeviceChangeCounter;
}
usyms->udev_device_unref(pUdevDevice);
}
}
}
}
else
} else
#endif /* SDL_USE_LIBUDEV */
{
#if defined(HAVE_INOTIFY)
@ -481,8 +481,9 @@ HIDAPI_ShutdownDiscovery()
}
#if defined(__WIN32__) || defined(__WINGDK__)
if (SDL_HIDAPI_discovery.m_hNotify)
if (SDL_HIDAPI_discovery.m_hNotify) {
UnregisterDeviceNotification(SDL_HIDAPI_discovery.m_hNotify);
}
if (SDL_HIDAPI_discovery.m_hwndMsg) {
DestroyWindow(SDL_HIDAPI_discovery.m_hwndMsg);
@ -509,8 +510,7 @@ HIDAPI_ShutdownDiscovery()
SDL_UDEV_ReleaseUdevSyms();
usyms = NULL;
}
}
else
} else
#endif /* SDL_USE_LIBUDEV */
{
#if defined(HAVE_INOTIFY)
@ -808,14 +808,8 @@ SDL_libusb_get_string_descriptor(libusb_device_handle *dev,
uint8_t descriptor_index, uint16_t lang_id,
unsigned char *data, int length)
{
return libusb_control_transfer(dev,
LIBUSB_ENDPOINT_IN | 0x0, /* Endpoint 0 IN */
LIBUSB_REQUEST_GET_DESCRIPTOR,
(LIBUSB_DT_STRING << 8) | descriptor_index,
lang_id,
data,
(uint16_t) length,
1000);
return libusb_control_transfer(dev, LIBUSB_ENDPOINT_IN | 0x0, LIBUSB_REQUEST_GET_DESCRIPTOR, (LIBUSB_DT_STRING << 8) | descriptor_index, lang_id,
data, (uint16_t)length, 1000); /* Endpoint 0 IN */
}
#define libusb_get_string_descriptor SDL_libusb_get_string_descriptor
#endif /* __FreeBSD__ */
@ -1240,7 +1234,7 @@ struct SDL_hid_device_info *SDL_hid_enumerate(unsigned short vendor_id, unsigned
#endif
for (usb_dev = usb_devs; usb_dev; usb_dev = usb_dev->next) {
new_dev = (struct SDL_hid_device_info*) SDL_malloc(sizeof(struct SDL_hid_device_info));
if (!new_dev) {
if (new_dev == NULL) {
LIBUSB_hid_free_enumeration(usb_devs);
SDL_hid_free_enumeration(devs);
SDL_OutOfMemory();
@ -1313,7 +1307,7 @@ struct SDL_hid_device_info *SDL_hid_enumerate(unsigned short vendor_id, unsigned
#endif
if (!bFound) {
new_dev = (struct SDL_hid_device_info*) SDL_malloc(sizeof(struct SDL_hid_device_info));
if (!new_dev) {
if (new_dev == NULL) {
#ifdef HAVE_LIBUSB
if (libusb_ctx.libhandle) {
LIBUSB_hid_free_enumeration(usb_devs);

View file

@ -168,7 +168,7 @@ SDL_LoadVIDPIDListFromHint(const char *hint, SDL_vidpid_list *list)
spot = (char *)hint;
}
if (!spot) {
if (spot == NULL) {
return;
}
@ -176,7 +176,7 @@ SDL_LoadVIDPIDListFromHint(const char *hint, SDL_vidpid_list *list)
entry = (Uint16)SDL_strtol(spot, &spot, 0);
entry <<= 16;
spot = SDL_strstr(spot, "0x");
if (!spot) {
if (spot == NULL) {
break;
}
entry |= (Uint16)SDL_strtol(spot, &spot, 0);
@ -222,9 +222,9 @@ static SDL_bool HasSameOutput(SDL_ExtendedGameControllerBind *a, SDL_ExtendedGam
}
if (a->outputType == SDL_CONTROLLER_BINDTYPE_AXIS) {
return (a->output.axis.axis == b->output.axis.axis);
return a->output.axis.axis == b->output.axis.axis;
} else {
return (a->output.button == b->output.button);
return a->output.button == b->output.button;
}
}
@ -266,7 +266,7 @@ static void HandleJoystickAxis(SDL_GameController *gamecontroller, int axis, int
}
}
if (last_match && (!match || !HasSameOutput(last_match, match))) {
if (last_match && (match == NULL || !HasSameOutput(last_match, match))) {
/* Clear the last input that this axis generated */
ResetOutput(gamecontroller, last_match);
}
@ -549,8 +549,7 @@ static ControllerMapping_t *SDL_CreateMappingForAndroidController(SDL_JoystickGU
SDL_strlcat(mapping_string, "righttrigger:a5,", sizeof(mapping_string));
}
return SDL_PrivateAddMappingForGUID(guid, mapping_string,
&existing, SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT);
return SDL_PrivateAddMappingForGUID(guid, mapping_string, &existing, SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT);
}
#endif /* __ANDROID__ */
@ -681,8 +680,7 @@ static ControllerMapping_t *SDL_CreateMappingForHIDAPIController(SDL_JoystickGUI
}
}
return SDL_PrivateAddMappingForGUID(guid, mapping_string,
&existing, SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT);
return SDL_PrivateAddMappingForGUID(guid, mapping_string, &existing, SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT);
}
/*
@ -696,8 +694,7 @@ static ControllerMapping_t *SDL_CreateMappingForRAWINPUTController(SDL_JoystickG
SDL_strlcpy(mapping_string, "none,*,", sizeof(mapping_string));
SDL_strlcat(mapping_string, "a:b0,b:b1,x:b2,y:b3,back:b6,guide:b10,start:b7,leftstick:b8,rightstick:b9,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,", sizeof(mapping_string));
return SDL_PrivateAddMappingForGUID(guid, mapping_string,
&existing, SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT);
return SDL_PrivateAddMappingForGUID(guid, mapping_string, &existing, SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT);
}
/*
@ -715,8 +712,7 @@ static ControllerMapping_t *SDL_CreateMappingForWGIController(SDL_JoystickGUID g
SDL_strlcpy(mapping_string, "none,*,", sizeof(mapping_string));
SDL_strlcat(mapping_string, "a:b0,b:b1,x:b2,y:b3,back:b6,start:b7,leftstick:b8,rightstick:b9,leftshoulder:b4,rightshoulder:b5,dpup:b10,dpdown:b12,dpleft:b13,dpright:b11,leftx:a1,lefty:a0~,rightx:a3,righty:a2~,lefttrigger:a4,righttrigger:a5,", sizeof(mapping_string));
return SDL_PrivateAddMappingForGUID(guid, mapping_string,
&existing, SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT);
return SDL_PrivateAddMappingForGUID(guid, mapping_string, &existing, SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT);
}
/*
@ -808,7 +804,7 @@ static ControllerMapping_t *SDL_PrivateGetControllerMappingForGUID(SDL_JoystickG
return s_pXInputMapping;
}
#endif
if (!mapping) {
if (mapping == NULL) {
if (SDL_IsJoystickHIDAPI(guid)) {
mapping = SDL_CreateMappingForHIDAPIController(guid);
} else if (SDL_IsJoystickRAWINPUT(guid)) {
@ -847,13 +843,14 @@ SDL_GameControllerAxis SDL_GameControllerGetAxisFromString(const char *pchString
++pchString;
}
if (!pchString || !pchString[0]) {
if (pchString == NULL || !pchString[0]) {
return SDL_CONTROLLER_AXIS_INVALID;
}
for (entry = 0; map_StringForControllerAxis[entry]; ++entry) {
if (!SDL_strcasecmp(pchString, map_StringForControllerAxis[entry]))
return (SDL_GameControllerAxis) entry;
if (!SDL_strcasecmp(pchString, map_StringForControllerAxis[entry])) {
return (SDL_GameControllerAxis)entry;
}
}
return SDL_CONTROLLER_AXIS_INVALID;
}
@ -900,12 +897,14 @@ static const char* map_StringForControllerButton[] = {
SDL_GameControllerButton SDL_GameControllerGetButtonFromString(const char *pchString)
{
int entry;
if (!pchString || !pchString[0])
if (pchString == NULL || !pchString[0]) {
return SDL_CONTROLLER_BUTTON_INVALID;
}
for (entry = 0; map_StringForControllerButton[entry]; ++entry) {
if (SDL_strcasecmp(pchString, map_StringForControllerButton[entry]) == 0)
return (SDL_GameControllerButton) entry;
if (SDL_strcasecmp(pchString, map_StringForControllerButton[entry]) == 0) {
return (SDL_GameControllerButton)entry;
}
}
return SDL_CONTROLLER_BUTTON_INVALID;
}
@ -1114,7 +1113,7 @@ static char *SDL_PrivateGetControllerGUIDFromMappingString(const char *pMapping)
const char *pFirstComma = SDL_strchr(pMapping, ',');
if (pFirstComma) {
char *pchGUID = SDL_malloc(pFirstComma - pMapping + 1);
if (!pchGUID) {
if (pchGUID == NULL) {
SDL_OutOfMemory();
return NULL;
}
@ -1154,15 +1153,17 @@ static char *SDL_PrivateGetControllerNameFromMappingString(const char *pMapping)
char *pchName;
pFirstComma = SDL_strchr(pMapping, ',');
if (!pFirstComma)
if (pFirstComma == NULL) {
return NULL;
}
pSecondComma = SDL_strchr(pFirstComma + 1, ',');
if (!pSecondComma)
if (pSecondComma == NULL) {
return NULL;
}
pchName = SDL_malloc(pSecondComma - pFirstComma);
if (!pchName) {
if (pchName == NULL) {
SDL_OutOfMemory();
return NULL;
}
@ -1180,12 +1181,14 @@ static char *SDL_PrivateGetControllerMappingFromMappingString(const char *pMappi
const char *pFirstComma, *pSecondComma;
pFirstComma = SDL_strchr(pMapping, ',');
if (!pFirstComma)
if (pFirstComma == NULL) {
return NULL;
}
pSecondComma = SDL_strchr(pFirstComma + 1, ',');
if (!pSecondComma)
if (pSecondComma == NULL) {
return NULL;
}
return SDL_strdup(pSecondComma + 1); /* mapping is everything after the 3rd comma */
}
@ -1225,13 +1228,13 @@ SDL_PrivateAddMappingForGUID(SDL_JoystickGUID jGUID, const char *mappingString,
Uint16 crc;
pchName = SDL_PrivateGetControllerNameFromMappingString(mappingString);
if (!pchName) {
if (pchName == NULL) {
SDL_SetError("Couldn't parse name from %s", mappingString);
return NULL;
}
pchMapping = SDL_PrivateGetControllerMappingFromMappingString(mappingString);
if (!pchMapping) {
if (pchMapping == NULL) {
SDL_free(pchName);
SDL_SetError("Couldn't parse %s", mappingString);
return NULL;
@ -1288,7 +1291,7 @@ SDL_PrivateAddMappingForGUID(SDL_JoystickGUID jGUID, const char *mappingString,
*existing = SDL_TRUE;
} else {
pControllerMapping = SDL_malloc(sizeof(*pControllerMapping));
if (!pControllerMapping) {
if (pControllerMapping == NULL) {
SDL_free(pchName);
SDL_free(pchMapping);
SDL_OutOfMemory();
@ -1331,7 +1334,7 @@ static ControllerMapping_t *SDL_PrivateGetControllerMappingForNameAndGUID(const
mapping = SDL_PrivateGetControllerMappingForGUID(guid);
#ifdef __LINUX__
if (!mapping && name) {
if (mapping == NULL && name) {
if (SDL_strstr(name, "Xbox 360 Wireless Receiver")) {
/* The Linux driver xpad.c maps the wireless dpad to buttons */
SDL_bool existing;
@ -1344,7 +1347,7 @@ static ControllerMapping_t *SDL_PrivateGetControllerMappingForNameAndGUID(const
}
#endif /* __LINUX__ */
if (!mapping) {
if (mapping == NULL) {
mapping = s_pDefaultMapping;
}
return mapping;
@ -1426,8 +1429,7 @@ static ControllerMapping_t *SDL_PrivateGenerateAutomaticControllerMapping(const
SDL_PrivateAppendToMappingString(mapping, sizeof(mapping), "lefttrigger", &raw_map->lefttrigger);
SDL_PrivateAppendToMappingString(mapping, sizeof(mapping), "righttrigger", &raw_map->righttrigger);
return SDL_PrivateAddMappingForGUID(guid, mapping,
&existing, SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT);
return SDL_PrivateAddMappingForGUID(guid, mapping, &existing, SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT);
}
static ControllerMapping_t *SDL_PrivateGetControllerMapping(int device_index)
@ -1441,13 +1443,13 @@ static ControllerMapping_t *SDL_PrivateGetControllerMapping(int device_index)
if ((device_index < 0) || (device_index >= SDL_NumJoysticks())) {
SDL_SetError("There are %d joysticks available", SDL_NumJoysticks());
SDL_UnlockJoysticks();
return (NULL);
return NULL;
}
name = SDL_JoystickNameForIndex(device_index);
guid = SDL_JoystickGetDeviceGUID(device_index);
mapping = SDL_PrivateGetControllerMappingForNameAndGUID(name, guid);
if (!mapping) {
if (mapping == NULL) {
SDL_GamepadMapping raw_map;
SDL_zero(raw_map);
@ -1544,7 +1546,7 @@ SDL_PrivateGameControllerAddMapping(const char *mappingString, SDL_ControllerMap
SDL_bool existing = SDL_FALSE;
ControllerMapping_t *pControllerMapping;
if (!mappingString) {
if (mappingString == NULL) {
return SDL_InvalidParamError("mappingString");
}
@ -1611,7 +1613,7 @@ SDL_PrivateGameControllerAddMapping(const char *mappingString, SDL_ControllerMap
#endif
pchGUID = SDL_PrivateGetControllerGUIDFromMappingString(mappingString);
if (!pchGUID) {
if (pchGUID == NULL) {
return SDL_SetError("Couldn't parse GUID from %s", mappingString);
}
if (!SDL_strcasecmp(pchGUID, "default")) {
@ -1623,7 +1625,7 @@ SDL_PrivateGameControllerAddMapping(const char *mappingString, SDL_ControllerMap
SDL_free(pchGUID);
pControllerMapping = SDL_PrivateAddMappingForGUID(jGUID, mappingString, &existing, priority);
if (!pControllerMapping) {
if (pControllerMapping == NULL) {
return -1;
}
@ -1691,7 +1693,7 @@ CreateMappingString(ControllerMapping_t *mapping, SDL_JoystickGUID guid)
}
pMappingString = SDL_malloc(needed);
if (!pMappingString) {
if (pMappingString == NULL) {
SDL_OutOfMemory();
return NULL;
}
@ -1778,8 +1780,9 @@ SDL_GameControllerLoadHints()
char *pchNewLine = NULL;
pchNewLine = SDL_strchr(pUserMappings, '\n');
if (pchNewLine)
if (pchNewLine) {
*pchNewLine = '\0';
}
SDL_PrivateGameControllerAddMapping(pUserMappings, SDL_CONTROLLER_MAPPING_PRIORITY_USER);
@ -1841,7 +1844,7 @@ SDL_GameControllerInitMappings(void)
SDL_AddHintCallback(SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT,
SDL_GameControllerIgnoreDevicesExceptChanged, NULL);
return (0);
return 0;
}
int
@ -1862,7 +1865,7 @@ SDL_GameControllerInit(void)
}
}
return (0);
return 0;
}
@ -1930,7 +1933,7 @@ SDL_GameControllerMappingForDeviceIndex(int joystick_index)
/* allocate enough memory for GUID + ',' + name + ',' + mapping + \0 */
needed = SDL_strlen(pchGUID) + 1 + SDL_strlen(mapping->name) + 1 + SDL_strlen(mapping->mapping) + 1;
pMappingString = SDL_malloc(needed);
if (!pMappingString) {
if (pMappingString == NULL) {
SDL_OutOfMemory();
SDL_UnlockJoysticks();
return NULL;
@ -2085,14 +2088,14 @@ SDL_GameControllerOpen(int device_index)
gamecontroller = gamecontrollerlist;
++gamecontroller->ref_count;
SDL_UnlockJoysticks();
return (gamecontroller);
return gamecontroller;
}
gamecontrollerlist = gamecontrollerlist->next;
}
/* Find a controller mapping */
pSupportedController = SDL_PrivateGetControllerMapping(device_index);
if (!pSupportedController) {
if (pSupportedController == NULL) {
SDL_SetError("Couldn't find mapping for device (%d)", device_index);
SDL_UnlockJoysticks();
return NULL;
@ -2146,7 +2149,7 @@ SDL_GameControllerOpen(int device_index)
SDL_UnlockJoysticks();
return (gamecontroller);
return gamecontroller;
}
/*
@ -2377,7 +2380,7 @@ int SDL_GameControllerSetSensorEnabled(SDL_GameController *gamecontroller, SDL_S
SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller);
int i;
if (!joystick) {
if (joystick == NULL) {
return -1;
}
@ -2439,7 +2442,7 @@ SDL_GameControllerGetSensorDataRate(SDL_GameController *gamecontroller, SDL_Sens
SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller);
int i;
if (!joystick) {
if (joystick == NULL) {
return 0.0f;
}
@ -2471,7 +2474,7 @@ SDL_GameControllerGetSensorDataWithTimestamp(SDL_GameController *gamecontroller,
SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller);
int i;
if (!joystick) {
if (joystick == NULL) {
return -1;
}
@ -2507,7 +2510,7 @@ SDL_GameControllerPath(SDL_GameController *gamecontroller)
{
SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller);
if (!joystick) {
if (joystick == NULL) {
return NULL;
}
return SDL_JoystickPath(joystick);
@ -2518,7 +2521,7 @@ SDL_GameControllerGetType(SDL_GameController *gamecontroller)
{
SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller);
if (!joystick) {
if (joystick == NULL) {
return SDL_CONTROLLER_TYPE_UNKNOWN;
}
return SDL_GetJoystickGameControllerTypeFromGUID(SDL_JoystickGetGUID(joystick), SDL_JoystickName(joystick));
@ -2529,7 +2532,7 @@ SDL_GameControllerGetPlayerIndex(SDL_GameController *gamecontroller)
{
SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller);
if (!joystick) {
if (joystick == NULL) {
return -1;
}
return SDL_JoystickGetPlayerIndex(joystick);
@ -2543,7 +2546,7 @@ SDL_GameControllerSetPlayerIndex(SDL_GameController *gamecontroller, int player_
{
SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller);
if (!joystick) {
if (joystick == NULL) {
return;
}
SDL_JoystickSetPlayerIndex(joystick, player_index);
@ -2554,7 +2557,7 @@ SDL_GameControllerGetVendor(SDL_GameController *gamecontroller)
{
SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller);
if (!joystick) {
if (joystick == NULL) {
return 0;
}
return SDL_JoystickGetVendor(joystick);
@ -2565,7 +2568,7 @@ SDL_GameControllerGetProduct(SDL_GameController *gamecontroller)
{
SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller);
if (!joystick) {
if (joystick == NULL) {
return 0;
}
return SDL_JoystickGetProduct(joystick);
@ -2576,7 +2579,7 @@ SDL_GameControllerGetProductVersion(SDL_GameController *gamecontroller)
{
SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller);
if (!joystick) {
if (joystick == NULL) {
return 0;
}
return SDL_JoystickGetProductVersion(joystick);
@ -2587,7 +2590,7 @@ SDL_GameControllerGetFirmwareVersion(SDL_GameController *gamecontroller)
{
SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller);
if (!joystick) {
if (joystick == NULL) {
return 0;
}
return SDL_JoystickGetFirmwareVersion(joystick);
@ -2598,7 +2601,7 @@ SDL_GameControllerGetSerial(SDL_GameController *gamecontroller)
{
SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller);
if (!joystick) {
if (joystick == NULL) {
return NULL;
}
return SDL_JoystickGetSerial(joystick);
@ -2674,8 +2677,9 @@ SDL_GameControllerButtonBind SDL_GameControllerGetBindForAxis(SDL_GameController
CHECK_GAMECONTROLLER_MAGIC(gamecontroller, bind);
if (axis == SDL_CONTROLLER_AXIS_INVALID)
if (axis == SDL_CONTROLLER_AXIS_INVALID) {
return bind;
}
for (i = 0; i < gamecontroller->num_bindings; ++i) {
SDL_ExtendedGameControllerBind *binding = &gamecontroller->bindings[i];
@ -2708,8 +2712,9 @@ SDL_GameControllerButtonBind SDL_GameControllerGetBindForButton(SDL_GameControll
CHECK_GAMECONTROLLER_MAGIC(gamecontroller, bind);
if (button == SDL_CONTROLLER_BUTTON_INVALID)
if (button == SDL_CONTROLLER_BUTTON_INVALID) {
return bind;
}
for (i = 0; i < gamecontroller->num_bindings; ++i) {
SDL_ExtendedGameControllerBind *binding = &gamecontroller->bindings[i];
@ -2735,7 +2740,7 @@ SDL_GameControllerRumble(SDL_GameController *gamecontroller, Uint16 low_frequenc
{
SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller);
if (!joystick) {
if (joystick == NULL) {
return -1;
}
return SDL_JoystickRumble(joystick, low_frequency_rumble, high_frequency_rumble, duration_ms);
@ -2746,7 +2751,7 @@ SDL_GameControllerRumbleTriggers(SDL_GameController *gamecontroller, Uint16 left
{
SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller);
if (!joystick) {
if (joystick == NULL) {
return -1;
}
return SDL_JoystickRumbleTriggers(joystick, left_rumble, right_rumble, duration_ms);
@ -2757,7 +2762,7 @@ SDL_GameControllerHasLED(SDL_GameController *gamecontroller)
{
SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller);
if (!joystick) {
if (joystick == NULL) {
return SDL_FALSE;
}
return SDL_JoystickHasLED(joystick);
@ -2768,7 +2773,7 @@ SDL_GameControllerHasRumble(SDL_GameController *gamecontroller)
{
SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller);
if (!joystick) {
if (joystick == NULL) {
return SDL_FALSE;
}
return SDL_JoystickHasRumble(joystick);
@ -2779,7 +2784,7 @@ SDL_GameControllerHasRumbleTriggers(SDL_GameController *gamecontroller)
{
SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller);
if (!joystick) {
if (joystick == NULL) {
return SDL_FALSE;
}
return SDL_JoystickHasRumbleTriggers(joystick);
@ -2790,7 +2795,7 @@ SDL_GameControllerSetLED(SDL_GameController *gamecontroller, Uint8 red, Uint8 gr
{
SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller);
if (!joystick) {
if (joystick == NULL) {
return -1;
}
return SDL_JoystickSetLED(joystick, red, green, blue);
@ -2801,7 +2806,7 @@ SDL_GameControllerSendEffect(SDL_GameController *gamecontroller, const void *dat
{
SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller);
if (!joystick) {
if (joystick == NULL) {
return -1;
}
return SDL_JoystickSendEffect(joystick, data, size);
@ -2812,8 +2817,9 @@ SDL_GameControllerClose(SDL_GameController *gamecontroller)
{
SDL_GameController *gamecontrollerlist, *gamecontrollerlistprev;
if (!gamecontroller || gamecontroller->magic != &gamecontroller_magic)
if (gamecontroller == NULL || gamecontroller->magic != &gamecontroller_magic) {
return;
}
SDL_LockJoysticks();
@ -2917,7 +2923,7 @@ SDL_PrivateGameControllerAxis(SDL_GameController *gamecontroller, SDL_GameContro
posted = SDL_PushEvent(&event) == 1;
}
#endif /* !SDL_EVENTS_DISABLED */
return (posted);
return posted;
}
@ -2946,7 +2952,7 @@ SDL_PrivateGameControllerButton(SDL_GameController *gamecontroller, SDL_GameCont
break;
default:
/* Invalid state -- bail */
return (0);
return 0;
}
#endif /* !SDL_EVENTS_DISABLED */
@ -2957,12 +2963,12 @@ SDL_PrivateGameControllerButton(SDL_GameController *gamecontroller, SDL_GameCont
if (gamecontroller->joystick->delayed_guide_button) {
/* Skip duplicate press */
return (0);
return 0;
}
} else {
if (!SDL_TICKS_PASSED(now, gamecontroller->guide_button_down+SDL_MINIMUM_GUIDE_BUTTON_DELAY_MS)) {
gamecontroller->joystick->delayed_guide_button = SDL_TRUE;
return (0);
return 0;
}
gamecontroller->joystick->delayed_guide_button = SDL_FALSE;
}
@ -2978,7 +2984,7 @@ SDL_PrivateGameControllerButton(SDL_GameController *gamecontroller, SDL_GameCont
posted = SDL_PushEvent(&event) == 1;
}
#endif /* !SDL_EVENTS_DISABLED */
return (posted);
return posted;
}
/*
@ -3013,7 +3019,7 @@ SDL_GameControllerEventState(int state)
}
break;
}
return (state);
return state;
#endif /* SDL_EVENTS_DISABLED */
}

View file

@ -264,7 +264,7 @@ SDL_SetJoystickIDForPlayerIndex(int player_index, SDL_JoystickID instance_id)
if (player_index >= SDL_joystick_player_count) {
SDL_JoystickID *new_players = (SDL_JoystickID *)SDL_realloc(SDL_joystick_players, (player_index + 1)*sizeof(*SDL_joystick_players));
if (!new_players) {
if (new_players == NULL) {
SDL_OutOfMemory();
return SDL_FALSE;
}
@ -316,7 +316,7 @@ SDL_JoystickInit(void)
int i, status;
/* Create the joystick list lock */
if (!SDL_joystick_lock) {
if (SDL_joystick_lock == NULL) {
SDL_joystick_lock = SDL_CreateMutex();
}
@ -410,7 +410,7 @@ SDL_JoystickPathForIndex(int device_index)
SDL_UnlockJoysticks();
/* FIXME: Really we should reference count this path so it doesn't go away after unlock */
if (!path) {
if (path == NULL) {
SDL_Unsupported();
}
return path;
@ -1389,7 +1389,7 @@ static void UpdateEventsForDeviceRemoval(int device_index, Uint32 type)
}
events = SDL_small_alloc(SDL_Event, num_events, &isstack);
if (!events) {
if (events == NULL) {
return;
}
@ -1910,10 +1910,10 @@ SDL_CreateJoystickName(Uint16 vendor, Uint16 product, const char *vendor_name, c
return SDL_strdup(custom_name);
}
if (!vendor_name) {
if (vendor_name == NULL) {
vendor_name = "";
}
if (!product_name) {
if (product_name == NULL) {
product_name = "";
}
@ -1965,7 +1965,7 @@ SDL_CreateJoystickName(Uint16 vendor, Uint16 product, const char *vendor_name, c
name = SDL_strdup("Controller");
}
if (!name) {
if (name == NULL) {
return NULL;
}
@ -2030,7 +2030,7 @@ SDL_CreateJoystickGUID(Uint16 bus, Uint16 vendor, Uint16 product, Uint16 version
SDL_zero(guid);
if (!name) {
if (name == NULL) {
name = "";
}
@ -2220,7 +2220,7 @@ SDL_bool
SDL_IsJoystickXboxOne(Uint16 vendor_id, Uint16 product_id)
{
EControllerType eType = GuessControllerType(vendor_id, product_id);
return (eType == k_eControllerType_XBoxOneController);
return eType == k_eControllerType_XBoxOneController;
}
SDL_bool
@ -2294,71 +2294,68 @@ SDL_bool
SDL_IsJoystickPS4(Uint16 vendor_id, Uint16 product_id)
{
EControllerType eType = GuessControllerType(vendor_id, product_id);
return (eType == k_eControllerType_PS4Controller);
return eType == k_eControllerType_PS4Controller;
}
SDL_bool
SDL_IsJoystickPS5(Uint16 vendor_id, Uint16 product_id)
{
EControllerType eType = GuessControllerType(vendor_id, product_id);
return (eType == k_eControllerType_PS5Controller);
return eType == k_eControllerType_PS5Controller;
}
SDL_bool
SDL_IsJoystickNintendoSwitchPro(Uint16 vendor_id, Uint16 product_id)
{
EControllerType eType = GuessControllerType(vendor_id, product_id);
return (eType == k_eControllerType_SwitchProController ||
eType == k_eControllerType_SwitchInputOnlyController);
return eType == k_eControllerType_SwitchProController || eType == k_eControllerType_SwitchInputOnlyController;
}
SDL_bool
SDL_IsJoystickNintendoSwitchProInputOnly(Uint16 vendor_id, Uint16 product_id)
{
EControllerType eType = GuessControllerType(vendor_id, product_id);
return (eType == k_eControllerType_SwitchInputOnlyController);
return eType == k_eControllerType_SwitchInputOnlyController;
}
SDL_bool
SDL_IsJoystickNintendoSwitchJoyCon(Uint16 vendor_id, Uint16 product_id)
{
EControllerType eType = GuessControllerType(vendor_id, product_id);
return (eType == k_eControllerType_SwitchJoyConLeft ||
eType == k_eControllerType_SwitchJoyConRight);
return eType == k_eControllerType_SwitchJoyConLeft || eType == k_eControllerType_SwitchJoyConRight;
}
SDL_bool
SDL_IsJoystickNintendoSwitchJoyConLeft(Uint16 vendor_id, Uint16 product_id)
{
EControllerType eType = GuessControllerType(vendor_id, product_id);
return (eType == k_eControllerType_SwitchJoyConLeft);
return eType == k_eControllerType_SwitchJoyConLeft;
}
SDL_bool
SDL_IsJoystickNintendoSwitchJoyConRight(Uint16 vendor_id, Uint16 product_id)
{
EControllerType eType = GuessControllerType(vendor_id, product_id);
return (eType == k_eControllerType_SwitchJoyConRight);
return eType == k_eControllerType_SwitchJoyConRight;
}
SDL_bool
SDL_IsJoystickNintendoSwitchJoyConGrip(Uint16 vendor_id, Uint16 product_id)
{
return (vendor_id == USB_VENDOR_NINTENDO && product_id == USB_PRODUCT_NINTENDO_SWITCH_JOYCON_GRIP);
return vendor_id == USB_VENDOR_NINTENDO && product_id == USB_PRODUCT_NINTENDO_SWITCH_JOYCON_GRIP;
}
SDL_bool
SDL_IsJoystickNintendoSwitchJoyConPair(Uint16 vendor_id, Uint16 product_id)
{
return (vendor_id == USB_VENDOR_NINTENDO && product_id == USB_PRODUCT_NINTENDO_SWITCH_JOYCON_PAIR);
return vendor_id == USB_VENDOR_NINTENDO && product_id == USB_PRODUCT_NINTENDO_SWITCH_JOYCON_PAIR;
}
SDL_bool
SDL_IsJoystickSteamController(Uint16 vendor_id, Uint16 product_id)
{
EControllerType eType = GuessControllerType(vendor_id, product_id);
return (eType == k_eControllerType_SteamController ||
eType == k_eControllerType_SteamControllerV2);
return eType == k_eControllerType_SteamController || eType == k_eControllerType_SteamControllerV2;
}
SDL_bool

View file

@ -620,7 +620,7 @@ ANDROID_JoystickOpen(SDL_Joystick *joystick, int device_index)
joystick->nbuttons = item->nbuttons;
joystick->naxes = item->naxes;
return (0);
return 0;
}
static int

View file

@ -321,8 +321,9 @@ CreateHwData(const char *path)
hw->type = BSDJOY_UHID;
{
int ax;
for (ax = 0; ax < JOYAXE_count; ax++)
for (ax = 0; ax < JOYAXE_count; ax++) {
hw->axis_map[ax] = -1;
}
}
hw->repdesc = hid_get_report_desc(fd);
if (hw->repdesc == NULL) {
@ -356,8 +357,9 @@ CreateHwData(const char *path)
SDL_SetError("%s: Cannot start HID parser", path);
goto usberr;
}
for (i = 0; i < JOYAXE_count; i++)
for (i = 0; i < JOYAXE_count; i++) {
hw->axis_map[i] = -1;
}
while (hid_get_item(hdata, &hitem) > 0) {
switch (hitem.kind) {
@ -395,9 +397,11 @@ CreateHwData(const char *path)
}
}
hid_end_parse(hdata);
for (i = 0; i < JOYAXE_count; i++)
if (hw->axis_map[i] > 0)
for (i = 0; i < JOYAXE_count; i++) {
if (hw->axis_map[i] > 0) {
hw->axis_map[i] = hw->naxes++;
}
}
if (hw->naxes == 0 && hw->nbuttons == 0 && hw->nhats == 0) {
SDL_SetError("%s: Not a joystick, ignoring", path);
@ -447,7 +451,7 @@ MaybeAddDevice(const char *path)
}
hw = CreateHwData(path);
if (!hw) {
if (hw == NULL) {
return -1;
}
@ -477,7 +481,7 @@ MaybeAddDevice(const char *path)
}
#endif /* USB_GET_DEVICEINFO */
}
if (!name) {
if (name == NULL) {
name = SDL_strdup(path);
guid = SDL_CreateJoystickGUIDForName(name);
}
@ -634,7 +638,7 @@ BSD_JoystickOpen(SDL_Joystick *joy, int device_index)
}
hw = CreateHwData(item->path);
if (!hw) {
if (hw == NULL) {
return -1;
}
@ -739,16 +743,13 @@ BSD_JoystickUpdate(SDL_Joystick *joy)
else if (usage == HUG_DPAD_UP) {
dpad[0] = (Sint32) hid_get_data(REP_BUF_DATA(rep), &hitem);
SDL_PrivateJoystickHat(joy, 0, dpad_to_sdl(dpad));
}
else if (usage == HUG_DPAD_DOWN) {
} else if (usage == HUG_DPAD_DOWN) {
dpad[1] = (Sint32) hid_get_data(REP_BUF_DATA(rep), &hitem);
SDL_PrivateJoystickHat(joy, 0, dpad_to_sdl(dpad));
}
else if (usage == HUG_DPAD_RIGHT) {
} else if (usage == HUG_DPAD_RIGHT) {
dpad[2] = (Sint32) hid_get_data(REP_BUF_DATA(rep), &hitem);
SDL_PrivateJoystickHat(joy, 0, dpad_to_sdl(dpad));
}
else if (usage == HUG_DPAD_LEFT) {
} else if (usage == HUG_DPAD_LEFT) {
dpad[3] = (Sint32) hid_get_data(REP_BUF_DATA(rep), &hitem);
SDL_PrivateJoystickHat(joy, 0, dpad_to_sdl(dpad));
}

View file

@ -43,7 +43,7 @@ static recDevice *gpDeviceList = NULL;
void FreeRumbleEffectData(FFEFFECT *effect)
{
if (!effect) {
if (effect == NULL) {
return;
}
SDL_free(effect->rgdwAxes);
@ -59,7 +59,7 @@ FFEFFECT *CreateRumbleEffectData(Sint16 magnitude)
/* Create the effect */
effect = (FFEFFECT *)SDL_calloc(1, sizeof(*effect));
if (!effect) {
if (effect == NULL) {
return NULL;
}
effect->dwSize = sizeof(*effect);
@ -83,7 +83,7 @@ FFEFFECT *CreateRumbleEffectData(Sint16 magnitude)
effect->dwFlags |= FFEFF_CARTESIAN;
periodic = (FFPERIODIC *)SDL_calloc(1, sizeof(*periodic));
if (!periodic) {
if (periodic == NULL) {
FreeRumbleEffectData(effect);
return NULL;
}
@ -101,8 +101,9 @@ static recDevice *GetDeviceForIndex(int device_index)
recDevice *device = gpDeviceList;
while (device) {
if (!device->removed) {
if (device_index == 0)
if (device_index == 0) {
break;
}
--device_index;
}
@ -208,13 +209,10 @@ GetHIDScaledCalibratedState(recDevice * pDevice, recElement * pElement, SInt32 m
const float deviceScale = max - min;
const float readScale = pElement->maxReport - pElement->minReport;
int returnValue = SDL_FALSE;
if (GetHIDElementState(pDevice, pElement, pValue))
{
if (GetHIDElementState(pDevice, pElement, pValue)) {
if (readScale == 0) {
returnValue = SDL_TRUE; /* no scaling at all */
}
else
{
} else {
*pValue = ((*pValue - pElement->minReport) * deviceScale / readScale) + min;
returnValue = SDL_TRUE;
}
@ -547,7 +545,7 @@ JoystickDeviceWasAddedCallback(void *ctx, IOReturn res, void *sender, IOHIDDevic
}
device = (recDevice *) SDL_calloc(1, sizeof(recDevice));
if (!device) {
if (device == NULL) {
SDL_OutOfMemory();
return;
}
@ -580,7 +578,7 @@ JoystickDeviceWasAddedCallback(void *ctx, IOReturn res, void *sender, IOHIDDevic
}
/* Add device to the end of the list */
if ( !gpDeviceList ) {
if (gpDeviceList == NULL) {
gpDeviceList = device;
} else {
recDevice *curdevice;
@ -891,7 +889,7 @@ DARWIN_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint1
/* Scale and average the two rumble strengths */
Sint16 magnitude = (Sint16)(((low_frequency_rumble / 2) + (high_frequency_rumble / 2)) / 2);
if (!device) {
if (device == NULL) {
return SDL_SetError("Rumble failed, device disconnected");
}
@ -934,7 +932,7 @@ DARWIN_JoystickGetCapabilities(SDL_Joystick *joystick)
recDevice *device = joystick->hwdata;
Uint32 result = 0;
if (!device) {
if (device == NULL) {
return 0;
}
@ -971,7 +969,7 @@ DARWIN_JoystickUpdate(SDL_Joystick *joystick)
SInt32 value, range;
int i, goodRead = SDL_FALSE;
if (!device) {
if (device == NULL) {
return;
}

View file

@ -77,11 +77,11 @@ Emscripten_JoyStickConnected(int eventType, const EmscriptenGamepadEvent *gamepa
item->timestamp = gamepadEvent->timestamp;
for( i = 0; i < item->naxes; i++) {
for ( i = 0; i < item->naxes; i++) {
item->axis[i] = gamepadEvent->axis[i];
}
for( i = 0; i < item->nbuttons; i++) {
for ( i = 0; i < item->nbuttons; i++) {
item->analogButton[i] = gamepadEvent->analogButton[i];
item->digitalButton[i] = gamepadEvent->digitalButton[i];
}
@ -199,7 +199,7 @@ EMSCRIPTEN_JoystickInit(void)
/* handle already connected gamepads */
if (numjs > 0) {
for(i = 0; i < numjs; i++) {
for (i = 0; i < numjs; i++) {
retval = emscripten_get_gamepad_status(i, &gamepadState);
if (retval == EMSCRIPTEN_RESULT_SUCCESS) {
Emscripten_JoyStickConnected(EMSCRIPTEN_EVENT_GAMEPADCONNECTED,
@ -213,7 +213,7 @@ EMSCRIPTEN_JoystickInit(void)
0,
Emscripten_JoyStickConnected);
if(retval != EMSCRIPTEN_RESULT_SUCCESS) {
if (retval != EMSCRIPTEN_RESULT_SUCCESS) {
EMSCRIPTEN_JoystickQuit();
return SDL_SetError("Could not set gamepad connect callback");
}
@ -221,7 +221,7 @@ EMSCRIPTEN_JoystickInit(void)
retval = emscripten_set_gamepaddisconnected_callback(NULL,
0,
Emscripten_JoyStickDisconnected);
if(retval != EMSCRIPTEN_RESULT_SUCCESS) {
if (retval != EMSCRIPTEN_RESULT_SUCCESS) {
EMSCRIPTEN_JoystickQuit();
return SDL_SetError("Could not set gamepad disconnect callback");
}
@ -332,7 +332,7 @@ EMSCRIPTEN_JoystickOpen(SDL_Joystick *joystick, int device_index)
joystick->nbuttons = item->nbuttons;
joystick->naxes = item->naxes;
return (0);
return 0;
}
/* Function to update the state of a joystick - called as a device poll.
@ -351,10 +351,10 @@ EMSCRIPTEN_JoystickUpdate(SDL_Joystick *joystick)
if (item) {
result = emscripten_get_gamepad_status(item->index, &gamepadState);
if( result == EMSCRIPTEN_RESULT_SUCCESS) {
if(gamepadState.timestamp == 0 || gamepadState.timestamp != item->timestamp) {
for(i = 0; i < item->nbuttons; i++) {
if(item->digitalButton[i] != gamepadState.digitalButton[i]) {
if ( result == EMSCRIPTEN_RESULT_SUCCESS) {
if (gamepadState.timestamp == 0 || gamepadState.timestamp != item->timestamp) {
for (i = 0; i < item->nbuttons; i++) {
if (item->digitalButton[i] != gamepadState.digitalButton[i]) {
buttonState = gamepadState.digitalButton[i]? SDL_PRESSED: SDL_RELEASED;
SDL_PrivateJoystickButton(item->joystick, i, buttonState);
}
@ -364,8 +364,8 @@ EMSCRIPTEN_JoystickUpdate(SDL_Joystick *joystick)
item->digitalButton[i] = gamepadState.digitalButton[i];
}
for(i = 0; i < item->naxes; i++) {
if(item->axis[i] != gamepadState.axis[i]) {
for (i = 0; i < item->naxes; i++) {
if (item->axis[i] != gamepadState.axis[i]) {
/* do we need to do conversion? */
SDL_PrivateJoystickAxis(item->joystick, i,
(Sint16) (32767.*gamepadState.axis[i]));

View file

@ -68,8 +68,7 @@ extern "C"
numjoysticks = 0;
SDL_memset(SDL_joyport, 0, (sizeof SDL_joyport));
SDL_memset(SDL_joyname, 0, (sizeof SDL_joyname));
for (i = 0; (numjoysticks < MAX_JOYSTICKS) && (i < nports); ++i)
{
for (i = 0; (numjoysticks < MAX_JOYSTICKS) && (i < nports); ++i) {
if (joystick.GetDeviceName(i, name) == B_OK) {
if (joystick.Open(name) != B_ERROR) {
BString stick_name;

View file

@ -146,7 +146,7 @@ HIDAPI_DriverGameCube_InitDevice(SDL_HIDAPI_Device *device)
#endif
ctx = (SDL_DriverGameCube_Context *)SDL_calloc(1, sizeof(*ctx));
if (!ctx) {
if (ctx == NULL) {
SDL_OutOfMemory();
return SDL_FALSE;
}
@ -258,7 +258,7 @@ HIDAPI_DriverGameCube_HandleJoystickPacket(SDL_HIDAPI_Device *device, SDL_Driver
}
joystick = SDL_JoystickFromInstanceID(ctx->joysticks[i]);
if (!joystick) {
if (joystick == NULL) {
/* Hasn't been opened yet, skip */
return;
}

View file

@ -66,9 +66,7 @@ HIDAPI_DriverLuna_UnregisterHints(SDL_HintCallback callback, void *userdata)
static SDL_bool
HIDAPI_DriverLuna_IsEnabled(void)
{
return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_LUNA,
SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI,
SDL_HIDAPI_DEFAULT));
return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_LUNA, SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT));
}
static SDL_bool
@ -83,7 +81,7 @@ HIDAPI_DriverLuna_InitDevice(SDL_HIDAPI_Device *device)
SDL_DriverLuna_Context *ctx;
ctx = (SDL_DriverLuna_Context *)SDL_calloc(1, sizeof(*ctx));
if (!ctx) {
if (ctx == NULL) {
SDL_OutOfMemory();
return SDL_FALSE;
}
@ -289,14 +287,11 @@ HIDAPI_DriverLuna_HandleBluetoothStatePacket(SDL_Joystick *joystick, SDL_DriverL
int level = data[1] * 100 / 0xFF;
if (level == 0) {
SDL_PrivateJoystickBatteryLevel(joystick, SDL_JOYSTICK_POWER_EMPTY);
}
else if (level <= 20) {
} else if (level <= 20) {
SDL_PrivateJoystickBatteryLevel(joystick, SDL_JOYSTICK_POWER_LOW);
}
else if (level <= 70) {
} else if (level <= 70) {
SDL_PrivateJoystickBatteryLevel(joystick, SDL_JOYSTICK_POWER_MEDIUM);
}
else {
} else {
SDL_PrivateJoystickBatteryLevel(joystick, SDL_JOYSTICK_POWER_FULL);
}
@ -416,7 +411,7 @@ HIDAPI_DriverLuna_UpdateDevice(SDL_HIDAPI_Device *device)
#ifdef DEBUG_LUNA_PROTOCOL
HIDAPI_DumpPacket("Amazon Luna packet: size = %d", data, size);
#endif
if (!joystick) {
if (joystick == NULL) {
continue;
}
@ -434,7 +429,7 @@ HIDAPI_DriverLuna_UpdateDevice(SDL_HIDAPI_Device *device)
/* Read error, device is disconnected */
HIDAPI_JoystickDisconnected(device, device->joysticks[0]);
}
return (size >= 0);
return size >= 0;
}
static void

View file

@ -145,7 +145,7 @@ HIDAPI_DriverPS3_InitDevice(SDL_HIDAPI_Device *device)
}
ctx = (SDL_DriverPS3_Context *)SDL_calloc(1, sizeof(*ctx));
if (!ctx) {
if (ctx == NULL) {
SDL_OutOfMemory();
return SDL_FALSE;
}
@ -228,7 +228,7 @@ HIDAPI_DriverPS3_SetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_JoystickID
{
SDL_DriverPS3_Context *ctx = (SDL_DriverPS3_Context *)device->context;
if (!ctx) {
if (ctx == NULL) {
return;
}
@ -511,7 +511,7 @@ HIDAPI_DriverPS3_UpdateDevice(SDL_HIDAPI_Device *device)
#ifdef DEBUG_PS3_PROTOCOL
HIDAPI_DumpPacket("PS3 packet: size = %d", data, size);
#endif
if (!joystick) {
if (joystick == NULL) {
continue;
}
@ -553,7 +553,7 @@ HIDAPI_DriverPS3_UpdateDevice(SDL_HIDAPI_Device *device)
/* Read error, device is disconnected */
HIDAPI_JoystickDisconnected(device, device->joysticks[0]);
}
return (size >= 0);
return size >= 0;
}
static void
@ -634,7 +634,7 @@ HIDAPI_DriverPS3ThirdParty_InitDevice(SDL_HIDAPI_Device *device)
SDL_DriverPS3_Context *ctx;
ctx = (SDL_DriverPS3_Context *)SDL_calloc(1, sizeof(*ctx));
if (!ctx) {
if (ctx == NULL) {
SDL_OutOfMemory();
return SDL_FALSE;
}
@ -842,7 +842,7 @@ HIDAPI_DriverPS3ThirdParty_UpdateDevice(SDL_HIDAPI_Device *device)
#ifdef DEBUG_PS3_PROTOCOL
HIDAPI_DumpPacket("PS3 packet: size = %d", data, size);
#endif
if (!joystick) {
if (joystick == NULL) {
continue;
}
@ -859,7 +859,7 @@ HIDAPI_DriverPS3ThirdParty_UpdateDevice(SDL_HIDAPI_Device *device)
/* Read error, device is disconnected */
HIDAPI_JoystickDisconnected(device, device->joysticks[0]);
}
return (size >= 0);
return size >= 0;
}
static void

View file

@ -171,9 +171,7 @@ HIDAPI_DriverPS4_UnregisterHints(SDL_HintCallback callback, void *userdata)
static SDL_bool
HIDAPI_DriverPS4_IsEnabled(void)
{
return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_PS4,
SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI,
SDL_HIDAPI_DEFAULT));
return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_PS4, SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT));
}
static int ReadFeatureReport(SDL_hid_device *dev, Uint8 report_id, Uint8 *report, size_t length)
@ -248,7 +246,7 @@ HIDAPI_DriverPS4_InitDevice(SDL_HIDAPI_Device *device)
SDL_JoystickType joystick_type = SDL_JOYSTICK_TYPE_GAMECONTROLLER;
ctx = (SDL_DriverPS4_Context *)SDL_calloc(1, sizeof(*ctx));
if (!ctx) {
if (ctx == NULL) {
SDL_OutOfMemory();
return SDL_FALSE;
}
@ -425,7 +423,7 @@ HIDAPI_DriverPS4_LoadCalibrationData(SDL_HIDAPI_Device *device)
return;
}
for( tries = 0; tries < 5; ++tries ) {
for ( tries = 0; tries < 5; ++tries ) {
/* For Bluetooth controllers, this report switches them into advanced report mode */
size = ReadFeatureReport(device->dev, k_ePS4FeatureReportIdGyroCalibration_USB, data, sizeof(data));
if (size < 35) {
@ -1076,7 +1074,7 @@ HIDAPI_DriverPS4_UpdateDevice(SDL_HIDAPI_Device *device)
++packet_count;
ctx->last_packet = now;
if (!joystick) {
if (joystick == NULL) {
continue;
}
@ -1150,7 +1148,7 @@ HIDAPI_DriverPS4_UpdateDevice(SDL_HIDAPI_Device *device)
/* Read error, device is disconnected */
HIDAPI_JoystickDisconnected(device, device->joysticks[0]);
}
return (size >= 0);
return size >= 0;
}
static void

View file

@ -254,9 +254,7 @@ HIDAPI_DriverPS5_UnregisterHints(SDL_HintCallback callback, void *userdata)
static SDL_bool
HIDAPI_DriverPS5_IsEnabled(void)
{
return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_PS5,
SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI,
SDL_HIDAPI_DEFAULT));
return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_PS5, SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT));
}
static int ReadFeatureReport(SDL_hid_device *dev, Uint8 report_id, Uint8 *report, size_t length)
@ -349,7 +347,7 @@ HIDAPI_DriverPS5_InitDevice(SDL_HIDAPI_Device *device)
SDL_JoystickType joystick_type = SDL_JOYSTICK_TYPE_GAMECONTROLLER;
ctx = (SDL_DriverPS5_Context *)SDL_calloc(1, sizeof(*ctx));
if (!ctx) {
if (ctx == NULL) {
SDL_OutOfMemory();
return SDL_FALSE;
}
@ -1354,7 +1352,7 @@ HIDAPI_DriverPS5_UpdateDevice(SDL_HIDAPI_Device *device)
++packet_count;
ctx->last_packet = now;
if (!joystick) {
if (joystick == NULL) {
continue;
}
@ -1414,7 +1412,7 @@ HIDAPI_DriverPS5_UpdateDevice(SDL_HIDAPI_Device *device)
/* Read error, device is disconnected */
HIDAPI_JoystickDisconnected(device, device->joysticks[0]);
}
return (size >= 0);
return size >= 0;
}
static void

View file

@ -215,7 +215,7 @@ int SDL_HIDAPI_SendRumbleWithCallbackAndUnlock(SDL_HIDAPI_Device *device, const
}
request = (SDL_HIDAPI_RumbleRequest *)SDL_calloc(1, sizeof(*request));
if (!request) {
if (request == NULL) {
SDL_HIDAPI_UnlockRumble();
return SDL_OutOfMemory();
}

View file

@ -107,9 +107,7 @@ HIDAPI_DriverShield_UnregisterHints(SDL_HintCallback callback, void *userdata)
static SDL_bool
HIDAPI_DriverShield_IsEnabled(void)
{
return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_SHIELD,
SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI,
SDL_HIDAPI_DEFAULT));
return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_SHIELD, SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT));
}
static SDL_bool
@ -124,7 +122,7 @@ HIDAPI_DriverShield_InitDevice(SDL_HIDAPI_Device *device)
SDL_DriverShield_Context *ctx;
ctx = (SDL_DriverShield_Context *)SDL_calloc(1, sizeof(*ctx));
if (!ctx) {
if (ctx == NULL) {
SDL_OutOfMemory();
return SDL_FALSE;
}
@ -508,7 +506,7 @@ HIDAPI_DriverShield_UpdateDevice(SDL_HIDAPI_Device *device)
/* Byte 0 is HID report ID */
switch (data[0]) {
case k_ShieldReportIdControllerState:
if (!joystick) {
if (joystick == NULL) {
break;
}
if (size == 16) {
@ -518,7 +516,7 @@ HIDAPI_DriverShield_UpdateDevice(SDL_HIDAPI_Device *device)
}
break;
case k_ShieldReportIdControllerTouch:
if (!joystick) {
if (joystick == NULL) {
break;
}
HIDAPI_DriverShield_HandleTouchPacketV103(joystick, ctx, data, size);
@ -582,7 +580,7 @@ HIDAPI_DriverShield_UpdateDevice(SDL_HIDAPI_Device *device)
/* Read error, device is disconnected */
HIDAPI_JoystickDisconnected(device, device->joysticks[0]);
}
return (size >= 0);
return size >= 0;
}
static void

View file

@ -62,9 +62,7 @@ HIDAPI_DriverStadia_UnregisterHints(SDL_HintCallback callback, void *userdata)
static SDL_bool
HIDAPI_DriverStadia_IsEnabled(void)
{
return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_STADIA,
SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI,
SDL_HIDAPI_DEFAULT));
return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_STADIA, SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT));
}
static SDL_bool
@ -79,7 +77,7 @@ HIDAPI_DriverStadia_InitDevice(SDL_HIDAPI_Device *device)
SDL_DriverStadia_Context *ctx;
ctx = (SDL_DriverStadia_Context *)SDL_calloc(1, sizeof(*ctx));
if (!ctx) {
if (ctx == NULL) {
SDL_OutOfMemory();
return SDL_FALSE;
}
@ -283,7 +281,7 @@ HIDAPI_DriverStadia_UpdateDevice(SDL_HIDAPI_Device *device)
#ifdef DEBUG_STADIA_PROTOCOL
HIDAPI_DumpPacket("Google Stadia packet: size = %d", data, size);
#endif
if (!joystick) {
if (joystick == NULL) {
continue;
}
@ -294,7 +292,7 @@ HIDAPI_DriverStadia_UpdateDevice(SDL_HIDAPI_Device *device)
/* Read error, device is disconnected */
HIDAPI_JoystickDisconnected(device, device->joysticks[0]);
}
return (size >= 0);
return size >= 0;
}
static void

View file

@ -203,8 +203,9 @@ static uint8_t GetSegmentHeader( int nSegmentNumber, bool bLastPacket )
{
uint8_t header = REPORT_SEGMENT_DATA_FLAG;
header |= nSegmentNumber;
if ( bLastPacket )
if (bLastPacket) {
header |= REPORT_SEGMENT_LAST_FLAG;
}
return header;
}
@ -212,8 +213,9 @@ static uint8_t GetSegmentHeader( int nSegmentNumber, bool bLastPacket )
static void hexdump( const uint8_t *ptr, int len )
{
int i;
for ( i = 0; i < len ; ++i )
for (i = 0; i < len; ++i) {
printf("%02x ", ptr[i]);
}
printf("\n");
}
@ -236,21 +238,18 @@ static void InitializeSteamControllerPacketAssembler( SteamControllerPacketAssem
// Complete packet size on completion
static int WriteSegmentToSteamControllerPacketAssembler( SteamControllerPacketAssembler *pAssembler, const uint8_t *pSegment, int nSegmentLength )
{
if ( pAssembler->bIsBle )
{
if ( pAssembler->bIsBle ) {
uint8_t uSegmentHeader = pSegment[ 1 ];
int nSegmentNumber = uSegmentHeader & 0x07;
HEXDUMP( pSegment, nSegmentLength );
if ( pSegment[ 0 ] != BLE_REPORT_NUMBER )
{
if ( pSegment[ 0 ] != BLE_REPORT_NUMBER ) {
// We may get keyboard/mouse input events until controller stops sending them
return 0;
}
if ( nSegmentLength != MAX_REPORT_SEGMENT_SIZE )
{
if ( nSegmentLength != MAX_REPORT_SEGMENT_SIZE ) {
printf( "Bad segment size! %d\n", (int)nSegmentLength );
hexdump( pSegment, nSegmentLength );
ResetSteamControllerPacketAssembler( pAssembler );
@ -259,18 +258,15 @@ static int WriteSegmentToSteamControllerPacketAssembler( SteamControllerPacketAs
DPRINTF("GOT PACKET HEADER = 0x%x\n", uSegmentHeader);
if ( ( uSegmentHeader & REPORT_SEGMENT_DATA_FLAG ) == 0 )
{
if ( ( uSegmentHeader & REPORT_SEGMENT_DATA_FLAG ) == 0 ) {
// We get empty segments, just ignore them
return 0;
}
if ( nSegmentNumber != pAssembler->nExpectedSegmentNumber )
{
if ( nSegmentNumber != pAssembler->nExpectedSegmentNumber ) {
ResetSteamControllerPacketAssembler( pAssembler );
if ( nSegmentNumber )
{
if ( nSegmentNumber ) {
// This happens occasionally
DPRINTF("Bad segment number, got %d, expected %d\n",
nSegmentNumber, pAssembler->nExpectedSegmentNumber );
@ -282,16 +278,13 @@ static int WriteSegmentToSteamControllerPacketAssembler( SteamControllerPacketAs
pSegment + 2, // ignore header and report number
MAX_REPORT_SEGMENT_PAYLOAD_SIZE );
if ( uSegmentHeader & REPORT_SEGMENT_LAST_FLAG )
{
if ( uSegmentHeader & REPORT_SEGMENT_LAST_FLAG ) {
pAssembler->nExpectedSegmentNumber = 0;
return ( nSegmentNumber + 1 ) * MAX_REPORT_SEGMENT_PAYLOAD_SIZE;
}
pAssembler->nExpectedSegmentNumber++;
}
else
{
} else {
// Just pass through
SDL_memcpy( pAssembler->uBuffer,
pSegment,
@ -311,20 +304,19 @@ static int SetFeatureReport( SDL_hid_device *dev, unsigned char uBuffer[65], int
DPRINTF("SetFeatureReport %p %p %d\n", dev, uBuffer, nActualDataLen);
if ( bBle )
{
if ( bBle ) {
int nSegmentNumber = 0;
uint8_t uPacketBuffer[ MAX_REPORT_SEGMENT_SIZE ];
unsigned char *pBufferPtr = uBuffer + 1;
if ( nActualDataLen < 1 )
if (nActualDataLen < 1) {
return -1;
}
// Skip report number in data
nActualDataLen--;
while ( nActualDataLen > 0 )
{
while ( nActualDataLen > 0 ) {
int nBytesInPacket = nActualDataLen > MAX_REPORT_SEGMENT_PAYLOAD_SIZE ? MAX_REPORT_SEGMENT_PAYLOAD_SIZE : nActualDataLen;
nActualDataLen -= nBytesInPacket;
@ -353,8 +345,7 @@ static int GetFeatureReport( SDL_hid_device *dev, unsigned char uBuffer[65] )
DPRINTF("GetFeatureReport( %p %p )\n", dev, uBuffer );
if ( bBle )
{
if ( bBle ) {
int nRetries = 0;
uint8_t uSegmentBuffer[ MAX_REPORT_SEGMENT_SIZE + 1 ];
uint8_t ucBytesToRead = MAX_REPORT_SEGMENT_SIZE;
@ -371,8 +362,7 @@ static int GetFeatureReport( SDL_hid_device *dev, unsigned char uBuffer[65] )
++ucDataStartOffset;
#endif
while( nRetries < BLE_MAX_READ_RETRIES )
{
while ( nRetries < BLE_MAX_READ_RETRIES ) {
SDL_memset( uSegmentBuffer, 0, sizeof( uSegmentBuffer ) );
uSegmentBuffer[ 0 ] = BLE_REPORT_NUMBER;
nRet = SDL_hid_get_feature_report( dev, uSegmentBuffer, ucBytesToRead );
@ -386,14 +376,12 @@ static int GetFeatureReport( SDL_hid_device *dev, unsigned char uBuffer[65] )
else
nRetries++;
if ( nRet > 0 )
{
if ( nRet > 0 ) {
int nPacketLength = WriteSegmentToSteamControllerPacketAssembler( &assembler,
uSegmentBuffer + ucDataStartOffset,
nRet - ucDataStartOffset );
if ( nPacketLength > 0 && nPacketLength < 65 )
{
if ( nPacketLength > 0 && nPacketLength < 65 ) {
// Leave space for "report number"
uBuffer[ 0 ] = 0;
SDL_memcpy( uBuffer + 1, assembler.uBuffer, nPacketLength );
@ -416,14 +404,16 @@ static int ReadResponse( SDL_hid_device *dev, uint8_t uBuffer[65], int nExpected
DPRINTF("ReadResponse( %p %p %d )\n", dev, uBuffer, nExpectedResponse );
if ( nRet < 0 )
if (nRet < 0) {
return nRet;
}
DPRINTF("ReadResponse got %d bytes of data: ", nRet );
HEXDUMP( uBuffer, nRet );
if ( uBuffer[1] != nExpectedResponse )
if (uBuffer[1] != nExpectedResponse) {
return -1;
}
return nRet;
}
@ -447,35 +437,34 @@ static bool ResetSteamController( SDL_hid_device *dev, bool bSuppressErrorSpew,
buf[0] = 0;
buf[1] = ID_GET_ATTRIBUTES_VALUES;
res = SetFeatureReport( dev, buf, 2 );
if ( res < 0 )
{
if ( !bSuppressErrorSpew )
printf( "GET_ATTRIBUTES_VALUES failed for controller %p\n", dev );
if ( res < 0 ) {
if (!bSuppressErrorSpew) {
printf("GET_ATTRIBUTES_VALUES failed for controller %p\n", dev);
}
return false;
}
// Retrieve GET_ATTRIBUTES_VALUES result
// Wireless controller endpoints without a connected controller will return nAttrs == 0
res = ReadResponse( dev, buf, ID_GET_ATTRIBUTES_VALUES );
if ( res < 0 || buf[1] != ID_GET_ATTRIBUTES_VALUES )
{
if ( res < 0 || buf[1] != ID_GET_ATTRIBUTES_VALUES ) {
HEXDUMP(buf, res);
if ( !bSuppressErrorSpew )
printf( "Bad GET_ATTRIBUTES_VALUES response for controller %p\n", dev );
if (!bSuppressErrorSpew) {
printf("Bad GET_ATTRIBUTES_VALUES response for controller %p\n", dev);
}
return false;
}
nAttributesLength = buf[ 2 ];
if ( nAttributesLength > res )
{
if ( !bSuppressErrorSpew )
printf( "Bad GET_ATTRIBUTES_VALUES response for controller %p\n", dev );
if ( nAttributesLength > res ) {
if (!bSuppressErrorSpew) {
printf("Bad GET_ATTRIBUTES_VALUES response for controller %p\n", dev);
}
return false;
}
msg = (FeatureReportMsg *)&buf[1];
for ( i = 0; i < (int)msg->header.length / sizeof( ControllerAttribute ); ++i )
{
for ( i = 0; i < (int)msg->header.length / sizeof( ControllerAttribute ); ++i ) {
uint8_t unAttribute = msg->payload.getAttributes.attributes[i].attributeTag;
uint32_t unValue = msg->payload.getAttributes.attributes[i].attributeValue;
@ -494,8 +483,7 @@ static bool ResetSteamController( SDL_hid_device *dev, bool bSuppressErrorSpew,
break;
}
}
if ( punUpdateRateUS )
{
if ( punUpdateRateUS ) {
*punUpdateRateUS = unUpdateRateUS;
}
@ -503,10 +491,10 @@ static bool ResetSteamController( SDL_hid_device *dev, bool bSuppressErrorSpew,
buf[0] = 0;
buf[1] = ID_CLEAR_DIGITAL_MAPPINGS;
res = SetFeatureReport( dev, buf, 2 );
if ( res < 0 )
{
if ( !bSuppressErrorSpew )
printf( "CLEAR_DIGITAL_MAPPINGS failed for controller %p\n", dev );
if ( res < 0 ) {
if (!bSuppressErrorSpew) {
printf("CLEAR_DIGITAL_MAPPINGS failed for controller %p\n", dev);
}
return false;
}
@ -515,10 +503,10 @@ static bool ResetSteamController( SDL_hid_device *dev, bool bSuppressErrorSpew,
buf[1] = ID_LOAD_DEFAULT_SETTINGS;
buf[2] = 0;
res = SetFeatureReport( dev, buf, 3 );
if ( res < 0 )
{
if ( !bSuppressErrorSpew )
printf( "LOAD_DEFAULT_SETTINGS failed for controller %p\n", dev );
if ( res < 0 ) {
if (!bSuppressErrorSpew) {
printf("LOAD_DEFAULT_SETTINGS failed for controller %p\n", dev);
}
return false;
}
@ -545,10 +533,10 @@ buf[3+nSettings*3+2] = ((uint16_t)VALUE)>>8; \
buf[2] = nSettings*3;
res = SetFeatureReport( dev, buf, 3+nSettings*3 );
if ( res < 0 )
{
if ( !bSuppressErrorSpew )
printf( "SET_SETTINGS failed for controller %p\n", dev );
if ( res < 0 ) {
if (!bSuppressErrorSpew) {
printf("SET_SETTINGS failed for controller %p\n", dev);
}
return false;
}
@ -556,37 +544,32 @@ buf[3+nSettings*3+2] = ((uint16_t)VALUE)>>8; \
// Wait for ID_CLEAR_DIGITAL_MAPPINGS to be processed on the controller
bool bMappingsCleared = false;
int iRetry;
for ( iRetry = 0; iRetry < 2; ++iRetry )
{
for ( iRetry = 0; iRetry < 2; ++iRetry ) {
SDL_memset( buf, 0, 65 );
buf[1] = ID_GET_DIGITAL_MAPPINGS;
buf[2] = 1; // one byte - requesting from index 0
buf[3] = 0;
res = SetFeatureReport( dev, buf, 4 );
if ( res < 0 )
{
if ( res < 0 ) {
printf( "GET_DIGITAL_MAPPINGS failed for controller %p\n", dev );
return false;
}
res = ReadResponse( dev, buf, ID_GET_DIGITAL_MAPPINGS );
if ( res < 0 || buf[1] != ID_GET_DIGITAL_MAPPINGS )
{
if ( res < 0 || buf[1] != ID_GET_DIGITAL_MAPPINGS ) {
printf( "Bad GET_DIGITAL_MAPPINGS response for controller %p\n", dev );
return false;
}
// If the length of the digital mappings result is not 1 (index byte, no mappings) then clearing hasn't executed
if ( buf[2] == 1 && buf[3] == 0xFF )
{
if ( buf[2] == 1 && buf[3] == 0xFF ) {
bMappingsCleared = true;
break;
}
usleep( CONTROLLER_CONFIGURATION_DELAY_US );
}
if ( !bMappingsCleared && !bSuppressErrorSpew )
{
if ( !bMappingsCleared && !bSuppressErrorSpew ) {
printf( "Warning: CLEAR_DIGITAL_MAPPINGS never completed for controller %p\n", dev );
}
@ -602,10 +585,10 @@ buf[3+nSettings*3+2] = ((uint16_t)VALUE)>>8; \
buf[8] = MOUSE_BTN_RIGHT;
res = SetFeatureReport( dev, buf, 9 );
if ( res < 0 )
{
if ( !bSuppressErrorSpew )
printf( "SET_DIGITAL_MAPPINGS failed for controller %p\n", dev );
if ( res < 0 ) {
if (!bSuppressErrorSpew) {
printf("SET_DIGITAL_MAPPINGS failed for controller %p\n", dev);
}
return false;
}
#endif // ENABLE_MOUSE_MODE
@ -659,12 +642,9 @@ static void CloseSteamController( SDL_hid_device *dev )
//---------------------------------------------------------------------------
static float RemapValClamped( float val, float A, float B, float C, float D)
{
if ( A == B )
{
if ( A == B ) {
return ( val - B ) >= 0.0f ? D : C;
}
else
{
} else {
float cVal = (val - A) / (B - A);
cVal = clamp( cVal, 0.0f, 1.0f );
@ -717,65 +697,52 @@ static void FormatStatePacketUntilGyro( SteamControllerStateInternal_t *pState,
pState->ulButtons &= ~0xFFFF000000LL;
// The firmware uses this bit to tell us what kind of data is packed into the left two axises
if (pStatePacket->ButtonTriggerData.ulButtons & STEAM_LEFTPAD_FINGERDOWN_MASK)
{
if (pStatePacket->ButtonTriggerData.ulButtons & STEAM_LEFTPAD_FINGERDOWN_MASK) {
// Finger-down bit not set; "left pad" is actually trackpad
pState->sLeftPadX = pState->sPrevLeftPad[0] = pStatePacket->sLeftPadX;
pState->sLeftPadY = pState->sPrevLeftPad[1] = pStatePacket->sLeftPadY;
if (pStatePacket->ButtonTriggerData.ulButtons & STEAM_LEFTPAD_AND_JOYSTICK_MASK)
{
if (pStatePacket->ButtonTriggerData.ulButtons & STEAM_LEFTPAD_AND_JOYSTICK_MASK) {
// The controller is interleaving both stick and pad data, both are active
pState->sLeftStickX = pState->sPrevLeftStick[0];
pState->sLeftStickY = pState->sPrevLeftStick[1];
}
else
{
} else {
// The stick is not active
pState->sPrevLeftStick[0] = 0;
pState->sPrevLeftStick[1] = 0;
}
}
else
{
} else {
// Finger-down bit not set; "left pad" is actually joystick
// XXX there's a firmware bug where sometimes padX is 0 and padY is a large number (acutally the battery voltage)
// If that happens skip this packet and report last frames stick
/*
if ( m_eControllerType == k_eControllerType_SteamControllerV2 && pStatePacket->sLeftPadY > 900 )
{
if ( m_eControllerType == k_eControllerType_SteamControllerV2 && pStatePacket->sLeftPadY > 900 ) {
pState->sLeftStickX = pState->sPrevLeftStick[0];
pState->sLeftStickY = pState->sPrevLeftStick[1];
}
else
} else
*/
{
pState->sPrevLeftStick[0] = pState->sLeftStickX = pStatePacket->sLeftPadX;
pState->sPrevLeftStick[1] = pState->sLeftStickY = pStatePacket->sLeftPadY;
}
/*
if (m_eControllerType == k_eControllerType_SteamControllerV2)
{
if (m_eControllerType == k_eControllerType_SteamControllerV2) {
UpdateV2JoystickCap(&state);
}
*/
if (pStatePacket->ButtonTriggerData.ulButtons & STEAM_LEFTPAD_AND_JOYSTICK_MASK)
{
if (pStatePacket->ButtonTriggerData.ulButtons & STEAM_LEFTPAD_AND_JOYSTICK_MASK) {
// The controller is interleaving both stick and pad data, both are active
pState->sLeftPadX = pState->sPrevLeftPad[0];
pState->sLeftPadY = pState->sPrevLeftPad[1];
}
else
{
} else {
// The trackpad is not active
pState->sPrevLeftPad[0] = 0;
pState->sPrevLeftPad[1] = 0;
// Old controllers send trackpad click for joystick button when trackpad is not active
if (pState->ulButtons & STEAM_BUTTON_LEFTPAD_CLICKED_MASK)
{
if (pState->ulButtons & STEAM_BUTTON_LEFTPAD_CLICKED_MASK) {
pState->ulButtons &= ~STEAM_BUTTON_LEFTPAD_CLICKED_MASK;
pState->ulButtons |= STEAM_JOYSTICK_BUTTON_MASK;
}
@ -784,8 +751,9 @@ static void FormatStatePacketUntilGyro( SteamControllerStateInternal_t *pState,
// Fingerdown bit indicates if the packed left axis data was joystick or pad,
// but if we are interleaving both, the left finger is definitely on the pad.
if (pStatePacket->ButtonTriggerData.ulButtons & STEAM_LEFTPAD_AND_JOYSTICK_MASK)
if (pStatePacket->ButtonTriggerData.ulButtons & STEAM_LEFTPAD_AND_JOYSTICK_MASK) {
pState->ulButtons |= STEAM_LEFTPAD_FINGERDOWN_MASK;
}
pState->sRightPadX = pStatePacket->sRightPadX;
pState->sRightPadY = pStatePacket->sRightPadY;
@ -831,35 +799,30 @@ static bool UpdateBLESteamControllerState( const uint8_t *pData, int nDataSize,
pState->unPacketNum++;
ucOptionDataMask = ( *pData++ & 0xF0 );
ucOptionDataMask |= (uint32_t)(*pData++) << 8;
if ( ucOptionDataMask & k_EBLEButtonChunk1 )
{
if ( ucOptionDataMask & k_EBLEButtonChunk1 ) {
SDL_memcpy( &pState->ulButtons, pData, 3 );
pData += 3;
}
if ( ucOptionDataMask & k_EBLEButtonChunk2 )
{
if ( ucOptionDataMask & k_EBLEButtonChunk2 ) {
// The middle 2 bytes of the button bits over the wire are triggers when over the wire and non-SC buttons in the internal controller state packet
pState->sTriggerL = (unsigned short)RemapValClamped( (float)(( pData[ 0 ] << 7 ) | pData[ 0 ]), 0, STEAMCONTROLLER_TRIGGER_MAX_ANALOG, 0, SDL_MAX_SINT16 );
pState->sTriggerR = (unsigned short)RemapValClamped( (float)(( pData[ 1 ] << 7 ) | pData[ 1 ]), 0, STEAMCONTROLLER_TRIGGER_MAX_ANALOG, 0, SDL_MAX_SINT16 );
pData += 2;
}
if ( ucOptionDataMask & k_EBLEButtonChunk3 )
{
if ( ucOptionDataMask & k_EBLEButtonChunk3 ) {
uint8_t *pButtonByte = (uint8_t *)&pState->ulButtons;
pButtonByte[ 5 ] = *pData++;
pButtonByte[ 6 ] = *pData++;
pButtonByte[ 7 ] = *pData++;
}
if ( ucOptionDataMask & k_EBLELeftJoystickChunk )
{
if ( ucOptionDataMask & k_EBLELeftJoystickChunk ) {
// This doesn't handle any of the special headcrab stuff for raw joystick which is OK for now since that FW doesn't support
// this protocol yet either
int nLength = sizeof( pState->sLeftStickX ) + sizeof( pState->sLeftStickY );
SDL_memcpy( &pState->sLeftStickX, pData, nLength );
pData += nLength;
}
if ( ucOptionDataMask & k_EBLELeftTrackpadChunk )
{
if ( ucOptionDataMask & k_EBLELeftTrackpadChunk ) {
int nLength = sizeof( pState->sLeftPadX ) + sizeof( pState->sLeftPadY );
int nPadOffset;
SDL_memcpy( &pState->sLeftPadX, pData, nLength );
@ -873,8 +836,7 @@ static bool UpdateBLESteamControllerState( const uint8_t *pData, int nDataSize,
pState->sLeftPadY = clamp( pState->sLeftPadY + nPadOffset, SDL_MIN_SINT16, SDL_MAX_SINT16 );
pData += nLength;
}
if ( ucOptionDataMask & k_EBLERightTrackpadChunk )
{
if ( ucOptionDataMask & k_EBLERightTrackpadChunk ) {
int nLength = sizeof( pState->sRightPadX ) + sizeof( pState->sRightPadY );
int nPadOffset = 0;
@ -890,20 +852,17 @@ static bool UpdateBLESteamControllerState( const uint8_t *pData, int nDataSize,
pState->sRightPadY = clamp( pState->sRightPadY + nPadOffset, SDL_MIN_SINT16, SDL_MAX_SINT16 );
pData += nLength;
}
if ( ucOptionDataMask & k_EBLEIMUAccelChunk )
{
if ( ucOptionDataMask & k_EBLEIMUAccelChunk ) {
int nLength = sizeof( pState->sAccelX ) + sizeof( pState->sAccelY ) + sizeof( pState->sAccelZ );
SDL_memcpy( &pState->sAccelX, pData, nLength );
pData += nLength;
}
if ( ucOptionDataMask & k_EBLEIMUGyroChunk )
{
if ( ucOptionDataMask & k_EBLEIMUGyroChunk ) {
int nLength = sizeof( pState->sAccelX ) + sizeof( pState->sAccelY ) + sizeof( pState->sAccelZ );
SDL_memcpy( &pState->sGyroX, pData, nLength );
pData += nLength;
}
if ( ucOptionDataMask & k_EBLEIMUQuatChunk )
{
if ( ucOptionDataMask & k_EBLEIMUQuatChunk ) {
int nLength = sizeof( pState->sGyroQuatW ) + sizeof( pState->sGyroQuatX ) + sizeof( pState->sGyroQuatY ) + sizeof( pState->sGyroQuatZ );
SDL_memcpy( &pState->sGyroQuatW, pData, nLength );
pData += nLength;
@ -919,10 +878,8 @@ static bool UpdateSteamControllerState( const uint8_t *pData, int nDataSize, Ste
{
ValveInReport_t *pInReport = (ValveInReport_t*)pData;
if ( pInReport->header.unReportVersion != k_ValveInReportMsgVersion )
{
if ( ( pData[ 0 ] & 0x0F ) == k_EBLEReportState )
{
if ( pInReport->header.unReportVersion != k_ValveInReportMsgVersion ) {
if ( ( pData[ 0 ] & 0x0F ) == k_EBLEReportState ) {
return UpdateBLESteamControllerState( pData, nDataSize, pState );
}
return false;
@ -934,13 +891,13 @@ static bool UpdateSteamControllerState( const uint8_t *pData, int nDataSize, Ste
return false;
}
if ( pInReport->header.ucType == ID_CONTROLLER_STATE )
{
if ( pInReport->header.ucType == ID_CONTROLLER_STATE ) {
ValveControllerStatePacket_t *pStatePacket = &pInReport->payload.controllerState;
// No new data to process; indicate that we received a state packet, but otherwise do nothing.
if ( pState->unPacketNum == pStatePacket->unPacketNum )
if (pState->unPacketNum == pStatePacket->unPacketNum) {
return true;
}
FormatStatePacketUntilGyro( pState, pStatePacket );
@ -957,15 +914,14 @@ static bool UpdateSteamControllerState( const uint8_t *pData, int nDataSize, Ste
pState->sGyroY = pStatePacket->sGyroY;
pState->sGyroZ = pStatePacket->sGyroZ;
}
else if ( pInReport->header.ucType == ID_CONTROLLER_BLE_STATE )
{
} else if ( pInReport->header.ucType == ID_CONTROLLER_BLE_STATE ) {
ValveControllerBLEStatePacket_t *pBLEStatePacket = &pInReport->payload.controllerBLEState;
ValveControllerStatePacket_t *pStatePacket = &pInReport->payload.controllerState;
// No new data to process; indicate that we received a state packet, but otherwise do nothing.
if ( pState->unPacketNum == pStatePacket->unPacketNum )
if (pState->unPacketNum == pStatePacket->unPacketNum) {
return true;
}
FormatStatePacketUntilGyro( pState, pStatePacket );
@ -1041,7 +997,7 @@ HIDAPI_DriverSteam_InitDevice(SDL_HIDAPI_Device *device)
SDL_DriverSteam_Context *ctx;
ctx = (SDL_DriverSteam_Context *)SDL_calloc(1, sizeof(*ctx));
if (!ctx) {
if (ctx == NULL) {
SDL_OutOfMemory();
return SDL_FALSE;
}
@ -1171,8 +1127,7 @@ HIDAPI_DriverSteam_UpdateDevice(SDL_HIDAPI_Device *device)
return SDL_FALSE;
}
for (;;)
{
for (;;) {
uint8_t data[128];
int r, nPacketLength;
const Uint8 *pPacket;
@ -1182,7 +1137,7 @@ HIDAPI_DriverSteam_UpdateDevice(SDL_HIDAPI_Device *device)
break;
}
if (!joystick) {
if (joystick == NULL) {
continue;
}

View file

@ -400,9 +400,9 @@ static SDL_bool WritePacket(SDL_DriverSwitch_Context *ctx, void *pBuf, Uint8 ucL
ucLen = (Uint8)unWriteSize;
}
if (ctx->m_bSyncWrite) {
return (SDL_hid_write(ctx->device->dev, (Uint8 *)pBuf, ucLen) >= 0);
return SDL_hid_write(ctx->device->dev, (Uint8 *)pBuf, ucLen) >= 0;
} else {
return (WriteOutput(ctx, (Uint8 *)pBuf, ucLen) >= 0);
return WriteOutput(ctx, (Uint8 *)pBuf, ucLen) >= 0;
}
}
@ -411,7 +411,7 @@ static SDL_bool WriteSubcommand(SDL_DriverSwitch_Context *ctx, ESwitchSubcommand
SwitchSubcommandInputPacket_t *reply = NULL;
int nTries;
for (nTries = 1; !reply && nTries <= ctx->m_nMaxWriteAttempts; ++nTries) {
for (nTries = 1; reply == NULL && nTries <= ctx->m_nMaxWriteAttempts; ++nTries) {
SwitchSubcommandOutputPacket_t commandPacket;
ConstructSubcommand(ctx, ucCommandID, pBuf, ucLen, &commandPacket);
@ -435,7 +435,7 @@ static SDL_bool WriteProprietary(SDL_DriverSwitch_Context *ctx, ESwitchProprieta
for (nTries = 1; nTries <= ctx->m_nMaxWriteAttempts; ++nTries) {
SwitchProprietaryOutputPacket_t packet;
if ((!pBuf && ucLen > 0) || ucLen > sizeof(packet.rgucProprietaryData)) {
if ((pBuf == NULL && ucLen > 0) || ucLen > sizeof(packet.rgucProprietaryData)) {
return SDL_FALSE;
}
@ -596,8 +596,9 @@ static SDL_bool BReadDeviceInfo(SDL_DriverSwitch_Context *ctx)
ctx->m_eControllerType = CalculateControllerType(ctx, (ESwitchDeviceInfoControllerType)status->ucDeviceType);
for (i = 0; i < sizeof (ctx->m_rgucMACAddress); ++i)
ctx->m_rgucMACAddress[i] = status->rgucMACAddress[ sizeof(ctx->m_rgucMACAddress) - i - 1 ];
for (i = 0; i < sizeof(ctx->m_rgucMACAddress); ++i) {
ctx->m_rgucMACAddress[i] = status->rgucMACAddress[sizeof(ctx->m_rgucMACAddress) - i - 1];
}
return SDL_TRUE;
}
@ -776,14 +777,14 @@ static SDL_bool LoadStickCalibration(SDL_DriverSwitch_Context *ctx, Uint8 input_
}
for (stick = 0; stick < 2; ++stick) {
for(axis = 0; axis < 2; ++axis) {
for (axis = 0; axis < 2; ++axis) {
ctx->m_StickExtents[stick].axis[axis].sMin = -(Sint16)(ctx->m_StickCalData[stick].axis[axis].sMin * 0.7f);
ctx->m_StickExtents[stick].axis[axis].sMax = (Sint16)(ctx->m_StickCalData[stick].axis[axis].sMax * 0.7f);
}
}
for (stick = 0; stick < 2; ++stick) {
for(axis = 0; axis < 2; ++axis) {
for (axis = 0; axis < 2; ++axis) {
ctx->m_SimpleStickExtents[stick].axis[axis].sMin = (Sint16)(SDL_MIN_SINT16 * 0.5f);
ctx->m_SimpleStickExtents[stick].axis[axis].sMax = (Sint16)(SDL_MAX_SINT16 * 0.5f);
}
@ -869,7 +870,8 @@ static Sint16 ApplyStickCalibration(SDL_DriverSwitch_Context *ctx, int nStick, i
ctx->m_StickExtents[nStick].axis[nAxis].sMin = sRawValue;
}
return (Sint16)HIDAPI_RemapVal(sRawValue, ctx->m_StickExtents[nStick].axis[nAxis].sMin, ctx->m_StickExtents[nStick].axis[nAxis].sMax, SDL_MIN_SINT16, SDL_MAX_SINT16);
return (Sint16)HIDAPI_RemapVal(sRawValue, ctx->m_StickExtents[nStick].axis[nAxis].sMin, ctx->m_StickExtents[nStick].axis[nAxis].sMax,
SDL_MIN_SINT16, SDL_MAX_SINT16);
}
static Sint16 ApplySimpleStickCalibration(SDL_DriverSwitch_Context *ctx, int nStick, int nAxis, Sint16 sRawValue)
@ -886,7 +888,8 @@ static Sint16 ApplySimpleStickCalibration(SDL_DriverSwitch_Context *ctx, int nSt
ctx->m_SimpleStickExtents[nStick].axis[nAxis].sMin = sRawValue;
}
return (Sint16)HIDAPI_RemapVal(sRawValue, ctx->m_SimpleStickExtents[nStick].axis[nAxis].sMin, ctx->m_SimpleStickExtents[nStick].axis[nAxis].sMax, SDL_MIN_SINT16, SDL_MAX_SINT16);
return (Sint16)HIDAPI_RemapVal(sRawValue, ctx->m_SimpleStickExtents[nStick].axis[nAxis].sMin, ctx->m_SimpleStickExtents[nStick].axis[nAxis].sMax,
SDL_MIN_SINT16, SDL_MAX_SINT16);
}
static void SDLCALL SDL_GameControllerButtonReportingHintChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
@ -1051,9 +1054,7 @@ HIDAPI_DriverNintendoClassic_UnregisterHints(SDL_HintCallback callback, void *us
static SDL_bool
HIDAPI_DriverNintendoClassic_IsEnabled(void)
{
return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_NINTENDO_CLASSIC,
SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI,
SDL_HIDAPI_DEFAULT));
return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_NINTENDO_CLASSIC, SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT));
}
static SDL_bool
@ -1097,9 +1098,7 @@ HIDAPI_DriverJoyCons_UnregisterHints(SDL_HintCallback callback, void *userdata)
static SDL_bool
HIDAPI_DriverJoyCons_IsEnabled(void)
{
return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS,
SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI,
SDL_HIDAPI_DEFAULT));
return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS, SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT));
}
static SDL_bool
@ -1139,9 +1138,7 @@ HIDAPI_DriverSwitch_UnregisterHints(SDL_HintCallback callback, void *userdata)
static SDL_bool
HIDAPI_DriverSwitch_IsEnabled(void)
{
return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_SWITCH,
SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI,
SDL_HIDAPI_DEFAULT));
return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_SWITCH, SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT));
}
static SDL_bool
@ -1232,7 +1229,7 @@ HIDAPI_DriverSwitch_InitDevice(SDL_HIDAPI_Device *device)
SDL_DriverSwitch_Context *ctx;
ctx = (SDL_DriverSwitch_Context *)SDL_calloc(1, sizeof(*ctx));
if (!ctx) {
if (ctx == NULL) {
SDL_OutOfMemory();
return SDL_FALSE;
}
@ -2142,7 +2139,7 @@ HIDAPI_DriverSwitch_UpdateDevice(SDL_HIDAPI_Device *device)
++packet_count;
ctx->m_unLastInput = now;
if (!joystick) {
if (joystick == NULL) {
continue;
}
@ -2201,7 +2198,7 @@ HIDAPI_DriverSwitch_UpdateDevice(SDL_HIDAPI_Device *device)
/* Read error, device is disconnected */
HIDAPI_JoystickDisconnected(device, device->joysticks[0]);
}
return (size >= 0);
return size >= 0;
}
static void

View file

@ -216,13 +216,13 @@ static SDL_bool WriteOutput(SDL_DriverWii_Context *ctx, const Uint8 *data, int s
}
#endif
if (sync) {
return (SDL_hid_write(ctx->device->dev, data, size) >= 0);
return SDL_hid_write(ctx->device->dev, data, size) >= 0;
} else {
/* Use the rumble thread for general asynchronous writes */
if (SDL_HIDAPI_LockRumble() < 0) {
return SDL_FALSE;
}
return (SDL_HIDAPI_SendRumbleAndUnlock(ctx->device, data, size) >= 0);
return SDL_HIDAPI_SendRumbleAndUnlock(ctx->device, data, size) >= 0;
}
}
@ -234,7 +234,7 @@ static SDL_bool ReadInputSync(SDL_DriverWii_Context *ctx, EWiiInputReportIDs exp
int nRead = 0;
while ((nRead = ReadInput(ctx)) != -1) {
if (nRead > 0) {
if (ctx->m_rgucReadBuffer[0] == expectedID && (!isMine || isMine(ctx->m_rgucReadBuffer))) {
if (ctx->m_rgucReadBuffer[0] == expectedID && (isMine == NULL || isMine(ctx->m_rgucReadBuffer))) {
return SDL_TRUE;
}
} else {
@ -734,7 +734,7 @@ HIDAPI_DriverWii_InitDevice(SDL_HIDAPI_Device *device)
SDL_DriverWii_Context *ctx;
ctx = (SDL_DriverWii_Context *)SDL_calloc(1, sizeof(*ctx));
if (!ctx) {
if (ctx == NULL) {
SDL_OutOfMemory();
return SDL_FALSE;
}
@ -1529,7 +1529,7 @@ HIDAPI_DriverWii_UpdateDevice(SDL_HIDAPI_Device *device)
/* Read error, device is disconnected */
HIDAPI_JoystickDisconnected(device, device->joysticks[0]);
}
return (size >= 0);
return size >= 0;
}
static void

Some files were not shown because too many files have changed in this diff Show more