summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2b171da)
raw | patch | inline | side by side (parent: 2b171da)
author | Max Kellermann <max.kellermann@gmail.com> | |
Tue, 21 Mar 2017 21:41:58 +0000 (22:41 +0100) | ||
committer | Max Kellermann <max.kellermann@gmail.com> | |
Tue, 21 Mar 2017 21:41:58 +0000 (22:41 +0100) |
Makefile.am | patch | blob | history | |
src/screen_song.c | patch | blob | history | |
src/song_paint.c | patch | blob | history | |
src/status_bar.c | patch | blob | history | |
src/strfsong.c | patch | blob | history | |
src/time_format.c | [new file with mode: 0644] | patch | blob |
src/time_format.h | [new file with mode: 0644] | patch | blob |
src/utils.c | patch | blob | history | |
src/utils.h | patch | blob | history |
diff --git a/Makefile.am b/Makefile.am
index a70f478c9c6eb0e75a45b823a92ca8ab9e0bca88..ac11c693a64b83eb5ed2b3d36ea1d34afd88f95e 100644 (file)
--- a/Makefile.am
+++ b/Makefile.am
src/window.h \
src/wreadln.c src/wreadln.h \
src/strfsong.c src/strfsong.h \
+ src/time_format.c src/time_format.h \
src/utils.c src/utils.h
if ENABLE_ASYNC_CONNECT
diff --git a/src/screen_song.c b/src/screen_song.c
index 086768cec6b058f353604cf1b3df2bfd35156846..61c77d517fc0f5e3bf09fbd81fbbde5b98e0662d 100644 (file)
--- a/src/screen_song.c
+++ b/src/screen_song.c
#include "i18n.h"
#include "screen.h"
#include "charset.h"
-#include "utils.h"
+#include "time_format.h"
#include "mpdclient.h"
#include <mpd/client.h>
diff --git a/src/song_paint.c b/src/song_paint.c
index 3b55eaf7c2d88136d3e012fe09d87e46dc1d27f2..56b80a3772fa1dd0e90b15fa1ac28769045f096a 100644 (file)
--- a/src/song_paint.c
+++ b/src/song_paint.c
#include "song_paint.h"
#include "paint.h"
#include "strfsong.h"
-#include "utils.h"
+#include "time_format.h"
#include "hscroll.h"
#include "charset.h"
#include "config.h"
diff --git a/src/status_bar.c b/src/status_bar.c
index bdf3bcd6200cb324898ba63e675be63677f9733a..fc63d20e49e0d4fa4b50df1e5ac9b63e9da523db 100644 (file)
--- a/src/status_bar.c
+++ b/src/status_bar.c
#include "charset.h"
#include "strfsong.h"
#include "player_command.h"
-#include "utils.h"
+#include "time_format.h"
#include <mpd/client.h>
diff --git a/src/strfsong.c b/src/strfsong.c
index 8fe10160881ceb1930852d4d1999bdc3078d8c42..b64c350ba6dace76d83b8c70f0dd49d591b1eefc 100644 (file)
--- a/src/strfsong.c
+++ b/src/strfsong.c
#include "strfsong.h"
#include "charset.h"
-#include "utils.h"
+#include "time_format.h"
#include <mpd/client.h>
diff --git a/src/time_format.c b/src/time_format.c
--- /dev/null
+++ b/src/time_format.c
@@ -0,0 +1,76 @@
+/* ncmpc (Ncurses MPD Client)
+ * (c) 2004-2017 The Music Player Daemon Project
+ * Project homepage: http://musicpd.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "time_format.h"
+#include "i18n.h"
+
+#include <glib.h>
+
+void
+format_duration_short(char *buffer, size_t length, unsigned duration)
+{
+ if (duration < 3600)
+ g_snprintf(buffer, length,
+ "%i:%02i", duration / 60, duration % 60);
+ else
+ g_snprintf(buffer, length,
+ "%i:%02i:%02i", duration / 3600,
+ (duration % 3600) / 60, duration % 60);
+}
+
+void
+format_duration_long(char *p, size_t length, unsigned long duration)
+{
+ unsigned bytes_written = 0;
+
+ if (duration / 31536000 > 0) {
+ if (duration / 31536000 == 1)
+ bytes_written = g_snprintf(p, length, "%d %s, ", 1, _("year"));
+ else
+ bytes_written = g_snprintf(p, length, "%lu %s, ", duration / 31536000, _("years"));
+ duration %= 31536000;
+ length -= bytes_written;
+ p += bytes_written;
+ }
+ if (duration / 604800 > 0) {
+ if (duration / 604800 == 1)
+ bytes_written = g_snprintf(p, length, "%d %s, ",
+ 1, _("week"));
+ else
+ bytes_written = g_snprintf(p, length, "%lu %s, ",
+ duration / 604800, _("weeks"));
+ duration %= 604800;
+ length -= bytes_written;
+ p += bytes_written;
+ }
+ if (duration / 86400 > 0) {
+ if (duration / 86400 == 1)
+ bytes_written = g_snprintf(p, length, "%d %s, ",
+ 1, _("day"));
+ else
+ bytes_written = g_snprintf(p, length, "%lu %s, ",
+ duration / 86400, _("days"));
+ duration %= 86400;
+ length -= bytes_written;
+ p += bytes_written;
+ }
+
+ g_snprintf(p, length, "%02lu:%02lu:%02lu", duration / 3600,
+ duration % 3600 / 60, duration % 3600 % 60);
+}
diff --git a/src/time_format.h b/src/time_format.h
--- /dev/null
+++ b/src/time_format.h
@@ -0,0 +1,31 @@
+/* ncmpc (Ncurses MPD Client)
+ * (c) 2004-2017 The Music Player Daemon Project
+ * Project homepage: http://musicpd.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef TIME_FORMAT_H
+#define TIME_FORMAT_H
+
+#include <stddef.h>
+
+void
+format_duration_short(char *buffer, size_t length, unsigned duration);
+
+void
+format_duration_long(char *buffer, size_t length, unsigned long duration);
+
+#endif
diff --git a/src/utils.c b/src/utils.c
index 8f867ad36b87130d339b803bdde1ca2f4d366238..0c35c9e8e14089efb7483fe1c36374f0ad01221d 100644 (file)
--- a/src/utils.c
+++ b/src/utils.c
*/
#include "utils.h"
-#include "i18n.h"
#include <stdlib.h>
#include <string.h>
}
return list;
}
-
-void
-format_duration_short(char *buffer, size_t length, unsigned duration)
-{
- if (duration < 3600)
- g_snprintf(buffer, length,
- "%i:%02i", duration / 60, duration % 60);
- else
- g_snprintf(buffer, length,
- "%i:%02i:%02i", duration / 3600,
- (duration % 3600) / 60, duration % 60);
-}
-
-void
-format_duration_long(char *p, size_t length, unsigned long duration)
-{
- unsigned bytes_written = 0;
-
- if (duration / 31536000 > 0) {
- if (duration / 31536000 == 1)
- bytes_written = g_snprintf(p, length, "%d %s, ", 1, _("year"));
- else
- bytes_written = g_snprintf(p, length, "%lu %s, ", duration / 31536000, _("years"));
- duration %= 31536000;
- length -= bytes_written;
- p += bytes_written;
- }
- if (duration / 604800 > 0) {
- if (duration / 604800 == 1)
- bytes_written = g_snprintf(p, length, "%d %s, ",
- 1, _("week"));
- else
- bytes_written = g_snprintf(p, length, "%lu %s, ",
- duration / 604800, _("weeks"));
- duration %= 604800;
- length -= bytes_written;
- p += bytes_written;
- }
- if (duration / 86400 > 0) {
- if (duration / 86400 == 1)
- bytes_written = g_snprintf(p, length, "%d %s, ",
- 1, _("day"));
- else
- bytes_written = g_snprintf(p, length, "%lu %s, ",
- duration / 86400, _("days"));
- duration %= 86400;
- length -= bytes_written;
- p += bytes_written;
- }
-
- g_snprintf(p, length, "%02lu:%02lu:%02lu", duration / 3600,
- duration % 3600 / 60, duration % 3600 % 60);
-}
diff --git a/src/utils.h b/src/utils.h
index ecd68bbf6e4b4f35e34bf6220fa85ef3a0f9aeab..010cfee5cc02a4017c05c3f7998dd9d828295ff2 100644 (file)
--- a/src/utils.h
+++ b/src/utils.h
GList *string_list_find(GList *string_list, const gchar *str);
GList *string_list_remove(GList *string_list, const gchar *str);
-void
-format_duration_short(char *buffer, size_t length, unsigned duration);
-
-void
-format_duration_long(char *buffer, size_t length, unsigned long duration);
-
#endif