Code

utils: move format_duration_*() to time_format.c
authorMax Kellermann <max.kellermann@gmail.com>
Tue, 21 Mar 2017 21:41:58 +0000 (22:41 +0100)
committerMax Kellermann <max.kellermann@gmail.com>
Tue, 21 Mar 2017 21:41:58 +0000 (22:41 +0100)
Makefile.am
src/screen_song.c
src/song_paint.c
src/status_bar.c
src/strfsong.c
src/time_format.c [new file with mode: 0644]
src/time_format.h [new file with mode: 0644]
src/utils.c
src/utils.h

index a70f478c9c6eb0e75a45b823a92ca8ab9e0bca88..ac11c693a64b83eb5ed2b3d36ea1d34afd88f95e 100644 (file)
@@ -62,6 +62,7 @@ src_ncmpc_SOURCES = \
        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
index 086768cec6b058f353604cf1b3df2bfd35156846..61c77d517fc0f5e3bf09fbd81fbbde5b98e0662d 100644 (file)
@@ -25,7 +25,7 @@
 #include "i18n.h"
 #include "screen.h"
 #include "charset.h"
-#include "utils.h"
+#include "time_format.h"
 #include "mpdclient.h"
 
 #include <mpd/client.h>
index 3b55eaf7c2d88136d3e012fe09d87e46dc1d27f2..56b80a3772fa1dd0e90b15fa1ac28769045f096a 100644 (file)
@@ -20,7 +20,7 @@
 #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"
index bdf3bcd6200cb324898ba63e675be63677f9733a..fc63d20e49e0d4fa4b50df1e5ac9b63e9da523db 100644 (file)
@@ -24,7 +24,7 @@
 #include "charset.h"
 #include "strfsong.h"
 #include "player_command.h"
-#include "utils.h"
+#include "time_format.h"
 
 #include <mpd/client.h>
 
index 8fe10160881ceb1930852d4d1999bdc3078d8c42..b64c350ba6dace76d83b8c70f0dd49d591b1eefc 100644 (file)
@@ -19,7 +19,7 @@
 
 #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
new file mode 100644 (file)
index 0000000..8db5cbd
--- /dev/null
@@ -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
new file mode 100644 (file)
index 0000000..c3a4b54
--- /dev/null
@@ -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
index 8f867ad36b87130d339b803bdde1ca2f4d366238..0c35c9e8e14089efb7483fe1c36374f0ad01221d 100644 (file)
@@ -18,7 +18,6 @@
  */
 
 #include "utils.h"
-#include "i18n.h"
 
 #include <stdlib.h>
 #include <string.h>
@@ -58,56 +57,3 @@ string_list_remove(GList *string_list, const gchar *str)
        }
        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);
-}
index ecd68bbf6e4b4f35e34bf6220fa85ef3a0f9aeab..010cfee5cc02a4017c05c3f7998dd9d828295ff2 100644 (file)
@@ -27,10 +27,4 @@ GList *string_list_free(GList *string_list);
 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