move to debhelper compat 13, hopefully fixes cross-building
[debian/cpmtools] / cpmchattr.c
index 42704e72c7cc1ff1dbf7c96122d7538d022ee9b1..4ab7aaff93dce431dd20a41d0941bc4c1942df9b 100644 (file)
@@ -1,11 +1,12 @@
 /* #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"
 /*}}}*/
 
@@ -16,8 +17,9 @@ 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 uppercase=0;
   int c,i,usage=0,exitcode=0;
   struct cpmSuperBlock drive;
   struct cpmInode root;
@@ -27,10 +29,12 @@ int main(int argc, char *argv[]) /*{{{*/
   /*}}}*/
 
   /* parse options */ /*{{{*/
-  while ((c=getopt(argc,argv,"T:f:h?"))!=EOF) switch(c)
+  if (!(format=getenv("CPMTOOLSFMT"))) format=FORMAT;
+  while ((c=getopt(argc,argv,"T:f:uh?"))!=EOF) switch(c)
   {
     case 'T': devopts=optarg; break;
     case 'f': format=optarg; break;
+    case 'u': uppercase=1; break;
     case 'h':
     case '?': usage=1; break;
   }
@@ -38,23 +42,27 @@ 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)
   {
-    fprintf(stderr,"Usage: %s [-f format] [-T dsktype] image [NMrsa1234] pattern ...\n",cmd);
+    fprintf(stderr,"Usage: %s [-f format] [-T dsktype] [-u] image [NMrsa1234] pattern ...\n",cmd);
     exit(1);
   }
   /*}}}*/
   /* 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,uppercase)==-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)
@@ -67,7 +75,9 @@ int main(int argc, char *argv[]) /*{{{*/
     if (!rc) rc = cpmAttrGet(&ino, &attrib);
     if (!rc)
     {
-        int n, m;
+        unsigned int n;
+        int m;
+
         m = 0;
        for (n = 0; n < strlen(attrs); n++)
        {
@@ -101,6 +111,7 @@ int main(int argc, char *argv[]) /*{{{*/
       exitcode=1;
     }
   }
+  cpmUmount(&drive);
   exit(exitcode);
 }
 /*}}}*/