Imported Upstream version 2.17
[debian/cpmtools] / mkfs.cpm.c
index e15c36d35c8cc39ebff68d493d46ec1333dee3d5..0e0ac55c9da8eb32248ffce39e7b5c7a1c64b7a0 100644 (file)
@@ -1,16 +1,18 @@
 /* #includes */ /*{{{C}}}*//*{{{*/
+#include "config.h"
+
 #include <ctype.h>
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.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 "cpmfs.h"
+
+#ifdef USE_DMALLOC
+#include <dmalloc.h>
+#endif
 /*}}}*/
 /* #defines */ /*{{{*/
 #ifndef O_BINARY
@@ -101,7 +103,7 @@ const char cmd[]="mkfs.cpm";
 int main(int argc, char *argv[]) /*{{{*/
 {
   char *image;
-  const char *format=FORMAT;
+  const char *format;
   int c,usage=0;
   struct cpmSuperBlock drive;
   struct cpmInode root;
@@ -110,6 +112,7 @@ int main(int argc, char *argv[]) /*{{{*/
   char *bootTracks;
   const char *boot[4]={(const char*)0,(const char*)0,(const char*)0,(const char*)0};
 
+  if (!(format=getenv("CPMTOOLSFMT"))) format=FORMAT;
   while ((c=getopt(argc,argv,"b:f:L:h?"))!=EOF) switch(c)
   {
     case 'b':
@@ -128,7 +131,7 @@ int main(int argc, char *argv[]) /*{{{*/
   }
 
   if (optind!=(argc-1)) usage=1;
-  else image=argv[optind];
+  else image=argv[optind++];
 
   if (usage)
   {