mirror of
https://github.com/libretro/RetroArch
synced 2025-03-24 04:44:02 +00:00
(libretro-db) Style nits
This commit is contained in:
parent
b18efe5096
commit
3eec012af8
@ -32,7 +32,7 @@ static struct bintree_node *new_nil_node(struct bintree_node *parent)
|
||||
|
||||
static INLINE int is_nil(const struct bintree_node *node)
|
||||
{
|
||||
return (node == NULL) || (node->value == NIL_NODE);
|
||||
return (node == NULL) || (node->value == NIL_NODE);
|
||||
}
|
||||
|
||||
static int insert(struct bintree *t, struct bintree_node *root,
|
||||
@ -112,7 +112,7 @@ static void bintree_free_node(struct bintree_node *n)
|
||||
free(n);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
n->value = NULL;
|
||||
bintree_free_node(n->left);
|
||||
bintree_free_node(n->right);
|
||||
|
@ -14,13 +14,13 @@
|
||||
|
||||
static char *strndup_(const char *s, size_t n)
|
||||
{
|
||||
char* buff = calloc(n, sizeof(char));
|
||||
char* buff = calloc(n, sizeof(char));
|
||||
|
||||
if (!buff)
|
||||
return 0;
|
||||
if (!buff)
|
||||
return 0;
|
||||
|
||||
strncpy(buff, s, n);
|
||||
return buff;
|
||||
strncpy(buff, s, n);
|
||||
return buff;
|
||||
}
|
||||
|
||||
static struct rmsgpack_dom_value *get_map_value(
|
||||
@ -50,22 +50,22 @@ static int load_string(int fd, struct rmsgpack_dom_value *out)
|
||||
|
||||
static int load_uint(int fd, struct rmsgpack_dom_value *out)
|
||||
{
|
||||
char tok[MAX_TOKEN], *c;
|
||||
ssize_t tok_size;
|
||||
uint64_t value = 0;
|
||||
char tok[MAX_TOKEN], *c;
|
||||
ssize_t tok_size;
|
||||
uint64_t value = 0;
|
||||
|
||||
if ((tok_size = get_token(fd, tok, MAX_TOKEN)) < 0)
|
||||
return tok_size;
|
||||
if ((tok_size = get_token(fd, tok, MAX_TOKEN)) < 0)
|
||||
return tok_size;
|
||||
|
||||
for (c = tok; c < tok + tok_size; c++)
|
||||
for (c = tok; c < tok + tok_size; c++)
|
||||
{
|
||||
value *= 10;
|
||||
value += *c - '0';
|
||||
}
|
||||
value *= 10;
|
||||
value += *c - '0';
|
||||
}
|
||||
|
||||
out->type = RDT_UINT;
|
||||
out->uint_ = value;
|
||||
return 0;
|
||||
out->type = RDT_UINT;
|
||||
out->uint_ = value;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int load_bin(int fd, struct rmsgpack_dom_value *out)
|
||||
@ -259,37 +259,37 @@ failed:
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int rv = 0;
|
||||
int src = -1;
|
||||
int dst = -1;
|
||||
int rv = 0;
|
||||
int src = -1;
|
||||
int dst = -1;
|
||||
|
||||
if (argc != 3)
|
||||
printf("Usage: %s <dat file> <output file>\n", argv[0]);
|
||||
if (argc != 3)
|
||||
printf("Usage: %s <dat file> <output file>\n", argv[0]);
|
||||
|
||||
src = open(argv[1], O_RDONLY);
|
||||
src = open(argv[1], O_RDONLY);
|
||||
|
||||
if (src == -1)
|
||||
if (src == -1)
|
||||
{
|
||||
printf("Could not open source file '%s': %s\n", argv[1], strerror(errno));
|
||||
rv = errno;
|
||||
goto clean;
|
||||
}
|
||||
printf("Could not open source file '%s': %s\n", argv[1], strerror(errno));
|
||||
rv = errno;
|
||||
goto clean;
|
||||
}
|
||||
|
||||
dst = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
|
||||
dst = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
|
||||
|
||||
if (dst == -1)
|
||||
if (dst == -1)
|
||||
{
|
||||
printf("Could not open destination file '%s': %s\n", argv[1], strerror(errno));
|
||||
rv = errno;
|
||||
goto clean;
|
||||
}
|
||||
printf("Could not open destination file '%s': %s\n", argv[1], strerror(errno));
|
||||
rv = errno;
|
||||
goto clean;
|
||||
}
|
||||
|
||||
rv = rarchdb_create(dst, &dat_value_provider, &src);
|
||||
rv = rarchdb_create(dst, &dat_value_provider, &src);
|
||||
|
||||
clean:
|
||||
if (src != -1)
|
||||
close(src);
|
||||
if (dst != -1)
|
||||
close(dst);
|
||||
return rv;
|
||||
if (src != -1)
|
||||
close(src);
|
||||
if (dst != -1)
|
||||
close(dst);
|
||||
return rv;
|
||||
}
|
||||
|
@ -22,8 +22,8 @@
|
||||
|
||||
struct node_iter_ctx
|
||||
{
|
||||
libretrodb_t *db;
|
||||
libretrodb_index_t *idx;
|
||||
libretrodb_t *db;
|
||||
libretrodb_index_t *idx;
|
||||
};
|
||||
|
||||
static struct rmsgpack_dom_value sentinal;
|
||||
@ -80,7 +80,7 @@ static int validate_document(const struct rmsgpack_dom_value * doc)
|
||||
}
|
||||
|
||||
int libretrodb_create(FILE *fp, libretrodb_value_provider value_provider,
|
||||
void * ctx)
|
||||
void * ctx)
|
||||
{
|
||||
int rv;
|
||||
off_t root;
|
||||
@ -135,13 +135,13 @@ static int libretrodb_read_index_header(FILE *fp, libretrodb_index_t *idx)
|
||||
|
||||
static void libretrodb_write_index_header(FILE *fp, libretrodb_index_t * idx)
|
||||
{
|
||||
rmsgpack_write_map_header(fp, 3);
|
||||
rmsgpack_write_string(fp, "name", strlen("name"));
|
||||
rmsgpack_write_string(fp, idx->name, strlen(idx->name));
|
||||
rmsgpack_write_string(fp, "key_size", strlen("key_size"));
|
||||
rmsgpack_write_uint(fp, idx->key_size);
|
||||
rmsgpack_write_string(fp, "next", strlen("next"));
|
||||
rmsgpack_write_uint(fp, idx->next);
|
||||
rmsgpack_write_map_header(fp, 3);
|
||||
rmsgpack_write_string(fp, "name", strlen("name"));
|
||||
rmsgpack_write_string(fp, idx->name, strlen(idx->name));
|
||||
rmsgpack_write_string(fp, "key_size", strlen("key_size"));
|
||||
rmsgpack_write_uint(fp, idx->key_size);
|
||||
rmsgpack_write_string(fp, "next", strlen("next"));
|
||||
rmsgpack_write_uint(fp, idx->next);
|
||||
}
|
||||
|
||||
void libretrodb_close(libretrodb_t *db)
|
||||
@ -149,8 +149,8 @@ void libretrodb_close(libretrodb_t *db)
|
||||
if (!db)
|
||||
return;
|
||||
|
||||
fclose(db->fp);
|
||||
db->fp = NULL;
|
||||
fclose(db->fp);
|
||||
db->fp = NULL;
|
||||
}
|
||||
|
||||
int libretrodb_open(const char *path, libretrodb_t *db)
|
||||
@ -245,7 +245,7 @@ static int binsearch(const void * buff, const void * item,
|
||||
}
|
||||
|
||||
int libretrodb_find_entry(libretrodb_t *db, const char *index_name,
|
||||
const void *key, struct rmsgpack_dom_value *out)
|
||||
const void *key, struct rmsgpack_dom_value *out)
|
||||
{
|
||||
libretrodb_index_t idx;
|
||||
int rv;
|
||||
@ -294,8 +294,8 @@ int libretrodb_find_entry(libretrodb_t *db, const char *index_name,
|
||||
**/
|
||||
int libretrodb_cursor_reset(libretrodb_cursor_t *cursor)
|
||||
{
|
||||
cursor->eof = 0;
|
||||
return flseek(cursor->fp,
|
||||
cursor->eof = 0;
|
||||
return flseek(cursor->fp,
|
||||
cursor->db->root + sizeof(libretrodb_header_t),
|
||||
SEEK_SET);
|
||||
}
|
||||
@ -339,16 +339,16 @@ void libretrodb_cursor_close(libretrodb_cursor_t *cursor)
|
||||
if (!cursor)
|
||||
return;
|
||||
|
||||
fclose(cursor->fp);
|
||||
|
||||
if (cursor->query)
|
||||
libretrodb_query_free(cursor->query);
|
||||
|
||||
cursor->is_valid = 0;
|
||||
cursor->fp = NULL;
|
||||
cursor->eof = 1;
|
||||
cursor->db = NULL;
|
||||
cursor->query = NULL;
|
||||
fclose(cursor->fp);
|
||||
|
||||
if (cursor->query)
|
||||
libretrodb_query_free(cursor->query);
|
||||
|
||||
cursor->is_valid = 0;
|
||||
cursor->fp = NULL;
|
||||
cursor->eof = 1;
|
||||
cursor->db = NULL;
|
||||
cursor->query = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -371,9 +371,9 @@ int libretrodb_cursor_open(libretrodb_t *db, libretrodb_cursor_t *cursor,
|
||||
|
||||
cursor->db = db;
|
||||
cursor->is_valid = 1;
|
||||
|
||||
|
||||
libretrodb_cursor_reset(cursor);
|
||||
|
||||
|
||||
cursor->query = q;
|
||||
|
||||
if (q)
|
||||
@ -401,121 +401,121 @@ static uint64_t libretrodb_tell(libretrodb_t *db)
|
||||
int libretrodb_create_index(libretrodb_t *db,
|
||||
const char *name, const char *field_name)
|
||||
{
|
||||
int rv;
|
||||
struct node_iter_ctx nictx;
|
||||
struct rmsgpack_dom_value key;
|
||||
libretrodb_index_t idx;
|
||||
struct rmsgpack_dom_value item;
|
||||
struct rmsgpack_dom_value *field;
|
||||
struct bintree tree;
|
||||
uint64_t idx_header_offset;
|
||||
libretrodb_cursor_t cur = {0};
|
||||
void *buff = NULL;
|
||||
uint64_t *buff_u64 = NULL;
|
||||
uint8_t field_size = 0;
|
||||
uint64_t item_loc = libretrodb_tell(db);
|
||||
int rv;
|
||||
struct node_iter_ctx nictx;
|
||||
struct rmsgpack_dom_value key;
|
||||
libretrodb_index_t idx;
|
||||
struct rmsgpack_dom_value item;
|
||||
struct rmsgpack_dom_value *field;
|
||||
struct bintree tree;
|
||||
uint64_t idx_header_offset;
|
||||
libretrodb_cursor_t cur = {0};
|
||||
void *buff = NULL;
|
||||
uint64_t *buff_u64 = NULL;
|
||||
uint8_t field_size = 0;
|
||||
uint64_t item_loc = libretrodb_tell(db);
|
||||
|
||||
bintree_new(&tree, node_compare, &field_size);
|
||||
bintree_new(&tree, node_compare, &field_size);
|
||||
|
||||
if (libretrodb_cursor_open(db, &cur, NULL) != 0)
|
||||
if (libretrodb_cursor_open(db, &cur, NULL) != 0)
|
||||
{
|
||||
rv = -1;
|
||||
goto clean;
|
||||
}
|
||||
rv = -1;
|
||||
goto clean;
|
||||
}
|
||||
|
||||
key.type = RDT_STRING;
|
||||
key.string.len = strlen(field_name);
|
||||
key.type = RDT_STRING;
|
||||
key.string.len = strlen(field_name);
|
||||
|
||||
/* We know we aren't going to change it */
|
||||
key.string.buff = (char*)field_name;
|
||||
/* We know we aren't going to change it */
|
||||
key.string.buff = (char*)field_name;
|
||||
|
||||
while (libretrodb_cursor_read_item(&cur, &item) == 0)
|
||||
while (libretrodb_cursor_read_item(&cur, &item) == 0)
|
||||
{
|
||||
if (item.type != RDT_MAP)
|
||||
if (item.type != RDT_MAP)
|
||||
{
|
||||
rv = -EINVAL;
|
||||
printf("Only map keys are supported\n");
|
||||
goto clean;
|
||||
}
|
||||
rv = -EINVAL;
|
||||
printf("Only map keys are supported\n");
|
||||
goto clean;
|
||||
}
|
||||
|
||||
field = rmsgpack_dom_value_map_value(&item, &key);
|
||||
field = rmsgpack_dom_value_map_value(&item, &key);
|
||||
|
||||
if (!field)
|
||||
if (!field)
|
||||
{
|
||||
rv = -EINVAL;
|
||||
printf("field not found in item\n");
|
||||
goto clean;
|
||||
}
|
||||
rv = -EINVAL;
|
||||
printf("field not found in item\n");
|
||||
goto clean;
|
||||
}
|
||||
|
||||
if (field->type != RDT_BINARY)
|
||||
if (field->type != RDT_BINARY)
|
||||
{
|
||||
rv = -EINVAL;
|
||||
printf("field is not binary\n");
|
||||
goto clean;
|
||||
}
|
||||
rv = -EINVAL;
|
||||
printf("field is not binary\n");
|
||||
goto clean;
|
||||
}
|
||||
|
||||
if (field->binary.len == 0)
|
||||
if (field->binary.len == 0)
|
||||
{
|
||||
rv = -EINVAL;
|
||||
printf("field is empty\n");
|
||||
goto clean;
|
||||
}
|
||||
rv = -EINVAL;
|
||||
printf("field is empty\n");
|
||||
goto clean;
|
||||
}
|
||||
|
||||
if (field_size == 0)
|
||||
field_size = field->binary.len;
|
||||
else if (field->binary.len != field_size)
|
||||
if (field_size == 0)
|
||||
field_size = field->binary.len;
|
||||
else if (field->binary.len != field_size)
|
||||
{
|
||||
rv = -EINVAL;
|
||||
printf("field is not of correct size\n");
|
||||
goto clean;
|
||||
}
|
||||
rv = -EINVAL;
|
||||
printf("field is not of correct size\n");
|
||||
goto clean;
|
||||
}
|
||||
|
||||
buff = malloc(field_size + sizeof(uint64_t));
|
||||
if (!buff)
|
||||
buff = malloc(field_size + sizeof(uint64_t));
|
||||
if (!buff)
|
||||
{
|
||||
rv = -ENOMEM;
|
||||
goto clean;
|
||||
}
|
||||
rv = -ENOMEM;
|
||||
goto clean;
|
||||
}
|
||||
|
||||
memcpy(buff, field->binary.buff, field_size);
|
||||
memcpy(buff, field->binary.buff, field_size);
|
||||
|
||||
buff_u64 = (uint64_t *)buff + field_size;
|
||||
buff_u64 = (uint64_t *)buff + field_size;
|
||||
|
||||
memcpy(buff_u64, &item_loc, sizeof(uint64_t));
|
||||
memcpy(buff_u64, &item_loc, sizeof(uint64_t));
|
||||
|
||||
if (bintree_insert(&tree, buff) != 0)
|
||||
if (bintree_insert(&tree, buff) != 0)
|
||||
{
|
||||
printf("Value is not unique: ");
|
||||
rmsgpack_dom_value_print(field);
|
||||
printf("\n");
|
||||
rv = -EINVAL;
|
||||
goto clean;
|
||||
}
|
||||
buff = NULL;
|
||||
rmsgpack_dom_value_free(&item);
|
||||
item_loc = libretrodb_tell(db);
|
||||
}
|
||||
printf("Value is not unique: ");
|
||||
rmsgpack_dom_value_print(field);
|
||||
printf("\n");
|
||||
rv = -EINVAL;
|
||||
goto clean;
|
||||
}
|
||||
buff = NULL;
|
||||
rmsgpack_dom_value_free(&item);
|
||||
item_loc = libretrodb_tell(db);
|
||||
}
|
||||
|
||||
(void)rv;
|
||||
(void)idx_header_offset;
|
||||
(void)rv;
|
||||
(void)idx_header_offset;
|
||||
|
||||
idx_header_offset = flseek(db->fp, 0, SEEK_END);
|
||||
strncpy(idx.name, name, 50);
|
||||
idx_header_offset = flseek(db->fp, 0, SEEK_END);
|
||||
strncpy(idx.name, name, 50);
|
||||
|
||||
idx.name[49] = '\0';
|
||||
idx.key_size = field_size;
|
||||
idx.next = db->count * (field_size + sizeof(uint64_t));
|
||||
libretrodb_write_index_header(db->fp, &idx);
|
||||
idx.name[49] = '\0';
|
||||
idx.key_size = field_size;
|
||||
idx.next = db->count * (field_size + sizeof(uint64_t));
|
||||
libretrodb_write_index_header(db->fp, &idx);
|
||||
|
||||
nictx.db = db;
|
||||
nictx.idx = &idx;
|
||||
bintree_iterate(&tree, node_iter, &nictx);
|
||||
bintree_free(&tree);
|
||||
nictx.db = db;
|
||||
nictx.idx = &idx;
|
||||
bintree_iterate(&tree, node_iter, &nictx);
|
||||
bintree_free(&tree);
|
||||
clean:
|
||||
rmsgpack_dom_value_free(&item);
|
||||
if (buff)
|
||||
free(buff);
|
||||
if (cur.is_valid)
|
||||
libretrodb_cursor_close(&cur);
|
||||
return 0;
|
||||
rmsgpack_dom_value_free(&item);
|
||||
if (buff)
|
||||
free(buff);
|
||||
if (cur.is_valid)
|
||||
libretrodb_cursor_close(&cur);
|
||||
return 0;
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ static void raise_enomem(const char **error)
|
||||
}
|
||||
|
||||
static void raise_unknown_function(off_t where, const char *name,
|
||||
size_t len, const char **error)
|
||||
size_t len, const char **error)
|
||||
{
|
||||
int n = snprintf(tmp_error_buff, MAX_ERROR_LEN,
|
||||
#ifdef _WIN32
|
||||
@ -131,26 +131,26 @@ enum argument_type
|
||||
struct argument;
|
||||
|
||||
typedef struct rmsgpack_dom_value (*rarch_query_func)(
|
||||
struct rmsgpack_dom_value input,
|
||||
unsigned argc,
|
||||
const struct argument *argv
|
||||
);
|
||||
struct rmsgpack_dom_value input,
|
||||
unsigned argc,
|
||||
const struct argument *argv
|
||||
);
|
||||
|
||||
struct invocation
|
||||
{
|
||||
rarch_query_func func;
|
||||
unsigned argc;
|
||||
struct argument *argv;
|
||||
rarch_query_func func;
|
||||
unsigned argc;
|
||||
struct argument *argv;
|
||||
};
|
||||
|
||||
struct argument
|
||||
{
|
||||
enum argument_type type;
|
||||
union
|
||||
enum argument_type type;
|
||||
union
|
||||
{
|
||||
struct rmsgpack_dom_value value;
|
||||
struct invocation invocation;
|
||||
};
|
||||
struct rmsgpack_dom_value value;
|
||||
struct invocation invocation;
|
||||
};
|
||||
};
|
||||
|
||||
static void argument_free(struct argument *arg)
|
||||
@ -169,21 +169,21 @@ static void argument_free(struct argument *arg)
|
||||
|
||||
struct query
|
||||
{
|
||||
unsigned ref_count;
|
||||
struct invocation root;
|
||||
unsigned ref_count;
|
||||
struct invocation root;
|
||||
};
|
||||
|
||||
struct registered_func
|
||||
{
|
||||
const char *name;
|
||||
rarch_query_func func;
|
||||
const char *name;
|
||||
rarch_query_func func;
|
||||
};
|
||||
|
||||
static struct buffer parse_argument(struct buffer buff, struct argument *arg,
|
||||
const char **error);
|
||||
|
||||
static struct rmsgpack_dom_value is_true(struct rmsgpack_dom_value input,
|
||||
unsigned argc, const struct argument *argv)
|
||||
unsigned argc, const struct argument *argv)
|
||||
{
|
||||
struct rmsgpack_dom_value res = {0};
|
||||
|
||||
@ -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 argument arg;
|
||||
struct rmsgpack_dom_value res = {0};
|
||||
@ -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)
|
||||
{
|
||||
unsigned i;
|
||||
struct rmsgpack_dom_value res = {0};
|
||||
@ -258,7 +258,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)
|
||||
{
|
||||
struct rmsgpack_dom_value res = {0};
|
||||
struct rmsgpack_dom_value res = {0};
|
||||
unsigned i = 0;
|
||||
|
||||
res.type = RDT_BOOL;
|
||||
@ -395,12 +395,12 @@ clean:
|
||||
}
|
||||
|
||||
struct registered_func registered_functions[100] = {
|
||||
{"is_true", is_true},
|
||||
{"or", operator_or},
|
||||
{"and", operator_and},
|
||||
{"between", between},
|
||||
{"glob", q_glob},
|
||||
{NULL, NULL}
|
||||
{"is_true", is_true},
|
||||
{"or", operator_or},
|
||||
{"and", operator_and},
|
||||
{"between", between},
|
||||
{"glob", q_glob},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
static struct buffer chomp(struct buffer buff)
|
||||
@ -460,14 +460,14 @@ static void peek_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))
|
||||
if (is_eot(buff))
|
||||
{
|
||||
raise_unexpected_eof(buff.offset, error);
|
||||
return buff;
|
||||
}
|
||||
*c = buff.data[buff.offset];
|
||||
buff.offset++;
|
||||
return buff;
|
||||
raise_unexpected_eof(buff.offset, error);
|
||||
return buff;
|
||||
}
|
||||
*c = buff.data[buff.offset];
|
||||
buff.offset++;
|
||||
return buff;
|
||||
}
|
||||
|
||||
static struct buffer parse_string(struct buffer buff,
|
||||
@ -574,26 +574,26 @@ static struct buffer get_ident(struct buffer buff,
|
||||
{
|
||||
char c = '\0';
|
||||
|
||||
if (is_eot(buff))
|
||||
if (is_eot(buff))
|
||||
{
|
||||
raise_unexpected_eof(buff.offset, error);
|
||||
return buff;
|
||||
}
|
||||
|
||||
*ident = buff.data + buff.offset;
|
||||
*len = 0;
|
||||
peek_char(buff, &c, error);
|
||||
*ident = buff.data + buff.offset;
|
||||
*len = 0;
|
||||
peek_char(buff, &c, error);
|
||||
|
||||
if (*error)
|
||||
goto clean;
|
||||
if (!isalpha(c))
|
||||
return buff;
|
||||
if (*error)
|
||||
goto clean;
|
||||
if (!isalpha(c))
|
||||
return buff;
|
||||
|
||||
buff.offset++;
|
||||
*len = *len + 1;
|
||||
peek_char(buff, &c, error);
|
||||
buff.offset++;
|
||||
*len = *len + 1;
|
||||
peek_char(buff, &c, error);
|
||||
|
||||
while (!*error)
|
||||
while (!*error)
|
||||
{
|
||||
if (!(isalpha(c) || isdigit(c) || c == '_'))
|
||||
break;
|
||||
@ -603,7 +603,7 @@ static struct buffer get_ident(struct buffer buff,
|
||||
}
|
||||
|
||||
clean:
|
||||
return buff;
|
||||
return buff;
|
||||
}
|
||||
|
||||
static struct buffer parse_method_call(struct buffer buff,
|
||||
@ -842,15 +842,15 @@ static struct buffer parse_argument(struct buffer buff,
|
||||
|
||||
void libretrodb_query_free(void *q)
|
||||
{
|
||||
unsigned i;
|
||||
struct query *real_q = (struct query*)q;
|
||||
unsigned i;
|
||||
struct query *real_q = (struct query*)q;
|
||||
|
||||
real_q->ref_count--;
|
||||
if (real_q->ref_count > 0)
|
||||
return;
|
||||
real_q->ref_count--;
|
||||
if (real_q->ref_count > 0)
|
||||
return;
|
||||
|
||||
for (i = 0; i < real_q->root.argc; i++)
|
||||
argument_free(&real_q->root.argv[i]);
|
||||
for (i = 0; i < real_q->root.argc; i++)
|
||||
argument_free(&real_q->root.argv[i]);
|
||||
}
|
||||
|
||||
void *libretrodb_query_compile(libretrodb_t *db,
|
||||
|
@ -418,7 +418,7 @@ static int read_buff(FILE *fp, size_t size, char **pbuff, uint64_t *len)
|
||||
}
|
||||
|
||||
static int read_map(FILE *fp, uint32_t len,
|
||||
struct rmsgpack_read_callbacks *callbacks, void *data)
|
||||
struct rmsgpack_read_callbacks *callbacks, void *data)
|
||||
{
|
||||
int rv;
|
||||
unsigned i;
|
||||
|
@ -13,72 +13,72 @@
|
||||
|
||||
struct dom_reader_state
|
||||
{
|
||||
int i;
|
||||
struct rmsgpack_dom_value *stack[MAX_DEPTH];
|
||||
int i;
|
||||
struct rmsgpack_dom_value *stack[MAX_DEPTH];
|
||||
};
|
||||
|
||||
static struct rmsgpack_dom_value *dom_reader_state_pop(
|
||||
struct dom_reader_state *s)
|
||||
{
|
||||
struct rmsgpack_dom_value *v = s->stack[s->i];
|
||||
s->i--;
|
||||
return v;
|
||||
struct rmsgpack_dom_value *v = s->stack[s->i];
|
||||
s->i--;
|
||||
return v;
|
||||
}
|
||||
|
||||
static void puts_i64(int64_t dec)
|
||||
{
|
||||
signed char digits[19 + 1]; /* max i64: 9,223,372,036,854,775,807 */
|
||||
int i;
|
||||
uint64_t decimal = (dec < 0) ? (uint64_t)-dec : (uint64_t)+dec;
|
||||
|
||||
digits[19] = '\0';
|
||||
|
||||
for (i = sizeof(digits) - 2; i >= 0; i--)
|
||||
{
|
||||
digits[i] = decimal % 10;
|
||||
decimal /= 10;
|
||||
}
|
||||
signed char digits[19 + 1]; /* max i64: 9,223,372,036,854,775,807 */
|
||||
int i;
|
||||
uint64_t decimal = (dec < 0) ? (uint64_t)-dec : (uint64_t)+dec;
|
||||
|
||||
for (i = 0; i < sizeof(digits) - 1; i++)
|
||||
digits[i] += '0';
|
||||
for (i = 0; i < sizeof(digits) - 2; i++)
|
||||
if (digits[i] != '0')
|
||||
break; /* Don't print leading zeros to the console. */
|
||||
digits[19] = '\0';
|
||||
|
||||
if (dec < 0)
|
||||
putchar('-');
|
||||
fputs((char *)&digits[i], stdout);
|
||||
for (i = sizeof(digits) - 2; i >= 0; i--)
|
||||
{
|
||||
digits[i] = decimal % 10;
|
||||
decimal /= 10;
|
||||
}
|
||||
|
||||
for (i = 0; i < sizeof(digits) - 1; i++)
|
||||
digits[i] += '0';
|
||||
for (i = 0; i < sizeof(digits) - 2; i++)
|
||||
if (digits[i] != '0')
|
||||
break; /* Don't print leading zeros to the console. */
|
||||
|
||||
if (dec < 0)
|
||||
putchar('-');
|
||||
fputs((char *)&digits[i], stdout);
|
||||
}
|
||||
|
||||
static void puts_u64(uint64_t decimal)
|
||||
{
|
||||
char digits[20 + 1]; /* max u64: 18,446,744,073,709,551,616 */
|
||||
int i;
|
||||
char digits[20 + 1]; /* max u64: 18,446,744,073,709,551,616 */
|
||||
int i;
|
||||
|
||||
digits[20] = '\0';
|
||||
for (i = sizeof(digits) - 2; i >= 0; i--)
|
||||
{
|
||||
digits[i] = decimal % 10;
|
||||
decimal /= 10;
|
||||
}
|
||||
digits[20] = '\0';
|
||||
for (i = sizeof(digits) - 2; i >= 0; i--)
|
||||
{
|
||||
digits[i] = decimal % 10;
|
||||
decimal /= 10;
|
||||
}
|
||||
|
||||
for (i = 0; i < sizeof(digits) - 1; i++)
|
||||
digits[i] += '0';
|
||||
for (i = 0; i < sizeof(digits) - 2; i++)
|
||||
if (digits[i] != '0')
|
||||
break; /* Don't print leading zeros to the console. */
|
||||
for (i = 0; i < sizeof(digits) - 1; i++)
|
||||
digits[i] += '0';
|
||||
for (i = 0; i < sizeof(digits) - 2; i++)
|
||||
if (digits[i] != '0')
|
||||
break; /* Don't print leading zeros to the console. */
|
||||
|
||||
fputs(&digits[i], stdout);
|
||||
fputs(&digits[i], stdout);
|
||||
}
|
||||
|
||||
static int dom_reader_state_push(struct dom_reader_state *s,
|
||||
struct rmsgpack_dom_value *v)
|
||||
{
|
||||
if ((s->i + 1) == MAX_DEPTH)
|
||||
return -ENOMEM;
|
||||
s->i++;
|
||||
s->stack[s->i] = v;
|
||||
return 0;
|
||||
if ((s->i + 1) == MAX_DEPTH)
|
||||
return -ENOMEM;
|
||||
s->i++;
|
||||
s->stack[s->i] = v;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dom_read_nil(void *data)
|
||||
@ -140,7 +140,7 @@ static int dom_read_bin(void *value, uint32_t len, void *data)
|
||||
struct dom_reader_state *dom_state = (struct dom_reader_state *)data;
|
||||
struct rmsgpack_dom_value *v =
|
||||
(struct rmsgpack_dom_value*)dom_reader_state_pop(dom_state);
|
||||
|
||||
|
||||
v->type = RDT_BINARY;
|
||||
v->binary.len = len;
|
||||
v->binary.buff = (char *)value;
|
||||
@ -179,40 +179,40 @@ static int dom_read_map_start(uint32_t len, void *data)
|
||||
|
||||
static int dom_read_array_start(uint32_t len, void *data)
|
||||
{
|
||||
unsigned i;
|
||||
struct dom_reader_state *dom_state = (struct dom_reader_state *)data;
|
||||
struct rmsgpack_dom_value *v = dom_reader_state_pop(dom_state);
|
||||
struct rmsgpack_dom_value *items = NULL;
|
||||
unsigned i;
|
||||
struct dom_reader_state *dom_state = (struct dom_reader_state *)data;
|
||||
struct rmsgpack_dom_value *v = dom_reader_state_pop(dom_state);
|
||||
struct rmsgpack_dom_value *items = NULL;
|
||||
|
||||
v->type = RDT_ARRAY;
|
||||
v->array.len = len;
|
||||
v->array.items = NULL;
|
||||
v->type = RDT_ARRAY;
|
||||
v->array.len = len;
|
||||
v->array.items = NULL;
|
||||
|
||||
items = (struct rmsgpack_dom_value *)calloc(len, sizeof(struct rmsgpack_dom_pair));
|
||||
items = (struct rmsgpack_dom_value *)calloc(len, sizeof(struct rmsgpack_dom_pair));
|
||||
|
||||
if (!items)
|
||||
return -ENOMEM;
|
||||
if (!items)
|
||||
return -ENOMEM;
|
||||
|
||||
v->array.items = items;
|
||||
v->array.items = items;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
if (dom_reader_state_push(dom_state, &items[i]) < 0)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct rmsgpack_read_callbacks dom_reader_callbacks = {
|
||||
dom_read_nil,
|
||||
dom_read_bool,
|
||||
dom_read_int,
|
||||
dom_read_uint,
|
||||
dom_read_string,
|
||||
dom_read_bin,
|
||||
dom_read_map_start,
|
||||
dom_read_array_start
|
||||
dom_read_nil,
|
||||
dom_read_bool,
|
||||
dom_read_int,
|
||||
dom_read_uint,
|
||||
dom_read_string,
|
||||
dom_read_bin,
|
||||
dom_read_map_start,
|
||||
dom_read_array_start
|
||||
};
|
||||
|
||||
void rmsgpack_dom_value_free(struct rmsgpack_dom_value *v)
|
||||
@ -268,7 +268,7 @@ struct rmsgpack_dom_value *rmsgpack_dom_value_map_value(
|
||||
int rmsgpack_dom_value_cmp(
|
||||
const struct rmsgpack_dom_value *a,
|
||||
const struct rmsgpack_dom_value *b
|
||||
)
|
||||
)
|
||||
{
|
||||
int rv;
|
||||
unsigned i;
|
||||
|
Loading…
x
Reference in New Issue
Block a user