New upstream version 2.20
[debian/cpmtools] / cpmrm.c
diff --git a/cpmrm.c b/cpmrm.c
index e9353412510b93ff505b4971b99b2c8d7d68945b..65430da6d752548e98648baad4f7d0cbe722af84 100644 (file)
--- a/cpmrm.c
+++ b/cpmrm.c
@@ -7,7 +7,7 @@
 #include <string.h>
 #include <stdlib.h>
 
-#include "getopt.h"
+#include "getopt_.h"
 #include "cpmfs.h"
 
 #ifdef USE_DMALLOC
@@ -22,7 +22,7 @@ int main(int argc, char *argv[]) /*{{{*/
   /* variables */ /*{{{*/
   const char *err;
   const char *image;
-  const char *format=FORMAT;
+  const char *format;
   const char *devopts=NULL;
   int c,i,usage=0,exitcode=0;
   struct cpmSuperBlock drive;
@@ -32,6 +32,7 @@ int main(int argc, char *argv[]) /*{{{*/
   /*}}}*/
 
   /* parse options */ /*{{{*/
+  if (!(format=getenv("CPMTOOLSFMT"))) format=FORMAT;
   while ((c=getopt(argc,argv,"T:f:h?"))!=EOF) switch(c)
   {
     case 'T': devopts=optarg; break;
@@ -41,7 +42,7 @@ int main(int argc, char *argv[]) /*{{{*/
   }
 
   if (optind>=(argc-1)) usage=1;
-  else image=argv[optind];
+  else image=argv[optind++];
 
   if (usage)
   {
@@ -52,10 +53,14 @@ int main(int argc, char *argv[]) /*{{{*/
   /* open image */ /*{{{*/
   if ((err=Device_open(&drive.dev, image, O_RDWR, devopts)))
   {
-    fprintf(stderr,"%s: can not open %s (%s)\n",cmd,image,err);
+    fprintf(stderr,"%s: cannot open %s (%s)\n",cmd,image,err);
+    exit(1);
+  }
+  if (cpmReadSuper(&drive,&root,format)==-1)
+  {
+    fprintf(stderr,"%s: cannot read superblock (%s)\n",cmd,boo);
     exit(1);
   }
-  cpmReadSuper(&drive,&root,format);
   /*}}}*/
   cpmglob(optind,argc,argv,&root,&gargc,&gargv);
   for (i=0; i<gargc; ++i)
@@ -66,6 +71,7 @@ int main(int argc, char *argv[]) /*{{{*/
       exitcode=1;
     }
   }
+  cpmUmount(&drive);
   exit(exitcode);
 }
 /*}}}*/