]> arthur.barton.de Git - netatalk.git/commitdiff
reindent
authorHAT <hat@fa2.so-net.ne.jp>
Thu, 7 Jun 2012 15:57:05 +0000 (00:57 +0900)
committerHAT <hat@fa2.so-net.ne.jp>
Thu, 7 Jun 2012 15:57:05 +0000 (00:57 +0900)
contrib/shell_utils/apple_dump.in

index 500d28ffb6a50b3945ef044a14ec95fd05ace7e4..e98ad357e31a7dcc70ab30706023ffb55618d30f 100755 (executable)
 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 #  GNU General Public License for more details.
-# 
+#
 
-# 
+#
 # References:
-# 
+#
 # Applesingle and AppleDouble format internals (version 1)
 # http://users.phg-online.de/tk/netatalk/doc/Apple/v1/
-# 
+#
 # AppleSingle/AppleDouble Formats for Foreign Files Developer's Note (version2)
 # http://users.phg-online.de/tk/netatalk/doc/Apple/v2/AppleSingle_AppleDouble.pdf
-# 
+#
 # Inside Macintosh: Macintosh Toolbox Essentials /
 # Chapter 7 - Finder Interface / Finder Interface Reference
 # http://developer.apple.com/legacy/mac/library/documentation/mac/toolbox/Toolbox-463.html
-# 
+#
 # Finder Interface Reference
 # http://developer.apple.com/legacy/mac/library/documentation/Carbon/Reference/Finder_Interface/Reference/reference.html
-# 
+#
 # Technical Note TN1150  HFS Plus Volume Format
 # http://developer.apple.com/mac/library/technotes/tn/tn1150.html#FinderInfo
-# 
+#
 # CarbonHeaders source
 # http://www.opensource.apple.com/source/CarbonHeaders/CarbonHeaders-8A428/Finder.h
 # http://www.opensource.apple.com/source/CarbonHeaders/CarbonHeaders-9A581/Finder.h
-# 
+#
 # Xcode 3.2.1
 # /usr/bin/SetFile
 # /usr/bin/GetFileInfo
-# 
+#
 # Mac OS X 10.6.2 kernel source
 # http://www.opensource.apple.com/source/xnu/xnu-1486.2.11/bsd/vfs/vfs_xattr.c
-# 
+#
 
 use File::Basename;
 use File::Spec;
@@ -85,7 +85,7 @@ while ($arg = shift @ARGV)
         printf ("                   If FILE is not AppleSingle/AppleDouble format,\n");
         printf ("                   look for extended attribute, .AppleDouble/FILE and ._FILE.\n");
         printf ("                   If DIR, look for extended attribute,\n");
-       printf ("                   DIR/.AppleDouble/.Parent and ._DIR.\n");
+        printf ("                   DIR/.AppleDouble/.Parent and ._DIR.\n");
         printf ("  -e               Dump extended attribute of FILE or DIR\n");
         printf ("  -f               Dump FILE. Assume FinderInfo to be FileInfo.\n");
         printf ("  -d               Dump FILE. Assume FinderInfo to be DirInfo.\n");
@@ -106,19 +106,19 @@ while ($arg = shift @ARGV)
         $finderinfo = 0;
     } elsif ($arg eq "-e") {
         if ($eacommand == 0) {
-           printf (STDERR "%s: unsupported option -e\n", basename($0));
-           printf (STDERR "because neither getfattr, xattr nor runat is found.\n");
-           exit 1;
-       }
-       $eaoption = 1;
+            printf (STDERR "%s: unsupported option -e\n", basename($0));
+            printf (STDERR "because neither getfattr, xattr nor runat is found.\n");
+            exit 1;
+        }
+        $eaoption = 1;
     } elsif ($arg eq "-f") {
         $finderinfo = 1;
     } elsif ($arg eq "-d") {
         $finderinfo = 2;
     } elsif ($arg =~ /^-/) {
-       printf (STDERR "%s: invalid option %s\n", basename($0), $arg);
-       printf (STDERR "Try \`%s\ -h' for more information.\n", basename($0));
-       exit 1;
+        printf (STDERR "%s: invalid option %s\n", basename($0), $arg);
+        printf (STDERR "Try \`%s\ -h' for more information.\n", basename($0));
+        exit 1;
     } else {
         $afile = $arg;
     }
