X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=mood.c;h=b1ee78e4e67faac76be61ee9c09085dfde20972f;hp=93461ee845c558ec30c0da78bf548939f1247857;hb=869f0e06ec4e15abc9230c1b2d7615da5250802e;hpb=74f1e057c1579d880becb6a32acd43641b1a8c2b diff --git a/mood.c b/mood.c index 93461ee8..b1ee78e4 100644 --- a/mood.c +++ b/mood.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007-2011 Andre Noll + * Copyright (C) 2007-2012 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ @@ -107,12 +107,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; @@ -120,7 +124,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); @@ -134,7 +138,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; @@ -153,27 +158,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; @@ -364,8 +371,10 @@ static int load_mood(const struct osl_row *mood_row, struct mood **m) char *mood_name; struct osl_object mood_def; struct mood_line_parser_data mlpd = {.line_num = 0}; - int ret = mood_get_name_and_def_by_row(mood_row, &mood_name, &mood_def); + int ret; + *m = NULL; + ret = mood_get_name_and_def_by_row(mood_row, &mood_name, &mood_def); if (ret < 0) return ret; if (!*mood_name) @@ -422,7 +431,7 @@ out: void mood_check_callback(int fd, __a_unused const struct osl_object *query) { struct para_buffer pb = { - .max_size = SHMMAX, + .max_size = shm_get_shmmax(), .private_data = &fd, .max_size_handler = pass_buffer_as_shm };