locate: no CamelCase

Renamed functions and variables.
This commit is contained in:
Max Kellermann 2009-01-24 15:26:59 +01:00
parent daa5f5924d
commit 3582977e01
5 changed files with 76 additions and 89 deletions

View File

@ -834,7 +834,7 @@ handle_find(struct client *client, int argc, char *argv[])
{ {
int ret; int ret;
struct locate_item *items; struct locate_item *items;
int numItems = newLocateTagItemArrayFromArgArray(argv + 1, int numItems = locate_item_list_parse(argv + 1,
argc - 1, argc - 1,
&items); &items);
@ -848,7 +848,7 @@ handle_find(struct client *client, int argc, char *argv[])
command_error(client, ACK_ERROR_NO_EXIST, command_error(client, ACK_ERROR_NO_EXIST,
"directory or file not found"); "directory or file not found");
freeLocateTagItemArray(numItems, items); locate_item_list_free(numItems, items);
return ret; return ret;
} }
@ -858,7 +858,7 @@ handle_search(struct client *client, int argc, char *argv[])
{ {
int ret; int ret;
struct locate_item *items; struct locate_item *items;
int numItems = newLocateTagItemArrayFromArgArray(argv + 1, int numItems = locate_item_list_parse(argv + 1,
argc - 1, argc - 1,
&items); &items);
@ -872,7 +872,7 @@ handle_search(struct client *client, int argc, char *argv[])
command_error(client, ACK_ERROR_NO_EXIST, command_error(client, ACK_ERROR_NO_EXIST,
"directory or file not found"); "directory or file not found");
freeLocateTagItemArray(numItems, items); locate_item_list_free(numItems, items);
return ret; return ret;
} }
@ -882,7 +882,7 @@ handle_count(struct client *client, int argc, char *argv[])
{ {
int ret; int ret;
struct locate_item *items; struct locate_item *items;
int numItems = newLocateTagItemArrayFromArgArray(argv + 1, int numItems = locate_item_list_parse(argv + 1,
argc - 1, argc - 1,
&items); &items);
@ -896,7 +896,7 @@ handle_count(struct client *client, int argc, char *argv[])
command_error(client, ACK_ERROR_NO_EXIST, command_error(client, ACK_ERROR_NO_EXIST,
"directory or file not found"); "directory or file not found");
freeLocateTagItemArray(numItems, items); locate_item_list_free(numItems, items);
return ret; return ret;
} }
@ -905,7 +905,7 @@ static enum command_return
handle_playlistfind(struct client *client, int argc, char *argv[]) handle_playlistfind(struct client *client, int argc, char *argv[])
{ {
struct locate_item *items; struct locate_item *items;
int numItems = newLocateTagItemArrayFromArgArray(argv + 1, int numItems = locate_item_list_parse(argv + 1,
argc - 1, argc - 1,
&items); &items);
@ -916,7 +916,7 @@ handle_playlistfind(struct client *client, int argc, char *argv[])
queue_find(client, playlist_get_queue(), numItems, items); queue_find(client, playlist_get_queue(), numItems, items);
freeLocateTagItemArray(numItems, items); locate_item_list_free(numItems, items);
return COMMAND_RETURN_OK; return COMMAND_RETURN_OK;
} }
@ -925,7 +925,7 @@ static enum command_return
handle_playlistsearch(struct client *client, int argc, char *argv[]) handle_playlistsearch(struct client *client, int argc, char *argv[])
{ {
struct locate_item *items; struct locate_item *items;
int numItems = newLocateTagItemArrayFromArgArray(argv + 1, int numItems = locate_item_list_parse(argv + 1,
argc - 1, argc - 1,
&items); &items);
@ -936,7 +936,7 @@ handle_playlistsearch(struct client *client, int argc, char *argv[])
queue_search(client, playlist_get_queue(), numItems, items); queue_search(client, playlist_get_queue(), numItems, items);
freeLocateTagItemArray(numItems, items); locate_item_list_free(numItems, items);
return COMMAND_RETURN_OK; return COMMAND_RETURN_OK;
} }
@ -1113,7 +1113,7 @@ handle_list(struct client *client, int argc, char *argv[])
{ {
int numConditionals; int numConditionals;
struct locate_item *conditionals = NULL; struct locate_item *conditionals = NULL;
int tagType = getLocateTagItemType(argv[1]); int tagType = locate_parse_type(argv[1]);
int ret; int ret;
if (tagType < 0) { if (tagType < 0) {
@ -1135,12 +1135,12 @@ handle_list(struct client *client, int argc, char *argv[])
mpdTagItemKeys[TAG_ITEM_ALBUM]); mpdTagItemKeys[TAG_ITEM_ALBUM]);
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
} }
conditionals = newLocateTagItem(mpdTagItemKeys[TAG_ITEM_ARTIST], conditionals = locate_item_new(mpdTagItemKeys[TAG_ITEM_ARTIST],
argv[2]); argv[2]);
numConditionals = 1; numConditionals = 1;
} else { } else {
numConditionals = numConditionals =
newLocateTagItemArrayFromArgArray(argv + 2, locate_item_list_parse(argv + 2,
argc - 2, &conditionals); argc - 2, &conditionals);
if (numConditionals < 0) { if (numConditionals < 0) {
@ -1153,7 +1153,7 @@ handle_list(struct client *client, int argc, char *argv[])
ret = listAllUniqueTags(client, tagType, numConditionals, conditionals); ret = listAllUniqueTags(client, tagType, numConditionals, conditionals);
if (conditionals) if (conditionals)
freeLocateTagItemArray(numConditionals, conditionals); locate_item_list_free(numConditionals, conditionals);
if (ret == -1) if (ret == -1)
command_error(client, ACK_ERROR_NO_EXIST, command_error(client, ACK_ERROR_NO_EXIST,

View File

@ -80,7 +80,7 @@ searchInDirectory(struct song *song, void *_data)
struct search_data *data = _data; struct search_data *data = _data;
LocateTagItemArray *array = &data->array; LocateTagItemArray *array = &data->array;
if (strstrSearchTags(song, array->numItems, array->items)) if (locate_song_search(song, array->numItems, array->items))
return song_print_info(data->client, song); return song_print_info(data->client, song);
return 0; return 0;
@ -105,7 +105,7 @@ searchForSongsIn(struct client *client, const char *name,
ret = db_walk(name, searchInDirectory, NULL, &data); ret = db_walk(name, searchInDirectory, NULL, &data);
freeLocateTagItemArray(numItems, new_items); locate_item_list_free(numItems, new_items);
return ret; return ret;
} }
@ -116,7 +116,7 @@ findInDirectory(struct song *song, void *_data)
struct search_data *data = _data; struct search_data *data = _data;
LocateTagItemArray *array = &data->array; LocateTagItemArray *array = &data->array;
if (tagItemsFoundAndMatches(song, array->numItems, array->items)) if (locate_song_match(song, array->numItems, array->items))
return song_print_info(data->client, song); return song_print_info(data->client, song);
return 0; return 0;
@ -146,8 +146,8 @@ searchStatsInDirectory(struct song *song, void *data)
{ {
SearchStats *stats = data; SearchStats *stats = data;
if (tagItemsFoundAndMatches(song, stats->locateArray.numItems, if (locate_song_match(song, stats->locateArray.numItems,
stats->locateArray.items)) { 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;
@ -283,8 +283,8 @@ 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 (tagItemsFoundAndMatches(song, item->numConditionals, if (locate_song_match(song, item->numConditionals,
item->conditionals)) { item->conditionals)) {
visitTag(data->client, data->set, song, item->tagType); visitTag(data->client, data->set, song, item->tagType);
} }

View File

@ -29,36 +29,32 @@
#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"
int getLocateTagItemType(const char *str) int
locate_parse_type(const char *str)
{ {
int i; int i;
if (0 == strcasecmp(str, LOCATE_TAG_FILE_KEY) || if (0 == strcasecmp(str, LOCATE_TAG_FILE_KEY) ||
0 == strcasecmp(str, LOCATE_TAG_FILE_KEY_OLD)) 0 == strcasecmp(str, LOCATE_TAG_FILE_KEY_OLD))
{
return LOCATE_TAG_FILE_TYPE; return LOCATE_TAG_FILE_TYPE;
}
if (0 == strcasecmp(str, LOCATE_TAG_ANY_KEY)) if (0 == strcasecmp(str, LOCATE_TAG_ANY_KEY))
{
return LOCATE_TAG_ANY_TYPE; return LOCATE_TAG_ANY_TYPE;
}
for (i = 0; i < TAG_NUM_OF_ITEM_TYPES; i++) for (i = 0; i < TAG_NUM_OF_ITEM_TYPES; i++)
{
if (0 == strcasecmp(str, mpdTagItemKeys[i])) if (0 == strcasecmp(str, mpdTagItemKeys[i]))
return i; return i;
}
return -1; return -1;
} }
static int initLocateTagItem(struct locate_item *item, static int
const char *typeStr, const char *needle) locate_item_init(struct locate_item *item,
const char *type_string, const char *needle)
{ {
item->tagType = getLocateTagItemType(typeStr); item->tag = locate_parse_type(type_string);
if (item->tagType < 0) if (item->tag < 0)
return -1; return -1;
item->needle = g_strdup(needle); item->needle = g_strdup(needle);
@ -67,11 +63,11 @@ static int initLocateTagItem(struct locate_item *item,
} }
struct locate_item * struct locate_item *
newLocateTagItem(const char *typeStr, const char *needle) locate_item_new(const char *type_string, const char *needle)
{ {
struct locate_item *ret = g_new(struct locate_item, 1); struct locate_item *ret = g_new(struct locate_item, 1);
if (initLocateTagItem(ret, typeStr, needle) < 0) { if (locate_item_init(ret, type_string, needle) < 0) {
free(ret); free(ret);
ret = NULL; ret = NULL;
} }
@ -79,7 +75,8 @@ newLocateTagItem(const char *typeStr, const char *needle)
return ret; return ret;
} }
void freeLocateTagItemArray(int count, struct locate_item *array) void
locate_item_list_free(int count, struct locate_item *array)
{ {
int i; int i;
@ -90,27 +87,25 @@ void freeLocateTagItemArray(int count, struct locate_item *array)
} }
int int
newLocateTagItemArrayFromArgArray(char *argArray[], locate_item_list_parse(char *argv[], int argc, struct locate_item **arrayRet)
int numArgs, struct locate_item **arrayRet)
{ {
int i, j; int i, j;
struct locate_item *item; struct locate_item *item;
if (numArgs == 0) if (argc == 0)
return 0; return 0;
if (numArgs % 2 != 0) if (argc % 2 != 0)
return -1; return -1;
*arrayRet = g_new(struct locate_item, numArgs / 2); *arrayRet = g_new(struct locate_item, argc / 2);
for (i = 0, item = *arrayRet; i < numArgs / 2; i++, item++) { for (i = 0, item = *arrayRet; i < argc / 2; i++, item++) {
if (initLocateTagItem if (locate_item_init(item, argv[i * 2], argv[i * 2 + 1]) < 0)
(item, argArray[i * 2], argArray[i * 2 + 1]) < 0)
goto fail; goto fail;
} }
return numArgs / 2; return argc / 2;
fail: fail:
for (j = 0; j < i; j++) { for (j = 0; j < i; j++) {
@ -122,19 +117,20 @@ fail:
return -1; return -1;
} }
void freeLocateTagItem(struct locate_item *item) void
locate_item_free(struct locate_item *item)
{ {
free(item->needle); free(item->needle);
free(item); free(item);
} }
static int static int
strstrSearchTag(const struct song *song, enum tag_type type, const char *str) locate_tag_search(const struct song *song, enum tag_type type, const char *str)
{ {
int i; int i;
char *duplicate; char *duplicate;
int ret = 0; int ret = 0;
int8_t visitedTypes[TAG_NUM_OF_ITEM_TYPES] = { 0 }; int8_t visited_types[TAG_NUM_OF_ITEM_TYPES] = { 0 };
if (type == LOCATE_TAG_FILE_TYPE || type == LOCATE_TAG_ANY_TYPE) { if (type == LOCATE_TAG_FILE_TYPE || type == LOCATE_TAG_ANY_TYPE) {
char *uri, *p; char *uri, *p;
@ -154,7 +150,7 @@ strstrSearchTag(const struct song *song, enum tag_type type, const char *str)
return 0; return 0;
for (i = 0; i < song->tag->numOfItems && !ret; i++) { for (i = 0; i < song->tag->numOfItems && !ret; i++) {
visitedTypes[song->tag->items[i]->type] = 1; visited_types[song->tag->items[i]->type] = 1;
if (type != LOCATE_TAG_ANY_TYPE && if (type != LOCATE_TAG_ANY_TYPE &&
song->tag->items[i]->type != type) { song->tag->items[i]->type != type) {
continue; continue;
@ -172,34 +168,28 @@ strstrSearchTag(const struct song *song, enum tag_type type, const char *str)
* empty (first char is a \0), then it's a match as well and * empty (first char is a \0), then it's a match as well and
* we should return 1. * we should return 1.
*/ */
if (!*str && !visitedTypes[type]) if (!*str && !visited_types[type])
return 1; return 1;
return ret; return ret;
} }
int int
strstrSearchTags(const struct song *song, int numItems, locate_song_search(const struct song *song, int num_items,
const struct locate_item *items) const struct locate_item *items)
{ {
int i; for (int i = 0; i < num_items; i++)
if (!locate_tag_search(song, items[i].tag, items[i].needle))
for (i = 0; i < numItems; i++) {
if (!strstrSearchTag(song, items[i].tagType,
items[i].needle)) {
return 0; return 0;
}
}
return 1; return 1;
} }
static int static int
tagItemFoundAndMatches(const struct song *song, enum tag_type type, locate_tag_match(const struct song *song, enum tag_type type, const char *str)
const char *str)
{ {
int i; int i;
int8_t visitedTypes[TAG_NUM_OF_ITEM_TYPES] = { 0 }; int8_t visited_types[TAG_NUM_OF_ITEM_TYPES] = { 0 };
if (type == LOCATE_TAG_FILE_TYPE || type == LOCATE_TAG_ANY_TYPE) { if (type == LOCATE_TAG_FILE_TYPE || type == LOCATE_TAG_ANY_TYPE) {
char *uri = song_get_uri(song); char *uri = song_get_uri(song);
@ -217,7 +207,7 @@ tagItemFoundAndMatches(const struct song *song, enum tag_type type,
return 0; return 0;
for (i = 0; i < song->tag->numOfItems; i++) { for (i = 0; i < song->tag->numOfItems; i++) {
visitedTypes[song->tag->items[i]->type] = 1; visited_types[song->tag->items[i]->type] = 1;
if (type != LOCATE_TAG_ANY_TYPE && if (type != LOCATE_TAG_ANY_TYPE &&
song->tag->items[i]->type != type) { song->tag->items[i]->type != type) {
continue; continue;
@ -233,7 +223,7 @@ tagItemFoundAndMatches(const struct song *song, enum tag_type type,
* empty (first char is a \0), then it's a match as well and * empty (first char is a \0), then it's a match as well and
* we should return 1. * we should return 1.
*/ */
if (!*str && !visitedTypes[type]) if (!*str && !visited_types[type])
return 1; return 1;
return 0; return 0;
@ -241,17 +231,12 @@ tagItemFoundAndMatches(const struct song *song, enum tag_type type,
int int
tagItemsFoundAndMatches(const struct song *song, int numItems, locate_song_match(const struct song *song, int num_items,
const struct locate_item *items) const struct locate_item *items)
{ {
int i; for (int i = 0; i < num_items; i++)
if (!locate_tag_match(song, items[i].tag, items[i].needle))
for (i = 0; i < numItems; i++) {
if (!tagItemFoundAndMatches(song, items[i].tagType,
items[i].needle)) {
return 0; return 0;
}
}
return 1; return 1;
} }

View File

@ -28,32 +28,34 @@ struct song;
/* struct used for search, find, list queries */ /* struct used for search, find, list queries */
struct locate_item { struct locate_item {
int8_t tagType; int8_t tag;
/* what we are looking for */ /* what we are looking for */
char *needle; char *needle;
}; };
int getLocateTagItemType(const char *str); int
locate_parse_type(const char *str);
/* returns NULL if not a known type */ /* returns NULL if not a known type */
struct locate_item * struct locate_item *
newLocateTagItem(const char *typeString, const char *needle); locate_item_new(const char *type_string, const char *needle);
/* return number of items or -1 on error */ /* return number of items or -1 on error */
int int
newLocateTagItemArrayFromArgArray(char *argArray[], int numArgs, locate_item_list_parse(char *argv[], int argc, struct locate_item **arrayRet);
struct locate_item **arrayRet);
void freeLocateTagItemArray(int count, struct locate_item *array); void
locate_item_list_free(int count, struct locate_item *array);
void freeLocateTagItem(struct locate_item *item); void
locate_item_free(struct locate_item *item);
int int
strstrSearchTags(const struct song *song, int numItems, locate_song_search(const struct song *song, int numItems,
const struct locate_item *items); const struct locate_item *items);
int int
tagItemsFoundAndMatches(const struct song *song, int numItems, locate_song_match(const struct song *song, int numItems,
const struct locate_item *items); const struct locate_item *items);
#endif #endif

View File

@ -93,11 +93,11 @@ queue_search(struct client *client, const struct queue *queue,
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 (strstrSearchTags(song, num_items, new_items)) if (locate_song_search(song, num_items, new_items))
queue_print_song_info(client, queue, i); queue_print_song_info(client, queue, i);
} }
freeLocateTagItemArray(num_items, new_items); locate_item_list_free(num_items, new_items);
} }
void void
@ -107,7 +107,7 @@ queue_find(struct client *client, const struct queue *queue,
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 (tagItemsFoundAndMatches(song, num_items, items)) if (locate_song_match(song, num_items, items))
queue_print_song_info(client, queue, i); queue_print_song_info(client, queue, i);
} }
} }