From b64329b9942d2315dd968264e92a51d63a135a77 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 3 Oct 2008 14:28:42 +0200 Subject: [PATCH] screen_search: array index is tag id Save some bytes again: remove search_tag.id, make the array index equal to the tag id. --- src/screen_search.c | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/src/screen_search.c b/src/screen_search.c index b5b2496..989ac7e 100644 --- a/src/screen_search.c +++ b/src/screen_search.c @@ -34,38 +34,33 @@ #include #include -typedef struct { - int id; +static const struct { const char *name; const char *localname; -} search_tag_t; - -static search_tag_t search_tag[] = { - { MPD_TAG_ITEM_ARTIST, "artist", N_("artist") }, - { MPD_TAG_ITEM_ALBUM, "album", N_("album") }, - { MPD_TAG_ITEM_TITLE, "title", N_("title") }, - { MPD_TAG_ITEM_TRACK, "track", N_("track") }, - { MPD_TAG_ITEM_NAME, "name", N_("name") }, - { MPD_TAG_ITEM_GENRE, "genre", N_("genre") }, - { MPD_TAG_ITEM_DATE, "date", N_("date") }, - { MPD_TAG_ITEM_COMPOSER, "composer", N_("composer") }, - { MPD_TAG_ITEM_PERFORMER, "performer", N_("performer") }, - { MPD_TAG_ITEM_COMMENT, "comment", N_("comment") }, - { MPD_TAG_ITEM_FILENAME, "filename", N_("file") }, - { -1, NULL, NULL } +} search_tag[MPD_TAG_NUM_OF_ITEM_TYPES] = { + [MPD_TAG_ITEM_ARTIST] = { "artist", N_("artist") }, + [MPD_TAG_ITEM_ALBUM] = { "album", N_("album") }, + [MPD_TAG_ITEM_TITLE] = { "title", N_("title") }, + [MPD_TAG_ITEM_TRACK] = { "track", N_("track") }, + [MPD_TAG_ITEM_NAME] = { "name", N_("name") }, + [MPD_TAG_ITEM_GENRE] = { "genre", N_("genre") }, + [MPD_TAG_ITEM_DATE] = { "date", N_("date") }, + [MPD_TAG_ITEM_COMPOSER] = { "composer", N_("composer") }, + [MPD_TAG_ITEM_PERFORMER] = { "performer", N_("performer") }, + [MPD_TAG_ITEM_COMMENT] = { "comment", N_("comment") }, + [MPD_TAG_ITEM_FILENAME] = { "filename", N_("file") }, }; static int search_get_tag_id(char *name) { - int i = 0; + unsigned i; - while (search_tag[i].name) { - if (strcasecmp(search_tag[i].name, name) == 0 || - strcasecmp(search_tag[i].localname, name) == 0) - return search_tag[i].id; - i++; - } + for (i = 0; i < MPD_TAG_NUM_OF_ITEM_TYPES; ++i) + if (search_tag[i].name != NULL && + (strcasecmp(search_tag[i].name, name) == 0 || + strcasecmp(search_tag[i].localname, name) == 0)) + return i; return -1; } -- 2.30.2