converted MpdTagItem.type to an enum

Don't use CPP macros when you can use C enum... this also allows
better type checking.
This commit is contained in:
Max Kellermann 2008-08-26 08:27:09 +02:00
parent e754ed01a7
commit 0fc2422cd0
5 changed files with 28 additions and 22 deletions

View File

@ -413,6 +413,8 @@ static void copyTagToVorbisComment(ShoutData * sd)
case TAG_ITEM_TITLE: case TAG_ITEM_TITLE:
addTag(sd, "TITLE", sd->tag->items[i].value); addTag(sd, "TITLE", sd->tag->items[i].value);
break; break;
default:
break;
} }
} }
} }

View File

@ -254,7 +254,7 @@ static void freeListCommandItem(ListCommandItem * item)
free(item); free(item);
} }
static void visitTag(int fd, Song * song, int tagType) static void visitTag(int fd, Song * song, enum tag_type tagType)
{ {
int i; int i;
MpdTag *tag = song->tag; MpdTag *tag = song->tag;

View File

@ -121,7 +121,7 @@ void freeLocateTagItem(LocateTagItem * item)
free(item); free(item);
} }
static int strstrSearchTag(Song * song, int type, char *str) static int strstrSearchTag(Song * song, enum tag_type type, char *str)
{ {
int i; int i;
char *duplicate; char *duplicate;
@ -169,7 +169,7 @@ int strstrSearchTags(Song * song, int numItems, LocateTagItem * items)
return 1; return 1;
} }
static int tagItemFoundAndMatches(Song * song, int type, char *str) static int tagItemFoundAndMatches(Song * song, enum tag_type type, char *str)
{ {
int i; int i;

View File

@ -606,7 +606,7 @@ static void deleteItem(MpdTag * tag, int idx)
} }
} }
void clearItemsFromMpdTag(MpdTag * tag, int type) void clearItemsFromMpdTag(MpdTag * tag, enum tag_type type)
{ {
int i; int i;
@ -697,7 +697,8 @@ int mpdTagsAreEqual(MpdTag * tag1, MpdTag * tag2)
} \ } \
} }
static void appendToTagItems(MpdTag * tag, int type, char *value, int len) static void appendToTagItems(MpdTag * tag, enum tag_type type,
char *value, int len)
{ {
int i = tag->numOfItems; int i = tag->numOfItems;
char *duplicated = xmalloc(len + 1); char *duplicated = xmalloc(len + 1);
@ -717,7 +718,8 @@ static void appendToTagItems(MpdTag * tag, int type, char *value, int len)
free(duplicated); free(duplicated);
} }
void addItemToMpdTagWithLen(MpdTag * tag, int itemType, char *value, int len) void addItemToMpdTagWithLen(MpdTag * tag, enum tag_type itemType,
char *value, int len)
{ {
if (ignoreTagItems[itemType]) if (ignoreTagItems[itemType])
{ {

View File

@ -27,24 +27,25 @@
#include <id3tag.h> #include <id3tag.h>
#endif #endif
#define TAG_ITEM_ARTIST 0 enum tag_type {
#define TAG_ITEM_ALBUM 1 TAG_ITEM_ARTIST,
#define TAG_ITEM_TITLE 2 TAG_ITEM_ALBUM,
#define TAG_ITEM_TRACK 3 TAG_ITEM_TITLE,
#define TAG_ITEM_NAME 4 TAG_ITEM_TRACK,
#define TAG_ITEM_GENRE 5 TAG_ITEM_NAME,
#define TAG_ITEM_DATE 6 TAG_ITEM_GENRE,
#define TAG_ITEM_COMPOSER 7 TAG_ITEM_DATE,
#define TAG_ITEM_PERFORMER 8 TAG_ITEM_COMPOSER,
#define TAG_ITEM_COMMENT 9 TAG_ITEM_PERFORMER,
#define TAG_ITEM_DISC 10 TAG_ITEM_COMMENT,
TAG_ITEM_DISC,
#define TAG_NUM_OF_ITEM_TYPES 11 TAG_NUM_OF_ITEM_TYPES
};
extern const char *mpdTagItemKeys[]; extern const char *mpdTagItemKeys[];
typedef struct _MpdTagItem { typedef struct _MpdTagItem {
mpd_sint8 type; enum tag_type type;
char *value; char *value;
} MpdTagItem; } MpdTagItem;
@ -66,11 +67,12 @@ MpdTag *newMpdTag(void);
void initTagConfig(void); void initTagConfig(void);
void clearItemsFromMpdTag(MpdTag * tag, int itemType); void clearItemsFromMpdTag(MpdTag * tag, enum tag_type itemType);
void freeMpdTag(MpdTag * tag); void freeMpdTag(MpdTag * tag);
void addItemToMpdTagWithLen(MpdTag * tag, int itemType, char *value, int len); void addItemToMpdTagWithLen(MpdTag * tag, enum tag_type itemType,
char *value, int len);
#define addItemToMpdTag(tag, itemType, value) \ #define addItemToMpdTag(tag, itemType, value) \
addItemToMpdTagWithLen(tag, itemType, value, strlen(value)) addItemToMpdTagWithLen(tag, itemType, value, strlen(value))