openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

swap.pl (1356B)


      1 # 
      2 # 
      3 #
      4 # This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      5 # 
      6 # Copyright 2007-2019 Broadcom Inc. All rights reserved.
      7 #
      8 # swap.pl
      9 # SWAP the 32 bit words in the file. 1234 -> 4321
     10 #
     11 
     12     ($#ARGV == 1) ||
     13     die "Usage: $0 <unswapped-file> <swapped-file>\n" .
     14         "\tThis utility swaps the 32-bit words in <unswapped-file>\n" .
     15         "\tand writes them into <swapped-file>.\n";
     16 
     17     my $in_file=shift;
     18     my $out_file=shift;
     19 
     20     print STDOUT "Converting ", $in_file, " to  ", $out_file, " ...";
     21 
     22     $RECSIZE = 1; # size of record, in bytes
     23     $recno   = 0;  # which record to update
     24     open(FH, "<$in_file") || die "can't read $in_file : $!";
     25     open(FHO, ">$out_file") || die "can't write $out_file : $!";
     26 
     27     binmode FH;
     28     binmode FHO;
     29 
     30     while ( ! eof(FH) ) {
     31         if (read(FH, $byte0, $RECSIZE) != $RECSIZE) {
     32             $byte0 = "\000";
     33         }
     34         if (read(FH, $byte1, $RECSIZE) != $RECSIZE) {
     35             $byte1 = "\000";
     36         }
     37         if (read(FH, $byte2, $RECSIZE) != $RECSIZE) {
     38             $byte2 = "\000";
     39         }
     40         if (read(FH, $byte3, $RECSIZE) != $RECSIZE) {
     41             $byte3 = "\000";
     42         }
     43         print FHO $byte3, $byte2 ,$byte1 ,$byte0 ;
     44     }
     45     close FH;  
     46     close FHO;  
     47 
     48     print STDOUT "  done\n";