X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=mood.c;h=e5e8495369f1e7ffffe36bd463ec5aadf6163e39;hp=354ce3ca43cb7afe03349e7969153d7743814be3;hb=aac4fd33c39e979bc3f86632507e4ee2846d219a;hpb=f652ce6afe7f6fd0e42814505234cbf4321a736e diff --git a/mood.c b/mood.c index 354ce3ca..e5e84953 100644 --- a/mood.c +++ b/mood.c @@ -77,6 +77,10 @@ struct mood { struct list_head score_list; }; +/* + * If current_mood is NULL then no mood is currently open. If + * current_mood->name is NULL, the dummy mood is currently open + */ static struct mood *current_mood; /** @@ -218,7 +222,8 @@ static void destroy_mood(struct mood *m) static struct mood *alloc_new_mood(const char *name) { struct mood *m = para_calloc(sizeof(struct mood)); - m->name = para_strdup(name); + if (name) + m->name = para_strdup(name); INIT_LIST_HEAD(&m->accept_list); INIT_LIST_HEAD(&m->deny_list); INIT_LIST_HEAD(&m->score_list); @@ -381,7 +386,7 @@ static int load_mood(const struct osl_row *mood_row, struct mood **m) if (!*mood_name) return -E_DUMMY_ROW; mlpd.m = alloc_new_mood(mood_name); - ret = for_each_line_ro(mood_def.data, mood_def.size, + ret = for_each_line(FELF_READ_ONLY, mood_def.data, mood_def.size, parse_mood_line, &mlpd); osl_close_disk_object(&mood_def); if (ret < 0) { @@ -413,7 +418,7 @@ static int check_mood(struct osl_row *mood_row, void *data) ret = para_printf(pb, "checking mood %s...\n", mood_name); if (ret < 0) goto out; - ret = for_each_line_ro(mood_def.data, mood_def.size, + ret = for_each_line(FELF_READ_ONLY, mood_def.data, mood_def.size, parse_mood_line, &mlpd); if (ret < 0) para_printf(pb, "%s line %u: %s\n", mood_name, mlpd.line_num, @@ -850,9 +855,9 @@ int change_current_mood(char *mood_name) return ret; close_current_mood(); current_mood = m; - } else { + } else { /* load dummy mood */ close_current_mood(); - current_mood = alloc_new_mood("dummy"); + current_mood = alloc_new_mood(NULL); } aa.m = current_mood; PARA_NOTICE_LOG("computing statistics of admissible files\n"); @@ -867,7 +872,7 @@ int change_current_mood(char *mood_name) if (ret < 0) goto out; } - PARA_NOTICE_LOG("loaded mood %s\n", current_mood->name); + PARA_NOTICE_LOG("loaded mood %s\n", mood_name? mood_name : "(dummy)"); ret = statistics.num; out: free(aa.array); @@ -913,6 +918,8 @@ static int reload_current_mood(void) * This function performs actions required due to the occurrence of the given * event. Possible actions include reload of the current mood and update of the * score of an audio file. + * + * \return Standard. */ int moods_event_handler(enum afs_events event, __a_unused struct para_buffer *pb, void *data)