intl/chardet/tools/genverifier.pm

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 #!/usr/local/bin/perl
     3 # This Source Code Form is subject to the terms of the Mozilla Public
     4 # License, v. 2.0. If a copy of the MPL was not distributed with this
     5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
     7 package genverifier;
     8 use strict;
     9 use vars qw(@ISA @EXPORT @EXPORT_OK $VERSION);
    11 use Exporter;
    12 $VERSION = 1.00;
    13 @ISA = qw(Exporter);
    15 @EXPORT       = qw(
    16                    GenVerifier
    17                   );
    18 @EXPORT_OK    = qw();
    20 sub GenNPL {
    21   my($ret) = << "END_MPL";
    22 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
    23 /* This Source Code Form is subject to the terms of the Mozilla Public
    24  * License, v. 2.0. If a copy of the MPL was not distributed with this
    25  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
    26 END_MPL
    28   return $ret;
    29 }
    31 ##--------------------------------------------------------------
    32 sub GetClass {
    33   my($char, $clstbl) = @_;
    34   my($l);
    35   for($l =0; $l <= @$clstbl; $l++) {
    36     if(($clstbl->[$l][0] <= $char) && ($char <= $clstbl->[$l][1]))
    37     {
    38           return $clstbl->[$l][2];
    39     }
    40   }
    41   print "WARNING- there are no class for $char\n";
    42 };
    43 ##--------------------------------------------------------------
    44 sub GenClassPkg {
    45   my($name, $bits) = @_;
    46   return GenPkg($name, $bits, "_cls");
    47 }
    48 ##--------------------------------------------------------------
    49 sub GenStatePkg {
    50   my($name, $bits) = @_;
    51   return GenPkg($name, $bits, "_st");
    52 };
    53 ##--------------------------------------------------------------
    54 sub GenPkg {
    55   my($name, $bits, $tbl) = @_;
    56   my($ret);
    57   $ret = "  {" .
    58          "eIdxSft"  . $bits . "bits, " .
    59          "eSftMsk"  . $bits . "bits, " .
    60          "eBitSft"  . $bits . "bits, " .
    61          "eUnitMsk" . $bits . "bits, " .
    62          $name . $tbl . "" .
    63         " }";
    64   return $ret;
    65 };
    66 ##--------------------------------------------------------------
    67 sub Gen4BitsClass {
    68   my($name, $clstbl) = @_;
    69   my($i,$j);
    70   my($cls);
    71   my($ret);
    72   $ret = "";
    73   $ret .= "static const uint32_t " . $name . "_cls [ 256 / 8 ] = {\n";
    74   for($i = 0; $i < 0x100; $i+= 8) {
    75      $ret .= "PCK4BITS(";
    76      for($j = $i; $j < $i + 8; $j++) {
    77          $cls = &GetClass($j,$clstbl);
    78          $ret .= sprintf("%2d", $cls) ;
    79          if($j != ($i+7)) {
    80             $ret .= ",";
    81          }
    82      }
    83      if( $i+8 >= 0x100) {
    84         $ret .= ") ";
    85      } else {
    86         $ret .= "),";
    87      }
    88      $ret .= sprintf("  // %02x - %02x\n", $i, ($i+7));
    89   }
    90   $ret .= "};\n";
    91   return $ret;
    92 };
    93 ##--------------------------------------------------------------
    94 sub GenVerifier {
    95   my($name, $charset, $cls, $numcls, $st) = @_;
    96   my($ret);
    97   $ret = GenNPL();
    98   $ret .= GenNote();
    99   $ret .= GenHeader();
   100   $ret .= Gen4BitsClass($name, $cls);
   101   $ret .= "\n\n";
   102   $ret .= Gen4BitsState($name, $st);
   103   $ret .= "\n\n";
   104   $ret .= "const SMModel " . $name . "SMModel = {\n";
   105   $ret .= GenClassPkg($name, 4);
   106   $ret .= ",\n";
   107   $ret .= "   " . $numcls;
   108   $ret .= ",\n";
   109   $ret .= GenStatePkg($name, 4);
   110   $ret .= ",\n";
   111   $ret .= "  " . "CHAR_LEN_TABLE(" . $name . "CharLenTable),\n";
   112   $ret .= '  "' . $charset . '",' . "\n";
   113   $ret .= "};\n";
   114   return $ret;
   116 };
   117 ##--------------------------------------------------------------
   118 sub Gen4BitsState {
   119   my($name, $sttbl) = @_;
   120   my($lenafterpad) = (((@$sttbl-1) >> 3) + 1) << 3;
   121   my($i,$j);
   122   my($ret);
   123   $ret = "";
   124   $ret .= "static const uint32_t " . $name . "_st [ " . ($lenafterpad >> 3) . "] = {\n";
   125   for($i = 0; $i < $lenafterpad ; $i+= 8) {
   126      $ret .= "PCK4BITS(";
   127      for($j = $i; $j < $i + 8; $j++) {
   128          if(0 == $sttbl->[$j]) {
   129               $ret .= "eStart";
   130          } else { if(1 == $sttbl->[$j]) {
   131               $ret .= "eError";
   132          } else { if(2 == $sttbl->[$j]) {
   133               $ret .= "eItsMe";
   134          } else {
   135               $ret .= sprintf("     %d", $sttbl->[$j]) ;
   136          }}}
   137          if($j != ($i+7)) {
   138             $ret .= ",";
   139          }
   140      }
   141      if( $i+8 >= $lenafterpad ) {
   142         $ret .= ") ";
   143      } else {
   144         $ret .= "),";
   145      }
   146      $ret .= sprintf("  // %02x - %02x\n", $i, ($i+7));
   147   }
   148   $ret .= "};\n";
   149   return $ret;
   150 };
   151 ##--------------------------------------------------------------
   153 sub GenNote {
   154   my($ret) = << "END_NOTE";
   155 /*
   156  * DO NOT EDIT THIS DOCUMENT MANUALLY !!!
   157  * THIS FILE IS AUTOMATICALLY GENERATED BY THE TOOLS UNDER
   158  *    mozilla/intl/chardet/tools/
   159  * Please contact ftang\@netscape.com or mozilla-i18n\@mozilla.org
   160  * if you have any question. Thanks
   161  */
   162 END_NOTE
   163   return $ret;
   164 }
   166 ##--------------------------------------------------------------
   167 sub GenHeader {
   168   my($ret) = << "END_HEADER";
   169 #include "nsVerifier.h"
   170 END_HEADER
   172   return $ret;
   173 }
   174 ##--------------------------------------------------------------
   175 1; # this should be the last line

mercurial