Advertisement
Lighta

ra_checkitemdb

Jan 3rd, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.39 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use File::Basename;
  5. use Getopt::Long;
  6.  
  7. my $sItem_db_re = "db/re/item_db.txt";
  8. my $sItem_db_pre = "db/pre-re/item_db.txt";
  9.  
  10. Main();
  11.  
  12. sub Main {
  13.     my($filename, $dir, $suffix) = fileparse($0);
  14.     chdir $dir;
  15.     chdir ".."; #put ourself like was called in main folder
  16.     GetArgs();
  17.    
  18.     my %hDB_re_ID;
  19.     my %hDB_pre_ID;
  20.     my $nb_columns = 22;
  21.     my $line_format = "([^\,]*),"x($nb_columns-3)."(\{.*\}),"x(2)."(\{.*\})"; #Last 3 columns are scripts.
  22.        
  23.     ParseItemDBFile($sItem_db_re,\%hDB_re_ID,$line_format);
  24.     ParseItemDBFile($sItem_db_pre,\%hDB_pre_ID,$line_format);
  25.     #DisplayIDFound("RE",\%hDB_re_ID);
  26.     #DisplayIDFound("pRE",\%hDB_pre_ID);
  27.     SearchAndDisplayMissing("RE","pRE",\%hDB_re_ID,\%hDB_pre_ID);
  28.     SearchAndDisplayMissing("pRE","RE",\%hDB_pre_ID,\%hDB_re_ID);
  29. }
  30.  
  31. sub GetArgs {
  32.     my $sHelp;
  33.     GetOptions(
  34.     'dbre=s' => \$sItem_db_re, #re item db file
  35.     'dbpre=s' => \$sItem_db_pre, #pre item db file
  36.     'help!' => \$sHelp,
  37.     ) or $sHelp=1; #display help if invalid option 
  38.    
  39.     if( $sHelp ) {
  40.     print "Incorect option specified, available option are:\n"
  41.         ."\t --dbre filename => specify wich item re db file to use\n"
  42.         ."\t --dbpre filename => specify wich item pre db file to use\n";
  43.     exit;
  44.     }
  45. }
  46.  
  47. sub DisplayIDFound { my ($sFilename,$rHash) = @_;
  48.     my @aDB_ID = keys %$rHash;
  49.     print "Found $sFilename = [ @aDB_ID ] \n";
  50. }
  51.  
  52. sub ParseItemDBFile { my ($sFilename,$rHash,$sLine_format) = @_;
  53.     open FILE, "<$sFilename" or die "couldn't open file $sFilename \n";
  54.     while(my $ligne=<FILE>){
  55.     if ($ligne =~ /^\s*$/ ) { next; } #skip empty line
  56.         if ($ligne =~ /[^\r\n]+/) {
  57.                 $ligne = $&;
  58.                 if ($ligne =~ /^\/\//) {
  59.                     #print "Comment line founded : $ligne \n";
  60.                     next;
  61.                 }
  62.                 if ($ligne =~ $sLine_format) {
  63.                     my @champ = ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22);
  64.                     $$rHash{$1} = $ligne;
  65.                 }
  66.         }
  67.     }
  68.     close FILE;
  69. }
  70.  
  71. sub SearchAndDisplayMissing { my($sNameSrc,$sNameChk,$rhSrc,$rhChk) = @_;
  72.     print "Checking ID from $sNameSrc are into $sNameChk \n";
  73.     my $sCount = 0;
  74.     my %hChkData = %$rhChk;
  75.     my %hSrcData = %$rhSrc;
  76.     my @aListID = keys %hSrcData;
  77.  
  78.     foreach my $sID(@aListID){
  79.         unless($hChkData{$sID}){
  80.             print "Didn't found in $sNameChk => ID : ".$sID." with line ".$hSrcData{$sID}." \n\n";
  81.             $sCount++;
  82.         }
  83.     }
  84.     unless($sCount){
  85.         print "No missing ID found \n";
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement