chiark / gitweb /
dvd-sector-copy.c, dvdrip: Make input and output files positional args.
authorMark Wooding <mdw@distorted.org.uk>
Wed, 16 Feb 2022 21:15:22 +0000 (21:15 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Wed, 16 Feb 2022 23:29:33 +0000 (23:29 +0000)
They're not really optional.

dvd-sector-copy.c
dvdrip

index a43adb2afdce02721d71cc9cdfbb777af2775b8c..b1f4a53e5c41175eaa118c2421312c8f37b7ee5a 100644 (file)
@@ -43,8 +43,8 @@ static int status = 0;
 static void usage(FILE *fp)
 {
   fprintf(fp,
-         "usage: %s [-c] [-D DEV] [-R MAP] "
-               "[-b OUTMAP] [-o OUTFILE] [-r [START]-[END]]\n",
+         "usage: %s [-c] [-R MAP] [-b OUTMAP] [-r [START]-[END]]\n"
+         "\tDEVICE OUTFILE\n",
          prog);
 }
 
@@ -524,8 +524,7 @@ static void emit(secaddr start, secaddr end)
          if (ferror(mapfp))
            bail_syserr(errno, "error writing bad-sector map file");
        }
-       if (outfd >= 0 &&
-           lseek(outfd, (off_t)(bad_hi - bad_lo)*SECTORSZ, SEEK_CUR) < 0)
+       if (lseek(outfd, (off_t)(bad_hi - bad_lo)*SECTORSZ, SEEK_CUR) < 0)
          bail_syserr(errno, "failed to seek past bad sectors");
        status = 1;
       }
@@ -648,7 +647,7 @@ int main(int argc, char *argv[])
   off_t off;
   secaddr start, end;
   const struct event *ev;
-  const char *device = "/dev/dvd", *outfile = 0;
+  const char *device, *outfile;
   int opt, blksz;
   unsigned n;
   size_t i;
@@ -667,10 +666,9 @@ int main(int argc, char *argv[])
 
   p = strrchr(argv[0], '/'); prog = p ? p + 1 : argv[0];
   for (;;) {
-    opt = getopt(argc, argv, "hD:FR:b:co:r:"); if (opt < 0) break;
+    opt = getopt(argc, argv, "hFR:X:b:cr:"); if (opt < 0) break;
     switch (opt) {
       case 'h': usage(stderr); exit(0);
-      case 'D': device = optarg; break;
       case 'F': f |= f_fixup; break;
       case 'R':
        fp = fopen(optarg, "r");
@@ -698,7 +696,6 @@ int main(int argc, char *argv[])
        mapfile = optarg;
        break;
       case 'c': f |= f_continue; break;
-      case 'o': outfile = optarg; break;
       case 'r':
        start = 0; end = -1;
        if (parse_range(optarg, PRF_HYPHEN, &start, &end))
@@ -711,9 +708,11 @@ int main(int argc, char *argv[])
       default: f |= f_bogus; break;
     }
   }
-  if (optind < argc) f |= f_bogus;
+  if (argc - optind != 2) f |= f_bogus;
   if (f&f_bogus) { usage(stderr); exit(2); }
 
+  device = argv[optind]; outfile = argv[optind + 1];
+
   dvdfd = open(device, O_RDONLY);
   if (dvdfd < 0)
     bail_syserr(errno, "failed to open device `%s'", device);
@@ -743,7 +742,6 @@ int main(int argc, char *argv[])
   }
 
   if (f&f_continue) {
-    if (!outfile) bail("can't continue without output file");
     off = lseek(outfd, 0, SEEK_END);
     if (off < 0)
       bail_syserr(errno, "failed to seek to end of output file `%s'",
@@ -846,8 +844,7 @@ int main(int argc, char *argv[])
        break;
       case EV_WRITE:
        gettimeofday(&last_time, 0); last_pos = pos;
-       if (outfd >= 0 &&
-           lseek(outfd, (off_t)ev->pos*SECTORSZ, SEEK_SET) < 0)
+       if (lseek(outfd, (off_t)ev->pos*SECTORSZ, SEEK_SET) < 0)
          bail_syserr(errno,
                      "failed to seek to resume position "
                      "(sector %"PRIuSEC") in output file `%s'",
@@ -879,7 +876,7 @@ int main(int argc, char *argv[])
 
   if (progresslen) putchar('\n');
 
-  if (outfd >= 0 && ftruncate(outfd, (off_t)limit*SECTORSZ) < 0)
+  if (ftruncate(outfd, (off_t)limit*SECTORSZ) < 0)
     bail_syserr(errno, "failed to set output file `%s' length", outfile);
 
   if (dvd) DVDClose(dvd);
diff --git a/dvdrip b/dvdrip
index ac370762845890e05306e20c24c5ea3b2782690b..73400b66cbfeee78dc90fa71fdccc41ce2d092ac 100755 (executable)
--- a/dvdrip
+++ b/dvdrip
@@ -133,7 +133,8 @@ case $backup in
     ;;
   nil)
     if [ ! -f "$tmp/$tag/iso" ]; then
-      run_setrc "$DVD_SECTOR_COPY" -D"$dev" -c -b"$tmp/$tag/badblocks" -o"$tmp/$tag/iso.new"
+      run_setrc "$DVD_SECTOR_COPY" -c -b"$tmp/$tag/badblocks" \
+               "$dev" "$tmp/$tag/iso.new"
       case $rc in
        0)
          run mv "$tmp/$tag/iso.new" "$tmp/$tag/iso"