New upstream version 2.20
[debian/cpmtools] / cpmrm.c
diff --git a/cpmrm.c b/cpmrm.c
index b88bdcab9f477618c245e91e73c96ad813af306d..65430da6d752548e98648baad4f7d0cbe722af84 100644 (file)
--- a/cpmrm.c
+++ b/cpmrm.c
@@ -1,12 +1,18 @@
 /* #includes */ /*{{{C}}}*//*{{{*/
+#include "config.h"
+
 #include <ctype.h>
 #include <errno.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
-#include "config.h"
-#include "getopt.h"
+
+#include "getopt_.h"
 #include "cpmfs.h"
+
+#ifdef USE_DMALLOC
+#include <dmalloc.h>
+#endif
 /*}}}*/
 
 const char cmd[]="cpmrm";
@@ -16,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;
@@ -26,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;
@@ -35,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)
   {
@@ -46,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)
@@ -60,6 +71,7 @@ int main(int argc, char *argv[]) /*{{{*/
       exitcode=1;
     }
   }
+  cpmUmount(&drive);
   exit(exitcode);
 }
 /*}}}*/