From 4020326f589f1a96104a3b8101763e9e723cdd09 Mon Sep 17 00:00:00 2001 From: LibretroAdmin Date: Mon, 20 Jan 2025 04:37:27 +0100 Subject: [PATCH] Style nits --- audio/drivers/xaudio.c | 4 +- core_option_manager.c | 14 +-- frontend/drivers/platform_wii.c | 39 ++++--- libretro-db/c_converter.c | 179 ++++++++++++++++---------------- libretro-db/query.c | 9 +- libretro-db/rmsgpack.c | 20 ++-- 6 files changed, 133 insertions(+), 132 deletions(-) diff --git a/audio/drivers/xaudio.c b/audio/drivers/xaudio.c index 47320d5c4759..0e0cc6508eb3 100644 --- a/audio/drivers/xaudio.c +++ b/audio/drivers/xaudio.c @@ -192,7 +192,7 @@ static void xaudio2_free(xaudio2_t *handle) } static xaudio2_t *xaudio2_new(unsigned samplerate, unsigned channels, - size_t size, const char *device) + size_t len, const char *device) { int32_t idx_found = -1; WAVEFORMATEX wfx = {0}; @@ -292,7 +292,7 @@ static xaudio2_t *xaudio2_new(unsigned samplerate, unsigned channels, if (!handle->hEvent) goto error; - handle->bufsize = size / MAX_BUFFERS; + handle->bufsize = len / MAX_BUFFERS; handle->buf = (uint8_t*)calloc(1, handle->bufsize * MAX_BUFFERS); if (!handle->buf) goto error; diff --git a/core_option_manager.c b/core_option_manager.c index 9a26cf0b9c09..d72fb8b784c5 100644 --- a/core_option_manager.c +++ b/core_option_manager.c @@ -754,8 +754,8 @@ static bool core_option_manager_parse_variable( const char *value = option->vals->elems[i].data; uint32_t value_hash = *((uint32_t*)option->vals->elems[i].userdata); - if ((value_hash == entry_value_hash) && - string_is_equal(value, entry->value)) + if ( (value_hash == entry_value_hash) + && string_is_equal(value, entry->value)) { option->index = i; break; @@ -928,9 +928,9 @@ static bool core_option_manager_parse_option( * match an entry in the categories array * > Category key cannot contain a map delimiter * character */ - if (opt->cats && - !string_is_empty(category_key) && - !strstr(category_key, ":")) + if ( opt->cats + && !string_is_empty(category_key) + && !strstr(category_key, ":")) { for (i = 0; i < opt->cats_size; i++) { @@ -960,8 +960,8 @@ static bool core_option_manager_parse_option( { /* If option has a category, option key * cannot contain a map delimiter character */ - if (!string_is_empty(option->category_key) && - strstr(key, ":")) + if ( !string_is_empty(option->category_key) + && strstr(key, ":")) return false; option->key = strdup(key); diff --git a/frontend/drivers/platform_wii.c b/frontend/drivers/platform_wii.c index 5d78a8f7fe3f..a319d1fd54bb 100644 --- a/frontend/drivers/platform_wii.c +++ b/frontend/drivers/platform_wii.c @@ -80,10 +80,10 @@ static void dol_copy_argv_path(const char *dolpath, const char *argpath) } /* a relative path */ else if ( - (strstr(dolpath, "sd:/") != dolpath) && - (strstr(dolpath, "usb:/") != dolpath) && - (strstr(dolpath, "carda:/") != dolpath) && - (strstr(dolpath, "cardb:/") != dolpath) + (strstr(dolpath, "sd:/") != dolpath) + && (strstr(dolpath, "usb:/") != dolpath) + && (strstr(dolpath, "carda:/") != dolpath) + && (strstr(dolpath, "cardb:/") != dolpath) ) { fill_pathname_parent_dir(tmp, @@ -165,17 +165,16 @@ static void dol_copy_raw_argv(const char *dolpath, * heap memory and are restricted to the stack only. */ void system_exec_wii(const char *_path, bool should_load_game) { - char path[PATH_MAX_LENGTH]; - char args[PATH_MAX_LENGTH]; - size_t args_size; - size_t size; FILE *fp; void *dol; + char path[PATH_MAX_LENGTH]; + char args[PATH_MAX_LENGTH]; + size_t _len, __len; #ifndef IS_SALAMANDER bool verbosity = verbosity_is_enabled(); #endif - args_size = 0; + __len = 0; /* copy heap info into stack so it survives * us moving the .dol into MEM2. */ @@ -190,7 +189,7 @@ void system_exec_wii(const char *_path, bool should_load_game) if (net_st->fork_args.size) { memcpy(args, net_st->fork_args.args, net_st->fork_args.size); - args_size = net_st->fork_args.size; + __len = net_st->fork_args.size; } else #endif @@ -208,11 +207,11 @@ void system_exec_wii(const char *_path, bool should_load_game) } fseek(fp, 0, SEEK_END); - size = ftell(fp); + _len = ftell(fp); fseek(fp, 0, SEEK_SET); /* try to allocate a buffer for it. if we can't, fail. */ - dol = malloc(size); + dol = malloc(_len); if (!dol) { RARCH_ERR("Could not execute DOL file %s.\n", path); @@ -220,7 +219,7 @@ void system_exec_wii(const char *_path, bool should_load_game) goto exit; } - fread(dol, 1, size, fp); + fread(dol, 1, _len, fp); fclose(fp); fatUnmount("carda:"); @@ -231,17 +230,17 @@ void system_exec_wii(const char *_path, bool should_load_game) __io_usbstorage.shutdown(); /* don't use memcpy, there might be an overlap. */ - memmove(EXECUTE_ADDR, dol, size); - DCFlushRange(EXECUTE_ADDR, size); + memmove(EXECUTE_ADDR, dol, _len); + DCFlushRange(EXECUTE_ADDR, _len); - if (args_size) - dol_copy_raw_argv(path, args, args_size); + if (__len) + dol_copy_raw_argv(path, args, __len); else dol_copy_argv_path(path, should_load_game ? args : NULL); - size = booter_end - booter_start; - memcpy(BOOTER_ADDR, booter_start, size); - DCFlushRange(BOOTER_ADDR, size); + _len = booter_end - booter_start; + memcpy(BOOTER_ADDR, booter_start, _len); + DCFlushRange(BOOTER_ADDR, _len); SYS_ResetSystem(SYS_SHUTDOWN, 0, 0); __lwp_thread_stopmultitasking((void (*)(void))BOOTER_ADDR); diff --git a/libretro-db/c_converter.c b/libretro-db/c_converter.c index b2568d7cbd16..60724545adbc 100644 --- a/libretro-db/c_converter.c +++ b/libretro-db/c_converter.c @@ -136,22 +136,23 @@ static void dat_converter_list_free(dat_converter_list_t* list) { if (!list) return; + switch (list->type) { - case DAT_CONVERTER_LIST_LIST: - while (list->count--) - dat_converter_list_free(list->values[list->count].list); - break; - case DAT_CONVERTER_MAP_LIST: - while (list->count--) - { - if (list->values[list->count].map.type == DAT_CONVERTER_LIST_MAP) - dat_converter_list_free(list->values[list->count].map.value.list); - } - dat_converter_bt_node_free(list->bt_root); - break; - default: - break; + case DAT_CONVERTER_LIST_LIST: + while (list->count--) + dat_converter_list_free(list->values[list->count].list); + break; + case DAT_CONVERTER_MAP_LIST: + while (list->count--) + { + if (list->values[list->count].map.type == DAT_CONVERTER_LIST_MAP) + dat_converter_list_free(list->values[list->count].map.value.list); + } + dat_converter_bt_node_free(list->bt_root); + break; + default: + break; } free(list->values); @@ -190,7 +191,6 @@ static dat_converter_bt_node_t* dat_converter_bt_node_insert( if (map->type == DAT_CONVERTER_LIST_MAP) { int i; - retro_assert(list->values[(*node)->index].map.value.list->type == map->value.list->type); @@ -217,54 +217,52 @@ static void dat_converter_list_append(dat_converter_list_t* dst, void* item) dst->capacity <<= 1; dst->values = realloc(dst->values, sizeof(*dst->values) * dst->capacity); } + switch (dst->type) { - case DAT_CONVERTER_TOKEN_LIST: - { - dat_converter_token_t* token = (dat_converter_token_t*) item; - dst->values[dst->count].token = *token; - break; - } - case DAT_CONVERTER_STRING_LIST: - { - char* str = (char*) item; - dst->values[dst->count].string = str; - break; - } - case DAT_CONVERTER_MAP_LIST: - { - dat_converter_map_t* map = (dat_converter_map_t*) item; - if (!map->key) - dst->values[dst->count].map = *map; - else - { - map->hash = djb2_calculate(map->key); - dat_converter_bt_node_t* new_node = - dat_converter_bt_node_insert(dst, &dst->bt_root, map); + case DAT_CONVERTER_TOKEN_LIST: + { + dat_converter_token_t* token = (dat_converter_token_t*) item; + dst->values[dst->count].token = *token; + break; + } + case DAT_CONVERTER_STRING_LIST: + dst->values[dst->count].string = (char*)item; + break; + case DAT_CONVERTER_MAP_LIST: + { + dat_converter_map_t* map = (dat_converter_map_t*) item; + if (!map->key) + dst->values[dst->count].map = *map; + else + { + map->hash = djb2_calculate(map->key); + dat_converter_bt_node_t* new_node = + dat_converter_bt_node_insert(dst, &dst->bt_root, map); - if (!new_node) - return; + if (!new_node) + return; - dst->values[dst->count].map = *map; - new_node->index = dst->count; - new_node->hash = map->hash; - } - break; - } - case DAT_CONVERTER_LIST_LIST: - { - dat_converter_list_t* list = (dat_converter_list_t*) item; - dst->values[dst->count].list = list; - break; - } - default: - return; + dst->values[dst->count].map = *map; + new_node->index = dst->count; + new_node->hash = map->hash; + } + break; + } + case DAT_CONVERTER_LIST_LIST: + { + dat_converter_list_t* list = (dat_converter_list_t*) item; + dst->values[dst->count].list = list; + break; + } + default: + return; } dst->count++; } static dat_converter_list_t* dat_converter_lexer( - char* src, const char* dat_path) + char *src, const char* dat_path) { dat_converter_list_t* token_list = dat_converter_list_create(DAT_CONVERTER_TOKEN_LIST); @@ -278,7 +276,7 @@ static dat_converter_list_t* dat_converter_lexer( *src = '\0'; src++; token.column++; - token.label = NULL; + token.label = NULL; quoted_token = false; continue; } @@ -289,7 +287,7 @@ static dat_converter_list_t* dat_converter_lexer( src++; token.column = 1; token.line_no++; - token.label = NULL; + token.label = NULL; quoted_token = false; continue; } @@ -300,7 +298,7 @@ static dat_converter_list_t* dat_converter_lexer( src++; token.column++; quoted_token = !quoted_token; - token.label = NULL; + token.label = NULL; if (quoted_token) { @@ -410,26 +408,27 @@ struct dat_converter_match_key_t static dat_converter_match_key_t* dat_converter_match_key_create( const char* format) { - dat_converter_match_key_t* match_key; + char *dot; dat_converter_match_key_t* current_mk; - char* dot; - - match_key = malloc(sizeof(*match_key)); + dat_converter_match_key_t* + match_key = (dat_converter_match_key_t*) + malloc(sizeof(*match_key)); match_key->value = strdup(format); - match_key->next = NULL; - current_mk = match_key; + match_key->next = NULL; + current_mk = match_key; + + dot = match_key->value; - dot = match_key->value; while (*dot++) { if (*dot == '.') { *dot++ = '\0'; - current_mk->hash = djb2_calculate(current_mk->value); - current_mk->next = malloc(sizeof(*match_key)); - current_mk = current_mk->next; + current_mk->hash = djb2_calculate(current_mk->value); + current_mk->next = malloc(sizeof(*match_key)); + current_mk = current_mk->next; current_mk->value = dot; - current_mk->next = NULL; + current_mk->next = NULL; } } current_mk->hash = djb2_calculate(current_mk->value); @@ -460,26 +459,26 @@ static const char* dat_converter_get_match( retro_assert(match_key); - if (list->type != DAT_CONVERTER_MAP_LIST) - return NULL; - - for (i = 0; i < list->count; i++) + if (list->type == DAT_CONVERTER_MAP_LIST) { - if (list->values[i].map.hash == match_key->hash) + for (i = 0; i < list->count; i++) { - retro_assert(string_is_equal(list->values[i].map.key, match_key->value)); - - if (match_key->next) - return dat_converter_get_match( - list->values[i].map.value.list, match_key->next); + if (list->values[i].map.hash == match_key->hash) + { + retro_assert(string_is_equal(list->values[i].map.key, match_key->value)); - if ((list->values[i].map.type == DAT_CONVERTER_STRING_MAP)) - return list->values[i].map.value.string; + if (match_key->next) + return dat_converter_get_match( + list->values[i].map.value.list, match_key->next); - return NULL; + if ((list->values[i].map.type == DAT_CONVERTER_STRING_MAP)) + return list->values[i].map.value.string; + break; + } } } + return NULL; } @@ -499,9 +498,9 @@ static dat_converter_list_t* dat_converter_parser( if (!target) { dat_converter_map_t map; - target = dat_converter_list_create(DAT_CONVERTER_MAP_LIST); - map.key = NULL; - map.type = DAT_CONVERTER_LIST_MAP; + target = dat_converter_list_create(DAT_CONVERTER_MAP_LIST); + map.key = NULL; + map.type = DAT_CONVERTER_LIST_MAP; map.value.list = NULL; dat_converter_list_append(target, &map); } @@ -546,8 +545,10 @@ static dat_converter_list_t* dat_converter_parser( else map.key = NULL; - // If we are still not to skip the entry, append it to the list. - if (!skip) { + /* If we are still not to skip the entry, + * append it to the list. */ + if (!skip) + { dat_converter_list_append(target, &map); skip = true; } @@ -591,7 +592,7 @@ dat_converter_rdb_mappings_t rdb_mappings[] = {"name", "name", DAT_CONVERTER_RDB_TYPE_STRING}, {"description", "description", DAT_CONVERTER_RDB_TYPE_STRING}, {"genre", "genre", DAT_CONVERTER_RDB_TYPE_STRING}, - + {"achievements", "achievements", DAT_CONVERTER_RDB_TYPE_UINT}, {"category", "category", DAT_CONVERTER_RDB_TYPE_STRING}, {"language", "language", DAT_CONVERTER_RDB_TYPE_STRING}, @@ -609,7 +610,7 @@ dat_converter_rdb_mappings_t rdb_mappings[] = {"setting", "setting", DAT_CONVERTER_RDB_TYPE_STRING}, {"visual", "visual", DAT_CONVERTER_RDB_TYPE_STRING}, {"vehicular", "vehicular", DAT_CONVERTER_RDB_TYPE_STRING}, - + {"rom.name", "rom_name", DAT_CONVERTER_RDB_TYPE_STRING}, {"rom.size", "size", DAT_CONVERTER_RDB_TYPE_UINT}, {"users", "users", DAT_CONVERTER_RDB_TYPE_UINT}, @@ -654,6 +655,7 @@ static void dat_converter_value_provider_init(void) for (i = 0; i < (sizeof(rdb_mappings) / sizeof(*rdb_mappings)); i++) rdb_mappings_mk[i] = dat_converter_match_key_create(rdb_mappings[i].dat_key); } + static void dat_converter_value_provider_free(void) { int i; @@ -663,6 +665,7 @@ static void dat_converter_value_provider_free(void) rdb_mappings_mk[i] = NULL; } } + static int dat_converter_value_provider( dat_converter_list_item_t** current_item, struct rmsgpack_dom_value* out) { diff --git a/libretro-db/query.c b/libretro-db/query.c index f69d63a473d8..b144c0495d90 100644 --- a/libretro-db/query.c +++ b/libretro-db/query.c @@ -59,9 +59,7 @@ struct argument; typedef struct rmsgpack_dom_value (*rarch_query_func)( struct rmsgpack_dom_value input, - unsigned argc, - const struct argument *argv - ); + unsigned argc, const struct argument *argv); struct invocation { @@ -775,6 +773,7 @@ static struct buffer query_parse_table( *error = s; goto clean; } + memcpy(invocation->argv, args, sizeof(struct argument) * argi); @@ -900,7 +899,7 @@ void libretrodb_query_free(void *q) } void *libretrodb_query_compile(libretrodb_t *db, - const char *query, size_t buff_len, const char **error_string) + const char *query, size_t len, const char **error_string) { struct buffer buff; /* TODO/FIXME - static local variable */ @@ -917,7 +916,7 @@ void *libretrodb_query_compile(libretrodb_t *db, q->root.argv = NULL; buff.data = query; - buff.len = buff_len; + buff.len = len; buff.offset = 0; *error_string = NULL; diff --git a/libretro-db/rmsgpack.c b/libretro-db/rmsgpack.c index ca4d2ea8ebec..1cdcd0580d93 100644 --- a/libretro-db/rmsgpack.c +++ b/libretro-db/rmsgpack.c @@ -353,7 +353,7 @@ int rmsgpack_write_uint(RFILE *fd, uint64_t value) return -1; } -static int rmsgpack_read_uint(RFILE *fd, uint64_t *out, size_t len) +static int rmsgpack_read_uint(RFILE *fd, uint64_t *s, size_t len) { union { uint64_t u64; uint32_t u32; uint16_t u16; uint8_t u8; } tmp; @@ -363,22 +363,22 @@ static int rmsgpack_read_uint(RFILE *fd, uint64_t *out, size_t len) switch (len) { case 1: - *out = tmp.u8; + *s = tmp.u8; break; case 2: - *out = swap_if_little16(tmp.u16); + *s = swap_if_little16(tmp.u16); break; case 4: - *out = swap_if_little32(tmp.u32); + *s = swap_if_little32(tmp.u32); break; case 8: - *out = swap_if_little64(tmp.u64); + *s = swap_if_little64(tmp.u64); break; } return 0; } -static int rmsgpack_read_int(RFILE *fd, int64_t *out, size_t len) +static int rmsgpack_read_int(RFILE *fd, int64_t *s, size_t len) { union { uint64_t u64; uint32_t u32; uint16_t u16; uint8_t u8; } tmp; @@ -388,16 +388,16 @@ static int rmsgpack_read_int(RFILE *fd, int64_t *out, size_t len) switch (len) { case 1: - *out = (int8_t)tmp.u8; + *s = (int8_t)tmp.u8; break; case 2: - *out = (int16_t)swap_if_little16(tmp.u16); + *s = (int16_t)swap_if_little16(tmp.u16); break; case 4: - *out = (int32_t)swap_if_little32(tmp.u32); + *s = (int32_t)swap_if_little32(tmp.u32); break; case 8: - *out = (int64_t)swap_if_little64(tmp.u64); + *s = (int64_t)swap_if_little64(tmp.u64); break; } return 0;