added RESISTANCE to the list of acceptable uppercase words
[project-aon.git] / common / scripts / gblint.pl
index c824503..69cc5d1 100755 (executable)
@@ -70,6 +70,13 @@ my %sectionDocLookup = (
   'howcarry' => 'equipmnt',
   'howmuch'  => 'equipmnt',
   'howuse'   => 'equipmnt',
   'howcarry' => 'equipmnt',
   'howmuch'  => 'equipmnt',
   'howuse'   => 'equipmnt',
+  'backpack' => 'equipmnt',
+  'ammpouch' => 'equipmnt',
+  'medikit'  => 'equipmnt',
+  'canteen'  => 'equipmnt',
+  'weapons'  => 'weapons',
+  'close'    => 'weapons',
+  'missile'  => 'weapons',
   'cmbtrulz' => 'cmbtrulz',
   'evasion'  => 'cmbtrulz',
   'lorecrcl' => 'lorecrcl',
   'cmbtrulz' => 'cmbtrulz',
   'evasion'  => 'cmbtrulz',
   'lorecrcl' => 'lorecrcl',
@@ -167,10 +174,14 @@ while( $#ARGV > -1 && $ARGV[ 0 ] =~ /^-/ ) {
     shift @ARGV;
     $language = shift @ARGV;
   }
     shift @ARGV;
     $language = shift @ARGV;
   }
+  elsif( $ARGV[ 0 ] eq '-h' ) {
+    usage();
+    exit 0;
+  }
 }
 
 my $lineNumber = 1;
 }
 
 my $lineNumber = 1;
-my $currentSection = "_unknown";
+my $currentSection = '';
 
 while( my $line = <> ) {
   my @section = ( $line =~ /<section[^>]+id="([^"]*)"/g );
 
 while( my $line = <> ) {
   my @section = ( $line =~ /<section[^>]+id="([^"]*)"/g );
@@ -182,6 +193,7 @@ while( my $line = <> ) {
     else {
       $currentSection = $sectionDocLookup{$section[ 0 ]};
     }
     else {
       $currentSection = $sectionDocLookup{$section[ 0 ]};
     }
+    $currentSection = '_unknown' unless defined $currentSection;
   }
 
   if( $skipLines >= $lineNumber ) {
   }
 
   if( $skipLines >= $lineNumber ) {
@@ -223,7 +235,7 @@ while( my $line = <> ) {
 
   # ellipsis
   if( $line =~ /(\.\s*\.(\s*\.)?)/ ) { &printError( "ne", $currentSection, $lineNumber, "possible malformed ellipsis", "$1", "<ch.ellips/> or <ch.lellips/>" ); }
 
   # ellipsis
   if( $line =~ /(\.\s*\.(\s*\.)?)/ ) { &printError( "ne", $currentSection, $lineNumber, "possible malformed ellipsis", "$1", "<ch.ellips/> or <ch.lellips/>" ); }
-  if( $line =~ m{([[:space:]]<ch\.ellips/>)} || $line =~ m{(<ch\.ellips/>[[:space:]])} ) { &printError( "ne", $currentSection, $lineNumber, "<ch.ellips/> with extraneous surrounding space", "$1", "<ch.ellips/>" ); }
+  if( $line =~ m{([[:space:]]<ch\.ellips/>)}) { &printError( "ne", $currentSection, $lineNumber, "<ch.ellips/> with extraneous surrounding space", "$1", "<ch.ellips/>" ); }
   if( $line =~ m{([^>])(<ch\.lellips/>)} ) { &printError( "ne", $currentSection, $lineNumber, "possible <ch.lellips/> used in place of <ch.ellips/>", "$1$2", "$1<ch.ellips/>" ); }
   if( $line =~ m{(><ch\.ellips/>)} ) { &printError( "ne", $currentSection, $lineNumber, "possible <ch.ellips/> used in place of <ch.lellips/>", "$1", "><ch.lellips/>" ); }
 
   if( $line =~ m{([^>])(<ch\.lellips/>)} ) { &printError( "ne", $currentSection, $lineNumber, "possible <ch.lellips/> used in place of <ch.ellips/>", "$1$2", "$1<ch.ellips/>" ); }
   if( $line =~ m{(><ch\.ellips/>)} ) { &printError( "ne", $currentSection, $lineNumber, "possible <ch.ellips/> used in place of <ch.lellips/>", "$1", "><ch.lellips/>" ); }
 
@@ -295,6 +307,8 @@ while( my $line = <> ) {
         $1 ne "COMBAT" &&
         $1 ne "WILLPOWER" &&
         $1 ne "HAVOC" &&
         $1 ne "COMBAT" &&
         $1 ne "WILLPOWER" &&
         $1 ne "HAVOC" &&
+        $1 ne "TARGET" &&
+        $1 ne "RESISTANCE" &&
         $1 ne "CLOSE") ||
        ($language eq 'es' &&
         $1 ne 'DESTREZA' &&
         $1 ne "CLOSE") ||
        ($language eq 'es' &&
         $1 ne 'DESTREZA' &&
@@ -335,3 +349,16 @@ sub printError {
   ++$errorCount;
   if( $maxErrorCount > 0 && $errorCount > $maxErrorCount ) { die "Maximum number of errors ($maxErrorCount) exceeded. Quitting.\n"; }
 }
   ++$errorCount;
   if( $maxErrorCount > 0 && $errorCount > $maxErrorCount ) { die "Maximum number of errors ($maxErrorCount) exceeded. Quitting.\n"; }
 }
+
+sub usage {
+    print "Gamebook lintian checker - reads from standard input a gamebook XML file and prints out possible errors\n\n";
+    print "Usage: gblint.pl [-e <NUMBER>] [-s <NUMBER>] [-i <TEXT>] [--use-corr] [--skip-ASCII-check] [--language CODE]\n";
+    print "Options:\n";
+    print "\t-e <NUMBER>\tStops when NUMBER errors have been reached (by default it does not stop)\n";
+    print "\t-s <NUMBER>\tSkips NUMBER of lines before analysing\n";
+    print "\t-i <TEXT>\tAdds TEXT to error messages (default: '??')\n";
+    print "\t--use-corr\tPrints correction in report (default: disabled)\n";
+    print "\t--skip-ASCII-check\tDoes not check for non-ASCCI characters (default: enabled)\n";
+    print "\t--language CODE\tDefines the language of the gamebook file (default: 'en'\n";
+    print "\t-h\tPrint this help and exit\n";
+}