dvd-sector-copy.c: Sink debugging spew to the end of the `switch' arm.
[dvdrip] / dvd-sector-copy.c
index 9186d72..c6b4c19 100644 (file)
@@ -1024,8 +1024,6 @@ int main(int argc, char *argv[])
   if (argc - optind != 2) f |= f_bogus;
   if (f&f_bogus) { usage(stderr); exit(2); }
 
-  setlocale(LC_ALL, "");
-  progress_init(&progress);
   device = argv[optind]; outfile = argv[optind + 1];
 
   if (badblocks.n) {
@@ -1039,6 +1037,8 @@ int main(int argc, char *argv[])
 #endif
   }
 
+  setlocale(LC_ALL, "");
+  progress_init(&progress);
   if (open_dvd(device, O_RDONLY, &dvdfd, &dvd)) exit(2);
 
   blksz = SECTORSZ; volsz = device_size(dvdfd, device, &blksz);
@@ -1115,19 +1115,19 @@ int main(int argc, char *argv[])
 #ifdef DEBUG
   dump_eventq("initial");
 #endif
-  for (i = 0, f &= ~f_write, start = 0; i < eventq.n; i++) {
+  for (i = 0, f &= ~f_write, start = last = 0; i < eventq.n; i++) {
     ev = &eventq.v[i];
     if (ev->ev == EV_WRITE) { start = ev->pos; f |= f_write; }
     if (ev->pos >= limit) break;
     if (ev->ev == EV_STOP) { nsectors += ev->pos - start; f &= ~f_write; }
-    if (f&f_fixup) start = ev->pos;
+    if (f&f_fixup) last = ev->pos;
   }
   eventq.n = i;
 #ifdef DEBUG
   dump_eventq("trimmed");
 #endif
   if (f&f_fixup) {
-    put_event(EV_WRITE, 0, start);
+    put_event(EV_WRITE, 0, last);
     f |= f_write;
   }
   if (f&f_write) {
@@ -1178,11 +1178,11 @@ int main(int argc, char *argv[])
                      "failed to seek to resume position "
                      "(sector %"PRIuSEC") in output file `%s'",
                      ev->pos, outfile);
+       f |= f_write;
 #ifdef DEBUG
        progress_clear(&progress);
        printf(";; %8"PRIuSEC": begin write\n", pos);
 #endif
-       f |= f_write;
        break;
       case EV_STOP:
        f &= ~f_write;