X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=mood.c;h=e905f92cc64b4e99d55691d3d9e5805e3f3985d1;hp=bafe710c09372a7e8a1f82168324d9a64a0e633e;hb=c4bfb18b78b3935b8dbf68f70b219cfb2a192979;hpb=128c594f32be41d928df432298a013a168891ab7 diff --git a/mood.c b/mood.c index bafe710c..e905f92c 100644 --- a/mood.c +++ b/mood.c @@ -108,12 +108,16 @@ __a_const static uint64_t int_sqrt(uint64_t x) return res; } -/* returns 1 if row matches score item, 0 if not. */ -static int get_item_score(struct mood_item *item, const struct afs_info *afsi, +/* + * Returns true if row matches, false if it does not match. In any case score + * and score_arg_sum are set/increased accordingly. + */ +static bool get_item_score(struct mood_item *item, const struct afs_info *afsi, const struct afh_info *afhi, const char *path, long *score, long *score_arg_sum) { - int ret, match = 1; + int ret; + bool match = true; *score_arg_sum += item->random_score? 100 : PARA_ABS(item->score_arg); ret = 100; @@ -121,7 +125,7 @@ static int get_item_score(struct mood_item *item, const struct afs_info *afsi, ret = item->method->score_function(path, afsi, afhi, item->parser_data); if ((ret < 0 && !item->logical_not) || (ret >= 0 && item->logical_not)) - match = 0; /* no match */ + match = false; } if (item->random_score) *score = PARA_ABS(ret) * para_random(100); @@ -135,7 +139,8 @@ static int compute_mood_score(const struct osl_row *aft_row, struct mood *m, long *result) { struct mood_item *item; - int ret, match = 0; + int ret; + bool match; long score_arg_sum = 0, score = 0, item_score; struct afs_info afsi; struct afh_info afhi; @@ -154,27 +159,29 @@ static int compute_mood_score(const struct osl_row *aft_row, struct mood *m, return ret; /* reject audio file if it matches any entry in the deny list */ list_for_each_entry(item, &m->deny_list, mood_item_node) { - ret = get_item_score(item, &afsi, &afhi, path, &item_score, + match = get_item_score(item, &afsi, &afhi, path, &item_score, &score_arg_sum); - if (ret > 0) /* not admissible */ + if (match) /* not admissible */ return 0; score += item_score; } + match = false; list_for_each_entry(item, &m->accept_list, mood_item_node) { ret = get_item_score(item, &afsi, &afhi, path, &item_score, &score_arg_sum); if (ret == 0) continue; - match = 1; + match = true; score += item_score; } /* reject if there is no matching entry in the accept list */ if (!match && !list_empty(&m->accept_list)) return 0; list_for_each_entry(item, &m->score_list, mood_item_node) { - ret = get_item_score(item, &afsi, &afhi, path, &item_score, + match = get_item_score(item, &afsi, &afhi, path, &item_score, &score_arg_sum); - score += item_score; + if (match) + score += item_score; } if (score_arg_sum) score /= score_arg_sum;