From 75c2029b1c3b59a5922eebc7cf91607758823c45 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 27 Feb 2009 09:01:55 +0100 Subject: tag: no CamelCase Renamed numOfItems to num_items. --- src/command.c | 2 +- src/dbUtils.c | 6 ++-- src/decoder/_flac_common.c | 2 +- src/decoder/vorbis_plugin.c | 2 +- src/encoder/vorbis_encoder.c | 2 +- src/locate.c | 7 ++--- src/output/shout_plugin.c | 3 +- src/song_save.c | 4 +-- src/stats.c | 2 +- src/tag.c | 75 ++++++++++++++++++++++---------------------- src/tag.h | 6 ++-- src/tag_print.c | 8 ++--- src/tag_save.c | 6 ++-- 13 files changed, 60 insertions(+), 65 deletions(-) diff --git a/src/command.c b/src/command.c index 12094bfbf..6f97e06ef 100644 --- a/src/command.c +++ b/src/command.c @@ -1141,7 +1141,7 @@ handle_list(struct client *client, int argc, char *argv[]) if (tagType != TAG_ITEM_ALBUM) { command_error(client, ACK_ERROR_ARG, "should be \"%s\" for 3 arguments", - mpdTagItemKeys[TAG_ITEM_ALBUM]); + tag_item_names[TAG_ITEM_ALBUM]); return COMMAND_RETURN_ERROR; } diff --git a/src/dbUtils.c b/src/dbUtils.c index 8b3eee371..dc7f3879c 100644 --- a/src/dbUtils.c +++ b/src/dbUtils.c @@ -233,7 +233,6 @@ static void visitTag(struct client *client, struct strset *set, struct song *song, enum tag_type tagType) { - int i; struct tag *tag = song->tag; if (tagType == LOCATE_TAG_FILE_TYPE) { @@ -244,12 +243,13 @@ visitTag(struct client *client, struct strset *set, if (!tag) return; - for (i = 0; i < tag->numOfItems; i++) { + for (unsigned i = 0; i < tag->num_items; i++) { if (tag->items[i]->type == tagType) { strset_add(set, tag->items[i]->value); return; } } + strset_add(set, ""); } @@ -294,7 +294,7 @@ int listAllUniqueTags(struct client *client, int type, while ((value = strset_next(data.set)) != NULL) client_printf(client, "%s: %s\n", - mpdTagItemKeys[type], + tag_item_names[type], value); strset_free(data.set); diff --git a/src/decoder/_flac_common.c b/src/decoder/_flac_common.c index 63dc6e145..6c2d19fd9 100644 --- a/src/decoder/_flac_common.c +++ b/src/decoder/_flac_common.c @@ -158,7 +158,7 @@ flac_parse_comment(struct tag *tag, for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i) if (flac_copy_comment(tag, entry, - mpdTagItemKeys[i], i)) + tag_item_names[i], i)) return; } diff --git a/src/decoder/vorbis_plugin.c b/src/decoder/vorbis_plugin.c index 5d1611c97..f53629888 100644 --- a/src/decoder/vorbis_plugin.c +++ b/src/decoder/vorbis_plugin.c @@ -183,7 +183,7 @@ vorbis_parse_comment(struct tag *tag, const char *comment) for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i) if (vorbis_copy_comment(tag, comment, - mpdTagItemKeys[i], i)) + tag_item_names[i], i)) return; } diff --git a/src/encoder/vorbis_encoder.c b/src/encoder/vorbis_encoder.c index a4f427ef5..775258329 100644 --- a/src/encoder/vorbis_encoder.c +++ b/src/encoder/vorbis_encoder.c @@ -274,7 +274,7 @@ static void copy_tag_to_vorbis_comment(struct vorbis_encoder *encoder, const struct tag *tag) { - for (unsigned i = 0; i < tag->numOfItems; i++) { + for (unsigned i = 0; i < tag->num_items; i++) { switch (tag->items[i]->type) { case TAG_ITEM_ARTIST: add_tag(encoder, "ARTIST", tag->items[i]->value); diff --git a/src/locate.c b/src/locate.c index 55dad41c3..653c53009 100644 --- a/src/locate.c +++ b/src/locate.c @@ -42,7 +42,7 @@ locate_parse_type(const char *str) return LOCATE_TAG_ANY_TYPE; for (i = 0; i < TAG_NUM_OF_ITEM_TYPES; i++) - if (0 == strcasecmp(str, mpdTagItemKeys[i])) + if (0 == strcasecmp(str, tag_item_names[i])) return i; return -1; @@ -165,7 +165,7 @@ locate_tag_search(const struct song *song, enum tag_type type, const char *str) memset(visited_types, 0, sizeof(visited_types)); - for (i = 0; i < song->tag->numOfItems && !ret; i++) { + for (i = 0; i < song->tag->num_items && !ret; i++) { visited_types[song->tag->items[i]->type] = true; if (type != LOCATE_TAG_ANY_TYPE && song->tag->items[i]->type != type) { @@ -205,7 +205,6 @@ locate_song_search(const struct song *song, static bool locate_tag_match(const struct song *song, enum tag_type type, const char *str) { - int i; bool visited_types[TAG_NUM_OF_ITEM_TYPES]; if (type == LOCATE_TAG_FILE_TYPE || type == LOCATE_TAG_ANY_TYPE) { @@ -225,7 +224,7 @@ locate_tag_match(const struct song *song, enum tag_type type, const char *str) memset(visited_types, 0, sizeof(visited_types)); - for (i = 0; i < song->tag->numOfItems; i++) { + for (unsigned i = 0; i < song->tag->num_items; i++) { visited_types[song->tag->items[i]->type] = true; if (type != LOCATE_TAG_ANY_TYPE && song->tag->items[i]->type != type) { diff --git a/src/output/shout_plugin.c b/src/output/shout_plugin.c index 2ad7e7b56..47134a932 100644 --- a/src/output/shout_plugin.c +++ b/src/output/shout_plugin.c @@ -457,12 +457,11 @@ shout_tag_to_metadata(const struct tag *tag, char *dest, size_t size) { char artist[size]; char title[size]; - int i; artist[0] = 0; title[0] = 0; - for (i = 0; i < tag->numOfItems; i++) { + for (unsigned i = 0; i < tag->num_items; i++) { switch (tag->items[i]->type) { case TAG_ITEM_ARTIST: strncpy(artist, tag->items[i]->value, size); diff --git a/src/song_save.c b/src/song_save.c index 8011a32fb..aa477eae2 100644 --- a/src/song_save.c +++ b/src/song_save.c @@ -92,9 +92,9 @@ matchesAnMpdTagItemKey(char *buffer, enum tag_type *itemType) int i; for (i = 0; i < TAG_NUM_OF_ITEM_TYPES; i++) { - size_t len = strlen(mpdTagItemKeys[i]); + size_t len = strlen(tag_item_names[i]); - if (0 == strncmp(mpdTagItemKeys[i], buffer, len) && + if (0 == strncmp(tag_item_names[i], buffer, len) && buffer[len] == ':') { *itemType = i; return g_strchug(buffer + len + 1); diff --git a/src/stats.c b/src/stats.c index 937ca3e3f..a72234247 100644 --- a/src/stats.c +++ b/src/stats.c @@ -48,7 +48,7 @@ visit_tag(struct visit_data *data, const struct tag *tag) if (tag->time > 0) stats.song_duration += tag->time; - for (unsigned i = 0; i < tag->numOfItems; ++i) { + for (unsigned i = 0; i < tag->num_items; ++i) { const struct tag_item *item = tag->items[i]; switch (item->type) { diff --git a/src/tag.c b/src/tag.c index 09aa2f83f..ba1f333f7 100644 --- a/src/tag.c +++ b/src/tag.c @@ -41,7 +41,7 @@ static struct { struct tag_item *items[BULK_MAX]; } bulk; -const char *mpdTagItemKeys[TAG_NUM_OF_ITEM_TYPES] = { +const char *tag_item_names[TAG_NUM_OF_ITEM_TYPES] = { "Artist", "Album", "AlbumArtist", @@ -66,7 +66,7 @@ int8_t ignoreTagItems[TAG_NUM_OF_ITEM_TYPES]; static size_t items_size(const struct tag *tag) { - return (tag->numOfItems * sizeof(struct tag_item *)); + return tag->num_items * sizeof(struct tag_item *); } void tag_lib_init(void) @@ -99,7 +99,7 @@ void tag_lib_init(void) quit = 1; *s = '\0'; for (i = 0; i < TAG_NUM_OF_ITEM_TYPES; i++) { - if (strcasecmp(c, mpdTagItemKeys[i]) == 0) { + if (strcasecmp(c, tag_item_names[i]) == 0) { ignoreTagItems[i] = 0; break; } @@ -242,25 +242,25 @@ struct tag *tag_new(void) struct tag *ret = g_new(struct tag, 1); ret->items = NULL; ret->time = -1; - ret->numOfItems = 0; + ret->num_items = 0; return ret; } -static void deleteItem(struct tag *tag, int idx) +static void tag_delete_item(struct tag *tag, int idx) { - assert(idx < tag->numOfItems); - tag->numOfItems--; + assert(idx < tag->num_items); + tag->num_items--; g_mutex_lock(tag_pool_lock); tag_pool_put_item(tag->items[idx]); g_mutex_unlock(tag_pool_lock); - if (tag->numOfItems - idx > 0) { + if (tag->num_items - idx > 0) { memmove(tag->items + idx, tag->items + idx + 1, - tag->numOfItems - idx); + tag->num_items - idx); } - if (tag->numOfItems > 0) { + if (tag->num_items > 0) { tag->items = g_realloc(tag->items, items_size(tag)); } else { g_free(tag->items); @@ -272,9 +272,9 @@ void tag_clear_items_by_type(struct tag *tag, enum tag_type type) { int i; - for (i = 0; i < tag->numOfItems; i++) { + for (i = 0; i < tag->num_items; i++) { if (tag->items[i]->type == type) { - deleteItem(tag, i); + tag_delete_item(tag, i); /* decrement since when just deleted this node */ i--; } @@ -286,7 +286,7 @@ void tag_free(struct tag *tag) int i; g_mutex_lock(tag_pool_lock); - for (i = tag->numOfItems; --i >= 0; ) + for (i = tag->num_items; --i >= 0; ) tag_pool_put_item(tag->items[i]); g_mutex_unlock(tag_pool_lock); @@ -311,11 +311,11 @@ struct tag *tag_dup(const struct tag *tag) ret = tag_new(); ret->time = tag->time; - ret->numOfItems = tag->numOfItems; - ret->items = ret->numOfItems > 0 ? g_malloc(items_size(tag)) : NULL; + ret->num_items = tag->num_items; + ret->items = ret->num_items > 0 ? g_malloc(items_size(tag)) : NULL; g_mutex_lock(tag_pool_lock); - for (i = 0; i < tag->numOfItems; i++) + for (i = 0; i < tag->num_items; i++) ret->items[i] = tag_pool_dup_item(tag->items[i]); g_mutex_unlock(tag_pool_lock); @@ -335,33 +335,33 @@ tag_merge(const struct tag *base, const struct tag *add) ret = tag_new(); ret->time = add->time > 0 ? add->time : base->time; - ret->numOfItems = base->numOfItems + add->numOfItems; - ret->items = ret->numOfItems > 0 ? g_malloc(items_size(ret)) : NULL; + ret->num_items = base->num_items + add->num_items; + ret->items = ret->num_items > 0 ? g_malloc(items_size(ret)) : NULL; g_mutex_lock(tag_pool_lock); /* copy all items from "add" */ - for (unsigned i = 0; i < add->numOfItems; ++i) + for (unsigned i = 0; i < add->num_items; ++i) ret->items[i] = tag_pool_dup_item(add->items[i]); - n = add->numOfItems; + n = add->num_items; /* copy additional items from "base" */ - for (unsigned i = 0; i < base->numOfItems; ++i) + for (unsigned i = 0; i < base->num_items; ++i) if (!tag_has_type(add, base->items[i]->type)) ret->items[n++] = tag_pool_dup_item(base->items[i]); g_mutex_unlock(tag_pool_lock); - assert(n <= ret->numOfItems); + assert(n <= ret->num_items); - if (n < ret->numOfItems) { + if (n < ret->num_items) { /* some tags were not copied - shrink ret->items */ assert(n > 0); - ret->numOfItems = n; + ret->num_items = n; ret->items = g_realloc(ret->items, items_size(ret)); } @@ -374,7 +374,7 @@ tag_get_value(const struct tag *tag, enum tag_type type) assert(tag != NULL); assert(type < TAG_NUM_OF_ITEM_TYPES); - for (unsigned i = 0; i < tag->numOfItems; i++) + for (unsigned i = 0; i < tag->num_items; i++) if (tag->items[i]->type == type) return tag->items[i]->value; @@ -398,10 +398,10 @@ bool tag_equal(const struct tag *tag1, const struct tag *tag2) if (tag1->time != tag2->time) return false; - if (tag1->numOfItems != tag2->numOfItems) + if (tag1->num_items != tag2->num_items) return false; - for (i = 0; i < tag1->numOfItems; i++) { + for (i = 0; i < tag1->num_items; i++) { if (tag1->items[i]->type != tag2->items[i]->type) return false; if (strcmp(tag1->items[i]->value, tag2->items[i]->value)) { @@ -437,7 +437,7 @@ void tag_begin_add(struct tag *tag) assert(!bulk.busy); assert(tag != NULL); assert(tag->items == NULL); - assert(tag->numOfItems == 0); + assert(tag->num_items == 0); #ifndef NDEBUG bulk.busy = true; @@ -448,9 +448,9 @@ void tag_begin_add(struct tag *tag) void tag_end_add(struct tag *tag) { if (tag->items == bulk.items) { - assert(tag->numOfItems <= BULK_MAX); + assert(tag->num_items <= BULK_MAX); - if (tag->numOfItems > 0) { + if (tag->num_items > 0) { /* copy the tag items from the bulk list over to a new list (which fits exactly) */ tag->items = g_malloc(items_size(tag)); @@ -522,10 +522,11 @@ fix_tag_value(const char *p, size_t length) return cleared; } -static void appendToTagItems(struct tag *tag, enum tag_type type, - const char *value, size_t len) +static void +tag_add_item_internal(struct tag *tag, enum tag_type type, + const char *value, size_t len) { - unsigned int i = tag->numOfItems; + unsigned int i = tag->num_items; char *p; p = fix_tag_value(value, len); @@ -534,12 +535,12 @@ static void appendToTagItems(struct tag *tag, enum tag_type type, len = strlen(value); } - tag->numOfItems++; + tag->num_items++; if (tag->items != bulk.items) /* bulk mode disabled */ tag->items = g_realloc(tag->items, items_size(tag)); - else if (tag->numOfItems >= BULK_MAX) { + else if (tag->num_items >= BULK_MAX) { /* bulk list already full - switch back to non-bulk */ assert(bulk.busy); @@ -566,8 +567,8 @@ void tag_add_item_n(struct tag *tag, enum tag_type itemType, return; /* we can't hold more than 255 items */ - if (tag->numOfItems == 255) + if (tag->num_items == 255) return; - appendToTagItems(tag, itemType, value, len); + tag_add_item_internal(tag, itemType, value, len); } diff --git a/src/tag.h b/src/tag.h index 52e66bb77..0348ad47a 100644 --- a/src/tag.h +++ b/src/tag.h @@ -48,7 +48,7 @@ enum tag_type { TAG_NUM_OF_ITEM_TYPES }; -extern const char *mpdTagItemKeys[]; +extern const char *tag_item_names[]; struct tag_item { enum tag_type type; @@ -58,7 +58,7 @@ struct tag_item { struct tag { int time; struct tag_item **items; - uint8_t numOfItems; + uint8_t num_items; }; struct tag *tag_ape_load(const char *file); @@ -112,7 +112,7 @@ tag_merge(const struct tag *base, const struct tag *add); static inline bool tag_is_empty(const struct tag *tag) { - return tag->numOfItems == 0; + return tag->num_items == 0; } /** diff --git a/src/tag_print.c b/src/tag_print.c index 0ed107895..678965c1c 100644 --- a/src/tag_print.c +++ b/src/tag_print.c @@ -29,20 +29,18 @@ void tag_print_types(struct client *client) for (i = 0; i < TAG_NUM_OF_ITEM_TYPES; i++) { if (ignoreTagItems[i] == 0) client_printf(client, "tagtype: %s\n", - mpdTagItemKeys[i]); + tag_item_names[i]); } } void tag_print(struct client *client, const struct tag *tag) { - int i; - if (tag->time >= 0) client_printf(client, SONG_TIME "%i\n", tag->time); - for (i = 0; i < tag->numOfItems; i++) { + for (unsigned i = 0; i < tag->num_items; i++) { client_printf(client, "%s: %s\n", - mpdTagItemKeys[tag->items[i]->type], + tag_item_names[tag->items[i]->type], tag->items[i]->value); } } diff --git a/src/tag_save.c b/src/tag_save.c index dd2bf1ea3..b4a098f22 100644 --- a/src/tag_save.c +++ b/src/tag_save.c @@ -23,13 +23,11 @@ void tag_save(FILE *file, const struct tag *tag) { - int i; - if (tag->time >= 0) fprintf(file, SONG_TIME "%i\n", tag->time); - for (i = 0; i < tag->numOfItems; i++) + for (unsigned i = 0; i < tag->num_items; i++) fprintf(file, "%s: %s\n", - mpdTagItemKeys[tag->items[i]->type], + tag_item_names[tag->items[i]->type], tag->items[i]->value); } -- cgit v1.2.3