michael@0: #!/usr/local/bin/perl michael@0: michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: package genverifier; michael@0: use strict; michael@0: use vars qw(@ISA @EXPORT @EXPORT_OK $VERSION); michael@0: michael@0: use Exporter; michael@0: $VERSION = 1.00; michael@0: @ISA = qw(Exporter); michael@0: michael@0: @EXPORT = qw( michael@0: GenVerifier michael@0: ); michael@0: @EXPORT_OK = qw(); michael@0: michael@0: sub GenNPL { michael@0: my($ret) = << "END_MPL"; michael@0: /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: END_MPL michael@0: michael@0: return $ret; michael@0: } michael@0: michael@0: ##-------------------------------------------------------------- michael@0: sub GetClass { michael@0: my($char, $clstbl) = @_; michael@0: my($l); michael@0: for($l =0; $l <= @$clstbl; $l++) { michael@0: if(($clstbl->[$l][0] <= $char) && ($char <= $clstbl->[$l][1])) michael@0: { michael@0: return $clstbl->[$l][2]; michael@0: } michael@0: } michael@0: print "WARNING- there are no class for $char\n"; michael@0: }; michael@0: ##-------------------------------------------------------------- michael@0: sub GenClassPkg { michael@0: my($name, $bits) = @_; michael@0: return GenPkg($name, $bits, "_cls"); michael@0: } michael@0: ##-------------------------------------------------------------- michael@0: sub GenStatePkg { michael@0: my($name, $bits) = @_; michael@0: return GenPkg($name, $bits, "_st"); michael@0: }; michael@0: ##-------------------------------------------------------------- michael@0: sub GenPkg { michael@0: my($name, $bits, $tbl) = @_; michael@0: my($ret); michael@0: $ret = " {" . michael@0: "eIdxSft" . $bits . "bits, " . michael@0: "eSftMsk" . $bits . "bits, " . michael@0: "eBitSft" . $bits . "bits, " . michael@0: "eUnitMsk" . $bits . "bits, " . michael@0: $name . $tbl . "" . michael@0: " }"; michael@0: return $ret; michael@0: }; michael@0: ##-------------------------------------------------------------- michael@0: sub Gen4BitsClass { michael@0: my($name, $clstbl) = @_; michael@0: my($i,$j); michael@0: my($cls); michael@0: my($ret); michael@0: $ret = ""; michael@0: $ret .= "static const uint32_t " . $name . "_cls [ 256 / 8 ] = {\n"; michael@0: for($i = 0; $i < 0x100; $i+= 8) { michael@0: $ret .= "PCK4BITS("; michael@0: for($j = $i; $j < $i + 8; $j++) { michael@0: $cls = &GetClass($j,$clstbl); michael@0: $ret .= sprintf("%2d", $cls) ; michael@0: if($j != ($i+7)) { michael@0: $ret .= ","; michael@0: } michael@0: } michael@0: if( $i+8 >= 0x100) { michael@0: $ret .= ") "; michael@0: } else { michael@0: $ret .= "),"; michael@0: } michael@0: $ret .= sprintf(" // %02x - %02x\n", $i, ($i+7)); michael@0: } michael@0: $ret .= "};\n"; michael@0: return $ret; michael@0: }; michael@0: ##-------------------------------------------------------------- michael@0: sub GenVerifier { michael@0: my($name, $charset, $cls, $numcls, $st) = @_; michael@0: my($ret); michael@0: $ret = GenNPL(); michael@0: $ret .= GenNote(); michael@0: $ret .= GenHeader(); michael@0: $ret .= Gen4BitsClass($name, $cls); michael@0: $ret .= "\n\n"; michael@0: $ret .= Gen4BitsState($name, $st); michael@0: $ret .= "\n\n"; michael@0: $ret .= "const SMModel " . $name . "SMModel = {\n"; michael@0: $ret .= GenClassPkg($name, 4); michael@0: $ret .= ",\n"; michael@0: $ret .= " " . $numcls; michael@0: $ret .= ",\n"; michael@0: $ret .= GenStatePkg($name, 4); michael@0: $ret .= ",\n"; michael@0: $ret .= " " . "CHAR_LEN_TABLE(" . $name . "CharLenTable),\n"; michael@0: $ret .= ' "' . $charset . '",' . "\n"; michael@0: $ret .= "};\n"; michael@0: return $ret; michael@0: michael@0: }; michael@0: ##-------------------------------------------------------------- michael@0: sub Gen4BitsState { michael@0: my($name, $sttbl) = @_; michael@0: my($lenafterpad) = (((@$sttbl-1) >> 3) + 1) << 3; michael@0: my($i,$j); michael@0: my($ret); michael@0: $ret = ""; michael@0: $ret .= "static const uint32_t " . $name . "_st [ " . ($lenafterpad >> 3) . "] = {\n"; michael@0: for($i = 0; $i < $lenafterpad ; $i+= 8) { michael@0: $ret .= "PCK4BITS("; michael@0: for($j = $i; $j < $i + 8; $j++) { michael@0: if(0 == $sttbl->[$j]) { michael@0: $ret .= "eStart"; michael@0: } else { if(1 == $sttbl->[$j]) { michael@0: $ret .= "eError"; michael@0: } else { if(2 == $sttbl->[$j]) { michael@0: $ret .= "eItsMe"; michael@0: } else { michael@0: $ret .= sprintf(" %d", $sttbl->[$j]) ; michael@0: }}} michael@0: if($j != ($i+7)) { michael@0: $ret .= ","; michael@0: } michael@0: } michael@0: if( $i+8 >= $lenafterpad ) { michael@0: $ret .= ") "; michael@0: } else { michael@0: $ret .= "),"; michael@0: } michael@0: $ret .= sprintf(" // %02x - %02x\n", $i, ($i+7)); michael@0: } michael@0: $ret .= "};\n"; michael@0: return $ret; michael@0: }; michael@0: ##-------------------------------------------------------------- michael@0: michael@0: sub GenNote { michael@0: my($ret) = << "END_NOTE"; michael@0: /* michael@0: * DO NOT EDIT THIS DOCUMENT MANUALLY !!! michael@0: * THIS FILE IS AUTOMATICALLY GENERATED BY THE TOOLS UNDER michael@0: * mozilla/intl/chardet/tools/ michael@0: * Please contact ftang\@netscape.com or mozilla-i18n\@mozilla.org michael@0: * if you have any question. Thanks michael@0: */ michael@0: END_NOTE michael@0: return $ret; michael@0: } michael@0: michael@0: ##-------------------------------------------------------------- michael@0: sub GenHeader { michael@0: my($ret) = << "END_HEADER"; michael@0: #include "nsVerifier.h" michael@0: END_HEADER michael@0: michael@0: return $ret; michael@0: } michael@0: ##-------------------------------------------------------------- michael@0: 1; # this should be the last line