locate: use const pointers

Pass const pointers where no writes are performed.
This commit is contained in:
Max Kellermann 2009-01-22 16:12:34 +01:00
parent d47be76ce0
commit 1e6a26b6ca
4 changed files with 28 additions and 32 deletions

View File

@ -36,12 +36,12 @@
typedef struct _ListCommandItem {
int8_t tagType;
int numConditionals;
LocateTagItem *conditionals;
const LocateTagItem *conditionals;
} ListCommandItem;
typedef struct _LocateTagItemArray {
int numItems;
LocateTagItem *items;
const LocateTagItem *items;
} LocateTagItemArray;
typedef struct _SearchStats {
@ -87,31 +87,24 @@ searchInDirectory(struct song *song, void *_data)
}
int searchForSongsIn(struct client *client, const char *name,
int numItems, LocateTagItem * items)
int numItems, const LocateTagItem * items)
{
int ret;
int i;
char **originalNeedles = g_new(char *, numItems);
LocateTagItem *new_items =
g_memdup(items, sizeof(LocateTagItem) * numItems);
struct search_data data;
for (i = 0; i < numItems; i++) {
originalNeedles[i] = items[i].needle;
items[i].needle = g_utf8_casefold(originalNeedles[i], -1);
}
for (i = 0; i < numItems; i++)
new_items[i].needle = g_utf8_casefold(new_items[i].needle, -1);
data.client = client;
data.array.numItems = numItems;
data.array.items = items;
data.array.items = new_items;
ret = db_walk(name, searchInDirectory, NULL, &data);
for (i = 0; i < numItems; i++) {
g_free(items[i].needle);
items[i].needle = originalNeedles[i];
}
free(originalNeedles);
freeLocateTagItemArray(numItems, new_items);
return ret;
}
@ -129,7 +122,7 @@ findInDirectory(struct song *song, void *_data)
}
int findSongsIn(struct client *client, const char *name,
int numItems, LocateTagItem * items)
int numItems, const LocateTagItem * items)
{
struct search_data data;
@ -162,7 +155,7 @@ searchStatsInDirectory(struct song *song, void *data)
}
int searchStatsForSongsIn(struct client *client, const char *name,
int numItems, LocateTagItem * items)
int numItems, const LocateTagItem * items)
{
SearchStats stats;
int ret;
@ -234,7 +227,7 @@ int printInfoForAllIn(struct client *client, const char *name)
}
static ListCommandItem *newListCommandItem(int tagType, int numConditionals,
LocateTagItem * conditionals)
const LocateTagItem * conditionals)
{
ListCommandItem *item = g_new(ListCommandItem, 1);
@ -295,7 +288,7 @@ listUniqueTagsInDirectory(struct song *song, void *_data)
}
int listAllUniqueTags(struct client *client, int type, int numConditionals,
LocateTagItem * conditionals)
const LocateTagItem *conditionals)
{
int ret;
ListCommandItem *item = newListCommandItem(type, numConditionals,

View File

@ -32,18 +32,18 @@ int addAllInToStoredPlaylist(const char *name, const char *utf8file);
int printInfoForAllIn(struct client *client, const char *name);
int searchForSongsIn(struct client *client, const char *name,
int numItems, LocateTagItem * items);
int numItems, const LocateTagItem * items);
int findSongsIn(struct client *client, const char *name,
int numItems, LocateTagItem * items);
int numItems, const LocateTagItem * items);
int searchStatsForSongsIn(struct client *client, const char *name,
int numItems, LocateTagItem * items);
int numItems, const LocateTagItem * items);
unsigned long sumSongTimesIn(const char *name);
int listAllUniqueTags(struct client *client, int type, int numConditiionals,
LocateTagItem * conditionals);
const LocateTagItem *conditionals);
void printSavedMemoryFromFilenames(void);

View File

@ -127,7 +127,7 @@ void freeLocateTagItem(LocateTagItem * item)
}
static int
strstrSearchTag(struct song *song, enum tag_type type, char *str)
strstrSearchTag(const struct song *song, enum tag_type type, const char *str)
{
int i;
char *duplicate;
@ -177,7 +177,8 @@ strstrSearchTag(struct song *song, enum tag_type type, char *str)
}
int
strstrSearchTags(struct song *song, int numItems, LocateTagItem *items)
strstrSearchTags(const struct song *song, int numItems,
const LocateTagItem *items)
{
int i;
@ -192,7 +193,8 @@ strstrSearchTags(struct song *song, int numItems, LocateTagItem *items)
}
static int
tagItemFoundAndMatches(struct song *song, enum tag_type type, char *str)
tagItemFoundAndMatches(const struct song *song, enum tag_type type,
const char *str)
{
int i;
int8_t visitedTypes[TAG_NUM_OF_ITEM_TYPES] = { 0 };
@ -237,8 +239,8 @@ tagItemFoundAndMatches(struct song *song, enum tag_type type, char *str)
int
tagItemsFoundAndMatches(struct song *song, int numItems,
LocateTagItem * items)
tagItemsFoundAndMatches(const struct song *song, int numItems,
const LocateTagItem * items)
{
int i;

View File

@ -47,10 +47,11 @@ void freeLocateTagItemArray(int count, LocateTagItem * array);
void freeLocateTagItem(LocateTagItem * item);
int
strstrSearchTags(struct song *song, int numItems, LocateTagItem * items);
strstrSearchTags(const struct song *song, int numItems,
const LocateTagItem * items);
int
tagItemsFoundAndMatches(struct song *song, int numItems,
LocateTagItem * items);
tagItemsFoundAndMatches(const struct song *song, int numItems,
const LocateTagItem * items);
#endif