changeset 25704:1977ed7f06d4

Simplify cue-parsing
author reimar
date Sun, 13 Jan 2008 15:13:04 +0000
parents 986e8d8c1ae7
children aab0c3e38476
files stream/stream_cue.c
diffstat 1 files changed, 12 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/stream/stream_cue.c	Sun Jan 13 15:01:07 2008 +0000
+++ b/stream/stream_cue.c	Sun Jan 13 15:13:04 2008 +0000
@@ -95,12 +95,17 @@
 /* number of tracks on the cd */
 static int nTracks = 0;
 
+static int digits2int(char s[2], int errval) {
+  uint8_t a = s[0] - '0';
+  uint8_t b = s[1] - '0';
+  if (a > 9 || b > 9)
+    return errval;
+  return a * 10 + b;
+}
+
 /* presumes Line is preloaded with the "current" line of the file */
 static int cue_getTrackinfo(char *Line, tTrack *track)
 {
-  char min;
-  char sec;
-  char fps;
   int already_set = 0;
 
   /* Get the 'mode' */
@@ -131,19 +136,13 @@
     if (strncmp(&Line[4], "INDEX ", 6)==0)
     {
       /* check stuff here so if the answer is false the else stuff below won't be executed */
-      Line[12] = 0;
-      if ((already_set == 0) &&
-          ((strcmp(&Line[10], "00")==0) || (strcmp(&Line[10], "01")==0)))
+      if ((already_set == 0) && digits2int(Line + 10, 100) <= 1)
       {
         already_set = 1;
 
-        min = ((Line[13]-'0')<<4) | (Line[14]-'0');
-        sec = ((Line[16]-'0')<<4) | (Line[17]-'0');
-        fps = ((Line[19]-'0')<<4) | (Line[20]-'0');
-
-        track->minute = (((min>>4)*10) + (min&0xf));
-        track->second = (((sec>>4)*10) + (sec&0xf));
-        track->frame  = (((fps>>4)*10) + (fps&0xf));
+        track->minute = digits2int(Line + 13, 0);
+        track->second = digits2int(Line + 16, 0);
+        track->frame  = digits2int(Line + 19, 0);
       }
     }
     else if (strncmp(&Line[4], "PREGAP ", 7)==0) { ; /* ignore */ }