add to rules to get diskdefs in a compliant location again
[debian/cpmtools] / cpmchattr.c
index 9fbf074ca1934bcacb5ad72304e45cbe4467bd48..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,36 +42,42 @@ 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)
   {
     struct cpmInode ino;
-    int err;
+    int rc;
     cpm_attr_t attrib;
 
-    err = cpmNamei(&root,gargv[i], &ino)==-1;
-    if (!err) err = cpmAttrGet(&ino, &attrib);
-    if (!err)
+    rc = cpmNamei(&root,gargv[i], &ino)==-1;
+    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++)
        {
@@ -93,14 +103,15 @@ int main(int argc, char *argv[]) /*{{{*/
           } 
           if (m) attrib &= ~mask; else attrib |= mask;
        }
-        err = cpmAttrSet(&ino, attrib);
+        rc = cpmAttrSet(&ino, attrib);
     }
-    if (err)
+    if (rc)
     {
       fprintf(stderr,"%s: can not set attributes for %s: %s\n",cmd,gargv[i],boo);
       exitcode=1;
     }
   }
+  cpmUmount(&drive);
   exit(exitcode);
 }
 /*}}}*/