aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-01-24 15:56:34 +0100
committerMax Kellermann <max@duempel.org>2009-01-24 15:56:34 +0100
commit6a2118d04c7b73450edfffb6fdc40de1a05bfe94 (patch)
tree26b72b675bc6dcf864e58d4e9ff2a4869aa48f0c
parentba7c9962663d2e80a6320ca097c06a0849218d27 (diff)
downloadmpd-6a2118d04c7b73450edfffb6fdc40de1a05bfe94.tar.gz
mpd-6a2118d04c7b73450edfffb6fdc40de1a05bfe94.tar.xz
mpd-6a2118d04c7b73450edfffb6fdc40de1a05bfe94.zip
queue_print, dbUtils: use struct locate_item_list
Changed the function prototypes to get locate_item_list objects instead of num_items/items.
-rw-r--r--src/command.c13
-rw-r--r--src/dbUtils.c60
-rw-r--r--src/dbUtils.h12
-rw-r--r--src/locate.c18
-rw-r--r--src/locate.h8
-rw-r--r--src/queue_print.c15
-rw-r--r--src/queue_print.h6
7 files changed, 58 insertions, 74 deletions
diff --git a/src/command.c b/src/command.c
index 744aec8e7..7f1858a34 100644
--- a/src/command.c
+++ b/src/command.c
@@ -844,7 +844,7 @@ handle_find(struct client *client, int argc, char *argv[])
return COMMAND_RETURN_ERROR;
}
- ret = findSongsIn(client, NULL, list->length, list->items);
+ ret = findSongsIn(client, NULL, list);
if (ret == -1)
command_error(client, ACK_ERROR_NO_EXIST,
"directory or file not found");
@@ -869,7 +869,7 @@ handle_search(struct client *client, int argc, char *argv[])
return COMMAND_RETURN_ERROR;
}
- ret = searchForSongsIn(client, NULL, list->length, list->items);
+ ret = searchForSongsIn(client, NULL, list);
if (ret == -1)
command_error(client, ACK_ERROR_NO_EXIST,
"directory or file not found");
@@ -894,7 +894,7 @@ handle_count(struct client *client, int argc, char *argv[])
return COMMAND_RETURN_ERROR;
}
- ret = searchStatsForSongsIn(client, NULL, list->length, list->items);
+ ret = searchStatsForSongsIn(client, NULL, list);
if (ret == -1)
command_error(client, ACK_ERROR_NO_EXIST,
"directory or file not found");
@@ -918,7 +918,7 @@ handle_playlistfind(struct client *client, int argc, char *argv[])
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);
@@ -939,7 +939,7 @@ handle_playlistsearch(struct client *client, int argc, char *argv[])
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);
@@ -1155,8 +1155,7 @@ handle_list(struct client *client, int argc, char *argv[])
}
}
- ret = listAllUniqueTags(client, tagType, conditionals->length,
- conditionals->items);
+ ret = listAllUniqueTags(client, tagType, conditionals);
locate_item_list_free(conditionals);
diff --git a/src/dbUtils.c b/src/dbUtils.c
index e130ba680..00df5b606 100644
--- a/src/dbUtils.c
+++ b/src/dbUtils.c
@@ -35,17 +35,11 @@
typedef struct _ListCommandItem {
int8_t tagType;
- int numConditionals;
- const struct locate_item *conditionals;
+ const struct locate_item_list *criteria;
} ListCommandItem;
-typedef struct _LocateTagItemArray {
- int numItems;
- const struct locate_item *items;
-} LocateTagItemArray;
-
typedef struct _SearchStats {
- LocateTagItemArray locateArray;
+ const struct locate_item_list *criteria;
int numberOfSongs;
unsigned long playTime;
} SearchStats;
@@ -71,16 +65,15 @@ printSongInDirectory(struct song *song, G_GNUC_UNUSED void *data)
struct search_data {
struct client *client;
- LocateTagItemArray array;
+ const struct locate_item_list *criteria;
};
static int
searchInDirectory(struct song *song, void *_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 0;
@@ -88,21 +81,19 @@ searchInDirectory(struct song *song, void *_data)
int
searchForSongsIn(struct client *client, const char *name,
- int numItems, const struct locate_item *items)
+ const struct locate_item_list *criteria)
{
int ret;
- int i;
struct locate_item_list *new_list;
struct search_data data;
- new_list = locate_item_list_new(numItems);
- for (i = 0; i < numItems; i++)
+ new_list = locate_item_list_new(criteria->length);
+ for (unsigned i = 0; i < criteria->length; i++)
new_list->items[i].needle =
- g_utf8_casefold(items[i].needle, -1);
+ g_utf8_casefold(criteria->items[i].needle, -1);
data.client = client;
- data.array.numItems = numItems;
- data.array.items = new_list->items;
+ data.criteria = new_list;
ret = db_walk(name, searchInDirectory, NULL, &data);
@@ -115,9 +106,8 @@ static int
findInDirectory(struct song *song, void *_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 0;
@@ -125,13 +115,12 @@ findInDirectory(struct song *song, void *_data)
int
findSongsIn(struct client *client, const char *name,
- int numItems, const struct locate_item *items)
+ const struct locate_item_list *criteria)
{
struct search_data data;
data.client = client;
- data.array.numItems = numItems;
- data.array.items = items;
+ data.criteria = criteria;
return db_walk(name, findInDirectory, NULL, &data);
}
@@ -147,8 +136,7 @@ searchStatsInDirectory(struct song *song, void *data)
{
SearchStats *stats = data;
- if (locate_song_match(song, stats->locateArray.numItems,
- stats->locateArray.items)) {
+ if (locate_song_match(song, stats->criteria)) {
stats->numberOfSongs++;
if (song->tag->time > 0)
stats->playTime += song->tag->time;
@@ -159,13 +147,12 @@ searchStatsInDirectory(struct song *song, void *data)
int
searchStatsForSongsIn(struct client *client, const char *name,
- int numItems, const struct locate_item *items)
+ const struct locate_item_list *criteria)
{
SearchStats stats;
int ret;
- stats.locateArray.numItems = numItems;
- stats.locateArray.items = items;
+ stats.criteria = criteria;
stats.numberOfSongs = 0;
stats.playTime = 0;
@@ -231,14 +218,12 @@ int printInfoForAllIn(struct client *client, const char *name)
}
static ListCommandItem *
-newListCommandItem(int tagType, int numConditionals,
- const struct locate_item *conditionals)
+newListCommandItem(int tagType, const struct locate_item_list *criteria)
{
ListCommandItem *item = g_new(ListCommandItem, 1);
item->tagType = tagType;
- item->numConditionals = numConditionals;
- item->conditionals = conditionals;
+ item->criteria = criteria;
return item;
}
@@ -284,20 +269,17 @@ listUniqueTagsInDirectory(struct song *song, void *_data)
struct list_tags_data *data = _data;
ListCommandItem *item = data->item;
- if (locate_song_match(song, item->numConditionals,
- item->conditionals)) {
+ if (locate_song_match(song, item->criteria))
visitTag(data->client, data->set, song, item->tagType);
- }
return 0;
}
-int listAllUniqueTags(struct client *client, int type, int numConditionals,
- const struct locate_item *conditionals)
+int listAllUniqueTags(struct client *client, int type,
+ const struct locate_item_list *criteria)
{
int ret;
- ListCommandItem *item = newListCommandItem(type, numConditionals,
- conditionals);
+ ListCommandItem *item = newListCommandItem(type, criteria);
struct list_tags_data data = {
.client = client,
.item = item,
diff --git a/src/dbUtils.h b/src/dbUtils.h
index b32f6f41a..aabaea788 100644
--- a/src/dbUtils.h
+++ b/src/dbUtils.h
@@ -20,7 +20,7 @@
#define MPD_DB_UTILS_H
struct client;
-struct locate_item;
+struct locate_item_list;
int printAllIn(struct client *client, const char *name);
@@ -32,21 +32,21 @@ int printInfoForAllIn(struct client *client, const char *name);
int
searchForSongsIn(struct client *client, const char *name,
- int numItems, const struct locate_item * items);
+ const struct locate_item_list *criteria);
int
findSongsIn(struct client *client, const char *name,
- int numItems, const struct locate_item * items);
+ const struct locate_item_list *criteria);
int
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);
int
-listAllUniqueTags(struct client *client, int type, int numConditiionals,
- const struct locate_item *conditionals);
+listAllUniqueTags(struct client *client, int type,
+ const struct locate_item_list *criteria);
void printSavedMemoryFromFilenames(void);
diff --git a/src/locate.c b/src/locate.c
index 838378797..9f6eff686 100644
--- a/src/locate.c
+++ b/src/locate.c
@@ -177,11 +177,12 @@ locate_tag_search(const struct song *song, enum tag_type type, const char *str)
}
bool
-locate_song_search(const struct song *song, int num_items,
- const struct locate_item *items)
+locate_song_search(const struct song *song,
+ const struct locate_item_list *criteria)
{
- for (int i = 0; i < num_items; i++)
- if (!locate_tag_search(song, items[i].tag, items[i].needle))
+ for (unsigned i = 0; i < criteria->length; i++)
+ if (!locate_tag_search(song, criteria->items[i].tag,
+ criteria->items[i].needle))
return false;
return true;
@@ -234,11 +235,12 @@ locate_tag_match(const struct song *song, enum tag_type type, const char *str)
}
bool
-locate_song_match(const struct song *song, int num_items,
- const struct locate_item *items)
+locate_song_match(const struct song *song,
+ const struct locate_item_list *criteria)
{
- for (int i = 0; i < num_items; i++)
- if (!locate_tag_match(song, items[i].tag, items[i].needle))
+ for (unsigned i = 0; i < criteria->length; i++)
+ if (!locate_tag_match(song, criteria->items[i].tag,
+ criteria->items[i].needle))
return false;
return true;
diff --git a/src/locate.h b/src/locate.h
index d0083a426..0f1bd1a64 100644
--- a/src/locate.h
+++ b/src/locate.h
@@ -70,11 +70,11 @@ void
locate_item_free(struct locate_item *item);
bool
-locate_song_search(const struct song *song, int numItems,
- const struct locate_item *items);
+locate_song_search(const struct song *song,
+ const struct locate_item_list *criteria);
bool
-locate_song_match(const struct song *song, int numItems,
- const struct locate_item *items);
+locate_song_match(const struct song *song,
+ const struct locate_item_list *criteria);
#endif
diff --git a/src/queue_print.c b/src/queue_print.c
index 3c0437ca0..54cdc15ae 100644
--- a/src/queue_print.c
+++ b/src/queue_print.c
@@ -81,19 +81,20 @@ queue_print_changes_position(struct client *client, const struct queue *queue,
void
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;
- 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 =
- g_utf8_casefold(items[i].needle, -1);
+ g_utf8_casefold(criteria->items[i].needle, -1);
for (i = 0; i < queue_length(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);
}
@@ -102,12 +103,12 @@ queue_search(struct client *client, const struct queue *queue,
void
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++) {
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);
}
}
diff --git a/src/queue_print.h b/src/queue_print.h
index 11740bb37..038d86d4f 100644
--- a/src/queue_print.h
+++ b/src/queue_print.h
@@ -28,7 +28,7 @@
struct client;
struct queue;
-struct locate_item;
+struct locate_item_list;
void
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
queue_search(struct client *client, const struct queue *queue,
- unsigned num_items, const struct locate_item *items);
+ const struct locate_item_list *criteria);
void
queue_find(struct client *client, const struct queue *queue,
- unsigned num_items, const struct locate_item *items);
+ const struct locate_item_list *criteria);
#endif