From: Andre Noll Date: Tue, 8 Mar 2022 22:08:23 +0000 (+0100) Subject: mood.c: Simplify and rename load_mood(). X-Git-Tag: v0.7.2~14^2~13 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=5ae1a5bb9732d777f856d5bb003585f81e3c519a;p=paraslash.git mood.c: Simplify and rename load_mood(). 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. --- diff --git a/mood.c b/mood.c index 39871343..5b0ddfdd 100644 --- 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();