queue_print, dbUtils: use struct locate_item_list

Changed the function prototypes to get locate_item_list objects
instead of num_items/items.
This commit is contained in:
Max Kellermann 2009-01-24 15:56:34 +01:00
parent ba7c996266
commit 6a2118d04c
7 changed files with 58 additions and 74 deletions

View File

@ -844,7 +844,7 @@ handle_find(struct client *client, int argc, char *argv[])
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
} }
ret = findSongsIn(client, NULL, list->length, list->items); ret = findSongsIn(client, NULL, list);
if (ret == -1) if (ret == -1)
command_error(client, ACK_ERROR_NO_EXIST, command_error(client, ACK_ERROR_NO_EXIST,
"directory or file not found"); "directory or file not found");
@ -869,7 +869,7 @@ handle_search(struct client *client, int argc, char *argv[])
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
} }
ret = searchForSongsIn(client, NULL, list->length, list->items); ret = searchForSongsIn(client, NULL, list);
if (ret == -1) if (ret == -1)
command_error(client, ACK_ERROR_NO_EXIST, command_error(client, ACK_ERROR_NO_EXIST,
"directory or file not found"); "directory or file not found");
@ -894,7 +894,7 @@ handle_count(struct client *client, int argc, char *argv[])
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
} }
ret = searchStatsForSongsIn(client, NULL, list->length, list->items); ret = searchStatsForSongsIn(client, NULL, list);
if (ret == -1) if (ret == -1)
command_error(client, ACK_ERROR_NO_EXIST, command_error(client, ACK_ERROR_NO_EXIST,
"directory or file not found"); "directory or file not found");
@ -918,7 +918,7 @@ handle_playlistfind(struct client *client, int argc, char *argv[])
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
} }
queue_find(client, playlist_get_queue(), list->length, list->items); queue_find(client, playlist_get_queue(), list);
locate_item_list_free(list); locate_item_list_free(list);
@ -939,7 +939,7 @@ handle_playlistsearch(struct client *client, int argc, char *argv[])
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
} }
queue_search(client, playlist_get_queue(), list->length, list->items); queue_search(client, playlist_get_queue(), list);
locate_item_list_free(list); locate_item_list_free(list);
@ -1155,8 +1155,7 @@ handle_list(struct client *client, int argc, char *argv[])
} }
} }
ret = listAllUniqueTags(client, tagType, conditionals->length, ret = listAllUniqueTags(client, tagType, conditionals);
conditionals->items);
locate_item_list_free(conditionals); locate_item_list_free(conditionals);

View File

