Browse Source

Correction on the skipped subtitles

Olivier Marty 9 years ago
parent
commit
5c8e9a9d9b
3 changed files with 11 additions and 1 deletions
  1. 3 1
      main.c
  2. 7 0
      time.c
  3. 1 0
      time.h

+ 3 - 1
main.c

@@ -129,8 +129,10 @@ int main(int argc, char **argv)
   while(!feof(f))
   {
     id = next(f, id+1, &sline);
-    if(!timeSleepUntil(sline.begin)) // no error and in the future
+    if(timeInFuture(sline.end))
     {
+      timeSleepUntil(sline.begin);
+      
       printf("%ds\n", sline.begin.tv_sec);
       // show
       printf("%s\n", sline.text);

+ 7 - 0
time.c

@@ -82,3 +82,10 @@ struct timespec timeCreate(time_t s, long ns)
   return r;
 }
 
+int timeInFuture(struct timespec t)
+{
+  struct timespec tmp = timeGetRelative();
+  tmp = timeDiff(t, tmp);
+  return tmp.tv_sec >= 0;
+}
+

+ 1 - 0
time.h

@@ -27,6 +27,7 @@ void timeInitialize(int rel); // add rel seconds to the clock
 mytime timeGetRelative();
 // return -2 if t is in the past
 int timeSleepUntil(mytime t);
+int timeInFuture(mytime t);
 
 mytime timeCreate(time_t s, long ns);