paraslash 0.5.1
[paraslash.git] / score.c
diff --git a/score.c b/score.c
index f2a28b7559bd49308559262fa3d475d041cab88f..37f4c55072d920bcef85ec622f6568c91b0ed11e 100644 (file)
--- a/score.c
+++ b/score.c
@@ -1,10 +1,13 @@
 /*
- * Copyright (C) 2007-2008 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2007-2013 Andre Noll <maan@systemlinux.org>
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
 
 /** \file score.c Scoring functions to determine the audio file streaming order. */
+#include <regex.h>
+#include <osl.h>
+
 #include "para.h"
 #include "error.h"
 #include "string.h"
@@ -35,8 +38,8 @@ static int ptr_compare(const struct osl_object *obj1, const struct osl_object *o
  */
 static int score_compare(const struct osl_object *obj1, const struct osl_object *obj2)
 {
-       int d1 = *(int*)obj1->data;
-       int d2 = *(int*)obj2->data;
+       long d1 = *(long *)obj1->data;
+       long d2 = *(long *)obj2->data;
        int ret = NUM_COMPARE(d2, d1);
 
        if (ret)
@@ -93,7 +96,7 @@ static struct osl_table_description score_table_desc = {
  */
 int get_num_admissible_files(unsigned *num)
 {
-       return osl_get_num_rows(score_table, num);
+       return osl(osl_get_num_rows(score_table, num));
 }
 
 /**
@@ -109,7 +112,7 @@ int get_num_admissible_files(unsigned *num)
 static int get_score_of_row(void *score_row, long *score)
 {
        struct osl_object obj;
-       int ret = osl_get_object(score_table, score_row, SCORECOL_SCORE, &obj);
+       int ret = osl(osl_get_object(score_table, score_row, SCORECOL_SCORE, &obj));
 
        if (ret >= 0)
                *score = *(long *)obj.data;
@@ -138,10 +141,10 @@ int score_add(const struct osl_row *aft_row, long score)
        size = score_table_desc.column_descriptions[SCORECOL_SCORE].data_size;
        score_objs[SCORECOL_SCORE].data = para_malloc(size);
        score_objs[SCORECOL_SCORE].size = size;
-       *(int *)(score_objs[SCORECOL_SCORE].data) = score;
+       *(long *)(score_objs[SCORECOL_SCORE].data) = score;
 
 //     PARA_DEBUG_LOG("adding %p\n", *(void **) (score_objs[SCORECOL_AFT_ROW].data));
-       ret = osl_add_row(score_table, score_objs);
+       ret = osl(osl_add_row(score_table, score_objs));
        if (ret < 0) {
                PARA_ERROR_LOG("%s\n", para_strerror(-ret));
                free(score_objs[SCORECOL_SCORE].data);
@@ -152,7 +155,7 @@ int score_add(const struct osl_row *aft_row, long score)
 static int get_nth_score(unsigned n, long *score)
 {
        struct osl_row *row;
-       int ret = osl_get_nth_row(score_table, SCORECOL_SCORE, n, &row);
+       int ret = osl(osl_get_nth_row(score_table, SCORECOL_SCORE, n, &row));
 
        if (ret < 0)
                return ret;
@@ -165,13 +168,11 @@ static int get_nth_score(unsigned n, long *score)
  * \param aft_row Determines the audio file to change.
  * \param percent The position to re-insert the audio file.
  *
- * The percent parameter must be between \p 0 and 100 and. A value of zero
- * means to re-insert the audio file into the score table with a score lower
- * than any other admissible file.
+ * The percent parameter must be between 0 and 100. A value of zero means to
+ * re-insert the audio file into the score table with a score lower than any
+ * other admissible file.
  *
- * \return Positive on success, negative on errors. Possible errors: Errors
- * returned by osl_get_row(), get_num_admissible_files(), osl_get_nth_row(),
- * osl_get_object(), osl_update_object().
+ * \return Positive on success, negative on errors.
  */
 int score_update(const struct osl_row *aft_row, long percent)
 {
@@ -180,9 +181,9 @@ int score_update(const struct osl_row *aft_row, long percent)
        unsigned n, new_pos;
        struct osl_object obj = {.data = (struct osl_row *)aft_row,
                .size = sizeof(aft_row)};
-       int ret = osl_get_row(score_table, SCORECOL_AFT_ROW, &obj, &row);
+       int ret = osl(osl_get_row(score_table, SCORECOL_AFT_ROW, &obj, &row));
 
-       if (ret == -E_RB_KEY_NOT_FOUND) /* not an error */
+       if (ret == -OSL_ERRNO_TO_PARA_ERROR(E_OSL_RB_KEY_NOT_FOUND)) /* not an error */
                return 1;
        if (ret < 0)
                return ret;
@@ -198,7 +199,7 @@ int score_update(const struct osl_row *aft_row, long percent)
        obj.data = para_malloc(obj.size);
        *(long *)obj.data = new_score;
        PARA_DEBUG_LOG("new score: %ld, rank %u/%u\n", new_score, new_pos, n);
-       return osl_update_object(score_table, row, SCORECOL_SCORE, &obj);
+       return osl(osl_update_object(score_table, row, SCORECOL_SCORE, &obj));
 }
 
 /**
@@ -219,7 +220,7 @@ int get_score_and_aft_row(struct osl_row *score_row, long *score,
 
        if (ret < 0)
                return ret;
-       ret = osl_get_object(score_table, score_row, SCORECOL_AFT_ROW, &obj);
+       ret = osl(osl_get_object(score_table, score_row, SCORECOL_AFT_ROW, &obj));
        if (ret < 0)
                return ret;
        *aft_row = obj.data;
@@ -231,8 +232,7 @@ static int get_score_row_from_aft_row(const struct osl_row *aft_row,
 {
        struct osl_object obj = {.data = (struct osl_row *)aft_row,
                .size = sizeof(aft_row)};
-       return osl_get_row(score_table, SCORECOL_AFT_ROW, &obj, score_row);
-
+       return osl(osl_get_row(score_table, SCORECOL_AFT_ROW, &obj, score_row));
 }
 
 /**
@@ -250,7 +250,7 @@ static int get_score_row_from_aft_row(const struct osl_row *aft_row,
  */
 int admissible_file_loop(void *data, osl_rbtree_loop_func *func)
 {
-       return osl_rbtree_loop(score_table, SCORECOL_SCORE, data, func);
+       return osl(osl_rbtree_loop(score_table, SCORECOL_SCORE, data, func));
 }
 
 /**
@@ -265,7 +265,7 @@ int admissible_file_loop(void *data, osl_rbtree_loop_func *func)
  */
 int admissible_file_loop_reverse(void *data, osl_rbtree_loop_func *func)
 {
-       return osl_rbtree_loop_reverse(score_table, SCORECOL_SCORE, data, func);
+       return osl(osl_rbtree_loop_reverse(score_table, SCORECOL_SCORE, data, func));
 }
 
 /**
@@ -281,11 +281,11 @@ int score_get_best(struct osl_row **aft_row, long *score)
 {
        struct osl_row *row;
        struct osl_object obj;
-       int ret = osl_rbtree_last_row(score_table, SCORECOL_SCORE, &row);
+       int ret = osl(osl_rbtree_last_row(score_table, SCORECOL_SCORE, &row));
 
        if (ret < 0)
                return ret;
-       ret = osl_get_object(score_table, row, SCORECOL_AFT_ROW, &obj);
+       ret = osl(osl_get_object(score_table, row, SCORECOL_AFT_ROW, &obj));
        if (ret < 0)
                return ret;
        *aft_row = obj.data;
@@ -309,7 +309,7 @@ int score_delete(const struct osl_row *aft_row)
 
        if (ret < 0)
                return ret;
-       return osl_del_row(score_table, score_row);
+       return osl(osl_del_row(score_table, score_row));
 }
 
 /**
@@ -327,13 +327,13 @@ int row_belongs_to_score_table(const struct osl_row *aft_row, unsigned *rank)
        struct osl_row *score_row;
        int ret = get_score_row_from_aft_row(aft_row, &score_row);
 
-       if (ret == -E_RB_KEY_NOT_FOUND)
+       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_get_rank(score_table, score_row, SCORECOL_SCORE, rank);
+       ret = osl(osl_get_rank(score_table, score_row, SCORECOL_SCORE, rank));
        if (ret < 0)
                return ret;
        return 1;
@@ -356,7 +356,7 @@ static void score_close(void)
 static int score_open(__a_unused const char *dir)
 {
        score_table_desc.dir = NULL; /* this table has only volatile columns */
-       return osl_open_table(&score_table_desc, &score_table);
+       return osl(osl_open_table(&score_table_desc, &score_table));
 }
 
 /**