(libretro-db) Style nits

This commit is contained in:
twinaphex 2015-09-17 09:33:24 +02:00
parent c8535dce1f
commit 9fcb7d744e
7 changed files with 89 additions and 129 deletions

View File

@ -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);

View File

@ -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
}

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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, ...);