Imported Upstream version 2.17
[debian/cpmtools] / fsck.cpm.c
index 572823b1c7ce537466b25d84b3b0585b5d5a937b..c1458037fcb1b2660c621f68258e05861c48729e 100644 (file)
@@ -1,17 +1,20 @@
 /* #includes */ /*{{{C}}}*//*{{{*/
+#include "config.h"
+
 #include <assert.h>
 #include <ctype.h>
 #include <stdio.h>
 #include <string.h>
+#include <stdlib.h>
 #include <errno.h>
-#include "config.h"
-
-extern char *optarg;
-extern int optind,opterr,optopt;
-int getopt(int argc, char * const *argv, const char *optstring);
 
+#include "getopt_.h"
 #include "cpmdir.h"
 #include "cpmfs.h"
+
+#ifdef USE_DMALLOC
+#include <dmalloc.h>
+#endif
 /*}}}*/
 /* #defines */ /*{{{*/
 /* your favourite password *:-) */
@@ -568,13 +571,14 @@ int main(int argc, char *argv[])
 {
   const char *err;
   const char *image;
-  const char *format=FORMAT;
+  const char *format;
   const char *devopts=NULL;
   int c,usage=0;
   struct cpmSuperBlock sb;
   struct cpmInode root;
   enum Result ret;
 
+  if (!(format=getenv("CPMTOOLSFMT"))) format=FORMAT;
   while ((c=getopt(argc,argv,"T:f:nh?"))!=EOF) switch(c)
   {
     case 'f': format=optarg; break;
@@ -585,7 +589,7 @@ int main(int argc, char *argv[])
   }
 
   if (optind!=(argc-1)) usage=1;
-  else image=argv[optind];
+  else image=argv[optind++];
 
   if (usage)
   {