intl/chardet/tools/genverifier.pm

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial