[MPlayer-cvslog] r37515 - in branches/1.2: . gui/util/misc.c gui/util/misc.h

ib subversion at mplayerhq.hu
Tue Sep 8 23:02:27 CEST 2015


Author: ib
Date: Tue Sep  8 23:02:27 2015
New Revision: 37515

Log:
Merge r37499 from trunk:

Add auxiliary function msf2sec().

Modified:
   branches/1.2/   (props changed)
   branches/1.2/gui/util/misc.c
   branches/1.2/gui/util/misc.h

Modified: branches/1.2/gui/util/misc.c
==============================================================================
--- branches/1.2/gui/util/misc.c	Tue Sep  8 23:02:25 2015	(r37514)
+++ branches/1.2/gui/util/misc.c	Tue Sep  8 23:02:27 2015	(r37515)
@@ -21,6 +21,7 @@
  * @brief Miscellaneous utilities
  */
 
+#include <ctype.h>
 #include <string.h>
 
 #include "misc.h"
@@ -64,3 +65,38 @@ float constrain(float value)
 
     return value;
 }
+
+/**
+ * @brief Convert MM:SS:FF (minute/second/frame) to seconds.
+ *
+ * @param msf string in MM:SS:FF format
+ *
+ * @return seconds equivalent to @a msf (0 in case of error)
+ */
+float msf2sec(const char *msf)
+{
+    int i;
+
+    for (i = 0; i < 8; i++)
+        switch (i) {
+        case 0:
+        case 1:
+        case 3:
+        case 4:
+        case 6:
+        case 7:
+            if (!isdigit(msf[i]))
+                return 0.0f;
+            break;
+
+        case 2:
+        case 5:
+            if (msf[i] != ':')
+                return 0.0f;
+            break;
+        }
+
+    return (msf[0] - '0') * 600 + (msf[1] - '0') * 60 +
+           (msf[3] - '0') * 10 + (msf[4] - '0') +
+           ((msf[6] - '0') * 10 + (msf[7] - '0')) / 75.0f;
+}

Modified: branches/1.2/gui/util/misc.h
==============================================================================
--- branches/1.2/gui/util/misc.h	Tue Sep  8 23:02:25 2015	(r37514)
+++ branches/1.2/gui/util/misc.h	Tue Sep  8 23:02:27 2015	(r37515)
@@ -23,5 +23,6 @@
 
 float constrain(float value);
 char *fgetstr(char *str, int size, FILE *file);
+float msf2sec(const char *msf);
 
 #endif /* MPLAYER_GUI_MISC_H */


More information about the MPlayer-cvslog mailing list