locate: make the structs opaque
This commit is contained in:
@@ -227,9 +227,9 @@ handle_list(struct client *client, int argc, char *argv[])
|
|||||||
return COMMAND_RETURN_ERROR;
|
return COMMAND_RETURN_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
conditionals = locate_item_list_new(1);
|
conditionals =
|
||||||
conditionals->items[0].tag = TAG_ARTIST;
|
locate_item_list_new_single((unsigned)TAG_ARTIST,
|
||||||
conditionals->items[0].needle = g_strdup(argv[2]);
|
argv[2]);
|
||||||
} else {
|
} else {
|
||||||
conditionals =
|
conditionals =
|
||||||
locate_item_list_parse(argv + 2, argc - 2, false);
|
locate_item_list_parse(argv + 2, argc - 2, false);
|
||||||
|
31
src/locate.c
31
src/locate.c
@@ -31,6 +31,24 @@
|
|||||||
#define LOCATE_TAG_FILE_KEY_OLD "filename"
|
#define LOCATE_TAG_FILE_KEY_OLD "filename"
|
||||||
#define LOCATE_TAG_ANY_KEY "any"
|
#define LOCATE_TAG_ANY_KEY "any"
|
||||||
|
|
||||||
|
/* struct used for search, find, list queries */
|
||||||
|
struct locate_item {
|
||||||
|
int8_t tag;
|
||||||
|
/* what we are looking for */
|
||||||
|
char *needle;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An array of struct locate_item objects.
|
||||||
|
*/
|
||||||
|
struct locate_item_list {
|
||||||
|
/** number of items */
|
||||||
|
unsigned length;
|
||||||
|
|
||||||
|
/** this is a variable length array */
|
||||||
|
struct locate_item items[1];
|
||||||
|
};
|
||||||
|
|
||||||
int
|
int
|
||||||
locate_parse_type(const char *str)
|
locate_parse_type(const char *str)
|
||||||
{
|
{
|
||||||
@@ -74,17 +92,26 @@ locate_item_list_free(struct locate_item_list *list)
|
|||||||
g_free(list);
|
g_free(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct locate_item_list *
|
static struct locate_item_list *
|
||||||
locate_item_list_new(unsigned length)
|
locate_item_list_new(unsigned length)
|
||||||
{
|
{
|
||||||
struct locate_item_list *list =
|
struct locate_item_list *list =
|
||||||
g_malloc0(sizeof(*list) - sizeof(list->items[0]) +
|
g_malloc(sizeof(*list) - sizeof(list->items[0]) +
|
||||||
length * sizeof(list->items[0]));
|
length * sizeof(list->items[0]));
|
||||||
list->length = length;
|
list->length = length;
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct locate_item_list *
|
||||||
|
locate_item_list_new_single(unsigned tag, const char *needle)
|
||||||
|
{
|
||||||
|
struct locate_item_list *list = locate_item_list_new(1);
|
||||||
|
list->items[0].tag = tag;
|
||||||
|
list->items[0].needle = g_strdup(needle);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
struct locate_item_list *
|
struct locate_item_list *
|
||||||
locate_item_list_parse(char *argv[], unsigned argc, bool fold_case)
|
locate_item_list_parse(char *argv[], unsigned argc, bool fold_case)
|
||||||
{
|
{
|
||||||
|
26
src/locate.h
26
src/locate.h
@@ -28,36 +28,16 @@
|
|||||||
#define LOCATE_TAG_FILE_TYPE TAG_NUM_OF_ITEM_TYPES+10
|
#define LOCATE_TAG_FILE_TYPE TAG_NUM_OF_ITEM_TYPES+10
|
||||||
#define LOCATE_TAG_ANY_TYPE TAG_NUM_OF_ITEM_TYPES+20
|
#define LOCATE_TAG_ANY_TYPE TAG_NUM_OF_ITEM_TYPES+20
|
||||||
|
|
||||||
|
struct locate_item_list;
|
||||||
struct song;
|
struct song;
|
||||||
|
|
||||||
/* struct used for search, find, list queries */
|
|
||||||
struct locate_item {
|
|
||||||
int8_t tag;
|
|
||||||
/* what we are looking for */
|
|
||||||
char *needle;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An array of struct locate_item objects.
|
|
||||||
*/
|
|
||||||
struct locate_item_list {
|
|
||||||
/** number of items */
|
|
||||||
unsigned length;
|
|
||||||
|
|
||||||
/** this is a variable length array */
|
|
||||||
struct locate_item items[1];
|
|
||||||
};
|
|
||||||
|
|
||||||
gcc_pure
|
gcc_pure
|
||||||
int
|
int
|
||||||
locate_parse_type(const char *str);
|
locate_parse_type(const char *str);
|
||||||
|
|
||||||
/**
|
gcc_malloc
|
||||||
* Allocates a new struct locate_item_list, and initializes all
|
|
||||||
* members with zero bytes.
|
|
||||||
*/
|
|
||||||
struct locate_item_list *
|
struct locate_item_list *
|
||||||
locate_item_list_new(unsigned length);
|
locate_item_list_new_single(unsigned tag, const char *needle);
|
||||||
|
|
||||||
/* return number of items or -1 on error */
|
/* return number of items or -1 on error */
|
||||||
gcc_nonnull(1)
|
gcc_nonnull(1)
|
||||||
|
Reference in New Issue
Block a user