Commit f2536445 authored by Max Kellermann's avatar Max Kellermann

locate: make variables more local

parent ede70ee3
...@@ -34,8 +34,6 @@ ...@@ -34,8 +34,6 @@
int int
locate_parse_type(const char *str) locate_parse_type(const char *str)
{ {
int i;
if (0 == g_ascii_strcasecmp(str, LOCATE_TAG_FILE_KEY) || if (0 == g_ascii_strcasecmp(str, LOCATE_TAG_FILE_KEY) ||
0 == g_ascii_strcasecmp(str, LOCATE_TAG_FILE_KEY_OLD)) 0 == g_ascii_strcasecmp(str, LOCATE_TAG_FILE_KEY_OLD))
return LOCATE_TAG_FILE_TYPE; return LOCATE_TAG_FILE_TYPE;
...@@ -43,7 +41,7 @@ locate_parse_type(const char *str) ...@@ -43,7 +41,7 @@ locate_parse_type(const char *str)
if (0 == g_ascii_strcasecmp(str, LOCATE_TAG_ANY_KEY)) if (0 == g_ascii_strcasecmp(str, LOCATE_TAG_ANY_KEY))
return LOCATE_TAG_ANY_TYPE; return LOCATE_TAG_ANY_TYPE;
i = tag_name_parse_i(str); enum tag_type i = tag_name_parse_i(str);
if (i != TAG_NUM_OF_ITEM_TYPES) if (i != TAG_NUM_OF_ITEM_TYPES)
return i; return i;
...@@ -76,10 +74,9 @@ locate_item_list_free(struct locate_item_list *list) ...@@ -76,10 +74,9 @@ locate_item_list_free(struct locate_item_list *list)
struct locate_item_list * 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]) +
list = g_malloc0(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;
...@@ -88,12 +85,10 @@ locate_item_list_new(unsigned length) ...@@ -88,12 +85,10 @@ locate_item_list_new(unsigned length)
struct locate_item_list * struct locate_item_list *
locate_item_list_parse(char *argv[], int argc) locate_item_list_parse(char *argv[], int argc)
{ {
struct locate_item_list *list;
if (argc % 2 != 0) if (argc % 2 != 0)
return NULL; return NULL;
list = locate_item_list_new(argc / 2); struct locate_item_list *list = locate_item_list_new(argc / 2);
for (unsigned i = 0; i < list->length; ++i) { for (unsigned i = 0; i < list->length; ++i) {
if (!locate_item_init(&list->items[i], argv[i * 2], if (!locate_item_init(&list->items[i], argv[i * 2],
...@@ -130,15 +125,11 @@ locate_item_free(struct locate_item *item) ...@@ -130,15 +125,11 @@ locate_item_free(struct locate_item *item)
static bool static bool
locate_tag_search(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)
{ {
char *duplicate;
bool ret = false; bool ret = false;
bool visited_types[TAG_NUM_OF_ITEM_TYPES];
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 = song_get_uri(song);
char *p = g_utf8_casefold(uri, -1);
uri = song_get_uri(song);
p = g_utf8_casefold(uri, -1);
g_free(uri); g_free(uri);
if (strstr(p, str)) if (strstr(p, str))
...@@ -151,6 +142,7 @@ locate_tag_search(const struct song *song, enum tag_type type, const char *str) ...@@ -151,6 +142,7 @@ locate_tag_search(const struct song *song, enum tag_type type, const char *str)
if (!song->tag) if (!song->tag)
return false; return false;
bool visited_types[TAG_NUM_OF_ITEM_TYPES];
memset(visited_types, 0, sizeof(visited_types)); memset(visited_types, 0, sizeof(visited_types));
for (unsigned i = 0; i < song->tag->num_items && !ret; i++) { for (unsigned i = 0; i < song->tag->num_items && !ret; i++) {
...@@ -160,7 +152,7 @@ locate_tag_search(const struct song *song, enum tag_type type, const char *str) ...@@ -160,7 +152,7 @@ locate_tag_search(const struct song *song, enum tag_type type, const char *str)
continue; continue;
} }
duplicate = g_utf8_casefold(song->tag->items[i]->value, -1); char *duplicate = g_utf8_casefold(song->tag->items[i]->value, -1);
if (*str && strstr(duplicate, str)) if (*str && strstr(duplicate, str))
ret = true; ret = true;
g_free(duplicate); g_free(duplicate);
...@@ -193,8 +185,6 @@ locate_song_search(const struct song *song, ...@@ -193,8 +185,6 @@ locate_song_search(const struct song *song,
static bool static bool
locate_tag_match(const struct song *song, enum tag_type type, const char *str) locate_tag_match(const struct song *song, enum tag_type type, const char *str)
{ {
bool visited_types[TAG_NUM_OF_ITEM_TYPES];
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);
bool matches = strcmp(str, uri) == 0; bool matches = strcmp(str, uri) == 0;
...@@ -210,6 +200,7 @@ locate_tag_match(const struct song *song, enum tag_type type, const char *str) ...@@ -210,6 +200,7 @@ locate_tag_match(const struct song *song, enum tag_type type, const char *str)
if (!song->tag) if (!song->tag)
return false; return false;
bool visited_types[TAG_NUM_OF_ITEM_TYPES];
memset(visited_types, 0, sizeof(visited_types)); memset(visited_types, 0, sizeof(visited_types));
for (unsigned i = 0; i < song->tag->num_items; i++) { for (unsigned i = 0; i < song->tag->num_items; i++) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment