From 9fcb7d744e82a0ba62bf90038014634debf0e2c6 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Thu, 17 Sep 2015 09:33:24 +0200 Subject: [PATCH] (libretro-db) Style nits --- libretro-db/libretrodb.c | 28 ++++++++-------- libretro-db/libretrodb.h | 42 ++++++++++------------- libretro-db/lua_common.h | 6 +--- libretro-db/query.c | 36 ++++++++++---------- libretro-db/query.h | 3 +- libretro-db/rmsgpack.h | 68 ++++++++++++++------------------------ libretro-db/rmsgpack_dom.h | 35 ++++++++------------ 7 files changed, 89 insertions(+), 129 deletions(-) diff --git a/libretro-db/libretrodb.c b/libretro-db/libretrodb.c index 1694108c9c..c0dcd4f959 100644 --- a/libretro-db/libretrodb.c +++ b/libretro-db/libretrodb.c @@ -40,7 +40,7 @@ static int libretrodb_write_metadata(int fd, libretrodb_metadata_t *md) return rmsgpack_write_uint(fd, md->count); } -static int validate_document(const struct rmsgpack_dom_value * doc) +static int validate_document(const struct rmsgpack_dom_value *doc) { unsigned i; struct rmsgpack_dom_value key; @@ -75,7 +75,7 @@ static int validate_document(const struct rmsgpack_dom_value * doc) } int libretrodb_create(int fd, libretrodb_value_provider value_provider, - void * ctx) + void *ctx) { int rv; off_t root; @@ -128,7 +128,7 @@ static int libretrodb_read_index_header(int fd, libretrodb_index_t *idx) "next", &idx->next, NULL); } -static void libretrodb_write_index_header(int fd, libretrodb_index_t * idx) +static void libretrodb_write_index_header(int fd, libretrodb_index_t *idx) { rmsgpack_write_map_header(fd, 3); rmsgpack_write_string(fd, "name", strlen("name")); @@ -211,17 +211,17 @@ static int libretrodb_find_index(libretrodb_t *db, const char *index_name, return -1; } -static int node_compare(const void * a, const void * b, void * ctx) +static int node_compare(const void *a, const void *b, void *ctx) { return memcmp(a, b, *(uint8_t *)ctx); } -static int binsearch(const void * buff, const void * item, - uint64_t count, uint8_t field_size, uint64_t * offset) +static int binsearch(const void *buff, const void *item, + uint64_t count, uint8_t field_size, uint64_t *offset) { int mid = count / 2; int item_size = field_size + sizeof(uint64_t); - uint64_t * current = (uint64_t *)buff + (mid * item_size); + uint64_t *current = (uint64_t *)buff + (mid * item_size); int rv = node_compare(current, item, &field_size); if (rv == 0) @@ -245,7 +245,7 @@ int libretrodb_find_entry(libretrodb_t *db, const char *index_name, { libretrodb_index_t idx; int rv; - void * buff; + void *buff; uint64_t offset; ssize_t bufflen, nread = 0; @@ -260,7 +260,7 @@ int libretrodb_find_entry(libretrodb_t *db, const char *index_name, while (nread < bufflen) { - void * buff_ = (uint64_t *)buff + nread; + void *buff_ = (uint64_t *)buff + nread; rv = read(db->fd, buff_, bufflen - nread); if (rv <= 0) @@ -302,7 +302,7 @@ int libretrodb_cursor_reset(libretrodb_cursor_t *cursor) } int libretrodb_cursor_read_item(libretrodb_cursor_t *cursor, - struct rmsgpack_dom_value * out) + struct rmsgpack_dom_value *out) { int rv; @@ -384,7 +384,7 @@ int libretrodb_cursor_open(libretrodb_t *db, libretrodb_cursor_t *cursor, return 0; } -static int node_iter(void * value, void * ctx) +static int node_iter(void *value, void *ctx) { struct node_iter_ctx *nictx = (struct node_iter_ctx*)ctx; @@ -408,11 +408,11 @@ int libretrodb_create_index(libretrodb_t *db, struct rmsgpack_dom_value key; libretrodb_index_t idx; struct rmsgpack_dom_value item; - struct rmsgpack_dom_value * field; + struct rmsgpack_dom_value *field; uint64_t idx_header_offset; libretrodb_cursor_t cur = {0}; - void * buff = NULL; - uint64_t * buff_u64 = NULL; + void *buff = NULL; + uint64_t *buff_u64 = NULL; uint8_t field_size = 0; uint64_t item_loc = libretrodb_tell(db); bintree_t *tree = bintree_new(node_compare, &field_size); diff --git a/libretro-db/libretrodb.h b/libretro-db/libretrodb.h index a9c2b0ce97..262d0cba6f 100644 --- a/libretro-db/libretrodb.h +++ b/libretro-db/libretrodb.h @@ -49,29 +49,25 @@ typedef struct libretrodb_cursor int is_valid; int fd; int eof; - libretrodb_query_t * query; - libretrodb_t * db; + libretrodb_query_t *query; + libretrodb_t *db; } libretrodb_cursor_t; -typedef int (* libretrodb_value_provider)(void * ctx, - struct rmsgpack_dom_value * out); +typedef int (*libretrodb_value_provider)(void *ctx, + struct rmsgpack_dom_value *out); -int libretrodb_create(int fd, libretrodb_value_provider value_provider, - void * ctx); +int libretrodb_create(int fd, + libretrodb_value_provider value_provider, void *ctx); -void libretrodb_close(libretrodb_t * db); +void libretrodb_close(libretrodb_t *db); -int libretrodb_open(const char * path, libretrodb_t * db); +int libretrodb_open(const char *path, libretrodb_t *db); -int libretrodb_create_index(libretrodb_t * db, const char *name, +int libretrodb_create_index(libretrodb_t *db, const char *name, const char *field_name); -int libretrodb_find_entry( - libretrodb_t * db, - const char * index_name, - const void * key, - struct rmsgpack_dom_value * out -); +int libretrodb_find_entry(libretrodb_t *db, const char *index_name, + const void *key, struct rmsgpack_dom_value *out); /** * libretrodb_cursor_open: @@ -97,7 +93,7 @@ int libretrodb_cursor_open( * * Returns: ???. **/ -int libretrodb_cursor_reset(libretrodb_cursor_t * cursor); +int libretrodb_cursor_reset(libretrodb_cursor_t *cursor); /** * libretrodb_cursor_close: @@ -105,19 +101,15 @@ int libretrodb_cursor_reset(libretrodb_cursor_t * cursor); * * Closes cursor and frees up allocated memory. **/ -void libretrodb_cursor_close(libretrodb_cursor_t * cursor); +void libretrodb_cursor_close(libretrodb_cursor_t *cursor); -void *libretrodb_query_compile( - libretrodb_t * db, - const char * query, - size_t buff_len, - const char ** error -); +void *libretrodb_query_compile(libretrodb_t *db, const char *query, + size_t buff_len, const char **error); void libretrodb_query_free(void *q); -int libretrodb_cursor_read_item(libretrodb_cursor_t * cursor, - struct rmsgpack_dom_value * out); +int libretrodb_cursor_read_item(libretrodb_cursor_t *cursor, + struct rmsgpack_dom_value *out); #ifdef __cplusplus } diff --git a/libretro-db/lua_common.h b/libretro-db/lua_common.h index b46c1df365..9728d2c7c1 100644 --- a/libretro-db/lua_common.h +++ b/libretro-db/lua_common.h @@ -7,10 +7,6 @@ #include "rmsgpack_dom.h" -int libretrodb_lua_to_rmsgpack_value( - lua_State * L, - int index, - struct rmsgpack_dom_value * out -); +int libretrodb_lua_to_rmsgpack_value(lua_State *L, int index, struct rmsgpack_dom_value *out); #endif diff --git a/libretro-db/query.c b/libretro-db/query.c index 1f5bf9d7b9..001fcd2a98 100644 --- a/libretro-db/query.c +++ b/libretro-db/query.c @@ -46,7 +46,7 @@ static void raise_expected_number(off_t where, const char **error) *error = tmp_error_buff; } -static void raise_expected_string(off_t where, const char ** error) +static void raise_expected_string(off_t where, const char **error) { snprintf(tmp_error_buff, MAX_ERROR_LEN, #ifdef _WIN32 @@ -58,7 +58,7 @@ static void raise_expected_string(off_t where, const char ** error) *error = tmp_error_buff; } -static void raise_unexpected_eof(off_t where, const char ** error) +static void raise_unexpected_eof(off_t where, const char **error) { snprintf(tmp_error_buff, MAX_ERROR_LEN, #ifdef _WIN32 @@ -199,7 +199,7 @@ static struct rmsgpack_dom_value is_true(struct rmsgpack_dom_value input, } static struct rmsgpack_dom_value equals(struct rmsgpack_dom_value input, - unsigned argc, const struct argument * argv) + unsigned argc, const struct argument *argv) { struct rmsgpack_dom_value res; struct argument arg; @@ -228,7 +228,7 @@ static struct rmsgpack_dom_value equals(struct rmsgpack_dom_value input, } static struct rmsgpack_dom_value operator_or(struct rmsgpack_dom_value input, - unsigned argc, const struct argument * argv) + unsigned argc, const struct argument *argv) { struct rmsgpack_dom_value res; unsigned i; @@ -256,7 +256,7 @@ static struct rmsgpack_dom_value operator_or(struct rmsgpack_dom_value input, } static struct rmsgpack_dom_value between(struct rmsgpack_dom_value input, - unsigned argc, const struct argument * argv) + unsigned argc, const struct argument *argv) { struct rmsgpack_dom_value res; unsigned i = 0; @@ -289,7 +289,7 @@ static struct rmsgpack_dom_value between(struct rmsgpack_dom_value input, } static struct rmsgpack_dom_value operator_and(struct rmsgpack_dom_value input, - unsigned argc, const struct argument * argv) + unsigned argc, const struct argument *argv) { struct rmsgpack_dom_value res; unsigned i; @@ -318,7 +318,7 @@ static struct rmsgpack_dom_value operator_and(struct rmsgpack_dom_value input, } static struct rmsgpack_dom_value q_glob(struct rmsgpack_dom_value input, - unsigned argc, const struct argument * argv) + unsigned argc, const struct argument *argv) { struct rmsgpack_dom_value res; unsigned i = 0; @@ -412,7 +412,7 @@ static struct buffer chomp(struct buffer buff) } static struct buffer expect_char(struct buffer buff, - char c, const char ** error) + char c, const char **error) { if (buff.offset >= buff.len) raise_unexpected_eof(buff.offset, error); @@ -424,7 +424,7 @@ static struct buffer expect_char(struct buffer buff, return buff; } -static struct buffer expect_eof(struct buffer buff, const char ** error) +static struct buffer expect_eof(struct buffer buff, const char **error) { buff = chomp(buff); if (buff.offset < buff.len) @@ -432,7 +432,7 @@ static struct buffer expect_eof(struct buffer buff, const char ** error) return buff; } -static int peek(struct buffer buff, const char * data) +static int peek(struct buffer buff, const char *data) { size_t remain = buff.len - buff.offset; @@ -459,8 +459,8 @@ static void peek_char(struct buffer buff, char *c, const char **error) *c = buff.data[buff.offset]; } -static struct buffer get_char(struct buffer buff, char * c, - const char ** error) +static struct buffer get_char(struct buffer buff, char *c, + const char **error) { if (is_eot(buff)) { @@ -475,7 +475,7 @@ static struct buffer get_char(struct buffer buff, char * c, static struct buffer parse_string(struct buffer buff, struct rmsgpack_dom_value *value, const char **error) { - const char * str_start; + const char *str_start; char terminator = '\0'; char c = '\0'; @@ -613,7 +613,7 @@ static struct buffer parse_method_call(struct buffer buff, unsigned i; struct argument args[MAX_ARGS]; unsigned argi = 0; - struct registered_func * rf = registered_functions; + struct registered_func *rf = registered_functions; invocation->func = NULL; @@ -675,7 +675,7 @@ static struct buffer parse_method_call(struct buffer buff, invocation->argc = argi; invocation->argv = (struct argument*) - malloc(sizeof(struct argument) * argi); + malloc(sizeof(struct argument) *argi); if (!invocation->argv) { @@ -683,7 +683,7 @@ static struct buffer parse_method_call(struct buffer buff, goto error; } memcpy(invocation->argv, args, - sizeof(struct argument) * argi); + sizeof(struct argument) *argi); return buff; @@ -797,7 +797,7 @@ static struct buffer parse_table(struct buffer buff, goto error; } memcpy(invocation->argv, args, - sizeof(struct argument) * argi); + sizeof(struct argument) *argi); return buff; @@ -842,7 +842,7 @@ static struct buffer parse_argument(struct buffer buff, void libretrodb_query_free(void *q) { unsigned i; - struct query * real_q = (struct query*)q; + struct query *real_q = (struct query*)q; real_q->ref_count--; if (real_q->ref_count > 0) diff --git a/libretro-db/query.h b/libretro-db/query.h index f53f56af17..a0cd84e3c3 100644 --- a/libretro-db/query.h +++ b/libretro-db/query.h @@ -7,7 +7,6 @@ void libretrodb_query_inc_ref(libretrodb_query_t *q); void libretrodb_query_dec_ref(libretrodb_query_t *q); -int libretrodb_query_filter(libretrodb_query_t *q, - struct rmsgpack_dom_value * v); +int libretrodb_query_filter(libretrodb_query_t *q, struct rmsgpack_dom_value *v); #endif diff --git a/libretro-db/rmsgpack.h b/libretro-db/rmsgpack.h index 62668e3c6c..69d60b6145 100644 --- a/libretro-db/rmsgpack.h +++ b/libretro-db/rmsgpack.h @@ -5,53 +5,33 @@ struct rmsgpack_read_callbacks { - int (* read_nil) (void *); - int (* read_bool)(int, void *); - int (* read_int) (int64_t, void *); - int (* read_uint)(uint64_t, void *); - int (* read_string)(char *, uint32_t, void *); - int (* read_bin)(void *, uint32_t, void *); - int (* read_map_start) (uint32_t, void *); - int (* read_array_start)(uint32_t, void *); + int (*read_nil )(void *); + int (*read_bool )(int, void *); + int (*read_int )(int64_t, void *); + int (*read_uint )(uint64_t, void *); + int (*read_string )(char *, uint32_t, void *); + int (*read_bin )(void *, uint32_t, void *); + int (*read_map_start )(uint32_t, void *); + int (*read_array_start)(uint32_t, void *); }; -int rmsgpack_write_array_header( - int fd, - uint32_t size -); -int rmsgpack_write_map_header( - int fd, - uint32_t size -); -int rmsgpack_write_string( - int fd, - const char * s, - uint32_t len -); -int rmsgpack_write_bin( - int fd, - const void * s, - uint32_t len -); -int rmsgpack_write_nil(int fd); -int rmsgpack_write_bool( - int fd, - int value -); -int rmsgpack_write_int( - int fd, - int64_t value -); -int rmsgpack_write_uint( - int fd, - uint64_t value -); +int rmsgpack_write_array_header(int fd, uint32_t size); -int rmsgpack_read( - int fd, - struct rmsgpack_read_callbacks * callbacks, - void * data -); +int rmsgpack_write_map_header(int fd, uint32_t size); + +int rmsgpack_write_string(int fd, const char *s, uint32_t len); + +int rmsgpack_write_bin(int fd, const void *s, uint32_t len); + +int rmsgpack_write_nil(int fd); + +int rmsgpack_write_bool(int fd, int value); + +int rmsgpack_write_int(int fd, int64_t value); + +int rmsgpack_write_uint(int fd, uint64_t value ); + +int rmsgpack_read(int fd, struct rmsgpack_read_callbacks *callbacks, void *data); #endif diff --git a/libretro-db/rmsgpack_dom.h b/libretro-db/rmsgpack_dom.h index bc6a4e9690..cfaeb5c617 100644 --- a/libretro-db/rmsgpack_dom.h +++ b/libretro-db/rmsgpack_dom.h @@ -29,23 +29,23 @@ struct rmsgpack_dom_value struct { uint32_t len; - char * buff; + char *buff; } string; struct { uint32_t len; - char * buff; + char *buff; } binary; int bool_; struct { uint32_t len; - struct rmsgpack_dom_pair * items; + struct rmsgpack_dom_pair *items; } map; struct { uint32_t len; - struct rmsgpack_dom_value * items; + struct rmsgpack_dom_value *items; } array; } val; }; @@ -56,26 +56,19 @@ struct rmsgpack_dom_pair struct rmsgpack_dom_value value; }; -void rmsgpack_dom_value_print(struct rmsgpack_dom_value * obj); -void rmsgpack_dom_value_free(struct rmsgpack_dom_value * v); +void rmsgpack_dom_value_print(struct rmsgpack_dom_value *obj); +void rmsgpack_dom_value_free(struct rmsgpack_dom_value *v); + int rmsgpack_dom_value_cmp( - const struct rmsgpack_dom_value * a, - const struct rmsgpack_dom_value * b -); + const struct rmsgpack_dom_value *a, const struct rmsgpack_dom_value *b); -struct rmsgpack_dom_value * rmsgpack_dom_value_map_value( - const struct rmsgpack_dom_value * map, - const struct rmsgpack_dom_value * key -); +struct rmsgpack_dom_value *rmsgpack_dom_value_map_value( + const struct rmsgpack_dom_value *map, + const struct rmsgpack_dom_value *key); -int rmsgpack_dom_read( - int fd, - struct rmsgpack_dom_value * out -); -int rmsgpack_dom_write( - int fd, - const struct rmsgpack_dom_value * obj -); +int rmsgpack_dom_read(int fd, struct rmsgpack_dom_value *out); + +int rmsgpack_dom_write(int fd, const struct rmsgpack_dom_value *obj); int rmsgpack_dom_read_into(int fd, ...);