X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=score.c;h=fa12663cb936535cd43d623c37b331a86896a1cb;hb=b0a87fd7b5aeb8007afd3ac25d8548543d42080c;hp=2f49b104027ecbfc7fcd696deeb71ff6d417ced8;hpb=0efa0935594ec151c795e562a6614b3e45cbf22c;p=paraslash.git diff --git a/score.c b/score.c index 2f49b104..fa12663c 100644 --- a/score.c +++ b/score.c @@ -196,17 +196,15 @@ static int get_score_row_from_aft_row(const struct osl_row *aft_row, } /** - * Loop over all files in the score table. + * Call the given function for each row of the score table. * - * \param data A pointer to arbitrary data. - * \param func Function to be called for each admissible file. + * \param func Callback, called once per row. + * \param data Passed verbatim to the callback. * - * \return The return value of the underlying call to osl_rbtree_loop(). - * - * This is used for the ls command. The \a data parameter is passed as the - * second argument to \a func. + * \return The return value of the underlying call to osl_rbtree_loop(). The + * loop terminates early if the callback returns negative. */ -int admissible_file_loop(void *data, osl_rbtree_loop_func *func) +int score_loop(osl_rbtree_loop_func *func, void *data) { return osl(osl_rbtree_loop(score_table, SCORECOL_SCORE, data, func)); } @@ -257,27 +255,20 @@ int score_delete(const struct osl_row *aft_row) * Find out whether an audio file is contained in the score table. * * \param aft_row The row of the audio file table. - * \param rank Result pointer * - * \return Positive, if \a aft_row belongs to the audio file table, - * zero if not, negative on errors. If \a aft_row was found, and \a rank - * is not \p NULL, the rank of \a aft_row is returned in \a rank. + * \return If the lookup operation fails for any other reason than "not found", + * the function aborts the current process (afs), since this is considered a + * fatal error that should never happen. */ -int row_belongs_to_score_table(const struct osl_row *aft_row, unsigned *rank) +bool row_belongs_to_score_table(const struct osl_row *aft_row) { struct osl_row *score_row; int ret = get_score_row_from_aft_row(aft_row, &score_row); if (ret == -OSL_ERRNO_TO_PARA_ERROR(E_OSL_RB_KEY_NOT_FOUND)) - return 0; - if (ret < 0) - return ret; - if (!rank) - return 1; - ret = osl(osl_get_rank(score_table, score_row, SCORECOL_SCORE, rank)); - if (ret < 0) - return ret; - return 1; + return false; + assert(ret >= 0); + return true; } static void score_close(void) @@ -302,14 +293,8 @@ int clear_score_table(void) return score_open(NULL); } -/** - * Initialize the scoring subsystem. - * - * \param t The members of \a t are filled in by the function. - */ -void score_init(struct afs_table *t) -{ - t->name = score_table_desc.name; - t->open = score_open; - t->close = score_close; -} +/** The score table stores (aft row, score) pairs in memory. */ +const struct afs_table_operations score_ops = { + .open = score_open, + .close = score_close, +};