summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-09-01 21:59:13 +0200
committerwm4 <wm4@nowhere>2012-09-18 21:04:47 +0200
commit53bfaecd40aa7b34dcc9c90064e36f2ffe227fc0 (patch)
tree7c8865437d2e48d1c9782c37520d04d3e0604dca
parent5a13f5a5e8dd63c899581db86c51c9bb093fcdde (diff)
downloadmpv-53bfaecd40aa7b34dcc9c90064e36f2ffe227fc0.tar.bz2
mpv-53bfaecd40aa7b34dcc9c90064e36f2ffe227fc0.tar.xz
core: remove duplicated format_time() functions
This was an on-going transition to make mplayer format all times in the same format.
-rw-r--r--command.c12
-rw-r--r--m_property.c12
-rw-r--r--mpcommon.c19
-rw-r--r--mpcommon.h3
-rw-r--r--mplayer.c17
-rw-r--r--screenshot.c22
6 files changed, 32 insertions, 53 deletions
diff --git a/command.c b/command.c
index 1b0ff9dfeb..bde4396529 100644
--- a/command.c
+++ b/command.c
@@ -2082,16 +2082,6 @@ static const char *property_error_string(int error_value)
return "UNKNOWN";
}
-static char *format_time(double time)
-{
- int h, m, s = time;
- h = s / 3600;
- s -= h * 3600;
- m = s / 60;
- s -= m * 60;
- return talloc_asprintf(NULL, "%02d:%02d:%02d", h, m, s);
-}
-
static void show_chapters_on_osd(MPContext *mpctx)
{
int count = get_chapter_count(mpctx);
@@ -2106,7 +2096,7 @@ static void show_chapters_on_osd(MPContext *mpctx)
for (n = 0; n < count; n++) {
char *name = chapter_display_name(mpctx, n);
double t = chapter_start_time(mpctx, n);
- char* time = format_time(t);
+ char* time = mp_format_time(t, false);
res = talloc_asprintf_append(res, "%s", time);
talloc_free(time);
char *m1 = "> ", *m2 = " <";
diff --git a/m_property.c b/m_property.c
index 35c2c0e3b1..4d1fb90ed6 100644
--- a/m_property.c
+++ b/m_property.c
@@ -380,16 +380,6 @@ int m_property_double_ro(const m_option_t *prop, int action,
return M_PROPERTY_NOT_IMPLEMENTED;
}
-static char *format_time(double time)
-{
- int h, m, s = time;
- h = s / 3600;
- s -= h * 3600;
- m = s / 60;
- s -= m * 60;
- return talloc_asprintf(NULL, "%02d:%02d:%02d", h, m, s);
-}
-
int m_property_time_ro(const m_option_t *prop, int action,
void *arg, double var)
{
@@ -398,7 +388,7 @@ int m_property_time_ro(const m_option_t *prop, int action,
if (!arg)
return M_PROPERTY_ERROR;
else {
- *(char **)arg = format_time(var);
+ *(char **)arg = mp_format_time(var, false);
return M_PROPERTY_OK;
}
}
diff --git a/mpcommon.c b/mpcommon.c
index b6e618742e..d4811440aa 100644
--- a/mpcommon.c
+++ b/mpcommon.c
@@ -15,3 +15,22 @@
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+
+#include "talloc.h"
+#include "mpcommon.h"
+
+char *mp_format_time(double time, bool fractions)
+{
+ if (time < 0)
+ return talloc_strdup(NULL, "unknown");
+ int h, m, s = time;
+ h = s / 3600;
+ s -= h * 3600;
+ m = s / 60;
+ s -= m * 60;
+ char *res = talloc_asprintf(NULL, "%02d:%02d:%02d", h, m, s);
+ if (fractions)
+ res = talloc_asprintf_append(res, ".%03d",
+ (int)((time - (int)time) * 1000));
+ return res;
+}
diff --git a/mpcommon.h b/mpcommon.h
index d4ececc4b1..472a2e1943 100644
--- a/mpcommon.h
+++ b/mpcommon.h
@@ -20,6 +20,7 @@
#define MPLAYER_MPCOMMON_H
#include <stdlib.h>
+#include <stdbool.h>
// both int64_t and double should be able to represent this exactly
#define MP_NOPTS_VALUE (-1LL<<63)
@@ -77,4 +78,6 @@
extern const char *mplayer_version;
+char *mp_format_time(double time, bool fractions);
+
#endif /* MPLAYER_MPCOMMON_H */
diff --git a/mplayer.c b/mplayer.c
index 5b02e33588..66b5a236a7 100644
--- a/mplayer.c
+++ b/mplayer.c
@@ -1151,20 +1151,9 @@ static void saddf(char *buf, int len, const char *format, ...)
*/
static void sadd_hhmmssff(char *buf, int len, double time, bool fractions)
{
- if (time < 0) {
- saddf(buf, len, "unknown");
- return;
- }
- int h, m, s = time;
- h = s / 3600;
- s -= h * 3600;
- m = s / 60;
- s -= m * 60;
- saddf(buf, len, "%02d:", h);
- saddf(buf, len, "%02d:", m);
- saddf(buf, len, "%02d", s);
- if (fractions)
- saddf(buf, len, ".%02d", (int)((time - (int)time) * 100));
+ char *s = mp_format_time(time, fractions);
+ saddf(buf, len, "%s", s);
+ talloc_free(s);
}
static void sadd_percentage(char *buf, int len, int percent) {
diff --git a/screenshot.c b/screenshot.c
index 032fa132f4..79356ed9a2 100644
--- a/screenshot.c
+++ b/screenshot.c
@@ -67,20 +67,6 @@ static char *stripext(void *talloc_ctx, const char *s)
return talloc_asprintf(talloc_ctx, "%.*s", end - s, s);
}
-static char *format_time(void *talloc_ctx, double time, bool sub_seconds)
-{
- int h, m, s = time;
- h = s / 3600;
- s -= h * 3600;
- m = s / 60;
- s -= m * 60;
- char *res = talloc_asprintf(talloc_ctx, "%02d:%02d:%02d", h, m, s);
- if (sub_seconds)
- res = talloc_asprintf_append(res, ".%03d",
- (int)((time - (int)time) * 1000));
- return res;
-}
-
static char *do_format_property(struct MPContext *mpctx, struct bstr s) {
struct bstr prop_name = s;
int fallbackpos = bstrchr(s, ':');
@@ -179,10 +165,12 @@ static char *create_fname(struct MPContext *mpctx, char *template,
break;
}
case 'p':
- case 'P':
- append_filename(&res,
- format_time(res, get_current_time(mpctx), fmt == 'P'));
+ case 'P': {
+ char *t = mp_format_time(get_current_time(mpctx), fmt == 'P');
+ append_filename(&res, t);
+ talloc_free(t);
break;
+ }
case 't': {
char fmt = *template;
if (!fmt)