From 5653b88ebe36635ea7ad6a4a525b6b86f90ca82a Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Mon, 15 Jun 2009 18:25:25 +0200 Subject: Fix negative time display --- src/main.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 8965bb9..58007d8 100644 --- a/src/main.c +++ b/src/main.c @@ -282,12 +282,20 @@ int main (int argc, char **argv) { /* show time */ if (player.mode >= PLAYER_SAMPLESIZE_INITIALIZED && player.mode < PLAYER_FINISHED_PLAYBACK) { - long int songRemaining = player.songDuration - player.songPlayed; - BarUiMsg (MSG_TIME, "-%02i:%02i/%02i:%02i\r", - (int) songRemaining / BAR_PLAYER_MS_TO_S_FACTOR / 60, - (int) songRemaining / BAR_PLAYER_MS_TO_S_FACTOR % 60, - (int) player.songDuration / BAR_PLAYER_MS_TO_S_FACTOR / 60, - (int) player.songDuration / BAR_PLAYER_MS_TO_S_FACTOR % 60); + /* Ugly: songDuration is unsigned _long_ int! Lets hope this won't + * overflow */ + int songRemaining = (signed long int) (player.songDuration - player.songPlayed) + / BAR_PLAYER_MS_TO_S_FACTOR; + char pos = 0; + if (songRemaining < 0) { + /* Use plus sign if song is longer than expected */ + pos = 1; + songRemaining = -songRemaining; + } + BarUiMsg (MSG_TIME, "%c%02i:%02i/%02i:%02i\r", (pos ? '+' : '-'), + songRemaining / 60, songRemaining % 60, + player.songDuration / BAR_PLAYER_MS_TO_S_FACTOR / 60, + player.songDuration / BAR_PLAYER_MS_TO_S_FACTOR % 60); } } -- cgit v1.2.3