Imported Upstream version 2.17
[debian/cpmtools] / cpmchattr.c
index 42704e72c7cc1ff1dbf7c96122d7538d022ee9b1..dc55c3300660954a97467c3d8577246545277721 100644 (file)
@@ -1,12 +1,17 @@
 /* #includes */ /*{{{C}}}*//*{{{*/
+#include "config.h"
+
 #include <ctype.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[]="cpmchattr";
@@ -16,7 +21,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;
@@ -27,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;
@@ -38,8 +44,8 @@ int main(int argc, char *argv[]) /*{{{*/
   if (optind>=(argc-2)) usage=1;
   else 
   {
-    image=argv[optind];
-    attrs = argv[optind+1];
+    image=argv[optind++];
+    attrs = argv[optind++];
   }    
 
   if (usage)
@@ -101,6 +107,7 @@ int main(int argc, char *argv[]) /*{{{*/
       exitcode=1;
     }
   }
+  cpmUmount(&drive);
   exit(exitcode);
 }
 /*}}}*/