Update for SDL3 coding style (#6717)

I updated .clang-format and ran clang-format 14 over the src and test directories to standardize the code base.

In general I let clang-format have it's way, and added markup to prevent formatting of code that would break or be completely unreadable if formatted.

The script I ran for the src directory is added as build-scripts/clang-format-src.sh

This fixes:
#6592
#6593
#6594

(cherry picked from commit 5750bcb174)
This commit is contained in:
Sam Lantinga 2022-11-30 12:51:59 -08:00
parent 5c4bc807f7
commit b8d85c6939
764 changed files with 50598 additions and 54407 deletions

View file

@ -49,8 +49,7 @@ static int SDL_UDEV_load_syms(void);
static SDL_bool SDL_UDEV_hotplug_update_available(void);
static void device_event(SDL_UDEV_deviceevent type, struct udev_device *dev);
static SDL_bool
SDL_UDEV_load_sym(const char *fn, void **addr)
static SDL_bool SDL_UDEV_load_sym(const char *fn, void **addr)
{
*addr = SDL_LoadFunction(_this->udev_handle, fn);
if (*addr == NULL) {
@ -61,12 +60,12 @@ SDL_UDEV_load_sym(const char *fn, void **addr)
return SDL_TRUE;
}
static int
SDL_UDEV_load_syms(void)
static int SDL_UDEV_load_syms(void)
{
/* cast funcs to char* first, to please GCC's strict aliasing rules. */
#define SDL_UDEV_SYM(x) \
if (!SDL_UDEV_load_sym(#x, (void **) (char *) & _this->syms.x)) return -1
/* cast funcs to char* first, to please GCC's strict aliasing rules. */
#define SDL_UDEV_SYM(x) \
if (!SDL_UDEV_load_sym(#x, (void **)(char *)&_this->syms.x)) \
return -1
SDL_UDEV_SYM(udev_device_get_action);
SDL_UDEV_SYM(udev_device_get_devnode);
@ -94,13 +93,12 @@ SDL_UDEV_load_syms(void)
SDL_UDEV_SYM(udev_unref);
SDL_UDEV_SYM(udev_device_new_from_devnum);
SDL_UDEV_SYM(udev_device_get_devnum);
#undef SDL_UDEV_SYM
#undef SDL_UDEV_SYM
return 0;
}
static SDL_bool
SDL_UDEV_hotplug_update_available(void)
static SDL_bool SDL_UDEV_hotplug_update_available(void)
{
if (_this->udev_mon != NULL) {
const int fd = _this->syms.udev_monitor_get_fd(_this->udev_mon);
@ -111,14 +109,12 @@ SDL_UDEV_hotplug_update_available(void)
return SDL_FALSE;
}
int
SDL_UDEV_Init(void)
int SDL_UDEV_Init(void)
{
int retval = 0;
if (_this == NULL) {
_this = (SDL_UDEV_PrivateData *) SDL_calloc(1, sizeof(*_this));
_this = (SDL_UDEV_PrivateData *)SDL_calloc(1, sizeof(*_this));
if (_this == NULL) {
return SDL_OutOfMemory();
}
@ -151,7 +147,6 @@ SDL_UDEV_Init(void)
/* Do an initial scan of existing devices */
SDL_UDEV_Scan();
}
_this->ref_count += 1;
@ -159,8 +154,7 @@ SDL_UDEV_Init(void)
return retval;
}
void
SDL_UDEV_Quit(void)
void SDL_UDEV_Quit(void)
{
SDL_UDEV_CallbackList *item;
@ -194,8 +188,7 @@ SDL_UDEV_Quit(void)
}
}
void
SDL_UDEV_Scan(void)
void SDL_UDEV_Scan(void)
{
struct udev_enumerate *enumerate = NULL;
struct udev_list_entry *devs = NULL;
@ -283,11 +276,7 @@ SDL_UDEV_GetProductInfo(const char *device_path, Uint16 *vendor, Uint16 *product
return found;
}
void
SDL_UDEV_UnloadLibrary(void)
void SDL_UDEV_UnloadLibrary(void)
{
if (_this == NULL) {
return;
@ -299,8 +288,7 @@ SDL_UDEV_UnloadLibrary(void)
}
}
int
SDL_UDEV_LoadLibrary(void)
int SDL_UDEV_LoadLibrary(void)
{
int retval = 0, i;
@ -327,7 +315,7 @@ 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();
@ -356,7 +344,7 @@ static void get_caps(struct udev_device *dev, struct udev_device *pdev, const ch
int i;
unsigned long v;
SDL_memset(bitmask, 0, bitmask_len*sizeof(*bitmask));
SDL_memset(bitmask, 0, bitmask_len * sizeof(*bitmask));
value = _this->syms.udev_device_get_sysattr_value(pdev, attr);
if (value == NULL) {
return;
@ -365,7 +353,7 @@ static void get_caps(struct udev_device *dev, struct udev_device *pdev, const ch
SDL_strlcpy(text, value, sizeof(text));
i = 0;
while ((word = SDL_strrchr(text, ' ')) != NULL) {
v = SDL_strtoul(word+1, NULL, 16);
v = SDL_strtoul(word + 1, NULL, 16);
if (i < bitmask_len) {
bitmask[i] = v;
}
@ -378,8 +366,7 @@ static void get_caps(struct udev_device *dev, struct udev_device *pdev, const ch
}
}
static int
guess_device_class(struct udev_device *dev)
static int guess_device_class(struct udev_device *dev)
{
struct udev_device *pdev;
unsigned long bitmask_ev[NBITS(EV_MAX)];
@ -408,8 +395,7 @@ guess_device_class(struct udev_device *dev)
&bitmask_rel[0]);
}
static void
device_event(SDL_UDEV_deviceevent type, struct udev_device *dev)
static void device_event(SDL_UDEV_deviceevent type, struct udev_device *dev)
{
const char *subsystem;
const char *val = NULL;
@ -429,23 +415,23 @@ device_event(SDL_UDEV_deviceevent type, struct udev_device *dev)
/* udev rules reference: http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-input_id.c */
val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_JOYSTICK");
if (val != NULL && SDL_strcmp(val, "1") == 0 ) {
if (val != NULL && SDL_strcmp(val, "1") == 0) {
devclass |= SDL_UDEV_DEVICE_JOYSTICK;
}
val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_ACCELEROMETER");
if (SDL_GetHintBoolean(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, SDL_TRUE) &&
val != NULL && SDL_strcmp(val, "1") == 0 ) {
val != NULL && SDL_strcmp(val, "1") == 0) {
devclass |= SDL_UDEV_DEVICE_JOYSTICK;
}
val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_MOUSE");
if (val != NULL && SDL_strcmp(val, "1") == 0 ) {
if (val != NULL && SDL_strcmp(val, "1") == 0) {
devclass |= SDL_UDEV_DEVICE_MOUSE;
}
val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_TOUCHSCREEN");
if (val != NULL && SDL_strcmp(val, "1") == 0 ) {
if (val != NULL && SDL_strcmp(val, "1") == 0) {
devclass |= SDL_UDEV_DEVICE_TOUCHSCREEN;
}
@ -456,7 +442,7 @@ device_event(SDL_UDEV_deviceevent type, struct udev_device *dev)
Ref: http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-input_id.c#n183
*/
val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_KEY");
if (val != NULL && SDL_strcmp(val, "1") == 0 ) {
if (val != NULL && SDL_strcmp(val, "1") == 0) {
devclass |= SDL_UDEV_DEVICE_KEYBOARD;
}
@ -488,8 +474,7 @@ device_event(SDL_UDEV_deviceevent type, struct udev_device *dev)
}
}
void
SDL_UDEV_Poll(void)
void SDL_UDEV_Poll(void)
{
struct udev_device *dev = NULL;
const char *action = NULL;
@ -517,11 +502,10 @@ SDL_UDEV_Poll(void)
}
}
int
SDL_UDEV_AddCallback(SDL_UDEV_Callback cb)
int SDL_UDEV_AddCallback(SDL_UDEV_Callback cb)
{
SDL_UDEV_CallbackList *item;
item = (SDL_UDEV_CallbackList *) SDL_calloc(1, sizeof (SDL_UDEV_CallbackList));
item = (SDL_UDEV_CallbackList *)SDL_calloc(1, sizeof(SDL_UDEV_CallbackList));
if (item == NULL) {
return SDL_OutOfMemory();
}
@ -538,8 +522,7 @@ SDL_UDEV_AddCallback(SDL_UDEV_Callback cb)
return 1;
}
void
SDL_UDEV_DelCallback(SDL_UDEV_Callback cb)
void SDL_UDEV_DelCallback(SDL_UDEV_Callback cb)
{
SDL_UDEV_CallbackList *item;
SDL_UDEV_CallbackList *prev = NULL;
@ -578,8 +561,7 @@ SDL_UDEV_GetUdevSyms(void)
return &_this->syms;
}
void
SDL_UDEV_ReleaseUdevSyms(void)
void SDL_UDEV_ReleaseUdevSyms(void)
{
SDL_UDEV_Quit();
}