From d848dc0560a070a43cc7ad579987e869135a99a0 Mon Sep 17 00:00:00 2001 From: Matt Low Date: Wed, 16 Oct 2019 21:47:42 +0400 Subject: [PATCH] Readability/sensible ordering --- mpd_control.c | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/mpd_control.c b/mpd_control.c index 34a17f0..79bcbac 100644 --- a/mpd_control.c +++ b/mpd_control.c @@ -71,17 +71,31 @@ print_status(struct mpd_connection *conn, struct worker_meta *meta) const enum mpd_state state = mpd_status_get_state(status); - if (state == MPD_STATE_STOP || state == MPD_STATE_UNKNOWN) { - // Early exit - printf("\n"); - mpd_status_free(status); - fflush(stdout); - return 0; + char *play_icon = NULL; + switch (state) { + case MPD_STATE_PLAY: + play_icon = ""; + break; + case MPD_STATE_PAUSE: + play_icon = ""; + break; + default: + printf("\n"); + mpd_status_free(status); + fflush(stdout); + return 0; } const bool repeat = mpd_status_get_repeat(status); const bool random = mpd_status_get_random(status); + char state_icon[16]; + strcpy(state_icon, ""); + if (repeat) + strcat(state_icon, " "); + if (random) + strcat(state_icon, " "); + const unsigned queue_pos = mpd_status_get_song_pos(status); const unsigned queue_length = mpd_status_get_queue_length(status); const unsigned elapsed = mpd_status_get_elapsed_time(status); @@ -106,22 +120,6 @@ print_status(struct mpd_connection *conn, struct worker_meta *meta) if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS) return handle_error(conn); - char *play_icon; - if (state == MPD_STATE_PLAY) { - play_icon = ""; - } else if (state == MPD_STATE_PAUSE) { - play_icon = ""; - } else { - play_icon = ""; - } - - char state_icon[16]; - strcpy(state_icon, ""); - if (repeat) - strcat(state_icon, " "); - if (random) - strcat(state_icon, " "); - // the full song label. would be cool if this was customizable at runtime char full_label[strlen(artist) + strlen(title) + 4]; sprintf(full_label, "%s - %s", artist, title);