]> git.tue.mpg.de Git - paraslash.git/commitdiff
mood.c: Simplify and rename load_mood().
authorAndre Noll <maan@tuebingen.mpg.de>
Tue, 8 Mar 2022 22:08:23 +0000 (23:08 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Mon, 17 Oct 2022 18:36:21 +0000 (20:36 +0200)
We first turn the given mood name into a row of the mood table, then
get the mood definition from the row. It's equivalent and much easier
to call mood_get_def_by_name() instead.

Rename the function because init_mood_parser() tells the reader
what the function actually does.

mood.c

diff --git a/mood.c b/mood.c
index 398713437997ee30034f739404ee640b0e389281..5b0ddfdd7449cd89e1e32c51565b5012f1597e69 100644 (file)
--- a/mood.c
+++ b/mood.c
@@ -146,24 +146,25 @@ static struct mood *alloc_new_mood(const char *name)
        return m;
 }
 
-static int load_mood(const struct osl_row *mood_row, struct mood **m,
-               char **errmsg)
+static int init_mood_parser(const char *mood_name, struct mood **m, char **err)
 {
-       char *mood_name;
        struct osl_object mood_def;
        int ret;
 
-       ret = mood_get_name_and_def_by_row(mood_row, &mood_name, &mood_def);
+       if (!*mood_name) {
+               if (err)
+                       *err = make_message("empty mood name\n");
+               return -ERRNO_TO_PARA_ERROR(EINVAL);
+       }
+       ret = mood_get_def_by_name(mood_name, &mood_def);
        if (ret < 0) {
-               if (errmsg)
-                       *errmsg = make_message(
-                               "could not read mood definition");
+               if (err)
+                       *err = make_message("could not read mood definition\n");
                return ret;
        }
-       assert(*mood_name);
        *m = alloc_new_mood(mood_name);
        PARA_INFO_LOG("opening mood %s\n", mood_name);
-       ret = mp_init(mood_def.data, mood_def.size, &(*m)->parser_context, errmsg);
+       ret = mp_init(mood_def.data, mood_def.size, &(*m)->parser_context, err);
        osl_close_disk_object(&mood_def);
        if (ret < 0)
                destroy_mood(*m);
@@ -619,23 +620,7 @@ int change_current_mood(const char *mood_name, char **errmsg)
 
        if (mood_name) {
                struct mood *m;
-               struct osl_row *row;
-               struct osl_object obj;
-
-               if (!*mood_name) {
-                       *errmsg = make_message("empty mood name");
-                       return -ERRNO_TO_PARA_ERROR(EINVAL);
-               }
-               obj.data = (char *)mood_name;
-               obj.size = strlen(mood_name) + 1;
-               ret = osl(osl_get_row(moods_table, BLOBCOL_NAME, &obj, &row));
-               if (ret < 0) {
-                       if (errmsg)
-                               *errmsg = make_message("no such mood: %s",
-                                       mood_name);
-                       return ret;
-               }
-               ret = load_mood(row, &m, errmsg);
+               ret = init_mood_parser(mood_name, &m, errmsg);
                if (ret < 0)
                        return ret;
                close_current_mood();