@ -35,17 +35,11 @@
typedef struct _ListCommandItem { typedef struct _ListCommandItem {
int8_t tagType; int8_t tagType;
int numConditionals; const struct locate_item_list *criteria;
const struct locate_item *conditionals;
} ListCommandItem; } ListCommandItem;
typedef struct _LocateTagItemArray {
int numItems;
const struct locate_item *items;
} LocateTagItemArray;
typedef struct _SearchStats { typedef struct _SearchStats {
LocateTagItemArray locateArray; const struct locate_item_list *criteria;
int numberOfSongs; int numberOfSongs;
unsigned long playTime; unsigned long playTime;
} SearchStats; } SearchStats;
@ -71,16 +65,15 @@ printSongInDirectory(struct song *song, G_GNUC_UNUSED void *data)
struct search_data { struct search_data {
struct client *client; struct client *client;
LocateTagItemArray array; const struct locate_item_list *criteria;
}; };
static int static int
searchInDirectory(struct song *song, void *_data) searchInDirectory(struct song *song, void *_data)
{ {
struct search_data *data = _data; struct search_data *data = _data;
LocateTagItemArray *array = &data->array;
if (locate_song_search(song, array->numItems, array->items)) if (locate_song_search(song, data->criteria))
return song_print_info(data->client, song); return song_print_info(data->client, song);
return 0; return 0;
@ -88,21 +81,19 @@ searchInDirectory(struct song *song, void *_data)
int int
searchForSongsIn(struct client *client, const char *name, searchForSongsIn(struct client *client, const char *name,
int numItems, const struct locate_item *items) const struct locate_item_list *criteria)
{ {
int ret; int ret;
int i;
struct locate_item_list *new_list; struct locate_item_list *new_list;
struct search_data data; struct search_data data;
new_list = locate_item_list_new(numItems); new_list = locate_item_list_new(criteria->length);
for (i = 0; i < numItems; i++) for (unsigned i = 0; i < criteria->length; i++)
new_list->items[i].needle = new_list->items[i].needle =
g_utf8_casefold(items[i].needle, -1); g_utf8_casefold(criteria->items[i].needle, -1);
data.client = client; data.client = client;
data.array.numItems = numItems; data.criteria = new_list;
data.array.items = new_list->items;
ret = db_walk(name, searchInDirectory, NULL, &data); ret = db_walk(name, searchInDirectory, NULL, &data);
@ -115,9 +106,8 @@ static int
findInDirectory(struct song *song, void *_data) findInDirectory(struct song *song, void *_data)
{ {
struct search_data *data = _data; struct search_data *data = _data;
LocateTagItemArray *array = &data->array;
if (locate_song_match(song, array->numItems, array->items)) if (locate_song_match(song, data->criteria))
return song_print_info(data->client, song); return song_print_info(data->client, song);
return 0; return 0;
@ -125,13 +115,12 @@ findInDirectory(struct song *song, void *_data)
int int
findSongsIn(struct client *client, const char *name, findSongsIn(struct client *client, const char *name,
int numItems, const struct locate_item *items) const struct locate_item_list *criteria)
{ {
struct search_data data; struct search_data data;
data.client = client; data.client = client;
data.array.numItems = numItems; data.criteria = criteria;
data.array.items = items;
return db_walk(name, findInDirectory, NULL, &data); return db_walk(name, findInDirectory, NULL, &data);
} }
@ -147,8 +136,7 @@ searchStatsInDirectory(struct song *song, void *data)
{ {
SearchStats *stats = data; SearchStats *stats = data;
if (locate_song_match(song, stats->locateArray.numItems, if (locate_song_match(song, stats->criteria)) {
stats->locateArray.items)) {
stats->numberOfSongs++; stats->numberOfSongs++;
if (song->tag->time > 0) if (song->tag->time > 0)
stats->playTime += song->tag->time; stats->playTime += song->tag->time;
@ -159,13 +147,12 @@ searchStatsInDirectory(struct song *song, void *data)
int int
searchStatsForSongsIn(struct client *client, const char *name, searchStatsForSongsIn(struct client *client, const char *name,
int numItems, const struct locate_item *items) const struct locate_item_list *criteria)
{ {
SearchStats stats; SearchStats stats;
int ret; int ret;
stats.locateArray.numItems = numItems; stats.criteria = criteria;
stats.locateArray.items = items;
stats.numberOfSongs = 0; stats.numberOfSongs = 0;
stats.playTime = 0; stats.playTime = 0;
@ -231,14 +218,12 @@ int printInfoForAllIn(struct client *client, const char *name)
} }
static ListCommandItem * static ListCommandItem *
newListCommandItem(int tagType, int numConditionals, newListCommandItem(int tagType, const struct locate_item_list *criteria)
const struct locate_item *conditionals)
{ {
ListCommandItem *item = g_new(ListCommandItem, 1); ListCommandItem *item = g_new(ListCommandItem, 1);
item->tagType = tagType; item->tagType = tagType;
item->numConditionals = numConditionals; item->criteria = criteria;
item->conditionals = conditionals;
return item; return item;
} }
@ -284,20 +269,17 @@ listUniqueTagsInDirectory(struct song *song, void *_data)
struct list_tags_data *data = _data; struct list_tags_data *data = _data;
ListCommandItem *item = data->item; ListCommandItem *item = data->item;
if (locate_song_match(song, item->numConditionals, if (locate_song_match(song, item->criteria))
item->conditionals)) {
visitTag(data->client, data->set, song, item->tagType); visitTag(data->client, data->set, song, item->tagType);
}
return 0; return 0;
} }
int listAllUniqueTags(struct client *client, int type, int numConditionals, int listAllUniqueTags(struct client *client, int type,
const struct locate_item *conditionals) const struct locate_item_list *criteria)
{ {
int ret; int ret;
ListCommandItem *item = newListCommandItem(type, numConditionals, ListCommandItem *item = newListCommandItem(type, criteria);
conditionals);
struct list_tags_data data = { struct list_tags_data data = {
.client = client, .client = client,
.item = item, .item = item,

View File

@ -20,7 +20,7 @@
#define MPD_DB_UTILS_H #define MPD_DB_UTILS_H
struct client; struct client;
struct locate_item; struct locate_item_list;
int printAllIn(struct client *client, const char *name); int printAllIn(struct client *client, const char *name);
@ -32,21 +32,21 @@ int printInfoForAllIn(struct client *client, const char *name);
int int
searchForSongsIn(struct client *client, const char *name, searchForSongsIn(struct client *client, const char *name,
int numItems, const struct locate_item * items); const struct locate_item_list *criteria);
int int
findSongsIn(struct client *client, const char *name, findSongsIn(struct client *client, const char *name,
int numItems, const struct locate_item * items); const struct locate_item_list *criteria);
int int
searchStatsForSongsIn(struct client *client, const char *name, searchStatsForSongsIn(struct client *client, const char *name,
int numItems, const struct locate_item * items); const struct locate_item_list *criteria);
unsigned long sumSongTimesIn(const char *name); unsigned long sumSongTimesIn(const char *name);
int int
listAllUniqueTags(struct client *client, int type, int numConditiionals, listAllUniqueTags(struct client *client, int type,
const struct locate_item *conditionals); const struct locate_item_list *criteria);
void printSavedMemoryFromFilenames(void); void printSavedMemoryFromFilenames(void);

View File

@ -177,11 +177,12 @@ locate_tag_search(const struct song *song, enum tag_type type, const char *str)
} }
bool bool
locate_song_search(const struct song *song, int num_items, locate_song_search(const struct song *song,
const struct locate_item *items) const struct locate_item_list *criteria)
{ {
for (int i = 0; i < num_items; i++) for (unsigned i = 0; i < criteria->length; i++)
if (!locate_tag_search(song, items[i].tag, items[i].needle)) if (!locate_tag_search(song, criteria->items[i].tag,
criteria->items[i].needle))
return false; return false;
return true; return true;
@ -234,11 +235,12 @@ locate_tag_match(const struct song *song, enum tag_type type, const char *str)
} }
bool bool
locate_song_match(const struct song *song, int num_items, locate_song_match(const struct song *song,
const struct locate_item *items) const struct locate_item_list *criteria)
{ {
for (int i = 0; i < num_items; i++) for (unsigned i = 0; i < criteria->length; i++)
if (!locate_tag_match(song, items[i].tag, items[i].needle)) if (!locate_tag_match(song, criteria->items[i].tag,
criteria->items[i].needle))
return false; return false;
return true; return true;

View File

@ -70,11 +70,11 @@ void
locate_item_free(struct locate_item *item); locate_item_free(struct locate_item *item);
bool bool
locate_song_search(const struct song *song, int numItems, locate_song_search(const struct song *song,
const struct locate_item *items); const struct locate_item_list *criteria);
bool bool
locate_song_match(const struct song *song, int numItems, locate_song_match(const struct song *song,
const struct locate_item *items); const struct locate_item_list *criteria);
#endif #endif

View File

@ -81,19 +81,20 @@ queue_print_changes_position(struct client *client, const struct queue *queue,
void void
queue_search(struct client *client, const struct queue *queue, queue_search(struct client *client, const struct queue *queue,
unsigned num_items, const struct locate_item *items) const struct locate_item_list *criteria)
{ {
unsigned i; unsigned i;
struct locate_item_list *new_list = locate_item_list_new(num_items); struct locate_item_list *new_list =
locate_item_list_new(criteria->length);
for (i = 0; i < num_items; i++) for (i = 0; i < criteria->length; i++)
new_list->items[i].needle = new_list->items[i].needle =
g_utf8_casefold(items[i].needle, -1); g_utf8_casefold(criteria->items[i].needle, -1);
for (i = 0; i < queue_length(queue); i++) { for (i = 0; i < queue_length(queue); i++) {
const struct song *song = queue_get(queue, i); const struct song *song = queue_get(queue, i);
if (locate_song_search(song, num_items, new_list->items)) if (locate_song_search(song, new_list))
queue_print_song_info(client, queue, i); queue_print_song_info(client, queue, i);
} }
@ -102,12 +103,12 @@ queue_search(struct client *client, const struct queue *queue,
void void
queue_find(struct client *client, const struct queue *queue, queue_find(struct client *client, const struct queue *queue,
unsigned num_items, const struct locate_item *items) const struct locate_item_list *criteria)
{ {
for (unsigned i = 0; i < queue_length(queue); i++) { for (unsigned i = 0; i < queue_length(queue); i++) {
const struct song *song = queue_get(queue, i); const struct song *song = queue_get(queue, i);
if (locate_song_match(song, num_items, items)) if (locate_song_match(song, criteria))
queue_print_song_info(client, queue, i); queue_print_song_info(client, queue, i);
} }
} }

View File

@ -28,7 +28,7 @@
struct client; struct client;
struct queue; struct queue;
struct locate_item; struct locate_item_list;
void void
queue_print_song_info(struct client *client, const struct queue *queue, queue_print_song_info(struct client *client, const struct queue *queue,
@ -60,10 +60,10 @@ queue_print_changes_position(struct client *client, const struct queue *queue,
void void
queue_search(struct client *client, const struct queue *queue, queue_search(struct client *client, const struct queue *queue,
unsigned num_items, const struct locate_item *items); const struct locate_item_list *criteria);
void void
queue_find(struct client *client, const struct queue *queue, queue_find(struct client *client, const struct queue *queue,
unsigned num_items, const struct locate_item *items); const struct locate_item_list *criteria);
#endif #endif