@@ -140,16 +140,16 @@ $abspath = File::Spec->rel2abs($afile);
 
 if ( $eaoption == 1 ) {
     if ( -f $afile ) {
-       $finderinfo = 1;
+        $finderinfo = 1;
     } elsif ( -d $afile ) {
-       $finderinfo = 2;
+        $finderinfo = 2;
     } else {
-       printf (STDERR "unknown error: %s\n", $afile);
-       exit 1;
+        printf (STDERR "unknown error: %s\n", $afile);
+        exit 1;
     }
     if ( 0 == checkea($afile) ) {
-       printf (STDERR "\"%s\"'s extended attribute is not found\n",  $afile);
-       exit 1;
+        printf (STDERR "\"%s\"'s extended attribute is not found\n",  $afile);
+        exit 1;
     }
     $openfile = eaopenfile($afile);
     $openmessage = "Dumping \"$afile\"'s extended attribute...\n";
@@ -157,26 +157,26 @@ if ( $eaoption == 1 ) {
     $openfile = $afile;
 } elsif ( -f $afile ) {
     if ( $basename eq ".Parent") {
-       $finderinfo = 2;
+        $finderinfo = 2;
     } elsif ( $path =~ /\/.AppleDouble\/$/ ) {
         $finderinfo = 1;
     } elsif ( $basename =~ /^._/ ) {
-       if ( -f $path.substr($basename, 2) ) {
-           $finderinfo = 1;
-       } elsif ( -d $path.substr($basename, 2) ) {
-           $finderinfo = 2;
-       }
+        if ( -f $path.substr($basename, 2) ) {
+            $finderinfo = 1;
+        } elsif ( -d $path.substr($basename, 2) ) {
+            $finderinfo = 2;
+        }
     }
     if (!open(INFILE, "<$afile")) {
-       printf (STDERR "cannot open %s\n",  $afile);
-       exit 1;
+        printf (STDERR "cannot open %s\n",  $afile);
+        exit 1;
     }
     read(INFILE,$buf,4);
     $val = unpack("N", $buf );
     close(INFILE);
     if ($val == 0x00051600 || $val == 0x00051607) {
         $openfile = $afile;
-       $openmessage = "Dumping \"$openfile\"...\n";
+        $openmessage = "Dumping \"$openfile\"...\n";
     } else {
         printf ("\"%s\" is not AppleSingle/AppleDouble format.\n", $afile);
         $finderinfo = 1;
@@ -185,30 +185,30 @@ if ( $eaoption == 1 ) {
         $osxfile = $path."._".$basename;
 
         if ( 1 == checkea($afile) ) {
-           printf ("\"%s\"\'s extended attribute is found.\n", $afile);
+            printf ("\"%s\"\'s extended attribute is found.\n", $afile);
             $adcount++;
-           $openfile = eaopenfile($afile);
-           $openmessage = "Dumping \"$afile\"'s extended attribute...\n";
-       }
-       if ( -e $netatalkfile ) {
+            $openfile = eaopenfile($afile);
+            $openmessage = "Dumping \"$afile\"'s extended attribute...\n";
+        }
+        if ( -e $netatalkfile ) {
             printf ("\"%s\" is found.\n", $netatalkfile);
-           $openfile = $netatalkfile;
-           $openmessage = "Dumping \"$openfile\"...\n";
+            $openfile = $netatalkfile;
+            $openmessage = "Dumping \"$openfile\"...\n";
         }
-       if ( -e $osxfile ) {
+        if ( -e $osxfile ) {
             printf ("\"%s\" is found.\n", $osxfile);
             $adcount++;
-           $openfile = $osxfile;
-           $openmessage = "Dumping \"$openfile\"...\n";
+            $openfile = $osxfile;
+            $openmessage = "Dumping \"$openfile\"...\n";
         }
-       if ( $adcount == 0 ) {
+        if ( $adcount == 0 ) {
             printf ("AppleSingle/AppleDouble data is not found.\n");
             exit 1;
-       }
-       if ( $adcount != 1 ) {
+        }
+        if ( $adcount != 1 ) {
             printf ("Specify any one.\n");
             exit 1;
-       }
+        }
     }
 } elsif ( -d $afile) {
     printf ("\"%s\" is a directory.\n", $afile);
@@ -218,30 +218,30 @@ if ( $eaoption == 1 ) {
     $osxfile = $path."._".$basename;
 
     if ( 1 == checkea($afile) ) {
-       printf ("\"%s\"\'s extended attribute is found.\n", $afile);
-       $adcount++;
-       $openfile = eaopenfile($afile);
-       $openmessage = "Dumping \"$afile\"'s extended attribute...\n";
+        printf ("\"%s\"\'s extended attribute is found.\n", $afile);
+        $adcount++;
+        $openfile = eaopenfile($afile);
+        $openmessage = "Dumping \"$afile\"'s extended attribute...\n";
     }
     if ( -e $netatalkfile ) {
-       printf ("\"%s\" is found.\n", $netatalkfile);
-       $adcount++;
-       $openfile= $netatalkfile;
-       $openmessage = "Dumping \"$openfile\"...\n";
+        printf ("\"%s\" is found.\n", $netatalkfile);
+        $adcount++;
+        $openfile= $netatalkfile;
+        $openmessage = "Dumping \"$openfile\"...\n";
     }
     if ( -e $osxfile ) {
-       printf ("\"%s\" is found.\n", $osxfile);
-       $adcount++;
-       $openfile = $osxfile;
-       $openmessage = "Dumping \"$openfile\"...\n";
+        printf ("\"%s\" is found.\n", $osxfile);
+        $adcount++;
+        $openfile = $osxfile;
+        $openmessage = "Dumping \"$openfile\"...\n";
     }
     if ( $adcount == 0 ) {
-       printf ("AppleSingle/AppleDouble data is not found.\n");
-       exit 1;
+        printf ("AppleSingle/AppleDouble data is not found.\n");
+        exit 1;
     }
     if ( $adcount != 1 ) {
-       printf ("Specify any one.\n");
-       exit 1;
+        printf ("Specify any one.\n");
+        exit 1;
     }
 } else {
     printf (STDERR "unknown error: %s\n", $afile);
@@ -383,8 +383,8 @@ for ( $num = 0 ; $num < $entnum ; $num++) {
 #    RAW Dump ---------------------------------------------------
 
     if ( ($quo > 0) || ($rem > 0)) {
-       print "\n";
-       print "-RAW DUMP--:  0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F : (ASCII)\n";
+        print "\n";
+        print "-RAW DUMP--:  0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F : (ASCII)\n";
     }
 
     seek(INFILE, $ofst, 0);
@@ -434,16 +434,16 @@ sub finderinfodump {
     seek(INFILE, $ofst, 0);
 
     if ($finderinfo == 0) {
-       print "\n";
-       print "-NOTE------: cannot detect whether FInfo or DInfo. assume FInfo.\n";
+        print "\n";
+        print "-NOTE------: cannot detect whether FInfo or DInfo. assume FInfo.\n";
     }
 
     if ($finderinfo == 0 || $finderinfo == 1) {
-       filefinderinfodump();
+        filefinderinfodump();
     } elsif ($finderinfo == 2) {
-       dirfinderinfodump();
+        dirfinderinfodump();
     } else {
-       print STDERR "unknown FinderInfo type\n"
+        print STDERR "unknown FinderInfo type\n"
     }
 
     if ($len > 32) { eadump(); }
@@ -602,27 +602,27 @@ sub flagsdump {
     printf ("color      : %d%d%d      : %s\n", ($flags >>  3) & 1,
             ($flags >>  2) & 1,
             ($flags >>  1) & 1,
-           @colortype[($flags & 0xE)>>1]);
+            @colortype[($flags & 0xE)>>1]);
     printf ("isOnDesk   : %d\n", ($flags >>  0) & 1);
 
 }
 
 sub xflagsdump {
-    
+
     read(INFILE,$buf,2);
     $flags = unpack("n", $buf );
-    
+
     if (($flags >> 15) == 1) {
-       print "Script     : ";
-       hexdump($buf, 1, 4, "");
+        print "Script     : ";
+        hexdump($buf, 1, 4, "");
     } else {
-       printf ("AreInvalid : %d\n", ($flags >> 15) & 1);
-       printf ("unknown bit: %d\n", ($flags >> 14) & 1);
-       printf ("unknown bit: %d\n", ($flags >> 13) & 1);
-       printf ("unknown bit: %d\n", ($flags >> 12) & 1);
-       printf ("unknown bit: %d\n", ($flags >> 11) & 1);
-       printf ("unknown bit: %d\n", ($flags >> 10) & 1);
-       printf ("unknown bit: %d\n", ($flags >>  9) & 1);
+        printf ("AreInvalid : %d\n", ($flags >> 15) & 1);
+        printf ("unknown bit: %d\n", ($flags >> 14) & 1);
+        printf ("unknown bit: %d\n", ($flags >> 13) & 1);
+        printf ("unknown bit: %d\n", ($flags >> 12) & 1);
+        printf ("unknown bit: %d\n", ($flags >> 11) & 1);
+        printf ("unknown bit: %d\n", ($flags >> 10) & 1);
+        printf ("unknown bit: %d\n", ($flags >>  9) & 1);
     }
 
     printf ("CustomBadge: %d\n", ($flags >>  8) & 1);
@@ -638,7 +638,7 @@ sub xflagsdump {
 }
 
 sub eadump {
-    
+
     print "\n";
     print "-EA--------:\n";
 
@@ -692,45 +692,45 @@ sub eadump {
     printf("     : %d\n", $ea_num_attrs);
 
     $pos = tell(INFILE);
-    
+
     for ($i = 0 ; $i < $ea_num_attrs ; $i++) {
-       
-       $pos = (($pos & 0x3) == 0) ? ($pos) : ((($pos >> 2) + 1) << 2);
-       seek(INFILE, $pos, 0);
-
-       print "-EA ENTRY--:\n";
-       
-       read(INFILE,$buf,4);
-       $ea_offset = unpack("N", $buf );
-       printf("offset     : %08X", $ea_offset);
-       printf(" : %d\n", $ea_offset);
-       
-       read(INFILE,$buf,4);
-       $ea_length = unpack("N", $buf );
-       printf("length     : %08X", $ea_length);
-       printf(" : %d\n", $ea_length);
-       
-       read(INFILE,$buf,2);
-       print "flags      : ";
-       hexdump($buf, 2, 4, "");
-       
-       read(INFILE,$buf,1);
-       $ea_namelen = unpack("C", $buf );
-       printf("namelen    : %02X", $ea_namelen);
-       printf("       : %d\n", $ea_namelen);
-
-       $ea_namequo = $ea_namelen >> 4;
-       $ea_namerem = $ea_namelen & 0xF;
-       print "-EA NAME---:  0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F : (ASCII)\n";
-       rawdump($ea_namequo, $ea_namerem);
-
-       $pos = tell(INFILE);
-
-       seek(INFILE, $ea_offset, 0);
-       $ea_quo = $ea_length >> 4;
-       $ea_rem = $ea_length & 0xF;
-       print "-EA VALUE--:  0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F : (ASCII)\n";
-       rawdump($ea_quo, $ea_rem);
+
+        $pos = (($pos & 0x3) == 0) ? ($pos) : ((($pos >> 2) + 1) << 2);
+        seek(INFILE, $pos, 0);
+
+        print "-EA ENTRY--:\n";
+
+        read(INFILE,$buf,4);
+        $ea_offset = unpack("N", $buf );
+        printf("offset     : %08X", $ea_offset);
+        printf(" : %d\n", $ea_offset);
+
+        read(INFILE,$buf,4);
+        $ea_length = unpack("N", $buf );
+        printf("length     : %08X", $ea_length);
+        printf(" : %d\n", $ea_length);
+
+        read(INFILE,$buf,2);
+        print "flags      : ";
+        hexdump($buf, 2, 4, "");
+
+        read(INFILE,$buf,1);
+        $ea_namelen = unpack("C", $buf );
+        printf("namelen    : %02X", $ea_namelen);
+        printf("       : %d\n", $ea_namelen);
+
+        $ea_namequo = $ea_namelen >> 4;
+        $ea_namerem = $ea_namelen & 0xF;
+        print "-EA NAME---:  0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F : (ASCII)\n";
+        rawdump($ea_namequo, $ea_namerem);
+
+        $pos = tell(INFILE);
+
+        seek(INFILE, $ea_offset, 0);
+        $ea_quo = $ea_length >> 4;
+        $ea_rem = $ea_length & 0xF;
+        print "-EA VALUE--:  0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F : (ASCII)\n";
+        rawdump($ea_quo, $ea_rem);
     }
 }
 
@@ -738,56 +738,54 @@ sub bedump  {
     my ($ofst, $len) = @_;
     my ($i);
     my ($value);
-    
+
     seek(INFILE, $ofst, 0);
-    
+
     printf("%2dbit-BE   : ", $len * 8 );
-    
+
     $value = 0;
     for ( $i=0 ; $i < $len ; $i++ ) {
-       read(INFILE,$buf,1);
-       $bytedata[$i] = unpack("C", $buf );
-       $value += $bytedata[$i] << (($len - $i -1) * 8) ;
+        read(INFILE,$buf,1);
+        $bytedata[$i] = unpack("C", $buf );
+          $value += $bytedata[$i] << (($len - $i -1) * 8) ;
     }
 
     for ( $i=0 ; $i < $len ; $i++ ) {
-       printf("%02X", $bytedata[$i]);
+        printf("%02X", $bytedata[$i]);
     }
 
     printf(" : %s", $value);
     print "\n";
-    
 }
 
 sub ledump  {
     my ($ofst, $len) = @_;
     my ($i);
     my ($value);
-    
+
     seek(INFILE, $ofst, 0);
-    
+
     printf("%2dbit-LE   : ", $len * 8 );
-    
+
     $value = 0;
     for ( $i=0 ; $i < $len ; $i++ ) {
-       read(INFILE,$buf,1);
-       $bytedata[$len - $i - 1] = unpack("C", $buf );
-       $value += $bytedata[$len - $i -1] << ($i * 8) ;
+        read(INFILE,$buf,1);
+        $bytedata[$len - $i - 1] = unpack("C", $buf );
+          $value += $bytedata[$len - $i -1] << ($i * 8) ;
     }
 
     for ( $i=0 ; $i < $len ; $i++ ) {
-       printf("%02X", $bytedata[$i]);
+        printf("%02X", $bytedata[$i]);
     }
 
     printf(" : %s", $value);
     print "\n";
-    
 }
 
 sub rawdump {
     my ($quo, $rem) = @_;
     my ($addrs, $line, $buf);
-    
+
     $addrs = 0;
     for ( $line = 0 ; $line < $quo ; $line++) {
         read(INFILE, $buf, 16);
@@ -800,7 +798,6 @@ sub rawdump {
         printf ( "%08X   :", $addrs);
         hexdump($buf, $rem, 16, " ");
     }
-    
 }
 
 sub hexdump {
@@ -838,37 +835,37 @@ sub checkea {
     $file =~ s/\$/\\\$/g;
     $file =~ s/\`/\\\`/g;
     if ( $eacommand == 1 ) {
-       open(EALIST, "getfattr \"$file\" |");
-       while(<EALIST>) {
-           if ( $_ eq "user.org.netatalk.Metadata\n" ) {
-               close (EALIST);
-               return 1;
-           }
-       }
-       close (EALIST);
-       return 0;
+        open(EALIST, "getfattr \"$file\" |");
+        while(<EALIST>) {
+            if ( $_ eq "user.org.netatalk.Metadata\n" ) {
+                close (EALIST);
+                return 1;
+            }
+        }
+        close (EALIST);
+        return 0;
     } elsif ( $eacommand == 2 ) {
-       open(EALIST, "attr -q -l \"$file\" |");
-       while(<EALIST>) {
-           if ( $_ eq "org.netatalk.Metadata\n" ) {
-               close (EALIST);
-               return 1;
-           }
-       }
-       close (EALIST);
-       return 0;
+        open(EALIST, "attr -q -l \"$file\" |");
+        while(<EALIST>) {
+            if ( $_ eq "org.netatalk.Metadata\n" ) {
+                close (EALIST);
+                return 1;
+            }
+        }
+        close (EALIST);
+        return 0;
     } elsif ( $eacommand == 3 ) {
-       open(EALIST, "runat \"$file\" ls -1 |");
-       while(<EALIST>) {
-           if ( $_ eq "org.netatalk.Metadata\n" ) {
-               close (EALIST);
-               return 1;
-           }
-       }
-       close (EALIST);
-       return 0;
+        open(EALIST, "runat \"$file\" ls -1 |");
+        while(<EALIST>) {
+            if ( $_ eq "org.netatalk.Metadata\n" ) {
+                close (EALIST);
+                return 1;
+            }
+        }
+        close (EALIST);
+        return 0;
     } else {
-       return 0;
+        return 0;
     }
 }
 
@@ -882,13 +879,13 @@ sub eaopenfile {
     ($eatempfh, $eatempfile) = tempfile(UNLINK => 1);
 
     if ( $eacommand == 1 ) {
-       system("getfattr --only-values -n user.org.netatalk.Metadata \"$file\" > $eatempfile");
+        system("getfattr --only-values -n user.org.netatalk.Metadata \"$file\" > $eatempfile");
     } elsif ( $eacommand == 2 ) {
-       system("attr -q -g org.netatalk.Metadata \"$file\" > $eatempfile");
+        system("attr -q -g org.netatalk.Metadata \"$file\" > $eatempfile");
     } elsif ( $eacommand == 3 ) {
-       system("runat \"$file\" cat org.netatalk.Metadata > $eatempfile");
+        system("runat \"$file\" cat org.netatalk.Metadata > $eatempfile");
     } else {
-       return "";
+        return "";
     }
 
     close($eatempfh);